帮助:应用程序在访问源代码时崩溃
这是我在 VC++ 项目中插入的简单 asm 代码。 addr_curr_ebp是EBP指针的当前地址。它指向堆栈帧内的旧 EBP 值。此后的 4 个字节是应用程序函数内的返回地址。我从代码部分提取一个字节。我与 gtalk、vlc 等其他应用程序一起运行我的代码。当我在代码中包含 ProbStat 1 和 2 时,应用程序总是崩溃。当我删除这些语句时,一切正常。你觉得这是什么?
__asm{
push eax
push ebx
push cx
mov ebx, addr_curr_ebp
mov eax, [ebx + 4]
mov cl, BYTE PTR [eax - 5] //ProbStat 1
mov ret_5, cl // ProbStat 2
pop cx
pop ebx
pop eax
}
Here is a simple asm code I have inserted in VC++ project. addr_curr_ebp is the current address of EBP pointer. It is pointing to the old EBP value inside the stack frame. 4 bytes after this is the return address inside the application function. I extract a single byte from the code section. I run my code along with other applications like gtalk, vlc etc. The application always crashes when I include ProbStat 1 and 2 in my code. When I remove these statements everything works fine. What do you think this is?
__asm{
push eax
push ebx
push cx
mov ebx, addr_curr_ebp
mov eax, [ebx + 4]
mov cl, BYTE PTR [eax - 5] //ProbStat 1
mov ret_5, cl // ProbStat 2
pop cx
pop ebx
pop eax
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码片段不足以查看“ret_5”所在的位置。如果它是某个类的成员,您将自动崩溃。 ecx 寄存器存储“this”指针,你把它弄乱了。
不知道这是做什么的,在我看来,您需要使用 _ReturnAddress 内在函数。它返回调用此代码的调用指令之后的指令地址。将其分配给 unsigned char*,无需以这种方式进行汇编。
Your code snippet isn't good enough to see where "ret_5" is located. You'll get an automatic crash if it is a member of a class. The ecx register stores the "this" pointer, you're messing it up.
Not sure what this does, sound to me like you need to use the _ReturnAddress intrinsic. It returns the address of the instruction after the call instruction that called this code. Assign it to an unsigned char*, no need for assembly this way.