Skip to content

Commit

Permalink
Fix collection was modified exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Byass committed Oct 4, 2021
1 parent 1b834be commit 985a2e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,9 @@ public StringBuilder GetFullDumpNoIL()
public void AnalyzeMethod()
{
//Main instruction loop
foreach (var instruction in _instructions)
for (var index = 0; index < _instructions.Count; index++)
{
var instruction = _instructions[index];
try
{
PerformInstructionChecks(instruction);
Expand Down
20 changes: 15 additions & 5 deletions LibCpp2IL/PE/PE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,22 @@ private void LoadPeExportTable()
addrExportTable = peOptionalHeader64.DataDirectory.First().VirtualAddress;
}

//Non-virtual addresses for these
var directoryEntryExports = ReadClassAtVirtualAddress<PeDirectoryEntryExport>(addrExportTable + peImageBase);
try
{
//Non-virtual addresses for these
var directoryEntryExports = ReadClassAtVirtualAddress<PeDirectoryEntryExport>(addrExportTable + peImageBase);

peExportedFunctionPointers = ReadClassArrayAtVirtualAddress<uint>(directoryEntryExports.RawAddressOfExportTable + peImageBase, directoryEntryExports.NumberOfExports);
peExportedFunctionNamePtrs = ReadClassArrayAtVirtualAddress<uint>(directoryEntryExports.RawAddressOfExportNameTable + peImageBase, directoryEntryExports.NumberOfExportNames);
peExportedFunctionOrdinals = ReadClassArrayAtVirtualAddress<ushort>(directoryEntryExports.RawAddressOfExportOrdinalTable + peImageBase, directoryEntryExports.NumberOfExportNames); //This uses the name count per MSoft spec
peExportedFunctionPointers = ReadClassArrayAtVirtualAddress<uint>(directoryEntryExports.RawAddressOfExportTable + peImageBase, directoryEntryExports.NumberOfExports);
peExportedFunctionNamePtrs = ReadClassArrayAtVirtualAddress<uint>(directoryEntryExports.RawAddressOfExportNameTable + peImageBase, directoryEntryExports.NumberOfExportNames);
peExportedFunctionOrdinals = ReadClassArrayAtVirtualAddress<ushort>(directoryEntryExports.RawAddressOfExportOrdinalTable + peImageBase, directoryEntryExports.NumberOfExportNames); //This uses the name count per MSoft spec
}
catch (EndOfStreamException)
{
LibLogger.WarnNewline($"PE does not appear to contain a valid export table! It would be apparently located at virt address 0x{addrExportTable + peImageBase:X}, raw 0x{MapVirtualAddressToRaw(addrExportTable + peImageBase):X}, but that's beyond the end of the binary. No exported functions will be accessible.");
peExportedFunctionPointers = Array.Empty<uint>();
peExportedFunctionNamePtrs = Array.Empty<uint>();
peExportedFunctionOrdinals = Array.Empty<ushort>();
}
}

public override ulong GetVirtualAddressOfExportedFunctionByName(string toFind)
Expand Down

0 comments on commit 985a2e8

Please sign in to comment.