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