我正在尝试利用 GetThreadContext 查看当前调试寄存器的设置。无论我调试什么程序,它都返回0xCCCCCCCC。我能够成功设置断点 ctx.Dr0,然后使用自定义异常处理程序捕获这些中断,但如果我尝试查看存储在 ctx.Dr0 的地址,它总是显示为 0xCCCCCCCC。这是为什么?
谢谢
CONTEXT ctx;
GetThreadContext(GetCurrentThread(),&ctx);
cout << hex << ctx.Eip << endl;
编辑**
我觉得我的问题问得不够好,因为当时我没有意识到我的思路有问题。我实际上是在尝试从我想要获取其上下文的线程中调用 GetThreadContext。由于显而易见的原因,这不起作用。相反,我认为 CONTEXT ctx = {CONTEXT_FULL} 有效。最有帮助的答案是下面的 Hans Passant 评论。
最佳答案
您无法获得正在运行的线程的有效上下文。您需要挂起要获取上下文的线程。因此,尝试在当前线程中执行此操作是行不通的。 GetThreadContext()
中明确说明了这一点文档:
You cannot get a valid context for a running thread. Use the SuspendThread function to suspend the thread before calling GetThreadContext.
If you call GetThreadContext for the current thread, the function returns successfully; however, the context returned is not valid.
关于c++ - GetThreadContext 寄存器总是返回 0xCCCCCCCC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18195934/