VC_EXCRPTION_REGISTRATION结构 异常处理

本文详细探讨了MS的VC_EXCRCEPTION_REGISTRATION结构,并对比了实际反汇编结果与《软件加密技术内幕》一书中的描述。分析了__EH_prolog函数在堆栈中创建的数据结构,指出书中关于prev和handler字段顺序可能存在的不一致。
这几天研究MS的异常处理,看了《软件加密技术内幕》中关于MS的VC_EXCRPTION_REGISTRATION结构,书中对其结构是如下所说:
struct VC_EXCEPTION_REGISTRATION
{
  VC_EXCEPTION_REGISTRATION* prev;
  FARPROC                    handler;
  scopetable_entry*          scopetable;
  int                        _index;
  DWORD                      _ebp;
}
在堆栈中的排列顺序应该是:
    prev        原FS:(0)的值
    handler     _except_handler
    scopetable  vc_scope_table
    _index      0ffffffffh
    _ebp        ebp的值
但是反汇编msvcrt.dll以后,找到__EH_prolog函数

__EH_prolog     proc near
push    0FFFFFFFFh
push    eax
mov     eax, large fs:0
push    eax
mov     eax, [esp+0Ch]
mov     large fs:0, esp
mov     [esp+0Ch], ebp
lea     ebp, [esp+0Ch]
push    eax
retn

根据改函数分析,其会在堆栈形成一个如下所示的数据结构:

  esp+0c,通过mov eax,[esp+0ch]-->push eax
  fs:0
  eax
  0ffffffffh
  原ebp值,通过mov [esp+0ch],ebp语句

在此比较奇怪,__EH_prolog函数形成的结构与书中记录的不一样,是否应该将书中的prev和handler顺序互换一下?

 
回复时引用此帖 返回顶端

VIP会员
VIP会员

资 料:
注册日期: Apr 2004
帖子: 54 hume 品行端正
精华: 0
现金: 206 Kx
致谢数: 0
获感谢文章数:0
获会员感谢数:0
2 旧2007-06-14, 13:58:11 默认
hume 当前离线

在C++中,_EH_prolog对应于try{}catch(){}

.text:77B83264                     public _EH_prolog
.text:77B83264     _EH_prolog      proc near               ; CODE XREF: sub_77B82669+5p
.text:77B83264 000                 push    0FFFFFFFFh      ; before the retn instruction, stack is as follows:
.text:77B83264                                             ;
.text:77B83264                                             ; return address
.text:77B83264                                             ; fs:[0]
.text:77B83264                                             ; handler
.text:77B83264                                             ; 0FFFFFFFFh
.text:77B83264                                             ; ebp
.text:77B83264                                             ;
.text:77B83264                                             ;
.text:77B83266 004                 push    eax
.text:77B83267 008                 mov     eax, large fs:0
.text:77B8326D 008                 push    eax
.text:77B8326E 00C                 mov     eax, [esp+12]   ; eax = return eip
.text:77B83272 00C                 mov     large fs:0, esp
.text:77B83279 00C                 mov     [esp+12], ebp   ; return eip is overwritten by ebp
.text:77B8327D 00C                 lea     ebp, [esp+12]
.text:77B83281 00C                 push    eax
.text:77B83282 010                 retn                    ; after the retn stack is:
.text:77B83282     _EH_prolog      endp ;;
.text:77B83282                                             ; fs:[0]
.text:77B83282                                             ; handler
.text:77B83282                                             ; 0FFFFFFFFh
.text:77B83282                                             ; ebp

书中讲的是VC特有的__try{}__except(){}块的结构,描述对应于__SEH_prolog和__SEH_epilog。
.text:77B984C4     __SEH_prolog    proc near               ; CODE XREF: _wtof+7p
.text:77B984C4                                             ; wcstod+7p ...
.text:77B984C4
.text:77B984C4     arg_4           = dword ptr  8
.text:77B984C4
.text:77B984C4 000                 push    offset _except_handler3
.text:77B984C9 004                 mov     eax, large fs:0
.text:77B984CF 004                 push    eax
.text:77B984D0 008                 mov     eax, [esp+8+arg_4]
.text:77B984D4 008                 mov     [esp+8+arg_4], ebp
.text:77B984D8 008                 lea     ebp, [esp+8+arg_4]
.text:77B984DC 008                 sub     esp, eax
.text:77B984DE 008                 push    ebx
.text:77B984DF 00C                 push    esi
.text:77B984E0 010                 push    edi
.text:77B984E1 014                 mov     eax, [ebp-8]
.text:77B984E4 014                 mov     [ebp-18h], esp
.text:77B984E7 014                 push    eax
.text:77B984E8 018                 mov     eax, [ebp-4]
.text:77B984EB 018                 mov     dword ptr [ebp-4], 0FFFFFFFFh
.text:77B984F2 018                 mov     [ebp-8], eax
.text:77B984F5 018                 lea     eax, [ebp-10h]
.text:77B984F8 018                 mov     large fs:0, eax
.text:77B984FE 018                 retn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值