From b23c8a21cec648523b4157ce139fd41573cbba27 Mon Sep 17 00:00:00 2001 From: Sebastian Solnica Date: Sat, 9 Dec 2023 08:09:13 +0100 Subject: [PATCH] Fixed NullPointerException when exports dir was missing --- withdll/DllInjection.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/withdll/DllInjection.cs b/withdll/DllInjection.cs index 64c2f60..fbd0e52 100644 --- a/withdll/DllInjection.cs +++ b/withdll/DllInjection.cs @@ -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 cmdlineArgs, bool debug, List dllPaths)