SEH分析笔记(X64篇)
v1.0.0
boxcounter
历史:
v1.0.0, 2011-11-4:最初版本。
[不介意转载,但请注明出处 www.boxcounter.com
附件里有本文的原始稿,一样的内容,更好的高亮和排版。
本文的部分代码可能会因为论坛的自动换行变得很乱,需要的朋友手动复制到自己的代码编辑器就可以正常显示了]
在之前的《SEH分析笔记(X86篇)》中,我借助 wrk1.2 介绍了 x86 下 windows 系统内核中的 SEH 实现。这次我们来看看 x64 位 windows 系统内核中 SEH 的实现。
本文需要大家熟悉 x64 位系统的一些特性,比如调用约定、Prolog 和 Epilog。可以通过这几篇文章熟悉一下:
Overview of x64 Calling Conventions , MSDN
The history of calling conventions, part 5: amd64 , The Old New Thing
Everything You Need To Know To Start Programming 64-Bit Windows Systems , Matt Pietrek
首先回顾一下前一篇文章。
在 x86 windows 中,函数通过以下几个步骤来参与 SEH :
1. 在自身的栈空间中分配并初始化一个 EXCEPTION_REGISTRATION(_RECORD) 结构体。
2. 将该 EXCEPTION_REGISTRATION(_RECORD) 挂入当前线程的异常链表。
当某函数触发异常时,系统首先会通过调用 KiDispatchException 来给内核调试器一个机会,如果内核调试器没有处理该异常,则该机会被转给 RtlDispatchException,这个函数就开始分发该异常。分发过程为:
从当前线程的异常链表头开始遍历,对于每一个 SEH 注册信息(即 EXCEPTION_REGISTRATION(_RECORD)),调用其 Handler。根据 Handler 的返回值做相应的后续处理:
1. 返回 ExceptionContinueExecution,表示 Handler 已经修复了异常触发点,从异常触发点继续执行。
2. 返回 ExceptionContinueSearch,表示该 Handler 没有处理该异常,继续遍历异常链表。
3. Handler 没有修复异常触发点,但是却能处理该异常(某个 __except 过滤代码返回 EXCEPTION_EXECUTE_HANDLER)。这种情况下,处理完该异常后就从异常解决代码(__except 代码块)继续执行,Handler 不会返回。
以上是简略的 x86 SEH 流程,其中省略了很多细节,比如展开、错误处理、ExceptionNestedException 和 ExceptionCollidedUnwind 等等。
之所以在这里重温这个流程,是因为 x64 中 SEH 的流程总体思路也是如此,只是细节上做了一些修改。但这并不表示熟悉 x86 SEH 就能很轻松的掌握 x64 SEH。
本文分为四个部分:“异常注册”、“异常分发”、“展开、解决”和“ExceptionNestedException 和 ExceptionCollidedUnwind”。依然以 MSC 的增强版为分析对象。分析环境为:WDK 7600.16385.1,内置的 cl 的版本是15.00.30729.207,link 的版本是9.00.30729.207,测试虚拟机系统为 amd64 WinXP + wrk1.2。
在讲述之前,需要先定义几个名词,以简化后续的讲述。
RVA —— 熟悉 PE 格式的朋友都懂的,表示某个绝对地址相对于所在模块的基地址的偏移。
EXCEPT_POINT —— 异常触发点。
EXCEPT_FILTER —— __except 小括号内的异常过滤代码。
EXCEPT_HANDLER —— __except 大括号内的异常解决代码。
FINALLY_HANDLER —— __finally 大括号内的代码。
以下面的伪码为例,
[font=Consolas][color=#000000] [/color][color=#800080]1 [/color][color=#000000]__try
[/color][color=#800080]2 [/color][color=#000080]{
[/color][color=#800080]3 [/color][color=#000000]__try
[/color][color=#800080]4 [/color][color=#000080]{
[/color][color=#800080]5 [/color][color=#000080]*(([/color][color=#000000]ULONG[/color][color=#000080]*)[/color][color=#000000]NULL[/color][color=#000080]) = [/color][color=#800080]0[/color][color=#000080];
[/color][color=#800080]6 [/color][color=#000080]}
[/color][color=#800080]7 [/color][color=#000000]__except[/color][color=#000080](([/color][color=#000000]STATUS_INVALID_PARAMETER [/color][color=#000080]== [/color][color=#000000]GetExceptionCode[/color][color=#000080]()) ? [/color][color=#000000]EXCEPTION_CONTINUE_SEARCH [/color][color=#000080]: [/color][color=#000000]EXCEPTION_EXECUTE_HANDLER[/color][color=#000080])
[/color][color=#800080]8 [/color][color=#000080]{
[/color][color=#800080]9 [/color][color=#000080]...
[/color][color=#800080]10 [/color][color=#000080]}
[/color][color=#800080]11 [/color][color=#000080]}
[/color][color=#800080]12 [/color][color=#000000]__finally
[/color][color=#800080]13 [/color][color=#000080]{
[/color][color=#800080]14 [/color][color=#000080]...
[/color][color=#800080]15 [/color][color=#000080]{[/color][/font]
[font=Consolas][color=#000000] [/color][color=#0000FF]typedef struct [/color][color=#000000]_RUNTIME_FUNCTION [/color][color=#000080]{
[/color][color=#000000]ULONG BeginAddress[/color][color=#000080];
[/color][color=#000000]ULONG EndAddress[/color][color=#000080];
[/color][color=#000000]ULONG UnwindData[/color][color=#000080];
} [/color][color=#000000]RUNTIME_FUNCTION[/color][color=#000080], *[/color][color=#000000]PRUNTIME_FUNCTION[/color][color=#000080];
[/color][color=#0000FF]typedef enum [/color][color=#000000]_UNWIND_OP_CODES [/color][color=#000080]{
[/color][color=#000000]UWOP_PUSH_NONVOL [/color][color=#000080]= [/color][color=#800080]0[/color][color=#000080],
[/color][color=#000000]UWOP_ALLOC_LARGE[/color][color=#000080], [/color][color=#008000]// 1
[/color][color=#000000]UWOP_ALLOC_SMALL[/color][color=#000080], [/color][color=#008000]// 2
[/color][color=#000000]UWOP_SET_FPREG[/color][color=#000080], [/color][color=#008000]// 3
[/color][color=#000000]UWOP_SAVE_NONVOL[/color][color=#000080], [/color][color=#008000]// 4
[/color][color=#000000]UWOP_SAVE_NONVOL_FAR[/color][color=#000080], [/color][color=#008000]// 5
[/color][color=#000000]UWOP_SPARE_CODE1[/color][color=#000080], [/color][color=#008000]// 6
[/color][color=#000000]UWOP_SPARE_CODE2[/color][color=#000080], [/color][color=#008000]// 7
[/color][color=#000000]UWOP_SAVE_XMM128[/color][color=#000080], [/color][color=#008000]// 8
[/color][color=#000000]UWOP_SAVE_XMM128_FAR[/color][color=#000080], [/color][color=#008000]// 9
[/color][color=#000000]UWOP_PUSH_MACHFRAME [/color][color=#008000]// 10
[/color][color=#000080]} [/color][color=#000000]UNWIND_OP_CODES[/color][color=#000080], *[/color][color=#000000]PUNWIND_OP_CODES[/color][color=#000080];
[/color][color=#0000FF]typedef union [/color][color=#000000]_UNWIND_CODE [/color][color=#000080]{
[/color][color=#0000FF]struct [/color][color=#000080]{
[/color][color=#000000]UCHAR CodeOffset[/color][color=#000080];
[/color][color=#000000]UCHAR UnwindOp [/color][color=#000080]: [/color][color=#800080]4[/color][color=#000080];
[/color][color=#000000]UCHAR OpInfo [/color][color=#000080]: [/color][color=#800080]4[/color][color=#000080];
};
[/color][color=#000000]USHORT FrameOffset[/color][color=#000080];
} [/color][color=#000000]UNWIND_CODE[/color][color=#000080], *[/color][color=#000000]PUNWIND_CODE[/color][color=#000080];
[/color][color=#0000FF]#define [/color][color=#000000]UNW_FLAG_NHANDLER [/color][color=#800080]0x0
[/color][color=#0000FF]#define [/color][color=#000000]UNW_FLAG_EHANDLER [/color][color=#800080]0x1
[/color][color=#0000FF]#define [/color][color=#000000]UNW_FLAG_UHANDLER [/color][color=#800080]0x2
[/color][color=#0000FF]#define [/color][color=#000000]UNW_FLAG_CHAININFO [/color][color=#800080]0x4
[/color][color=#0000FF]typedef struct [/color][color=#000000]_UNWIND_INFO [/color][color=#000080]{
[/color][color=#000000]UCHAR Version [/color][color=#000080]: [/color][color=#800080]3[/color][color=#000080];
[/color][color=#000000]UCHAR Flags [/color][color=#000080]: [/color][color=#800080]5[/color][color=#000080];
[/color][color=#000000]UCHAR SizeOfProlog[/color][color=#000080];
[/color][color=#000000]UCHAR CountOfCodes[/color][color=#000080];
[/color][color=#000000]UCHAR FrameRegister [/color][color=#000080]: [/color][color=#800080]4[/color][color=#000080];
[/color][color=#000000]UCHAR FrameOffset [/color][color=#000080]: [/color][color=#800080]4[/color][color=#000080];
[/color][color=#000000]UNWIND_CODE UnwindCode[/color][color=#000080][[/color][color=#800080]1[/color][color=#000080]];
[/color][color=#008000]//
// The unwind codes are followed by an optional DWORD aligned field that
// contains the exception handler address or a function table entry if
// chained unwind information is specified. If an exception handler address
// is specified, then it is followed by the language specified exception
// handler data.
//
// union {
// struct {
// ULONG ExceptionHandler;
// ULONG ExceptionData[];
// };
//
// RUNTIME_FUNCTION FunctionEntry;
// };
//
[/color][color=#000080]} [/color][color=#000000]UNWIND_INFO[/color][color=#000080], *[/color][color=#000000]PUNWIND_INFO[/color][color=#000080];
[/color][color=#0000FF]typedef struct [/color][color=#000000]_SCOPE_TABLE [/color][color=#000080]{
[/color][color=#000000]ULONG Count[/color][color=#000080];
[/color][color=#0000FF]struct
[/color][color=#000080]{
[/color][color=#000000]ULONG BeginAddress[/color][color=#000080];
[/color][color=#000000]ULONG EndAddress[/color][color=#000080];
[/color][color=#000000]ULONG HandlerAddress[/color][color=#000080];
[/color][color=#000000]ULONG JumpTarget[/color][color=#000080];
} [/color][color=#000000]ScopeRecord[/color][color=#000080][[/color][color=#800080]1[/color][color=#000080]];
} [/color][color=#000000]SCOPE_TABLE[/color][color=#000080], *[/color][color=#000000]PSCOPE_TABLE[/color][color=#000080];[/color][/font]
VOID
KiDispatchException (
IN PEXCEPTION_RECORD ExceptionRecord,
IN PKEXCEPTION_FRAME ExceptionFrame,
IN PKTRAP_FRAME TrapFrame,
IN KPROCESSOR_MODE PreviousMode,
IN BOOLEAN FirstChance
);
[font=Consolas][color=#000000] [/color][color=#0000FF]#define [/color][color=#000000]UNWIND_HISTORY_TABLE_SIZE [/color][color=#800080]12
[/color][color=#0000FF]typedef struct [/color][color=#000000]_UNWIND_HISTORY_TABLE_ENTRY [/color][color=#000080]{
[/color][color=#000000]ULONG64 ImageBase[/color][color=#000080];
[/color][color=#000000]PRUNTIME_FUNCTION FunctionEntry[/color][color=#000080];
} [/color][color=#000000]UNWIND_HISTORY_TABLE_ENTRY[/color][color=#000080], *[/color][color=#000000]PUNWIND_HISTORY_TABLE_ENTRY[/color][color=#000080];
[/color][color=#0000FF]#define [/color][color=#000000]UNWIND_HISTORY_TABLE_NONE [/color][color=#800080]0
[/color][color=#0000FF]#define [/color][color=#000000]UNWIND_HISTORY_TABLE_GLOBAL [/color][color=#800080]1
[/color][color=#0000FF]#define [/color][color=#000000]UNWIND_HISTORY_TABLE_LOCAL [/color][color=#800080]2
[/color][color=#0000FF]typedef struct [/color][color=#000000]_UNWIND_HISTORY_TABLE [/color][color=#000080]{
[/color][color=#000000]ULONG Count[/color][color=#000080];
[/color][color=#000000]UCHAR Search[/color][color=#000080];
[/color][color=#000000]ULONG64 LowAddress[/color][color=#000080];
[/color][color=#000000]ULONG64 HighAddress[/color][color=#000080];
[/color][color=#000000]UNWIND_HISTORY_TABLE_ENTRY Entry[/color][color=#000080][[/color][color=#000000]UNWIND_HISTORY_TABLE_SIZE[/color][color=#000080]];
} [/color][color=#000000]UNWIND_HISTORY_TABLE[/color][color=#000080], *[/color][color=#000000]PUNWIND_HISTORY_TABLE[/color][color=#000080];
[/color][color=#000000]PRUNTIME_FUNCTION
RtlLookupFunctionEntry [/color][color=#000080](
[/color][color=#000000]IN ULONG64 ControlPc[/color][color=#000080],
[/color][color=#000000]OUT PULONG64 ImageBase[/color][color=#000080],
[/color][color=#000000]IN OUT PUNWIND_HISTORY_TABLE HistoryTable OPTIONAL
[/color][color=#000080]);[/color][/font]
PEXCEPTION_ROUTINE
RtlVirtualUnwind (
IN ULONG HandlerType,
IN ULONG64 ImageBase,
IN ULONG64 ControlPc,
IN PRUNTIME_FUNCTION FunctionEntry,
IN OUT PCONTEXT ContextRecord,
OUT PVOID *HandlerData,
OUT PULONG64 EstablisherFrame,
IN OUT PKNONVOLATILE_CONTEXT_POINTERS ContextPointers OPTIONAL
);
EXCEPTION_DISPOSITION
RtlpExecuteHandlerForException (
IN PEXCEPTION_RECORD ExceptionRecord,
IN PVOID EstablisherFrame,
IN OUT PCONTEXT ContextRecord,
IN OUT PVOID DispatcherContext
);
typedef struct _DISPATCHER_CONTEXT {
ULONG64 ControlPc;
ULONG64 ImageBase;
PRUNTIME_FUNCTION FunctionEntry;
ULONG64 EstablisherFrame;
ULONG64 TargetIp;
PCONTEXT ContextRecord;
PEXCEPTION_ROUTINE LanguageHandler;
PVOID HandlerData;
PUNWIND_HISTORY_TABLE HistoryTable;
ULONG ScopeIndex;
ULONG Fill0;
} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
EXCEPTION_DISPOSITION
__C_specific_handler (
IN PEXCEPTION_RECORD pExceptionRecord,
IN PVOID pEstablisherFrame,
IN OUT PCONTEXT pContext,
IN OUT PVOID pDispatcherContext
);
[font=Consolas][color=#000000] kd[/color][color=#0A246A]> [/color][color=#000000]uf nt!__C_specific_handler
nt!__C_specific_handler[/color][color=#0A246A]:
[/color][color=#000000]fffff800`[/color][color=#800080]008a42d0 [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]10h[/color][color=#0A246A]],[/color][color=#000000]rdx [/color][color=#008000]; 在栈上保存 pEstablisherFrame
[/color][color=#000000]fffff800`[/color][color=#800080]008a42d5 [/color][color=#0A246A]mov [/color][color=#000000]rax[/color][color=#0A246A],[/color][color=#000000]rsp
fffff800`[/color][color=#800080]008a42d8 [/color][color=#0A246A]sub [/color][color=#000000]rsp[/color][color=#0A246A],[/color][color=#800080]88h
[/color][color=#000000]fffff800`[/color][color=#800080]008a42df [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rax[/color][color=#0A246A]-[/color][color=#800080]8[/color][color=#0A246A]],[/color][color=#000000]rbx
fffff800`[/color][color=#800080]008a42e3 [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rax[/color][color=#0A246A]-[/color][color=#800080]10h[/color][color=#0A246A]],[/color][color=#000000]rbp
fffff800`[/color][color=#800080]008a42e7 [/color][color=#0A246A]mov [/color][color=#000000]rbp[/color][color=#0A246A],qword ptr [[/color][color=#000000]r9[/color][color=#0A246A]] [/color][color=#008000]; rbp = pDispatcherContext->ControlPc
[/color][color=#000000]fffff800`[/color][color=#800080]008a42ea [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rax[/color][color=#0A246A]-[/color][color=#800080]18h[/color][color=#0A246A]],[/color][color=#000000]rsi
fffff800`[/color][color=#800080]008a42ee [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rax[/color][color=#0A246A]-[/color][color=#800080]20h[/color][color=#0A246A]],[/color][color=#000000]rdi
fffff800`[/color][color=#800080]008a42f2 [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rax[/color][color=#0A246A]-[/color][color=#800080]28h[/color][color=#0A246A]],[/color][color=#000000]r12
fffff800`[/color][color=#800080]008a42f6 [/color][color=#0A246A]mov [/color][color=#000000]r12[/color][color=#0A246A],qword ptr [[/color][color=#000000]r9[/color][color=#0A246A]+[/color][color=#800080]38h[/color][color=#0A246A]] [/color][color=#008000]; r12 = pDispatcherContext->HandlerData
[/color][color=#000000]fffff800`[/color][color=#800080]008a42fa [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rax[/color][color=#0A246A]-[/color][color=#800080]30h[/color][color=#0A246A]],[/color][color=#000000]r13
fffff800`[/color][color=#800080]008a42fe [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rax[/color][color=#0A246A]-[/color][color=#800080]38h[/color][color=#0A246A]],[/color][color=#000000]r14
fffff800`[/color][color=#800080]008a4302 [/color][color=#0A246A]mov [/color][color=#000000]r14[/color][color=#0A246A],qword ptr [[/color][color=#000000]r9[/color][color=#0A246A]+[/color][color=#800080]8[/color][color=#0A246A]] [/color][color=#008000]; r14 = pDispatcherContext->ImageBase
[/color][color=#000000]fffff800`[/color][color=#800080]008a4306 [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rax[/color][color=#0A246A]-[/color][color=#800080]40h[/color][color=#0A246A]],[/color][color=#000000]r15
fffff800`[/color][color=#800080]008a430a [/color][color=#0A246A]mov [/color][color=#000000]r13[/color][color=#0A246A],[/color][color=#000000]r9 [/color][color=#008000]; r13 = pDispatcherContext
[/color][color=#000000]fffff800`[/color][color=#800080]008a430d [/color][color=#0A246A]sub [/color][color=#000000]rbp[/color][color=#0A246A],[/color][color=#000000]r14 [/color][color=#008000]; l_OffsetInFunc = pDispatcherContext->ControlPc - pDispatcherContext->ImageBase
[/color][color=#000000]fffff800`[/color][color=#800080]008a4310 [/color][color=#0A246A]test byte ptr [[/color][color=#000000]rcx[/color][color=#0A246A]+[/color][color=#800080]4[/color][color=#0A246A]],[/color][color=#800080]66h [/color][color=#008000]; pExceptionRecord->ExceptionFlags, EXCEPTION_UNWIND (0x66)
[/color][color=#000000]fffff800`[/color][color=#800080]008a4314 [/color][color=#0A246A]mov [/color][color=#000000]rsi[/color][color=#0A246A],[/color][color=#000000]rdx [/color][color=#008000]; rsi = pEstablisherFrame
[/color][color=#000000]fffff800`[/color][color=#800080]008a4317 [/color][color=#0A246A]mov [/color][color=#000000]r15[/color][color=#0A246A],[/color][color=#000000]rcx [/color][color=#008000]; r15 = pExceptionRecord
[/color][color=#0A246A]< [/color][color=#000000]fffff800`[/color][color=#800080]008a431a [/color][color=#0A246A]jne [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xf5 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a43c5[/color][color=#0A246A])
:
: -------------------------------------------------------------------
: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x50[/color][color=#0A246A]:
: [/color][color=#000000]fffff800`[/color][color=#800080]008a4320 [/color][color=#000000]movsxd rdi[/color][color=#0A246A],dword ptr [[/color][color=#000000]r9[/color][color=#0A246A]+[/color][color=#800080]48h[/color][color=#0A246A]] [/color][color=#008000]; l_ScopeIndex (rdi) = pDispatcherContext->ScopeIndex
[/color][color=#0A246A]: [/color][color=#000000]fffff800`[/color][color=#800080]008a4324 [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rax[/color][color=#0A246A]-[/color][color=#800080]58h[/color][color=#0A246A]],[/color][color=#000000]rcx [/color][color=#008000]; [rax-58h] = pExceptionRecord,供给 GetExceptionCode(Information) 使用
[/color][color=#0A246A]: [/color][color=#000000]fffff800`[/color][color=#800080]008a4328 [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rax[/color][color=#0A246A]-[/color][color=#800080]50h[/color][color=#0A246A]],[/color][color=#000000]r8 [/color][color=#008000]; [rax-50h] = pContext,供给 GetExceptionCode(Information) 使用
[/color][color=#0A246A]: [/color][color=#000000]fffff800`[/color][color=#800080]008a432c [/color][color=#0A246A]cmp [/color][color=#FF8000]edi[/color][color=#0A246A],dword ptr [[/color][color=#000000]r12[/color][color=#0A246A]] [/color][color=#008000]; cmp l_ScopeIndex, pDispatcherContext->HandlerData->Count
[/color][color=#0A246A]: [/color][color=#000000]fffff800`[/color][color=#800080]008a4330 [/color][color=#0A246A]mov [/color][color=#000000]rax[/color][color=#0A246A],[/color][color=#000000]rdi [/color][color=#008000]; rax = l_ScopeIndex
[/color][color=#0A246A]:< [/color][color=#000000]fffff800`[/color][color=#800080]008a4333 [/color][color=#0A246A]jae [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x166 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a4436[/color][color=#0A246A])
::
:: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x69[/color][color=#0A246A]:
:: [/color][color=#000000]fffff800`[/color][color=#800080]008a4339 [/color][color=#0A246A]add [/color][color=#000000]rax[/color][color=#0A246A],[/color][color=#000000]rax [/color][color=#008000]; 这里 *2,下面紧接着 *8,目的是跳过指定数目的 ScopeRecord(大小为16字节)
[/color][color=#0A246A]:: [/color][color=#000000]fffff800`[/color][color=#800080]008a433c [/color][color=#0A246A]lea [/color][color=#000000]rbx[/color][color=#0A246A],[[/color][color=#000000]r12[/color][color=#0A246A]+[/color][color=#000000]rax[/color][color=#0A246A]*[/color][color=#800080]8[/color][color=#0A246A]+[/color][color=#800080]0Ch[/color][color=#0A246A]] [/color][color=#008000]; rbx = &(pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].HandlerAddress)
[/color][color=#0A246A]::
:: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x71[/color][color=#0A246A]:
:: [/color][color=#008000]; 检查 ControlPc 处于哪个 __try 保护域,之步骤一
[/color][color=#0A246A]:: > [/color][color=#000000]fffff800`[/color][color=#800080]008a4341 [/color][color=#0A246A]mov [/color][color=#FF8000]eax[/color][color=#0A246A],dword ptr [[/color][color=#000000]rbx[/color][color=#0A246A]-[/color][color=#800080]8[/color][color=#0A246A]] [/color][color=#008000]; eax = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].BeginAddress
[/color][color=#0A246A]:: : [/color][color=#000000]fffff800`[/color][color=#800080]008a4344 [/color][color=#0A246A]cmp [/color][color=#000000]rbp[/color][color=#0A246A],[/color][color=#000000]rax [/color][color=#008000]; cmp l_OffsetInFunc, pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].BeginAddress
[/color][color=#0A246A]::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a4347 [/color][color=#0A246A]jb [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xdd [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a43ad[/color][color=#0A246A])
::: :
::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x79[/color][color=#0A246A]:
::: : [/color][color=#008000]; 检查 ControlPc 处于哪个 __try 保护域,之步骤二
[/color][color=#0A246A]::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a4349 [/color][color=#0A246A]mov [/color][color=#FF8000]eax[/color][color=#0A246A],dword ptr [[/color][color=#000000]rbx[/color][color=#0A246A]-[/color][color=#800080]4[/color][color=#0A246A]] [/color][color=#008000]; eax = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].EndAddress
[/color][color=#0A246A]::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a434c [/color][color=#0A246A]cmp [/color][color=#000000]rbp[/color][color=#0A246A],[/color][color=#000000]rax [/color][color=#008000]; cmp l_OffsetInFunc, pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].EndAddress
[/color][color=#0A246A]:::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a434f [/color][color=#0A246A]jae [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xdd [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a43ad[/color][color=#0A246A])
:::: :
:::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x81[/color][color=#0A246A]:
:::: : [/color][color=#008000]; 判断是否是 __try/__finally(JumpTarget 为 NULL)。如果是,那么跳转到下一个 ScopeRecord 继续遍历。
[/color][color=#0A246A]:::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a4351 [/color][color=#0A246A]cmp dword ptr [[/color][color=#000000]rbx[/color][color=#0A246A]+[/color][color=#800080]4[/color][color=#0A246A]],[/color][color=#800080]0 [/color][color=#008000]; cmp pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].JumpTarget, NULL
[/color][color=#0A246A]::::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a4355 [/color][color=#0A246A]je [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xdd [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a43ad[/color][color=#0A246A])
::::: :
::::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x87[/color][color=#0A246A]:
::::: : [/color][color=#008000]; 到这里,已经找到与异常地址最匹配的 __try/__except
[/color][color=#0A246A]::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a4357 [/color][color=#0A246A]mov [/color][color=#FF8000]eax[/color][color=#0A246A],dword ptr [[/color][color=#000000]rbx[/color][color=#0A246A]] [/color][color=#008000]; eax = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].HandlerAddress
[/color][color=#0A246A]::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a4359 [/color][color=#0A246A]cmp [/color][color=#FF8000]eax[/color][color=#0A246A],[/color][color=#800080]1 [/color][color=#008000]; cmp pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].HandlerAddress, EXCEPTION_EXECUTE_HANDLER (0x1)
[/color][color=#0A246A]:::::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a435c [/color][color=#0A246A]je [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xa3 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a4373[/color][color=#0A246A]) [/color][color=#008000]; 如果返回 EXCEPTION_EXECUTE_HANDLER 则跳转
[/color][color=#0A246A]:::::: :
:::::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x8e[/color][color=#0A246A]:
:::::: : [/color][color=#008000]; 是 __try/__except,且过滤域并不是 EXCEPTION_EXECUTE_HANDLER,执行 HandlerAddress
[/color][color=#0A246A]:::::: : [/color][color=#008000]; (注:HandlerAddress 指向的函数仍有可能会返回 EXCEPTION_EXECUTE_HANDLER)
[/color][color=#0A246A]:::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a435e [/color][color=#0A246A]lea [/color][color=#000000]rcx[/color][color=#0A246A],[[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]30h[/color][color=#0A246A]]
:::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a4363 [/color][color=#0A246A]add [/color][color=#000000]rax[/color][color=#0A246A],[/color][color=#000000]r14 [/color][color=#008000]; rax = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].HandlerAddress + pDispatcherContext->ImageBase
[/color][color=#0A246A]:::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a4366 [/color][color=#0A246A]mov [/color][color=#000000]rdx[/color][color=#0A246A],[/color][color=#000000]rsi [/color][color=#008000]; rdx = pEstablisherFrame
[/color][color=#0A246A]:::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a4369 [/color][color=#0A246A]call [/color][color=#000000]rax [/color][color=#008000]; 调用 EXCEPT_FILTER
[/color][color=#0A246A]:::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a436b [/color][color=#0A246A]test [/color][color=#FF8000]eax[/color][color=#0A246A],[/color][color=#FF8000]eax
[/color][color=#0A246A]::::::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a436d [/color][color=#0A246A]js [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xee [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a43be[/color][color=#0A246A]) [/color][color=#008000]; 返回 EXCEPTION_CONTINUE_EXECUTION (-1) 则跳转
[/color][color=#0A246A]::::::: :
::::::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x9f[/color][color=#0A246A]:
::::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a436f [/color][color=#0A246A]test [/color][color=#FF8000]eax[/color][color=#0A246A],[/color][color=#FF8000]eax
[/color][color=#0A246A]:::::::<: [/color][color=#000000]fffff800`[/color][color=#800080]008a4371 [/color][color=#0A246A]jle [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xdd [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a43ad[/color][color=#0A246A]) [/color][color=#008000]; 返回 EXCEPTION_CONTINUE_SEARCH (0) 则跳转
[/color][color=#0A246A]:::::::::
::::::::: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xa3[/color][color=#0A246A]:
::::::::: [/color][color=#008000]; 返回的是 EXCEPTION_EXECUTE_HANDLER
[/color][color=#0A246A]:::::>::: [/color][color=#000000]fffff800`[/color][color=#800080]008a4373 [/color][color=#0A246A]mov [/color][color=#FF8000]ecx[/color][color=#0A246A],dword ptr [[/color][color=#000000]rbx[/color][color=#0A246A]+[/color][color=#800080]4[/color][color=#0A246A]] [/color][color=#008000]; ecx = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].JumpTarget
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a4376 [/color][color=#0A246A]mov [/color][color=#000000]r8d[/color][color=#0A246A],[/color][color=#800080]1
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a437c [/color][color=#0A246A]mov [/color][color=#000000]rdx[/color][color=#0A246A],[/color][color=#000000]rsi [/color][color=#008000]; rdx = pEstablisherFrame
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a437f [/color][color=#0A246A]add [/color][color=#000000]rcx[/color][color=#0A246A],[/color][color=#000000]r14 [/color][color=#008000]; rcx = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].JumpTarget + pDispatcherContext->ImageBase
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a4382 [/color][color=#0A246A]call [/color][color=#000000]nt!_NLG_Notify [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008b1460[/color][color=#0A246A])
::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a4387 [/color][color=#0A246A]mov [/color][color=#000000]rax[/color][color=#0A246A],qword ptr [[/color][color=#000000]r13[/color][color=#0A246A]+[/color][color=#800080]40h[/color][color=#0A246A]] [/color][color=#008000]; rax = pDispatcherContext->HistoryTable
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a438b [/color][color=#0A246A]mov [/color][color=#FF8000]edx[/color][color=#0A246A],dword ptr [[/color][color=#000000]rbx[/color][color=#0A246A]+[/color][color=#800080]4[/color][color=#0A246A]] [/color][color=#008000]; edx = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].JumpTarget
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a438e [/color][color=#000000]movsxd r9[/color][color=#0A246A],dword ptr [[/color][color=#000000]r15[/color][color=#0A246A]] [/color][color=#008000]; r9 = pExceptionRecord->ExceptionCode
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a4391 [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]28h[/color][color=#0A246A]],[/color][color=#000000]rax [/color][color=#008000]; _ARG_6 = pDispatcherContext->HistoryTable
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a4396 [/color][color=#0A246A]mov [/color][color=#000000]rax[/color][color=#0A246A],qword ptr [[/color][color=#000000]r13[/color][color=#0A246A]+[/color][color=#800080]28h[/color][color=#0A246A]] [/color][color=#008000]; rax = pDispatcherContext->ContextRecord
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a439a [/color][color=#0A246A]add [/color][color=#000000]rdx[/color][color=#0A246A],[/color][color=#000000]r14 [/color][color=#008000]; rdx = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].JumpTarget + pDispatcherContext->ImageBase
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a439d [/color][color=#0A246A]mov [/color][color=#000000]r8[/color][color=#0A246A],[/color][color=#000000]r15 [/color][color=#008000]; r8 = pExceptionRecord
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a43a0 [/color][color=#0A246A]mov [/color][color=#000000]rcx[/color][color=#0A246A],[/color][color=#000000]rsi [/color][color=#008000]; rcx = pEstablisherFrame
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a43a3 [/color][color=#0A246A]mov qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]20h[/color][color=#0A246A]],[/color][color=#000000]rax [/color][color=#008000]; _ARG_5 = pDispatcherContext->ContextRecord
[/color][color=#0A246A]::::: ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a43a8 [/color][color=#0A246A]call [/color][color=#000000]nt!RtlUnwindEx [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]00891e80[/color][color=#0A246A]) [/color][color=#008000]; 这里不会返回
[/color][color=#0A246A]::::: ::: [/color][color=#008000]; RtlUnwindEx(pEstablisherFrame,
[/color][color=#0A246A]::::: ::: [/color][color=#008000]; pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].JumpTarget + pDispatcherContext->ImageBase
[/color][color=#0A246A]::::: ::: [/color][color=#008000]; pExceptionRecord,
[/color][color=#0A246A]::::: ::: [/color][color=#008000]; pExceptionRecord->ExceptionCode
[/color][color=#0A246A]::::: ::: [/color][color=#008000]; pDispatcherContext->ContextRecord,
[/color][color=#0A246A]::::: ::: [/color][color=#008000]; pDispatcherContext->HistoryTable)
[/color][color=#0A246A]::::: :::
::::: ::: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xdd[/color][color=#0A246A]:
::>>> :>: [/color][color=#000000]fffff800`[/color][color=#800080]008a43ad [/color][color=#0A246A]inc [/color][color=#FF8000]edi [/color][color=#008000]; l_ScopeIndex += 1
[/color][color=#0A246A]:: : : [/color][color=#000000]fffff800`[/color][color=#800080]008a43af [/color][color=#0A246A]add [/color][color=#000000]rbx[/color][color=#0A246A],[/color][color=#800080]10h [/color][color=#008000]; 调整到下一个 ScopeRecord::HandlerAddress
[/color][color=#0A246A]:: : : [/color][color=#000000]fffff800`[/color][color=#800080]008a43b3 [/color][color=#0A246A]cmp [/color][color=#FF8000]edi[/color][color=#0A246A],dword ptr [[/color][color=#000000]r12[/color][color=#0A246A]] [/color][color=#008000]; cmp l_ScopeIndex, pDispatcherContext->HandlerData->Count
[/color][color=#0A246A]:: : < [/color][color=#000000]fffff800`[/color][color=#800080]008a43b7 [/color][color=#0A246A]jb [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x71 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a4341[/color][color=#0A246A])
:: :
:: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xe9[/color][color=#0A246A]:
:: : [/color][color=#008000]; pDispatcherContext->HandlerData 遍历完毕
[/color][color=#0A246A]::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a43b9 [/color][color=#0A246A]jmp [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x166 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a4436[/color][color=#0A246A])
::: :
::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xee[/color][color=#0A246A]:
::: > [/color][color=#000000]fffff800`[/color][color=#800080]008a43be [/color][color=#0A246A]xor [/color][color=#FF8000]eax[/color][color=#0A246A],[/color][color=#FF8000]eax [/color][color=#008000]; eax = ExceptionContinueExecution
[/color][color=#0A246A]:::< [/color][color=#000000]fffff800`[/color][color=#800080]008a43c0 [/color][color=#0A246A]jmp [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x16b [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a443b[/color][color=#0A246A])
::::
:::: -------------------------------------------------------------------------------------
:::: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0xf5[/color][color=#0A246A]:
:::: [/color][color=#008000]; 设置了 EXCEPTION_UNWIND,当前是展开过程
[/color][color=#0A246A]>::: [/color][color=#000000]fffff800`[/color][color=#800080]008a43c5 [/color][color=#000000]movsxd rdi[/color][color=#0A246A],dword ptr [[/color][color=#000000]r9[/color][color=#0A246A]+[/color][color=#800080]48h[/color][color=#0A246A]] [/color][color=#008000]; l_ScopeIndex (rdi) = pDispatcherContext->ScopeIndex
[/color][color=#0A246A]::: [/color][color=#000000]fffff800`[/color][color=#800080]008a43c9 [/color][color=#0A246A]mov [/color][color=#000000]rsi[/color][color=#0A246A],qword ptr [[/color][color=#000000]r9[/color][color=#0A246A]+[/color][color=#800080]20h[/color][color=#0A246A]] [/color][color=#008000]; rsi = pDispatcherContext->TargetIp
[/color][color=#0A246A]::: [/color][color=#000000]fffff800`[/color][color=#800080]008a43cd [/color][color=#0A246A]sub [/color][color=#000000]rsi[/color][color=#0A246A],[/color][color=#000000]r14 [/color][color=#008000]; rsi = pDispatcherContext->TargetIp - pDispatcherContext->ImageBase
[/color][color=#0A246A]::: [/color][color=#000000]fffff800`[/color][color=#800080]008a43d0 [/color][color=#0A246A]cmp [/color][color=#FF8000]edi[/color][color=#0A246A],dword ptr [[/color][color=#000000]r12[/color][color=#0A246A]] [/color][color=#008000]; cmp l_ScopeIndex, pDispatcherContext->HandlerData->Count
[/color][color=#0A246A]::: [/color][color=#000000]fffff800`[/color][color=#800080]008a43d4 [/color][color=#0A246A]mov [/color][color=#000000]rax[/color][color=#0A246A],[/color][color=#000000]rdi [/color][color=#008000]; rax = l_ScopeIndex
[/color][color=#0A246A]:::< [/color][color=#000000]fffff800`[/color][color=#800080]008a43d7 [/color][color=#0A246A]jae [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x166 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a4436[/color][color=#0A246A])
::::
:::: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x109[/color][color=#0A246A]:
:::: [/color][color=#000000]fffff800`[/color][color=#800080]008a43d9 [/color][color=#0A246A]add [/color][color=#000000]rax[/color][color=#0A246A],[/color][color=#000000]rax [/color][color=#008000];
[/color][color=#0A246A]:::: [/color][color=#000000]fffff800`[/color][color=#800080]008a43dc [/color][color=#0A246A]lea [/color][color=#000000]rbx[/color][color=#0A246A],[[/color][color=#000000]r12[/color][color=#0A246A]+[/color][color=#000000]rax[/color][color=#0A246A]*[/color][color=#800080]8[/color][color=#0A246A]+[/color][color=#800080]8[/color][color=#0A246A]] [/color][color=#008000]; rbx = &(pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].EndAddress)
[/color][color=#0A246A]::::
:::: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x111[/color][color=#0A246A]:
:::: [/color][color=#008000]; 检查 ControlPc 处于哪个 __try 保护域,之步骤一
[/color][color=#0A246A]:::: > [/color][color=#000000]fffff800`[/color][color=#800080]008a43e1 [/color][color=#0A246A]mov [/color][color=#FF8000]eax[/color][color=#0A246A],dword ptr [[/color][color=#000000]rbx[/color][color=#0A246A]-[/color][color=#800080]4[/color][color=#0A246A]] [/color][color=#008000]; eax = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].BeginAddress
[/color][color=#0A246A]:::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a43e4 [/color][color=#0A246A]cmp [/color][color=#000000]rbp[/color][color=#0A246A],[/color][color=#000000]rax [/color][color=#008000]; cmp l_OffsetInFunc, pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].BeginAddress
[/color][color=#0A246A]::::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a43e7 [/color][color=#0A246A]jb [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x15a [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a442a[/color][color=#0A246A])
::::: :
::::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x119[/color][color=#0A246A]:
::::: : [/color][color=#008000]; 检查 ControlPc 处于哪个 __try 保护域,之步骤二
[/color][color=#0A246A]::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a43e9 [/color][color=#0A246A]mov [/color][color=#FF8000]ecx[/color][color=#0A246A],dword ptr [[/color][color=#000000]rbx[/color][color=#0A246A]] [/color][color=#008000]; ecx = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].EndAddress
[/color][color=#0A246A]::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a43eb [/color][color=#0A246A]cmp [/color][color=#000000]rbp[/color][color=#0A246A],[/color][color=#000000]rcx [/color][color=#008000]; cmp l_OffsetInFunc, pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].EndAddress
[/color][color=#0A246A]:::::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a43ee [/color][color=#0A246A]jae [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x15a [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a442a[/color][color=#0A246A])
:::::: :
:::::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x120[/color][color=#0A246A]:
:::::: : [/color][color=#008000]; 到这里,已经找到与异常地址匹配的最内层(如果有多层) __try/__except
[/color][color=#0A246A]:::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a43f0 [/color][color=#0A246A]cmp [/color][color=#000000]rsi[/color][color=#0A246A],[/color][color=#000000]rax [/color][color=#008000]; cmp pDispatcherContext->TargetIp - pDispatcherContext->ImageBase, pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].BeginAddress
[/color][color=#0A246A]::::::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a43f3 [/color][color=#0A246A]jb [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x131 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a4401[/color][color=#0A246A])
::::::: :
::::::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x125[/color][color=#0A246A]:
::::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a43f5 [/color][color=#0A246A]cmp [/color][color=#000000]rsi[/color][color=#0A246A],[/color][color=#000000]rcx [/color][color=#008000]; cmp pDispatcherContext->TargetIp - pDispatcherContext->ImageBase, pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].EndAddress
[/color][color=#0A246A]:::::::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a43f8 [/color][color=#0A246A]ja [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x131 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a4401[/color][color=#0A246A])
:::::::: :
:::::::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x12a[/color][color=#0A246A]:
:::::::: : [/color][color=#008000]; 如果标记了 EXCEPTION_TARGET_UNWIND,说明是最后一个需要局部展开的函数。但是该次局部展开只展开到 EXCEPT_HANDLER(不包含 EXCEPT_HANDLER),所以需要判断 TargetIp
[/color][color=#0A246A]:::::::: : [/color][color=#000000]fffff800`[/color][color=#800080]008a43fa [/color][color=#0A246A]test byte ptr [[/color][color=#000000]r15[/color][color=#0A246A]+[/color][color=#800080]4[/color][color=#0A246A]],[/color][color=#800080]20h [/color][color=#008000]; test pExceptionRecord->ExceptionFlags, EXCEPTION_TARGET_UNWIND (0x20)
[/color][color=#0A246A]::::::::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a43ff [/color][color=#0A246A]jne [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x166 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a4436[/color][color=#0A246A])
::::::::: :
::::::::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x131[/color][color=#0A246A]:
::::::>>: : [/color][color=#000000]fffff800`[/color][color=#800080]008a4401 [/color][color=#0A246A]mov [/color][color=#FF8000]eax[/color][color=#0A246A],dword ptr [[/color][color=#000000]rbx[/color][color=#0A246A]+[/color][color=#800080]8[/color][color=#0A246A]] [/color][color=#008000]; eax = pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].JumpTarget
[/color][color=#0A246A]:::::: : : [/color][color=#000000]fffff800`[/color][color=#800080]008a4404 [/color][color=#0A246A]test [/color][color=#FF8000]eax[/color][color=#0A246A],[/color][color=#FF8000]eax [/color][color=#008000]; 判断 pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].JumpTarget 是否为 NULL,即是否是 __try/__finally
[/color][color=#0A246A]:::::: :< : [/color][color=#000000]fffff800`[/color][color=#800080]008a4406 [/color][color=#0A246A]je [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x13f [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a440f[/color][color=#0A246A]) [/color][color=#008000]; 如果是 __try/__finally 则跳转
[/color][color=#0A246A]:::::: :: :
:::::: :: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x138[/color][color=#0A246A]:
:::::: :: : [/color][color=#000000]fffff800`[/color][color=#800080]008a4408 [/color][color=#0A246A]cmp [/color][color=#000000]rsi[/color][color=#0A246A],[/color][color=#000000]rax [/color][color=#008000]; cmp pDispatcherContext->TargetIp, pDispatcherContext->HandlerData->ScopeRecord[l_ScopeIndex].JumpTarget
[/color][color=#0A246A]:::::: ::< : [/color][color=#000000]fffff800`[/color][color=#800080]008a440b [/color][color=#0A246A]je [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x166 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a4436[/color][color=#0A246A])
:::::: ::: :
:::::: ::: : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x13d[/color][color=#0A246A]:
:::::: :::<: [/color][color=#000000]fffff800`[/color][color=#800080]008a440d [/color][color=#0A246A]jmp [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x15a [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a442a[/color][color=#0A246A])
:::::: :::::
:::::: ::::: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x13f[/color][color=#0A246A]:
:::::: ::::: [/color][color=#008000]; 注意这里是先修改 pDispatcherContext->ScopeIndex,然后调用 EXCEPT_HANDLER。这样如果 EXCEPT_HANDLER 触发异常,后续展开就会跳过这个 EXCEPT_HANDLER。
[/color][color=#0A246A]:::::: :>::: [/color][color=#000000]fffff800`[/color][color=#800080]008a440f [/color][color=#0A246A]mov [/color][color=#000000]rdx[/color][color=#0A246A],qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]98h[/color][color=#0A246A]]
:::::: : ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a4417 [/color][color=#0A246A]lea [/color][color=#FF8000]eax[/color][color=#0A246A],[[/color][color=#000000]rdi[/color][color=#0A246A]+[/color][color=#800080]1[/color][color=#0A246A]] [/color][color=#008000]; eax = l_ScopeIndex + 1
[/color][color=#0A246A]:::::: : ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a441a [/color][color=#0A246A]mov [/color][color=#FF8000]cl[/color][color=#0A246A],[/color][color=#800080]1
[/color][color=#0A246A]:::::: : ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a441c [/color][color=#0A246A]mov dword ptr [[/color][color=#000000]r13[/color][color=#0A246A]+[/color][color=#800080]48h[/color][color=#0A246A]],[/color][color=#FF8000]eax [/color][color=#008000]; pDispatcherContext->ScopeIndex = eax
[/color][color=#0A246A]:::::: : ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a4420 [/color][color=#0A246A]mov [/color][color=#000000]r8d[/color][color=#0A246A],dword ptr [[/color][color=#000000]rbx[/color][color=#0A246A]+[/color][color=#800080]4[/color][color=#0A246A]] [/color][color=#008000]; r8d = pDispatcherContext->HandlerData->ScopeRecord[i].HandlerAddress
[/color][color=#0A246A]:::::: : ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a4424 [/color][color=#0A246A]add [/color][color=#000000]r8[/color][color=#0A246A],[/color][color=#000000]r14 [/color][color=#008000]; r8 = pDispatcherContext->HandlerData->ScopeRecord[i].HandlerAddress + pDispatcherContext->ImageBase
[/color][color=#0A246A]:::::: : ::: [/color][color=#000000]fffff800`[/color][color=#800080]008a4427 [/color][color=#0A246A]call [/color][color=#000000]r8 [/color][color=#008000]; 调用 __finally 处理块,会返回(注:对于 __try/__finally,HandlerAddress 保存的是 __finally 代码块的 RVA)
[/color][color=#0A246A]:::::: : :::
:::::: : ::: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x15a[/color][color=#0A246A]:
::::>> : :>: [/color][color=#000000]fffff800`[/color][color=#800080]008a442a [/color][color=#0A246A]inc [/color][color=#FF8000]edi [/color][color=#008000]; l_ScopeIndex += 1
[/color][color=#0A246A]:::: : : : [/color][color=#000000]fffff800`[/color][color=#800080]008a442c [/color][color=#0A246A]add [/color][color=#000000]rbx[/color][color=#0A246A],[/color][color=#800080]10h [/color][color=#008000]; 调整到下一个 ScopeRecord::HandlerAddress
[/color][color=#0A246A]:::: : : : [/color][color=#000000]fffff800`[/color][color=#800080]008a4430 [/color][color=#0A246A]cmp [/color][color=#FF8000]edi[/color][color=#0A246A],dword ptr [[/color][color=#000000]r12[/color][color=#0A246A]] [/color][color=#008000]; cmp l_ScopeIndex, pDispatcherContext->HandlerData->Count
[/color][color=#0A246A]:::: : : < [/color][color=#000000]fffff800`[/color][color=#800080]008a4434 [/color][color=#0A246A]jb [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x111 [/color][color=#0A246A]([/color][color=#000000]fffff800`[/color][color=#800080]008a43e1[/color][color=#0A246A])
:::: : :
:::: : : [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x166[/color][color=#0A246A]:
>>:> > > [/color][color=#000000]fffff800`[/color][color=#800080]008a4436 [/color][color=#0A246A]mov [/color][color=#FF8000]eax[/color][color=#0A246A],[/color][color=#800080]1 [/color][color=#008000]; eax = ExceptionContinueSearch (0n1)
[/color][color=#0A246A]:
: [/color][color=#000000]nt!__C_specific_handler[/color][color=#0A246A]+[/color][color=#800080]0x16b[/color][color=#0A246A]:
> [/color][color=#000000]fffff800`[/color][color=#800080]008a443b [/color][color=#0A246A]mov [/color][color=#000000]r15[/color][color=#0A246A],qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]48h[/color][color=#0A246A]]
[/color][color=#000000]fffff800`[/color][color=#800080]008a4440 [/color][color=#0A246A]mov [/color][color=#000000]r14[/color][color=#0A246A],qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]50h[/color][color=#0A246A]]
[/color][color=#000000]fffff800`[/color][color=#800080]008a4445 [/color][color=#0A246A]mov [/color][color=#000000]r13[/color][color=#0A246A],qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]58h[/color][color=#0A246A]]
[/color][color=#000000]fffff800`[/color][color=#800080]008a444a [/color][color=#0A246A]mov [/color][color=#000000]r12[/color][color=#0A246A],qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]60h[/color][color=#0A246A]]
[/color][color=#000000]fffff800`[/color][color=#800080]008a444f [/color][color=#0A246A]mov [/color][color=#000000]rdi[/color][color=#0A246A],qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]68h[/color][color=#0A246A]]
[/color][color=#000000]fffff800`[/color][color=#800080]008a4454 [/color][color=#0A246A]mov [/color][color=#000000]rsi[/color][color=#0A246A],qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]70h[/color][color=#0A246A]]
[/color][color=#000000]fffff800`[/color][color=#800080]008a4459 [/color][color=#0A246A]mov [/color][color=#000000]rbp[/color][color=#0A246A],qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]78h[/color][color=#0A246A]]
[/color][color=#000000]fffff800`[/color][color=#800080]008a445e [/color][color=#0A246A]mov [/color][color=#000000]rbx[/color][color=#0A246A],qword ptr [[/color][color=#000000]rsp[/color][color=#0A246A]+[/color][color=#800080]80h[/color][color=#0A246A]]
[/color][color=#000000]fffff800`[/color][color=#800080]008a4466 [/color][color=#0A246A]add [/color][color=#000000]rsp[/color][color=#0A246A],[/color][color=#800080]88h
[/color][color=#000000]fffff800`[/color][color=#800080]008a446d [/color][color=#000000]ret[/color][/font]
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
上传的附件: