Skip to content

Commit 3a485d3

Browse files
committed
Correct a couple of things
1 parent e1da5f1 commit 3a485d3

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

SabreTools.Serialization/Models/PortableExecutable/Resource/DirectoryEntry.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/// IMAGE_DIRECTORY_ENTRY_RESOURCE DataDirectory.
1818
/// </summary>
1919
/// <see href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format"/>
20+
/// <see href="https://learn.microsoft.com/en-us/previous-versions/ms809762(v=msdn.10)#pe-file-resources"/>
2021
public sealed class DirectoryEntry
2122
{
2223
#region Offset 0x00

SabreTools.Serialization/Readers/PortableExecutable.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ public class PortableExecutable : BaseBinaryReader<Executable>
326326
tableData,
327327
ref tableOffset,
328328
offset,
329-
(int)optionalHeader.ResourceTable.Size,
330-
pex.ResourceDirectoryTable, pex.SectionTable);
329+
optionalHeader.ResourceTable.Size,
330+
pex.ResourceDirectoryTable,
331+
pex.SectionTable);
331332

332333
#region Hidden Resources
333334

@@ -1513,21 +1514,16 @@ public static Data.Models.PortableExecutable.Resource.DataEntry ParseResourceDat
15131514
/// </summary>
15141515
/// <param name="data">Byte array to parse</param>
15151516
/// <param name="offset">Offset into the byte array</param>
1516-
/// <param name="nameEntry">Indicates if the value is a name entry or not</param>
15171517
/// <returns>Filled ResourceDirectoryEntry on success, null on error</returns>
1518-
public static Data.Models.PortableExecutable.Resource.DirectoryEntry ParseResourceDirectoryEntry(byte[] data, ref int offset, bool nameEntry)
1518+
public static Data.Models.PortableExecutable.Resource.DirectoryEntry ParseResourceDirectoryEntry(byte[] data, ref int offset)
15191519
{
15201520
var obj = new Data.Models.PortableExecutable.Resource.DirectoryEntry();
15211521

1522-
// TODO: Figure out why the high bit is set for names
1523-
// The original version of this code also had this fix, but there
1524-
// was no comment or documentation as to why. The official MSDN
1525-
// documentation makes no mention of the high bit being set here,
1526-
// only for the offset below.
1527-
if (nameEntry)
1528-
obj.NameOffset = data.ReadUInt32LittleEndian(ref offset) & ~0x80000000U;
1522+
uint nameField = data.ReadUInt32LittleEndian(ref offset);
1523+
if ((nameField & 0x80000000) != 0)
1524+
obj.NameOffset = nameField & ~0x80000000U;
15291525
else
1530-
obj.IntegerID = data.ReadUInt32LittleEndian(ref offset);
1526+
obj.IntegerID = nameField;
15311527

15321528
uint offsetField = data.ReadUInt32LittleEndian(ref offset);
15331529
if ((offsetField & 0x80000000) != 0)
@@ -1587,11 +1583,10 @@ public static Data.Models.PortableExecutable.Resource.DirectoryString ParseResou
15871583
// Perform top-level pass of data
15881584
for (int i = 0; i < totalEntryCount; i++)
15891585
{
1590-
bool nameEntry = i < obj.NumberOfNameEntries;
1591-
obj.Entries[i] = ParseResourceDirectoryEntry(tableData, ref offset, nameEntry);
1586+
obj.Entries[i] = ParseResourceDirectoryEntry(tableData, ref offset);
15921587

15931588
// Read the name from the offset, if needed
1594-
if (nameEntry && obj.Entries[i].NameOffset > 0 && obj.Entries[i].NameOffset < tableData.Length)
1589+
if (obj.Entries[i].NameOffset > 0 && obj.Entries[i].NameOffset < tableData.Length)
15951590
{
15961591
int nameOffset = (int)obj.Entries[i].NameOffset;
15971592
obj.Entries[i].Name = ParseResourceDirectoryString(tableData, ref nameOffset);

0 commit comments

Comments
 (0)