C++ BaseAddress 和入口点地址
Posted
技术标签:
【中文标题】C++ BaseAddress 和入口点地址【英文标题】:C++ BaseAddress and entry point address 【发布时间】:2012-03-22 00:03:44 【问题描述】:我知道在 c# 中我可以做到:
Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
currentProcess.Modules[0].BaseAddress
currentProcess.Modules[0].EntryPointAddress
如何在 C++ 中获取这些信息?
看看我有:
void
get_module_name_for_address(LPVOID address,
TCHAR *buf, int buf_size)
HANDLE process;
HMODULE modules[256];
DWORD bytes_needed, num_modules;
unsigned int i;
buf[0] = '\0';
process = GetCurrentProcess();
if (EnumProcessModules(process, (HMODULE *) &modules,
sizeof(modules), &bytes_needed) == 0)
return;
if (bytes_needed > sizeof(modules))
bytes_needed = sizeof(modules);
num_modules = bytes_needed / sizeof(HMODULE);
for (i = 0; i < num_modules; i++)
MODULEINFO mi;
if (GetModuleInformation(process, modules[i], &mi, sizeof(mi)) != 0)
LPVOID start, end;
start = mi.lpBaseOfDll;
end = (char *) start + mi.SizeOfImage;
if (address >= start && address <= end)
GetModuleBaseName(process, modules[i], buf, buf_size);
return;
【问题讨论】:
您的问题是什么?您的代码显然可以满足您的需求。 MSDN 示例满足您的所有需求:msdn.microsoft.com/en-us/library/windows/desktop/… 【参考方案1】:非托管代码中的GetModuleInformation():http://msdn.microsoft.com/en-us/library/ms683201%28v=VS.85%29.aspx
【讨论】:
以上是关于C++ BaseAddress 和入口点地址的主要内容,如果未能解决你的问题,请参考以下文章
C++ Builder 2009 - IndySystem120.bpl - 未找到入口点
如何在 Visual Studio (C++) 中找到应用程序的入口点