Skip to content

Commit

Permalink
Finish task and publish 2.7.710.0 version
Browse files Browse the repository at this point in the history
Finish task and publish 2.7.710.0 version
  • Loading branch information
Gaoyifei1011 committed Jul 10, 2024
1 parent bd11ebb commit 4bcad96
Show file tree
Hide file tree
Showing 56 changed files with 2,738 additions and 302 deletions.
12 changes: 12 additions & 0 deletions WindowsTools/Extensions/DataType/Enums/Decision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using WindowsTools.Extensions.PriExtract;

namespace WindowsTools.Extensions.DataType.Enums
{
public class Decision
{
public ushort Index { get; set; }

public IReadOnlyList<QualifierSet> QualifierSetsList { get; set; }
}
}
13 changes: 13 additions & 0 deletions WindowsTools/Extensions/DataType/Enums/PriDescriptorFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace WindowsTools.Extensions.DataType.Enums
{
[Flags]
public enum PriDescriptorFlags : ushort
{
AutoMerge = 1,
IsDeploymentMergeable = 2,
IsDeploymentMergeResult = 4,
IsAutomergeMergeResult = 8
}
}
18 changes: 18 additions & 0 deletions WindowsTools/Extensions/DataType/Enums/QualifierType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace WindowsTools.Extensions.DataType.Enums
{
public enum QualifierType
{
Language,
Contrast,
Scale,
HomeRegion,
TargetSize,
LayoutDirection,
Theme,
AlternateForm,
DXFeatureLevel,
Configuration,
DeviceFamily,
Custom
}
}
13 changes: 13 additions & 0 deletions WindowsTools/Extensions/DataType/Enums/ResourceValueType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace WindowsTools.Extensions.DataType.Enums
{
public enum ResourceValueType
{
UnicodeString,
UnicodePath,
EmbeddedData,
AsciiString,
Utf8String,
AsciiPath,
Utf8Path
}
}
53 changes: 53 additions & 0 deletions WindowsTools/Extensions/DataType/Methods/BinaryReaderExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.IO;
using System.Text;

namespace WindowsTools.Extensions.DataType.Methods
{
/// <summary>
/// BinaryReader 类的扩展方法
/// </summary>
public static class BinaryReaderExtension
{
public static void ExpectUInt16(this BinaryReader reader, ushort expectedValue)
{
if (reader.ReadUInt16() != expectedValue)
{
throw new InvalidDataException("Unexpected value read.");
}
}

public static void ExpectUInt32(this BinaryReader reader, uint expectedValue)
{
if (reader.ReadUInt32() != expectedValue)
{
throw new InvalidDataException("Unexpected value read.");
}
}

public static void ExpectString(this BinaryReader reader, string s)
{
if (new string(reader.ReadChars(s.Length)) != s)
{
throw new InvalidDataException("Unexpected value read.");
}
}

public static string ReadString(this BinaryReader reader, Encoding encoding, int length)
{
using BinaryReader r = new(reader.BaseStream, encoding, true);
return new string(r.ReadChars(length));
}

public static string ReadNullTerminatedString(this BinaryReader reader, Encoding encoding)
{
using BinaryReader binaryReader = new(reader.BaseStream, encoding, true);
StringBuilder result = new();
char c;
while ((c = binaryReader.ReadChar()) != '\0')
{
result.Append(c);
}
return result.ToString();
}
}
}
9 changes: 9 additions & 0 deletions WindowsTools/Extensions/PriExtract/ByteSpan.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace WindowsTools.Extensions.PriExtract
{
public class ByteSpan
{
public long Offset { get; set; }

public uint Length { get; set; }
}
}
18 changes: 18 additions & 0 deletions WindowsTools/Extensions/PriExtract/Candidate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using WindowsTools.Extensions.DataType.Enums;

namespace WindowsTools.Extensions.PriExtract
{
public class Candidate
{
public ushort QualifierSet { get; set; }

public ResourceValueType Type { get; set; }

public int? SourceFileIndex { get; set; }

public Tuple<ushort, ushort> DataItemSectionAndIndex { get; set; }

public ByteSpan Data { get; set; }
}
}
20 changes: 20 additions & 0 deletions WindowsTools/Extensions/PriExtract/CandidateInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using WindowsTools.Extensions.DataType.Enums;

namespace WindowsTools.Extensions.PriExtract
{
public class CandidateInfo
{
public byte Type { get; set; }

public ResourceValueType ResourceValueType { get; set; }

public ushort SourceFileIndex { get; set; }

public ushort DataItemIndex { get; set; }
public ushort DataItemSection { get; set; }

public ushort DataLength { get; set; }

public uint DataOffset { get; set; }
}
}
14 changes: 14 additions & 0 deletions WindowsTools/Extensions/PriExtract/CandidateSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;

namespace WindowsTools.Extensions.PriExtract
{
public class CandidateSet
{
public Tuple<int, int> ResourceMapSectionAndIndex { get; set; }

public ushort DecisionIndex { get; set; }

public IReadOnlyList<Candidate> CandidatesList { get; set; }
}
}
80 changes: 80 additions & 0 deletions WindowsTools/Extensions/PriExtract/DataItemSection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using WindowsTools.Extensions.DataType.Methods;

namespace WindowsTools.Extensions.PriExtract
{
public class DataItemSection
{
public uint SectionQualifier { get; private set; }

public uint Flags { get; private set; }

public uint SectionFlags { get; private set; }

public uint SectionLength { get; private set; }

public IReadOnlyList<ByteSpan> DataItemsList { get; private set; }

public DataItemSection(string sectionIdentifier, BinaryReader binaryReader)
{
if (new string(binaryReader.ReadChars(16)) != sectionIdentifier)
{
throw new InvalidDataException("Unexpected section identifier.");
}

SectionQualifier = binaryReader.ReadUInt32();
Flags = binaryReader.ReadUInt16();
SectionFlags = binaryReader.ReadUInt16();
SectionLength = binaryReader.ReadUInt32();
binaryReader.ExpectUInt32(0);

binaryReader.BaseStream.Seek(SectionLength - 16 - 24, SeekOrigin.Current);

binaryReader.ExpectUInt32(0xDEF5FADE);
binaryReader.ExpectUInt32(SectionLength);

binaryReader.BaseStream.Seek(-8 - (SectionLength - 16 - 24), SeekOrigin.Current);

using SubStream subStream = new(binaryReader.BaseStream, binaryReader.BaseStream.Position, (int)SectionLength - 16 - 24);
using BinaryReader subBinaryReader = new(subStream, Encoding.ASCII);

long sectionPosition = (binaryReader.BaseStream as SubStream)?.SubStreamPosition ?? 0;

binaryReader.ExpectUInt32(0);
ushort numStrings = binaryReader.ReadUInt16();
ushort numBlobs = binaryReader.ReadUInt16();
uint totalDataLength = binaryReader.ReadUInt32();

List<ByteSpan> dataItemsList = new(numStrings + numBlobs);

long dataStartOffset = binaryReader.BaseStream.Position +
numStrings * 2 * sizeof(ushort) + numBlobs * 2 * sizeof(uint);

for (int i = 0; i < numStrings; i++)
{
ushort stringOffset = binaryReader.ReadUInt16();
ushort stringLength = binaryReader.ReadUInt16();
dataItemsList.Add(new ByteSpan()
{
Offset = sectionPosition + dataStartOffset + stringOffset,
Length = stringLength
});
}

for (int i = 0; i < numBlobs; i++)
{
uint blobOffset = binaryReader.ReadUInt32();
uint blobLength = binaryReader.ReadUInt32();
dataItemsList.Add(new ByteSpan()
{
Offset = sectionPosition + dataStartOffset + blobOffset,
Length = blobLength
});
}

DataItemsList = dataItemsList;
}
}
}
9 changes: 9 additions & 0 deletions WindowsTools/Extensions/PriExtract/DecisionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace WindowsTools.Extensions.PriExtract
{
public class DecisionInfo
{
public ushort FirstQualifierSetIndexIndex { get; set; }

public ushort NumQualifierSetsInDecision { get; set; }
}
}
Loading

0 comments on commit 4bcad96

Please sign in to comment.