|
发表于 2022-4-18 12:34:37
|
显示全部楼层
- //获取模块基址
- PVOID GetModuleBaseAddr(const char* szWindowName, const char* szModuleName)
- {
- DWORD pid = GetProcessId(szWindowName);
- HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,NULL,pid);
- MODULEENTRY32 me32;
- ZeroMemory(&me32, sizeof(me32));
- me32.dwSize = sizeof(me32);
- HANDLE hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
- unsigned long long baseAddr = 0;
- while (Module32Next(hModuleSnap, &me32))
- {
- if (strstr(me32.szModule, szModuleName))
- {
- break;
- }
- }
- printf("%16s模块基址=%#p,%16s模块大小=%#x\n",szModuleName, me32.modBaseAddr, szModuleName,me32.modBaseSize);
- CloseHandle(hModuleSnap);
- CloseHandle(hProcess);
- return me32.modBaseAddr;
- }
- DWORD GetProcessId(const char* szWindowName)
- {
- HWND hwnd = FindWindowA(NULL, szWindowName);
- DWORD pid = 0;
- GetWindowThreadProcessId(hwnd, &pid);
- return pid;
- }
复制代码
|
|