#include <stdint.h>
uint64_t rip;
int main()
{
asm(
"movq %%rip, %0\n" : "=m" (rip)
);
sleep(10);
}
Run Code Online (Sandbox Code Playgroud)
当我编译我得到
cc -m64 rip.c -o rip
/tmp/ccwNbZi1.s: Assembler messages:
/tmp/ccwNbZi1.s:12: Error: suffix or operands invalid for `movq'
make: *** [rip] Error 1
Run Code Online (Sandbox Code Playgroud)
Ale*_*nze 14
您无法读取,(E|R)IP因为没有x86(/ 64)指令可以直接读取它.
"读取"它的唯一方法是使用CALL指令进行调用.它将保存堆栈上的返回地址和您可以读取的地址.
更新:在64位模式下,您可以利用RIP-relative地址,因此LEA RAX, [RIP]将为您提供自己的地址EAX.另一个解决方法是MOV RAX, $组装.