我正在尝试使用汇编程序获取当前进程的 PEB 地址。
cpp文件:
#include <iostream>
//#include <windows.h>
extern "C" int* __ptr64 Get_Ldr_Addr();
int main(int argc, char **argv)
{
std::cout << "asm " << Get_Ldr_Addr() << "\n";
//std::cout <<"peb "<< GetModuleHandle(0) << "\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
asm 文件:
.code
Get_Ldr_Addr proc
push rax
mov rax, GS:[30h]
mov rax, [rax + 60h]
pop rax
ret
Get_Ldr_Addr endp
end
Run Code Online (Sandbox Code Playgroud)
但是我从 GetModuleHandle(0) 和 Get_Ldr_Addr() 得到了不同的地址!
问题是什么?不应该是一样的吗?
问:如果函数是外部函数,它会检查调用它的进程的PEB或函数的dll(假设是一个dll)?
Tnx
如果您不介意 C。在 Microsoft Visual Studio 2015 中工作。使用“__readgsqword()”内在函数。
#include <winnt.h>
#include <winternl.h>
// Thread Environment Block (TEB)
#if defined(_M_X64) // x64
PTEB tebPtr = reinterpret_cast<PTEB>(__readgsqword(reinterpret_cast<DWORD_PTR>(&static_cast<NT_TIB*>(nullptr)->Self)));
#else // x86
PTEB tebPtr = reinterpret_cast<PTEB>(__readfsdword(reinterpret_cast<DWORD_PTR>(&static_cast<NT_TIB*>(nullptr)->Self)));
#endif
// Process Environment Block (PEB)
PPEB pebPtr = tebPtr->ProcessEnvironmentBlock;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11585 次 |
| 最近记录: |