汇编代码中的读取访问冲突
这是我在 VC++ 项目中插入的简单 asm 代码。 return_addr 是堆栈帧的返回地址。我有一个 StackWalk 函数(不是我编写的 codeproject.com/KB/threads/StackWalker.aspx),它使用 StackWalk64() 来提取帧。此细节不相关。使用返回地址,我从当前正在检查的堆栈中的函数代码中提取单个字节。
__asm{
push eax
push ecx
mov eax, return_addr
mov cl, BYTE PTR [eax - 5] //Problem Statement
mov ret_5, cl
pop ecx
pop eax
}
我与 gtalk、vlc 等其他应用程序一起运行我的代码。当我包含问题陈述时,应用程序总是崩溃。当我删除这些语句时,一切正常。我运行了一个调试器,它在问题语句处中断,显示访问冲突读取位置 0xzzzzzz 错误。我认为应用程序正在尝试读取某些受限制的 dll 或代码部分的代码,这会引发错误。我使用了 try catch 块,但这没有帮助。关于我能做什么有什么建议吗?
Here is a simple asm code I have inserted in VC++ project. return_addr is the return address of the stack frame. I have a StackWalk function (not been written by me codeproject.com/KB/threads/StackWalker.aspx) which uses StackWalk64() to extract the frames. Details of this are not relevant. Using the return address I extract a single byte from the code of the function in the stack currently being examined.
__asm{
push eax
push ecx
mov eax, return_addr
mov cl, BYTE PTR [eax - 5] //Problem Statement
mov ret_5, cl
pop ecx
pop eax
}
I run my code along with other applications like gtalk, vlc etc. The application always crashes when I include the Problem Statement. When I remove these statements everything works fine. I ran a debugger and it breaks at Problem Statement showing an Access Violation reading location 0xzzzzzz error. I suppose the application is trying to read the code of some restricted dll or code section and that raises an error. I used a try catch block but that didn't help. Any suggestions as to what I can do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很明显,无论
return_addr
值是什么,它都不会指向有效的内存位置,因为否则就不会发生访问冲突。因此,其中的细节非常相关。It is clear that whatever the
return_addr
value is, it does't point to a valid memory location, because otherwise the access violation wouldn't occur. So the details of that are very relevant.