首页
社区
课程
招聘
[己解决]关于《软件加密技术内幕》一书中的关于MS Exception结构的疑问
2007-6-14 13:06 5921

[己解决]关于《软件加密技术内幕》一书中的关于MS Exception结构的疑问

2007-6-14 13:06
5921
这几天研究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顺序互换一下?

阿里云助力开发者!2核2G 3M带宽不限流量!6.18限时价,开 发者可享99元/年,续费同价!

收藏
点赞0
打赏
分享
最新回复 (1)
雪    币: 1227
活跃值: (106)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
hume 2007-6-14 13:58
2
0
在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
游客
登录 | 注册 方可回帖
返回