#include<iostream>
#include<windows.h>
#include<tchar.h>
//因为这个变量是启动函数 调用入口函数时传递的。所以我们在这里说明一下在别的地方已经定义了
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
void dumpModule() {
//GetModuleHandle参数如果为nullptr,就返回本进程的内存开始地址,或者是一个c字符串,包含主调进程中加载的可执行文件名或dll名。如果找到返回相应的地址,否则返回null
HMODULE hModule = GetModuleHandle(nullptr);
_tprintf(TEXT("with GetModuleHandel(nullptr)=0x%p \n"), hModule);
//__ImageBase存有有进程的映射地址
_tprintf(TEXT("with __ImageBase=0x%p \n"), (HANDLE)&__ImageBase);
hModule = nullptr;
//这个增强函数第一个参数时标志位,第二参数是被调函数的进程地址,最后一个是存地址的变量
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,(PCTSTR)dumpModule,&hModule);
_tprintf(TEXT("with GetModuleHandleEx=0x%p \n"), hModule);
}
int _tmain() {
dumpModule();
system("pause");
return 0;
}
windows 显示程序被加载地址的三种方法
最新推荐文章于 2024-08-21 22:18:43 发布