Skip to content

Commit

Permalink
Fixed NullPointerException when exports dir was missing
Browse files Browse the repository at this point in the history
  • Loading branch information
lowleveldesign committed Dec 9, 2023
1 parent 971cb02 commit b23c8a2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions withdll/DllInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@ private static bool ExportsOrdinal1(string modulePath)
using var pereader = new PEReader(File.OpenRead(modulePath));

var exportsDirEntry = pereader.PEHeaders.PEHeader!.ExportTableDirectory;
unsafe
if (exportsDirEntry.RelativeVirtualAddress != 0)
{
var exportsDir = (IMAGE_EXPORT_DIRECTORY*)pereader.GetSectionData(exportsDirEntry.RelativeVirtualAddress).Pointer;

if (exportsDir->Base == 1)
unsafe
{
return ((uint*)pereader.GetSectionData((int)exportsDir->AddressOfFunctions).Pointer)[0] != 0;
}
var exportsDir = (IMAGE_EXPORT_DIRECTORY*)pereader.GetSectionData(exportsDirEntry.RelativeVirtualAddress).Pointer;

return false;
if (exportsDir->Base == 1)
{
return ((uint*)pereader.GetSectionData((int)exportsDir->AddressOfFunctions).Pointer)[0] != 0;
}
}
}
return false;
}

public static void StartProcessWithDlls(List<string> cmdlineArgs, bool debug, List<string> dllPaths)
Expand Down

0 comments on commit b23c8a2

Please sign in to comment.