mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-02-06 13:47:36 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf35b7c10b | ||
|
|
4026b8ca09 | ||
|
|
6d2e2d8c3b | ||
|
|
a2b08157cc |
@@ -10,7 +10,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>1.9.4</Version>
|
||||
<Version>1.9.5</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support All Frameworks -->
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>1.9.4</Version>
|
||||
<Version>1.9.5</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support All Frameworks -->
|
||||
|
||||
@@ -420,7 +420,14 @@ namespace SabreTools.Serialization.Deserializers
|
||||
obj.RelocationRecords = new RelocationRecord[obj.RelocationRecordCount];
|
||||
for (int i = 0; i < obj.RelocationRecords.Length; i++)
|
||||
{
|
||||
obj.RelocationRecords[i] = ParseRelocationRecord(data);
|
||||
if (data.Position >= data.Length)
|
||||
break;
|
||||
|
||||
var record = ParseRelocationRecord(data);
|
||||
if (record == null)
|
||||
break;
|
||||
|
||||
obj.RelocationRecords[i] = record;
|
||||
}
|
||||
|
||||
return obj;
|
||||
@@ -433,12 +440,20 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// <returns>Filled RelocationRecord on success, null on error</returns>
|
||||
public static RelocationRecord ParseRelocationRecord(Stream data)
|
||||
{
|
||||
// Handle partial relocation sections
|
||||
if (data.Position > data.Length - 4)
|
||||
return null;
|
||||
|
||||
var obj = new RelocationRecord();
|
||||
|
||||
obj.SourceType = (RelocationRecordSourceType)data.ReadByteValue();
|
||||
obj.Flags = (RelocationRecordFlag)data.ReadByteValue();
|
||||
obj.Offset = data.ReadUInt16LittleEndian();
|
||||
|
||||
// Handle incomplete entries
|
||||
if (data.Position > data.Length - 4)
|
||||
return obj;
|
||||
|
||||
switch (obj.Flags & RelocationRecordFlag.TARGET_MASK)
|
||||
{
|
||||
case RelocationRecordFlag.INTERNALREF:
|
||||
|
||||
@@ -337,11 +337,11 @@ namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
Name = new ResourceDirectoryString { UnicodeString = Encoding.Unicode.GetBytes("HIDDEN RESOURCE") },
|
||||
IntegerID = uint.MaxValue,
|
||||
DataEntryOffset = (uint)data.Position,
|
||||
DataEntryOffset = (uint)tableOffset,
|
||||
DataEntry = new ResourceDataEntry
|
||||
{
|
||||
Size = (uint)length,
|
||||
Data = data.ReadBytes(length),
|
||||
Data = tableData.ReadBytes(ref tableOffset, length),
|
||||
Codepage = (uint)Encoding.Unicode.CodePage,
|
||||
},
|
||||
};
|
||||
@@ -1601,7 +1601,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
continue;
|
||||
|
||||
// If the offset is within the table data, read from there
|
||||
if (nextOffset - tableStart + entry.DataEntry.Size <= tableLength)
|
||||
if (nextOffset > tableStart && nextOffset - tableStart + entry.DataEntry.Size <= tableLength)
|
||||
{
|
||||
dataOffset = (int)(nextOffset - tableStart);
|
||||
entry.DataEntry.Data = tableData.ReadBytes(ref dataOffset, (int)entry.DataEntry.Size);
|
||||
|
||||
@@ -729,7 +729,7 @@ namespace SabreTools.Serialization
|
||||
#region Creation data
|
||||
|
||||
dialogItemTemplate.CreationDataSize = entry.Data.ReadUInt16LittleEndian(ref offset);
|
||||
if (dialogItemTemplate.CreationDataSize != 0)
|
||||
if (dialogItemTemplate.CreationDataSize != 0 && dialogItemTemplate.CreationDataSize + offset < entry.Data.Length)
|
||||
dialogItemTemplate.CreationData = entry.Data.ReadBytes(ref offset, dialogItemTemplate.CreationDataSize);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>1.9.4</Version>
|
||||
<Version>1.9.5</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
|
||||
@@ -703,6 +703,14 @@ namespace SabreTools.Serialization.Wrappers
|
||||
if (magic.StartsWith([0x3C, 0x3F, 0x78, 0x6D, 0x6C]))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// "<?xml" in UTF-16 encoding
|
||||
if (magic.StartsWith([0x3C, 0x00, 0x3F, 0x00, 0x78, 0x00, 0x6D, 0x00, 0x6C, 0x00]))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// "<?xml" in UTF-16 encoding with byte order marks
|
||||
if (magic.StartsWith([0xFF, 0xFE, 0x3C, 0x00, 0x3F, 0x00, 0x78, 0x00, 0x6D, 0x00, 0x6C, 0x00]))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// "Description in Zip"
|
||||
if (extension.Equals("diz", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
Reference in New Issue
Block a user