diff --git a/Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs b/Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs index 50b05c21..3546ef32 100644 --- a/Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs +++ b/Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs @@ -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); diff --git a/LibCpp2IL/PE/PE.cs b/LibCpp2IL/PE/PE.cs index 9323ded7..7677a1f8 100644 --- a/LibCpp2IL/PE/PE.cs +++ b/LibCpp2IL/PE/PE.cs @@ -184,12 +184,22 @@ private void LoadPeExportTable() addrExportTable = peOptionalHeader64.DataDirectory.First().VirtualAddress; } - //Non-virtual addresses for these - var directoryEntryExports = ReadClassAtVirtualAddress(addrExportTable + peImageBase); + try + { + //Non-virtual addresses for these + var directoryEntryExports = ReadClassAtVirtualAddress(addrExportTable + peImageBase); - peExportedFunctionPointers = ReadClassArrayAtVirtualAddress(directoryEntryExports.RawAddressOfExportTable + peImageBase, directoryEntryExports.NumberOfExports); - peExportedFunctionNamePtrs = ReadClassArrayAtVirtualAddress(directoryEntryExports.RawAddressOfExportNameTable + peImageBase, directoryEntryExports.NumberOfExportNames); - peExportedFunctionOrdinals = ReadClassArrayAtVirtualAddress(directoryEntryExports.RawAddressOfExportOrdinalTable + peImageBase, directoryEntryExports.NumberOfExportNames); //This uses the name count per MSoft spec + peExportedFunctionPointers = ReadClassArrayAtVirtualAddress(directoryEntryExports.RawAddressOfExportTable + peImageBase, directoryEntryExports.NumberOfExports); + peExportedFunctionNamePtrs = ReadClassArrayAtVirtualAddress(directoryEntryExports.RawAddressOfExportNameTable + peImageBase, directoryEntryExports.NumberOfExportNames); + peExportedFunctionOrdinals = ReadClassArrayAtVirtualAddress(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(); + peExportedFunctionNamePtrs = Array.Empty(); + peExportedFunctionOrdinals = Array.Empty(); + } } public override ulong GetVirtualAddressOfExportedFunctionByName(string toFind)