我在 SetThreadContext 方面遇到问题。 我无法更改任何 volatile 寄存器(表 here )。
data.context.ContextFlags = CONTEXT_FULL;
SuspendThread(hThread);
GetThreadContext(hThread, &data.context);
...
CONTEXT* ctx = &data.context;
ctx->ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
ctx->Rax = (DWORD64)0x1000;
ctx->Rcx = (DWORD64)-1;
ctx->Rip = (DWORD64)allocatedMemory;
ctx->R10 = (DWORD64)0x12345678;
ctx->Rbp = (DWORD64)0xFFFFFFFF;
SetThreadContext(hThread, ctx);
ResumeThread(hThread);
该代码更改了 Rip 和 Rbp 寄存器,因为它们是非 volatile 的。 GetLastError 返回 0。 使用 THREAD_SET_CONTEXT | 打开线程THREAD_GET_CONTEXT | 线程获取上下文线程暂停恢复THREAD_SET_INFORMATION 权限。
为什么我无法更改 x64 应用程序中的 volatile 寄存器?在 x86 应用程序中,我可以更改任何寄存器( volatile 与否并不重要)。
附注是的,我尝试使用 ctx->ContextFlags = CONTEXT_FULL; 调用 SetThreadContext;
最佳答案
在 64 位 Windows 中,SetThreadContext 仅设置非 volatile 寄存器。 (请参阅 WRK 中/base/ntos/ps/amd64/psctxamd64.c 中的 PspGetSetContextInternal)1
仅设置的寄存器为:Rbx、Rsp、Rbp、Rsi、Rdi、R12-R15、Xmm6-Xmm15。
关于c++ - SetThreadContext x64 volatile 寄存器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25004311/