// 一小段反汇编引擎
// file asm_analzer.cpp
// begin copy
unsigned char unk_1314BDB0[320] = {
0x10, 0x05, 0xFF, 0xFF, 0x10, 0x41, 0x10, 0x41, 0x10, 0x81, 0x10, 0x81, 0x10, 0x81, 0x10, 0x81,
0x10, 0x05, 0xFF, 0xFF, 0x10, 0x41, 0x10, 0x41, 0x10, 0x81, 0x10, 0x81, 0x10, 0x81, 0x10, 0x81,
0xA0, 0x0D, 0xFF, 0xFF, 0xA0, 0x41, 0xA0, 0x41, 0xA0, 0x81, 0xA0, 0x81, 0xA0, 0x81, 0xA0, 0x81,
0xA0, 0x0D, 0xFF, 0xFF, 0xA0, 0x41, 0xA0, 0x41, 0xA0, 0x81, 0xA0, 0x81, 0xA0, 0x81, 0xA0, 0x81,
0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01,
0x36, 0x00, 0x36, 0x00, 0x30, 0x00, 0x30, 0x00, 0x36, 0x00, 0x36, 0x00, 0x36, 0x00, 0x36, 0x00,
0x20, 0x01, 0xFF, 0xFF, 0x20, 0x01, 0x20, 0x01, 0x10, 0x01, 0x18, 0x01, 0x10, 0x01, 0x18, 0x01,
0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01,
0x36, 0x00, 0x36, 0x00, 0x36, 0x00, 0x36, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x20, 0x01, 0xFF, 0xFF, 0x20, 0x01, 0x20, 0x01, 0xFF, 0xFF, 0x30, 0x01, 0xFF, 0xFF, 0x30, 0x01,
0x36, 0x00, 0x36, 0x00, 0x36, 0x00, 0x36, 0x00, 0x00, 0x00, 0x36, 0x00, 0x36, 0x00, 0x00, 0x00,
0x28, 0x01, 0x28, 0x01, 0x28, 0x01, 0x28, 0x01, 0x28, 0x01, 0x28, 0x01, 0x28, 0x01, 0x28, 0x01,
0x36, 0x02, 0x36, 0x02, 0x30, 0x00, 0x30, 0x00, 0x36, 0x02, 0x36, 0x02, 0x36, 0x02, 0x36, 0x02,
0x28, 0x01, 0xFF, 0xFF, 0x28, 0x01, 0x28, 0x01, 0x10, 0x01, 0xFF, 0xFF, 0x10, 0x01, 0x18, 0x01,
0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x18, 0x01, 0x18, 0x01, 0x18, 0x01, 0x18, 0x01, 0x18, 0x01, 0x18, 0x01, 0x18, 0x01, 0x18, 0x01,
0x36, 0x02, 0x36, 0x02, 0x30, 0x00, 0x36, 0x02, 0x36, 0x02, 0x36, 0x02, 0x36, 0x02, 0x36, 0x02,
0x18, 0x01, 0xFF, 0xFF, 0x18, 0x01, 0x18, 0x01, 0x30, 0x01, 0x28, 0x01, 0x30, 0x01, 0x28, 0x01,
0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x36, 0x00, 0x36, 0x00, 0xFF, 0xFF
};
unsigned char word_1314B9B0[512] = {
0x11, 0x42, 0xE4, 0x42, 0x11, 0x20, 0xE4, 0x20, 0x01, 0x84, 0x42, 0x8C, 0x00, 0x00, 0x00, 0x00,
0x11, 0x42, 0xE4, 0x42, 0x11, 0x20, 0xE4, 0x20, 0x01, 0x84, 0x42, 0x8C, 0x00, 0x00, 0x00, 0x00,
0x11, 0x42, 0xE4, 0x42, 0x11, 0x20, 0xE4, 0x20, 0x01, 0x84, 0x42, 0x8C, 0x00, 0x00, 0x00, 0x00,
0x11, 0x42, 0xE4, 0x42, 0x11, 0x20, 0xE4, 0x20, 0x01, 0x84, 0x42, 0x8C, 0x00, 0x00, 0x00, 0x00,
0x11, 0x42, 0xE4, 0x42, 0x11, 0x20, 0xE4, 0x20, 0x01, 0x84, 0x42, 0x8C, 0x00, 0x00, 0x00, 0x80,
0x11, 0x42, 0xE4, 0x42, 0x11, 0x20, 0xE4, 0x20, 0x01, 0x84, 0x42, 0x8C, 0x00, 0x00, 0x00, 0x80,
0x11, 0x42, 0xE4, 0x42, 0x11, 0x20, 0xE4, 0x20, 0x01, 0x84, 0x42, 0x8C, 0x00, 0x00, 0x00, 0x80,
0x11, 0x02, 0xE4, 0x02, 0x11, 0x00, 0xE4, 0x00, 0x01, 0x04, 0x42, 0x0C, 0x00, 0x00, 0x00, 0x80,
0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60,
0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60,
0x45, 0x00, 0x45, 0x00, 0x45, 0x00, 0x45, 0x00, 0x45, 0x00, 0x45, 0x00, 0x45, 0x00, 0x45, 0x00,
0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60, 0x45, 0x60,
0x00, 0x00, 0x00, 0x80, 0xE4, 0x00, 0x1A, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0C, 0xE4, 0x2C, 0x00, 0x04, 0xE4, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14,
0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14,
0x10, 0x05, 0xA0, 0x0D, 0x10, 0x05, 0xA0, 0x05, 0x11, 0x02, 0xE4, 0x02, 0x11, 0xA2, 0xE4, 0xA2,
0x11, 0x42, 0xE4, 0x42, 0x11, 0x20, 0xE4, 0x20, 0xE3, 0x42, 0xE4, 0x20, 0xE3, 0x00, 0xA0, 0x01,
0x00, 0x00, 0x46, 0xE0, 0x46, 0xE0, 0x46, 0xE0, 0x46, 0xE0, 0x46, 0xE0, 0x46, 0xE0, 0x46, 0xE0,
0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x01, 0x81, 0x42, 0x81, 0x01, 0x03, 0x42, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x04, 0x42, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
0x04, 0x64, 0x04, 0x64, 0x04, 0x64, 0x04, 0x64, 0x04, 0x64, 0x04, 0x64, 0x04, 0x64, 0x04, 0x64,
0x45, 0x6C, 0x45, 0x6C, 0x45, 0x6C, 0x45, 0x6C, 0x45, 0x6C, 0x45, 0x6C, 0x45, 0x6C, 0x45, 0x6C,
0x10, 0x45, 0xA0, 0x45, 0x00, 0x08, 0x00, 0x00, 0xE4, 0x20, 0xE4, 0x20, 0x10, 0x45, 0xA0, 0x4D,
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
0x10, 0x41, 0xA0, 0x41, 0x10, 0x41, 0xA0, 0x41, 0x00, 0x84, 0x00, 0x84, 0x00, 0x00, 0x00, 0x80,
0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00,
0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x01, 0x84, 0x42, 0x84, 0x01, 0x06, 0x42, 0x06,
0x00, 0x1C, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x14, 0x07, 0x80, 0x47, 0x80, 0x07, 0x02, 0x47, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x41, 0xA0, 0x01
};
unsigned char word_1314BBB0[512] = {
0x18, 0x01, 0x20, 0x01, 0xE4, 0x20, 0xE4, 0x20, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x01, 0x00, 0x00, 0x2D, 0x05,
0x3F, 0x00, 0x3F, 0x02, 0x3F, 0x00, 0x3F, 0x02, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x02,
0x10, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x23, 0x40, 0x23, 0x40, 0x23, 0x02, 0x23, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x3F, 0x00, 0x3F, 0x02, 0x2F, 0x00, 0x3F, 0x02, 0x3D, 0x00, 0x3D, 0x00, 0x3F, 0x00, 0x3F, 0x00,
0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20,
0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x20,
0x27, 0x42, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00,
0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x00,
0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00,
0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0x65, 0x00, 0xED, 0x00,
0xED, 0x04, 0xA8, 0x04, 0xA8, 0x04, 0xA8, 0x04, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x65, 0x02, 0xED, 0x02,
0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C,
0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x1C,
0x10, 0x41, 0x10, 0x41, 0x10, 0x41, 0x10, 0x41, 0x10, 0x41, 0x10, 0x41, 0x10, 0x41, 0x10, 0x41,
0x10, 0x41, 0x10, 0x41, 0x10, 0x41, 0x10, 0x41, 0x10, 0x41, 0x10, 0x41, 0x10, 0x41, 0x10, 0x41,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE4, 0x02, 0xE4, 0x47, 0xE4, 0x43, 0x11, 0xC2, 0xE4, 0xC2,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE4, 0x42, 0xE4, 0x47, 0xE4, 0x43, 0x20, 0x00, 0xE4, 0x20,
0x11, 0xC2, 0xE4, 0xC2, 0xE4, 0x20, 0xE4, 0x42, 0xE4, 0x20, 0xE4, 0x22, 0x54, 0x21, 0x1C, 0x21,
0xFF, 0xFF, 0xFF, 0xFF, 0xA0, 0x05, 0xE4, 0x42, 0xE4, 0x20, 0xE4, 0x20, 0x54, 0x21, 0x1C, 0x21,
0x11, 0xA2, 0xE4, 0xA2, 0x3F, 0x04, 0x24, 0x02, 0x65, 0x04, 0xAC, 0x24, 0x3F, 0x04, 0x28, 0x81,
0x05, 0x60, 0x05, 0x60, 0x05, 0x60, 0x05, 0x60, 0x05, 0x60, 0x05, 0x60, 0x05, 0x60, 0x05, 0x60,
0xFF, 0xFF, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x02, 0xAC, 0x20,
0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00,
0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0x3F, 0x00, 0xED, 0x02,
0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00,
0xFF, 0xFF, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00,
0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, 0x00, 0x00, 0x00
};
int jump_table[11];
int get_code_len(void *code)
{
#define var_14 -0x14
#define var_10 -0x10
#define var_C -0xc
#define var_8 -0x8 int retval;
__asm
{
; constructor the jump_table
lea eax, jump_table
mov ecx, loc_13148BE1
mov dword ptr [eax], ecx
add eax, 4
mov ecx, loc_13148B8B
mov dword ptr [eax], ecx
add eax, 4
mov ecx, loc_13148B92
mov dword ptr [eax], ecx
add eax, 4
mov ecx, loc_13148B9B
mov dword ptr [eax], ecx
add eax, 4
mov ecx, loc_13148BA4
mov dword ptr [eax], ecx
add eax, 4
mov ecx, loc_13148BAD
mov dword ptr [eax], ecx
add eax, 4
mov ecx, loc_13148BB6
mov dword ptr [eax], ecx
add eax, 4
mov ecx, loc_13148BBF
mov dword ptr [eax], ecx
add eax, 4
mov ecx, loc_13148BC8
mov dword ptr [eax], ecx
add eax, 4
mov ecx, loc_13148BD1
mov dword ptr [eax], ecx
add eax, 4
mov ecx, loc_13148BDA
mov dword ptr [eax], ecx
mov eax, code
pushad
push ebp
mov ebp, esp
add esp, 0FFFFFFECh mov edi, eax
test eax, eax
jz loc_13148C88
mov byte ptr [ebp-1], 0
xor edx, edx
mov dword ptr [ebp+var_8], 4
xor ecx, ecx
mov dword ptr [ebp+var_14], ecx
loc_13148A1D: ; CODE XREF: sub_131489E4+74j
movzx esi, byte ptr [eax]
inc eax
cmp si, 66h
jnz short loc_13148A30
mov dword ptr [ebp+var_8], 2
jmp short loc_13148A56
; ---------------------------------------------------------------------------
loc_13148A30: ; CODE XREF: sub_131489E4+41j
cmp si, 67h
jnz short loc_13148A3C
mov byte ptr [ebp-1], 1
jmp short loc_13148A56
; ---------------------------------------------------------------------------
loc_13148A3C: ; CODE XREF: sub_131489E4+50j
mov ecx, esi
and cx, 0E7h
cmp cx, 26h
jz short loc_13148A56
mov ecx, esi
add ecx, 0FFFFFF9Ch
sub cx, 2
jb short loc_13148A56
mov dl, 1
loc_13148A56: ; CODE XREF: sub_131489E4+4Aj
; sub_131489E4+56j ...
test dl, dl
jz short loc_13148A1D
cmp si, 0Fh
jnz short loc_13148A76
movzx esi, byte ptr [eax]
movzx edx, si
movzx ecx, word ptr word_1314BBB0[edx*2]
add si, 0F00h
inc eax
jmp short loc_13148A81
; ---------------------------------------------------------------------------
loc_13148A76: ; CODE XREF: sub_131489E4+7Aj
movzx edx, si
movzx ecx, word ptr word_1314B9B0[edx*2]
loc_13148A81: ; CODE XREF: sub_131489E4+90j
test cl, 38h
jz loc_13148C24
movzx edx, byte ptr [eax]
mov ebx, edx
and bl, 7
movzx ebx, bl
mov dword ptr [ebp+var_C], ebx
inc eax
mov ebx, edx
and bl, 0C0h
sub bl, 40h
jz short loc_13148AAA
sub bl, 40h
jz short loc_13148AB3
jmp short loc_13148ACB
; ---------------------------------------------------------------------------
loc_13148AAA: ; CODE XREF: sub_131489E4+BDj
mov dword ptr [ebp+var_10], 1
jmp short loc_13148AD0
; ---------------------------------------------------------------------------
loc_13148AB3: ; CODE XREF: sub_131489E4+C2j
cmp byte ptr [ebp-1], 0
jz short loc_13148AC2
mov dword ptr [ebp+var_10], 2
jmp short loc_13148AD0
; ---------------------------------------------------------------------------
loc_13148AC2: ; CODE XREF: sub_131489E4+D3j
mov dword ptr [ebp+var_10], 4
jmp short loc_13148AD0
; ---------------------------------------------------------------------------
loc_13148ACB: ; CODE XREF: sub_131489E4+C4j
xor ebx, ebx
mov dword ptr [ebp+var_10], ebx
loc_13148AD0: ; CODE XREF: sub_131489E4+CDj
; sub_131489E4+DCj ...
mov ebx, edx
and bl, 0C0h
cmp bl, 0C0h
setnz bl
and bl, byte ptr [ebp-1]
jnz short loc_13148B11
cmp dword ptr [ebp+var_C], 4
jnz short loc_13148AFC
mov ebx, edx
and bl, 0C0h
cmp bl, 0C0h
jz short loc_13148AFC
movzx ebx, byte ptr [eax]
and bl, 7
movzx ebx, bl
mov dword ptr [ebp+var_C], ebx
loc_13148AFC: ; CODE XREF: sub_131489E4+100j
; sub_131489E4+10Aj
test dl, 0C0h
jnz short loc_13148B0E
cmp dword ptr [ebp+var_C], 5
jnz short loc_13148B0E
mov dword ptr [ebp+var_10], 4
loc_13148B0E: ; CODE XREF: sub_131489E4+11Bj
; sub_131489E4+121j
add eax, dword ptr [ebp+var_10]
loc_13148B11: ; CODE XREF: sub_131489E4+FAj
mov ebx, ecx
and ebx, 38h
cmp ebx, 8
jnz loc_13148C24
movzx ecx, si
add ecx, 0FFFFFF28h
cmp ecx, 1Fh ; switch 32 cases
ja loc_13148BE1 ; default
; jumptable 13148B38 cases 8-29
movzx ecx, ds:byte_13148B3F[ecx]
jmp ds:jump_table[ecx*4] ; switch jump
; ---------------------------------------------------------------------------
byte_13148B3F: ; DATA XREF: sub_131489E4+14Dr
_asm _emit 3 _asm _emit 4 _asm _emit 5 _asm _emit 6
_asm _emit 7 _asm _emit 8 _asm _emit 9 _asm _emit 0ah ; indirect table for switch statement
_asm _emit 0 _asm _emit 0 _asm _emit 0 _asm _emit 0
_asm _emit 0 _asm _emit 0 _asm _emit 0 _asm _emit 0
_asm _emit 0 _asm _emit 0 _asm _emit 0 _asm _emit 0
_asm _emit 0 _asm _emit 0 _asm _emit 0 _asm _emit 0
_asm _emit 0 _asm _emit 0 _asm _emit 0 _asm _emit 0
_asm _emit 0 _asm _emit 0 _asm _emit 1 _asm _emit 2
; ---------------------------------------------------------------------------
loc_13148B8B: ; CODE XREF: sub_131489E4+154j
; DATA XREF: sub_131489E4:off_13148B5Fo
xor ecx, ecx ; jumptable 13148B38 case 30
mov dword ptr [ebp+var_14], ecx
jmp short loc_13148BE1 ; default
; jumptable 13148B38 cases 8-29
; ---------------------------------------------------------------------------
loc_13148B92: ; CODE XREF: sub_131489E4+154j
; DATA XREF: sub_131489E4:off_13148B5Fo
mov dword ptr [ebp+var_14], 1 ; jumptable 13148B38 case 31
jmp short loc_13148BE1 ; default
; jumptable 13148B38 cases 8-29
; ---------------------------------------------------------------------------
loc_13148B9B: ; CODE XREF: sub_131489E4+154j
; DATA XREF: sub_131489E4:off_13148B5Fo
mov DWORD ptr [ebp+var_14], 2 ; jumptable 13148B38 case 0
jmp short loc_13148BE1 ; default
; jumptable 13148B38 cases 8-29
; ---------------------------------------------------------------------------
loc_13148BA4: ; CODE XREF: sub_131489E4+154j
; DATA XREF: sub_131489E4:off_13148B5Fo
mov DWORD ptr [ebp+var_14], 3 ; jumptable 13148B38 case 1
jmp short loc_13148BE1 ; default
; jumptable 13148B38 cases 8-29
; ---------------------------------------------------------------------------
loc_13148BAD: ; CODE XREF: sub_131489E4+154j
; DATA XREF: sub_131489E4:off_13148B5Fo
mov dword ptr [ebp+var_14], 4 ; jumptable 13148B38 case 2
jmp short loc_13148BE1 ; default
; jumptable 13148B38 cases 8-29
; ---------------------------------------------------------------------------
loc_13148BB6: ; CODE XREF: sub_131489E4+154j
; DATA XREF: sub_131489E4:off_13148B5Fo
mov dword ptr [ebp+var_14], 5 ; jumptable 13148B38 case 3
jmp short loc_13148BE1 ; default
; jumptable 13148B38 cases 8-29
; ---------------------------------------------------------------------------
loc_13148BBF: ; CODE XREF: sub_131489E4+154j
; DATA XREF: sub_131489E4:off_13148B5Fo
mov dword ptr [ebp+var_14], 6 ; jumptable 13148B38 case 4
jmp short loc_13148BE1 ; default
; jumptable 13148B38 cases 8-29
; ---------------------------------------------------------------------------
loc_13148BC8: ; CODE XREF: sub_131489E4+154j
; DATA XREF: sub_131489E4:off_13148B5Fo
mov dword ptr [ebp+var_14], 7 ; jumptable 13148B38 case 5
jmp short loc_13148BE1 ; default
; jumptable 13148B38 cases 8-29
; ---------------------------------------------------------------------------
loc_13148BD1: ; CODE XREF: sub_131489E4+154j
; DATA XREF: sub_131489E4:off_13148B5Fo
mov dword ptr [ebp+var_14], 8 ; jumptable 13148B38 case 6
jmp short loc_13148BE1 ; default
; jumptable 13148B38 cases 8-29
; ---------------------------------------------------------------------------
loc_13148BDA: ; CODE XREF: sub_131489E4+154j
; DATA XREF: sub_131489E4:off_13148B5Fo
mov dword ptr [ebp+var_14], 9 ; jumptable 13148B38 case 7
loc_13148BE1: ; CODE XREF: sub_131489E4+147j
; sub_131489E4+154j ...
mov ecx, edx ; default
; jumptable 13148B38 cases 8-29
and cl, 0C0h
cmp cl, 0C0h
jz short loc_13148C08
movzx edx, dl
shr edx, 3
and edx, 7
mov ecx, dword ptr [ebp+var_14]
add ecx, ecx
add ecx, ecx
lea ecx, unk_1314BDB0[ecx*8]
movzx ecx, word ptr [ecx+edx*2]
jmp short loc_13148C24
; ---------------------------------------------------------------------------
loc_13148C08: ; CODE XREF: sub_131489E4+205j
movzx edx, dl
shr edx, 3
and edx, 7
mov ecx, dword ptr [ebp+var_14]
add ecx, ecx
add ecx, ecx
lea ecx, unk_1314BDB0[ecx*8]
movzx ecx, word ptr [ecx+edx*2+10h]
loc_13148C24: ; CODE XREF: sub_131489E4+A0j
; sub_131489E4+135j ...
and ecx, 0C00h
sub ecx, 400h
jz short loc_13148C44
sub ecx, 400h
jz short loc_13148C47
sub ecx, 400h
jz short loc_13148C4C
jmp short loc_13148C51
; ---------------------------------------------------------------------------
loc_13148C44: ; CODE XREF: sub_131489E4+24Cj
inc eax
jmp short loc_13148C88
; ---------------------------------------------------------------------------
loc_13148C47: ; CODE XREF: sub_131489E4+254j
add eax, 2
jmp short loc_13148C88
; ---------------------------------------------------------------------------
loc_13148C4C: ; CODE XREF: sub_131489E4+25Cj
add eax, dword ptr [ebp+var_8]
jmp short loc_13148C88
; ---------------------------------------------------------------------------
loc_13148C51: ; CODE XREF: sub_131489E4+25Ej
sub si, 9Ah
jz short loc_13148C6D
add esi, 0FFFFFFFAh
sub si, 4
jb short loc_13148C7A
sub si, 24h
jz short loc_13148C75
sub si, 22h
jnz short loc_13148C88
loc_13148C6D: ; CODE XREF: sub_131489E4+272j
add eax, dword ptr [ebp+var_8]
add eax, 2
jmp short loc_13148C88
; ---------------------------------------------------------------------------
loc_13148C75: ; CODE XREF: sub_131489E4+281j
add eax, 3
jmp short loc_13148C88
; ---------------------------------------------------------------------------
loc_13148C7A: ; CODE XREF: sub_131489E4+27Bj
cmp byte ptr [ebp-1], 0
jz short loc_13148C85
add eax, 2
jmp short loc_13148C88
; ---------------------------------------------------------------------------
loc_13148C85: ; CODE XREF: sub_131489E4+29Aj
add eax, 4
loc_13148C88: ; CODE XREF: sub_131489E4+21j
; sub_131489E4+261j ...
mov ebx, eax
sub ebx, edi
mov eax, ebx mov esp, ebp
pop ebp
mov retval, eax
popad
}
return retval;
}
// end copy
函数get_code_len能得到某个地址的指令长度 对于api hook来说, 经常需要用到反汇编引擎, 因为apihook一半采用inline hook, 就是把api开头的一些字节(>5)取走,
拷贝到一个新的内存, 最后在跳转回来.
然后api开始的地址jump到一个自己的函数去, 自己的函数处理以后, 在去call刚刚那个新内存, 达到hook的目的 早期曾做过一个api hook, 并没有用到反汇编引擎, 而是用了一种巧妙的方法来实现.
具体的说就是吧api的头5个字节备份起来, jump到自己的处理函数, 自己的处理函数把5个字节还原call一把, 然后在重新jump到自己去
但是这里存在一个问题, 在多线程的情况下, 如果某个线程call api的时候, 恰巧让代码还原了, 这时另外的线程
又call到这个api来了, 则这跳记录没被记录, 所幸这种概率很小, 因为一般的api执行速度很快, 很难碰到这个"临界点"
但是问题来了.
有个朋友让我帮他写个能hook send, recv函数的小功能, 并且提供修改机制. 也就是早期的wpe的功能.
send一般不容易出问题, 但recv不行, 因为recv是个阻塞函数, 如果没有收到数据则不返回,
如果2个线程都在调用recv(比如在游戏里面接收数据,游戏外挂同时接收数据), 则上面的那种还原代码不行
到网上找到一款软件packassist, 能够做到wpe的这点功能, 但是只是截取, 动态修改包的功能不行.
于是ida了下他的代码, 发现他hook api的方式就是用了指令抽取, 所以必须有反汇编引擎.
找到 get_code_len函数后, 下面就是吧他从ida里面嵌到vc内联汇编里面.
这里碰到几个问题.
1: 他开始下了个seh,seh handler是delphi的库处理函数, 比较复杂, 干脆取消
2: 有很多全局表, 于是od下他, 然后winhex打开进程内存, 按c格式拷贝, 在vc中复制。
3: switch case jump table. 这个比较麻烦, 因为vc内联汇编无法db offset label.(之前的1级表倒是可以_asm _emit掉)
于是想到用一个数组, 然后在代码开头跟这个数组初始化, 注意这里是全局数组, 一会说为什么必须是全局的
4: 对于 ida里面的 mov [ebp+Var_c], 1 这样的代码, 其中Var_c是-0xc, 是一个函数的局部变量。
这个栈帧是原来的代码构造的, 所以这里必须也用 push ebp mov ebp, esp sub esp, -20 这样的来构造。
要不用到自己的栈帧会吧自己的局部变量冲掉。
5: 因为在内联汇编里面用了新的栈帧, 所以一定不能在这个栈帧里面使用函数的局部变量, 所以3里面用全局
另外可以看到, 有一个eax的返回值放到retval里面, 这里可以正确的使用retval, 因为他出现在 pop ebp
这条语句后, 已经出了原函数的栈。
6: vc里面, 如果不显示的说明 word ptr, dword ptr, byte ptr, 那么他根据操作数的大小智能(弱智?)的
采用 byte ptr, word ptr... 比如 mov [ebp-4], 1 则是用byte ptr. 但ida不知道, 所以全部的局部变量
的使用, 必须手工修改一遍. 另外, 对于Var_c这样的东西, 这里是用 #define -0xc 这样实现的
如果是一个 const int Var_c = -0xc; 这样的形式, vc会编译出错误的代码.
7:delphi fastcall 采用 eax, edx, ecx分别传递前3个参数, 如果还有再依次push, 所以这里需要先跟eax给值
其实这种轻量级的反汇编引擎网上多的是, 姑且作为一种学习笔记吧。
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课