Re: [求助]windbg uf命令如何实现

WinDbg

[求助]windbg uf命令如何实现


vitamin 2011-02-23, 17:50 下午

使用uf命令将一个函数的反汇编代码都给列出来,即便代码不连续也可以列出来,想问一下uf命令是如何做到的。

比如:

0: kd> uf KeInitializeApc
nt!KeInitializeApc:
804e6c69 8bff            mov     edi,edi
804e6c6b 55              push    ebp
804e6c6c 8bec            mov     ebp,esp
804e6c6e 8b4508          mov     eax,dword ptr [ebp+8]
804e6c71 8b5510          mov     edx,dword ptr [ebp+10h]
804e6c74 83fa02          cmp     edx,2
804e6c77 8b4d0c          mov     ecx,dword ptr [ebp+0Ch]
804e6c7a 66c7001200      mov     word ptr [eax],12h
804e6c7f 66c740023000    mov     word ptr [eax+2],30h
804e6c85 0f846d0f0000    je      nt!KeInitializeApc+0x1e (804e7bf8)

nt!KeInitializeApc+0x24:
804e6c8b 894808          mov     dword ptr [eax+8],ecx
804e6c8e 8b4d14          mov     ecx,dword ptr [ebp+14h]
804e6c91 894814          mov     dword ptr [eax+14h],ecx
804e6c94 8b4d18          mov     ecx,dword ptr [ebp+18h]
804e6c97 88502c          mov     byte ptr [eax+2Ch],dl
804e6c9a 894818          mov     dword ptr [eax+18h],ecx
804e6c9d 8b4d1c          mov     ecx,dword ptr [ebp+1Ch]
804e6ca0 33d2            xor     edx,edx
804e6ca2 3bca            cmp     ecx,edx
804e6ca4 89481c          mov     dword ptr [eax+1Ch],ecx
804e6ca7 0f85c2010000    jne     nt!KeInitializeApc+0x42 (804e6e6f)

nt!KeInitializeApc+0x50:
804e6cad 88502d          mov     byte ptr [eax+2Dh],dl
804e6cb0 895020          mov     dword ptr [eax+20h],edx

nt!KeInitializeApc+0x56:
804e6cb3 88502e          mov     byte ptr [eax+2Eh],dl
804e6cb6 5d              pop     ebp
804e6cb7 c22000          ret     20h

nt!KeInitializeApc+0x42:
804e6e6f 8a4d20          mov     cl,byte ptr [ebp+20h]
804e6e72 88482d          mov     byte ptr [eax+2Dh],cl
804e6e75 8b4d24          mov     ecx,dword ptr [ebp+24h]
804e6e78 894820          mov     dword ptr [eax+20h],ecx
804e6e7b e933feffff      jmp     nt!KeInitializeApc+0x56 (804e6cb3)

nt!KeInitializeApc+0x1e:
804e7bf8 8a9165010000    mov     dl,byte ptr [ecx+165h]
804e7bfe e988f0ffff      jmp     nt!KeInitializeApc+0x24 (804e6c8b)

ret     20h后面的804e6e6f和804e7bf8 开始的两处代码跟前面的代码就不连续内存中的,uf命令也可以识别出来。请问uf是如何识别的?通过解析跳转指令发现的?还是符号文件有什么标记信息?

Re: [求助]windbg uf命令如何实现


王宇 2011-02-23, 19:18 下午
这个不太难做。从起点开始反汇编,分析时记录所有转移指令,结合基本块形成图结构。

distorm3 标榜自己具有“所谓的” Basic Flow Control analysis support 能力,看实现也就是标记 / 提示 (终止于) 所有的 flow control instructions,如下:

#define DF_STOP_ON_CALL 8
/* The decoder will stop and return to the caller when the instruction 'RET' (near and far) was decoded. */
#define DF_STOP_ON_RET 0x10
/* The decoder will stop and return to the caller when the instruction system-call/ret was decoded. */
#define DF_STOP_ON_SYS 0x20
/* The decoder will stop and return to the caller when any of the branch 'JMP', (near and far) instructions were decoded. */
#define DF_STOP_ON_UNC_BRANCH 0x40
/* The decoder will stop and return to the caller when any of the conditional branch instruction were decoded. */
#define DF_STOP_ON_CND_BRANCH 0x80
/* The decoder will stop and return to the caller when the instruction 'INT' (INT, INT1, INTO, INT 3) was decoded. */
#define DF_STOP_ON_INT 0x100
/* The decoder will stop and return to the caller when any of the 'CMOVxx' instruction was decoded. */
#define DF_STOP_ON_CMOV 0x200
/* The decoder will stop and return to the caller when any flow control instruction was decoded. */

Re: [求助]windbg uf命令如何实现


vitamin 2011-02-23, 19:42 下午

没注意distorm还有这功能。

flow control instructions在哪里设置呢?distorm_decode没有设置的选项啊, distorm_decompose函数没有用过,楼上的兄弟有用过吗?

Re: [求助]windbg uf命令如何实现


王宇 2011-02-23, 20:09 下午
我用过。

新接口的第一参数是 _CodeInfo,上述特性在 features 域。

distorm_decompose64/32 和 distorm_decode64/32 等的区别之一在于 decode_internal 的调用方法,也就是新参数 supportOldIntr。详细的解释 ( backward compatibility ) 在代码里有。

Powered by Community Server Powered by CnForums.Net