Is there a way in C++/windows to get the exe/DLL image base address? thanks :)
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
Find below code to find Image Base Address in CPP :
If you want to enumerate all process's modules, you can also use CreateToolhelp32Snapshot:
I found that the most convenient and accurate way to get module's base address (and in-memory image size) is through GetModuleInformation (include psapi.h, link to psapi.lib):
If you load the binary into your own process you can use GetModuleHandle. It returns a HMODULE, but that is the same as HINSTANCE and the base address.
If you want to know what base address the binary prefers you should read the PE header. See here and look for the ImageBase field in IMAGE_OPTIONAL_HEADER.
Edit: GetModuleHandle(NULL) will return the base address (altough the specified type is HMODULE) for the current process.
If you want to get your own ImageBase Address from inside a DLL/EXE then how about this:
If you are examining an DLL or EXE file on disk, use the dumpbin utility. It in installed with Visual Studio or the SDK.
Example Output of dumpbin /headers: