From f3ddc927bd079a88586d72ea71526732b3620da5 Mon Sep 17 00:00:00 2001 From: Grzegorz Rychlik Date: Tue, 7 Jan 2020 17:06:47 +0100 Subject: [PATCH] Add debug code and config to Loader --- Src/CebuLoader/CebuLoader.vcxproj | 4 ++-- Src/CebuLoader/CebuLoaderMain.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Src/CebuLoader/CebuLoader.vcxproj b/Src/CebuLoader/CebuLoader.vcxproj index 7db9686..b573986 100644 --- a/Src/CebuLoader/CebuLoader.vcxproj +++ b/Src/CebuLoader/CebuLoader.vcxproj @@ -35,7 +35,7 @@ - DynamicLibrary + Application true v141 Unicode @@ -55,7 +55,7 @@ Unicode - DynamicLibrary + Application true v141 Unicode diff --git a/Src/CebuLoader/CebuLoaderMain.cpp b/Src/CebuLoader/CebuLoaderMain.cpp index 14cbf44..3a18c1a 100644 --- a/Src/CebuLoader/CebuLoaderMain.cpp +++ b/Src/CebuLoader/CebuLoaderMain.cpp @@ -339,6 +339,7 @@ void ExecResource(void* baseAddress) LoadPe(resource); } +#ifdef NDEBUG BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID) { // Indicate successful load of the library. @@ -347,3 +348,17 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID) return TRUE; } +#else + +#include "tlhelp32.h" + +int main() +{ + auto ME32 = MODULEENTRY32{ sizeof(MODULEENTRY32), }; + auto moduleHandle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId()); + + Module32First(moduleHandle, &ME32); + CloseHandle(moduleHandle); + ExecResource(ME32.modBaseAddr); +} +#endif