开发者

Read Access Violation in assembly code

开发者 https://www.devze.com 2023-02-02 08:31 出处:网络
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/StackWal

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 cod开发者_如何学Pythone 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消