Compare commits

..

8 Commits
1.9.3 ... 1.9.5

Author SHA1 Message Date
Matt Nadareski
bf35b7c10b Bump version 2025-09-21 12:35:37 -04:00
Matt Nadareski
4026b8ca09 Handle differently-encoded XMLs as textfiles 2025-09-21 12:10:58 -04:00
Matt Nadareski
6d2e2d8c3b Handle some invalid parsing cases that were missed previously 2025-09-21 11:44:58 -04:00
Matt Nadareski
a2b08157cc Fix issue with split resource tables 2025-09-21 11:23:53 -04:00
Matt Nadareski
0108ecf4c1 Bump version 2025-09-21 09:33:55 -04:00
Matt Nadareski
4921da0bb5 Fix issues from porting MPQ from BOS 2025-09-21 00:04:16 -04:00
Matt Nadareski
0c836bb3b1 Try one more thing? 2025-09-20 23:39:49 -04:00
Matt Nadareski
a8e41c1505 Try this 2025-09-20 23:24:12 -04:00
8 changed files with 59 additions and 13 deletions

View File

@@ -10,7 +10,7 @@
<Nullable>enable</Nullable>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.9.3</Version>
<Version>1.9.5</Version>
</PropertyGroup>
<!-- Support All Frameworks -->

View File

@@ -10,7 +10,7 @@
<Nullable>enable</Nullable>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.9.3</Version>
<Version>1.9.5</Version>
</PropertyGroup>
<!-- Support All Frameworks -->

View File

@@ -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:

View File

@@ -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);

View File

@@ -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

View File

@@ -8,11 +8,13 @@
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<IncludeSymbols>true</IncludeSymbols>
<LangVersion>latest</LangVersion>
<!-- Added due to StormLibSharp -->
<NoWarn>CS8600;CS8601;CS8603;CS8604;CS8618;CS8625;CS8634;IL3000</NoWarn>
<Nullable>enable</Nullable>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.9.3</Version>
<Version>1.9.5</Version>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
@@ -26,6 +28,28 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
<!-- Support All Frameworks -->
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`)) OR $(TargetFramework.StartsWith(`net4`))">
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<!-- Set a build flag for Windows specifically -->
<PropertyGroup Condition="'$(RuntimeIdentifier)'=='win-x86'">
<DefineConstants>$(DefineConstants);WINX86</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(RuntimeIdentifier)'=='win-x64'">
<DefineConstants>$(DefineConstants);WINX64</DefineConstants>
</PropertyGroup>
<!-- Exclude certain parts of external modules for by default -->
<PropertyGroup>
<DefaultItemExcludes>
@@ -36,9 +60,8 @@
</DefaultItemExcludes>
</PropertyGroup>
<!-- Exclude all external modules for .NET Framework 2.0, .NET Framework 3.5, or non-Windows
builds -->
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`)) OR !$(RuntimeIdentifier.StartsWith(`win-x86`))">
<!-- Exclude all external modules for .NET Framework 2.0, .NET Framework 3.5, or non-Windows builds -->
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`)) OR !($(RuntimeIdentifier.StartsWith(`win-x86`)) OR $(RuntimeIdentifier.StartsWith(`win-x64`)))">
<DefaultItemExcludes>
$(DefaultItemExcludes);
_EXTERNAL\**

View File

@@ -1,6 +1,7 @@
using System;
using SabreTools.Serialization.Interfaces;
#if (NET452_OR_GREATER || NETCOREAPP) && (WINX86 || WINX64)
using System.IO;
using StormLibSharp;
#endif
@@ -42,7 +43,6 @@ namespace SabreTools.Serialization.Wrappers
// Loop over each entry
foreach (string sub in listfileLines)
{
// Ensure directory separators are consistent
string filename = sub;
if (Path.DirectorySeparatorChar == '\\')
filename = filename.Replace('/', '\\');
@@ -50,7 +50,7 @@ namespace SabreTools.Serialization.Wrappers
filename = filename.Replace('\\', '/');
// Ensure the full output directory exists
filename = Path.Combine(outDir, filename);
filename = Path.Combine(outputDirectory, filename);
var directoryName = Path.GetDirectoryName(filename);
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);

View File

@@ -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;