Skip to content

Commit

Permalink
Fixes IAT
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Sep 20, 2024
1 parent c60b1e7 commit 34b7655
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/LibObjectFile/PE/DataDirectory/PEImportDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override void Read(PEImageReader reader)
}

// Calculate its position within the original stream
var importLookupAddressTablePositionInFile = section.Position + rawEntry.ImportLookupTableRVA - section.VirtualAddress;
var importLookupAddressTablePositionInFile = section.Position + rawEntry.ImportAddressTableRVA - section.VirtualAddress;

// Find the section data for the ImportLookupTableRVA
if (!reader.File.TryFindSection(rawEntry.ImportLookupTableRVA, out section))
Expand Down
11 changes: 8 additions & 3 deletions src/LibObjectFile/PE/PEFile.Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,14 @@ private static void FillSectionDataWithMissingStreams(PEImageReader imageReader,
{
var currentPosition = startPosition;

for (var i = 0; i < dataParts.Count; i++)
// We are working on position, while the list is ordered by VirtualAddress
var listOrderedByPosition = new List<PESectionData>();
listOrderedByPosition.AddRange(dataParts.UnsafeList);
listOrderedByPosition.Sort((a, b) => a.Position.CompareTo(b.Position));

for (var i = 0; i < listOrderedByPosition.Count; i++)
{
var data = dataParts[i];
var data = listOrderedByPosition[i];
if (currentPosition < data.Position)
{
var sectionData = new PEStreamSectionData()
Expand All @@ -407,7 +412,7 @@ private static void FillSectionDataWithMissingStreams(PEImageReader imageReader,
imageReader.Position = currentPosition;
sectionData.Stream = imageReader.ReadAsStream(size);

dataParts.Insert(i, sectionData);
dataParts.Insert(data.Index, sectionData);
currentPosition = data.Position;
i++;
}
Expand Down

0 comments on commit 34b7655

Please sign in to comment.