Note that there are some explanatory texts on larger screens.

plurals
  1. POGetModuleHandle return INVALID_HANDLE_VALUE
    primarykey
    data
    text
    <p>So I am learning some dll injection stuff on a test executable. Once I have injected my dll, I try to get the module handle and with that I try to get the base address of the module(the main exe).</p> <pre><code>DWORD dwGetModuleBaseAddress(DWORD dwProcessIdentifier, WCHAR *lpszModuleName) { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessIdentifier); DWORD dwModuleBaseAddress = 0; if(hSnapshot != INVALID_HANDLE_VALUE) { MODULEENTRY32 ModuleEntry32 = {0}; ModuleEntry32.dwSize = sizeof(MODULEENTRY32); if(Module32First(hSnapshot, &amp;ModuleEntry32)) { do { if(wcscmp(ModuleEntry32.szModule, lpszModuleName) == 0) { dwModuleBaseAddress = (DWORD)ModuleEntry32.modBaseAddr; break; } } while(Module32Next(hSnapshot, &amp;ModuleEntry32)); } CloseHandle(hSnapshot); } return dwModuleBaseAddress; } </code></pre> <p>That is how I try to do it. This is after my dll is injected, but it seems to return INVALID_HANDLE_VALUE for some reason. I found the function from one website and modified it a bit but it still doesn't seem to work. If you have a more cleaner method to get the base address I would be glad to know about it.</p> <p>Edit the problem is now with this line:</p> <pre><code>if(wcscmp(ModuleEntry32.szModule, lpszModuleName) == 0) </code></pre> <p>It never is 0 but there is a module name I am looking for, I can see my exe in the debugger but this comparison doesn't somehow work.</p> <p>This is how I call the function</p> <pre><code>HWND window = FindWindow(0, LPCWSTR("test")); DWORD pID = 0; GetWindowThreadProcessId(window, &amp;pID); base = dwGetModuleBaseAddress(pID, (WCHAR*)("test")); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload