From 1ae589ed03110263d4ecd393cee97dbb7226c765 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Sat, 21 Sep 2019 23:11:20 +0200 Subject: DLLHelper can now fixup other DLL imports and TestDLL links static against MSVCRT runtime --- MemDriverLib/DLLHelper.cpp | 8 ++++---- TestDLL/TestDLL.vcxproj | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/MemDriverLib/DLLHelper.cpp b/MemDriverLib/DLLHelper.cpp index bd76552..78fdf83 100644 --- a/MemDriverLib/DLLHelper.cpp +++ b/MemDriverLib/DLLHelper.cpp @@ -28,7 +28,7 @@ static HMODULE GetRemoteModuleHandle(char *module_name, for (auto& mod : modules) { remote_module_name_length = strnlen(mod.BaseDllName, sizeof mod.BaseDllName); if (strlen(module_name) == remote_module_name_length && - !strncmp(module_name, mod.BaseDllName, remote_module_name_length)) + !_strnicmp(module_name, mod.BaseDllName, remote_module_name_length)) { return (HMODULE)mod.DllBase; } @@ -201,7 +201,7 @@ bool DLLHelper::FixImports() // Loop through all the required modules while ((module_name = (char *)GetPtrFromRVA((DWORD)(impDesc->Name), m_NTHeader, - (PBYTE)m_TargetBaseAddress))) + (PBYTE)m_DLLPtr))) { HMODULE localMod = LoadLibraryA(module_name); HMODULE remoteMod = GetRemoteModuleHandle(module_name, modules); @@ -216,13 +216,13 @@ bool DLLHelper::FixImports() IMAGE_THUNK_DATA *itd = (IMAGE_THUNK_DATA *)GetPtrFromRVA((DWORD)(impDesc->FirstThunk), m_NTHeader, - (PBYTE)m_TargetBaseAddress); + (PBYTE)m_DLLPtr); while (itd->u1.AddressOfData) { IMAGE_IMPORT_BY_NAME *iibn; iibn = (IMAGE_IMPORT_BY_NAME *)GetPtrFromRVA((DWORD)(itd->u1.AddressOfData), - m_NTHeader, (PBYTE)m_TargetBaseAddress); + m_NTHeader, (PBYTE)m_DLLPtr); itd->u1.Function = MakePtr(DWORD, GetRemoteProcAddress(localMod, remoteMod, (char *)iibn->Name), 0); diff --git a/TestDLL/TestDLL.vcxproj b/TestDLL/TestDLL.vcxproj index 0dc46b5..e75526b 100644 --- a/TestDLL/TestDLL.vcxproj +++ b/TestDLL/TestDLL.vcxproj @@ -92,12 +92,13 @@ true _DEBUG;TESTDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true - MultiThreadedDLL + MultiThreaded Windows true $(VCToolsInstallDir)lib\x64;$(OutputPath);%(AdditionalLibraryDirectories) + kernel32.lib;user32.lib @@ -142,6 +143,7 @@ true NDEBUG;TESTDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true + MultiThreaded Windows @@ -149,6 +151,7 @@ true true $(VCToolsInstallDir)lib\x64;$(OutputPath);%(AdditionalLibraryDirectories) + kernel32.lib;user32.lib -- cgit v1.2.3