好友
阅读权限20
听众
最后登录1970-1-1
|
有一个子函数,通过IDA后生成的伪代码如下,虽然能读懂C代码,但是不理解函数的参数对应到哪里去?
百度搜索了一些资料,大概能明白局部变量v5后面的注释“edx@1”表示的是edx第几次的值,“[sp+14h] [bp+8h]@1”标识ESP+14h或EBP+8h,但是根据单步跟踪时的数据,ESP+14h和EBP+8h计算出来的地址是一样的。
另外,这个子函数有5个传入参数,这5个参数从哪里传进去呢?如何确定他们对应的地址?
从汇编代码中可以看到有如下五个变量的,是对应子函数的5个参数地址吗?如果是的话这几个地址怎么理解?从哪个地址上算起?
.text:0040C940 arg_0 = qword ptr 4
.text:0040C940 arg_8 = dword ptr 0Ch
.text:0040C940 arg_C = dword ptr 10h
.text:0040C940 arg_10 = dword ptr 14h
.text:0040C940 arg_14 = dword ptr 18h
伪代码如下:
[C] 纯文本查看 复制代码 signed int __cdecl sub_40C940(__int64 a1, int a2, _WORD *a3, _BYTE *a4, _BYTE *a5)
{
int v5; // edx@1
int v6; // ebx@1
char v7; // cl@3
signed int result; // eax@5
int v9; // [sp+14h] [bp+8h]@1
v6 = (unsigned __int64)(a1 - 1944490498245963774i64) >> 32;
v5 = a1 - 1225961470;
v9 = (unsigned __int64)(a1 - 1944490498245963774i64) >> 32;
if ( a2 != -1 && BYTE2(v5) + (((unsigned __int8)v5 + (((unsigned __int8)v6 + (BYTE2(v9) << 8)) << 8)) << 8) != a2
|| (v7 = (BYTE2(v9) ^ BYTE1(v6) ^ v6 ^ BYTE3(v5) ^ BYTE2(v5) ^ v5 ^ (BYTE3(v9) ^ BYTE1(v5)) & 0x3F ^ ((unsigned __int8)(BYTE2(v9) ^ BYTE1(v6) ^ v6 ^ BYTE3(v5) ^ BYTE2(v5) ^ v5 ^ (BYTE3(v9) ^ BYTE1(v5)) & 0x3F) >> 4)) & 0xF,
(BYTE3(v9) ^ (unsigned __int8)(v7 << 6)) & 0xC0)
|| (BYTE1(v5) ^ (unsigned __int8)(16 * v7)) & 0xC0 )
{
*a3 = 0;
*a4 = 0;
*a5 = 0;
result = 0;
}
else
{
*a3 = BYTE3(v5) + (BYTE1(v6) << 8);
*a4 = BYTE1(v5) & 0x3F;
*a5 = BYTE3(v9) & 0x3F;
result = 1;
}
return result;
}
汇编代码如下:
[Asm] 纯文本查看 复制代码 .text:0040C940 ; =============== S U B R O U T I N E =======================================
.text:0040C940
.text:0040C940
.text:0040C940 sub_40C940 proc near ; CODE XREF: sub_404860+155p
.text:0040C940 ; sub_405D00+1A1p ...
.text:0040C940
.text:0040C940 arg_0 = qword ptr 4
.text:0040C940 arg_8 = dword ptr 0Ch
.text:0040C940 arg_C = dword ptr 10h
.text:0040C940 arg_10 = dword ptr 14h
.text:0040C940 arg_14 = dword ptr 18h
.text:0040C940
.text:0040C940 mov edx, dword ptr [esp+arg_0]
.text:0040C944 push ebx
.text:0040C945 mov ebx, dword ptr [esp+4+arg_0+4]
.text:0040C949 add edx, 0B6ED5002h
.text:0040C94F adc ebx, 0E503C831h
.text:0040C955 mov dword ptr [esp+4+arg_0+4], ebx
.text:0040C959 mov al, dh
.text:0040C95B xor al, byte ptr [esp+4+arg_0+7]
.text:0040C95F mov dword ptr [esp+4+arg_0], edx
.text:0040C963 and al, 3Fh
.text:0040C965 xor al, dl
.text:0040C967 xor al, byte ptr [esp+4+arg_0+2]
.text:0040C96B push esi
.text:0040C96C xor al, byte ptr [esp+8+arg_0+3]
.text:0040C970 mov esi, [esp+8+arg_8]
.text:0040C974 xor al, bl
.text:0040C976 xor al, bh
.text:0040C978 xor al, byte ptr [esp+8+arg_0+6]
.text:0040C97C push edi
.text:0040C97D mov cl, al
.text:0040C97F shr cl, 4
.text:0040C982 xor cl, al
.text:0040C984 and cl, 0Fh
.text:0040C987 cmp esi, 0FFFFFFFFh
.text:0040C98A jz short loc_40C9AF
.text:0040C98C movzx eax, byte ptr [esp+0Ch+arg_0+6]
.text:0040C991 shl eax, 8
.text:0040C994 movzx edi, bl
.text:0040C997 add eax, edi
.text:0040C999 shl eax, 8
.text:0040C99C movzx edi, dl
.text:0040C99F add eax, edi
.text:0040C9A1 movzx edi, byte ptr [esp+0Ch+arg_0+2]
.text:0040C9A6 shl eax, 8
.text:0040C9A9 add eax, edi
.text:0040C9AB cmp eax, esi
.text:0040C9AD jnz short loc_40CA0D
.text:0040C9AF
.text:0040C9AF loc_40C9AF: ; CODE XREF: sub_40C940+4Aj
.text:0040C9AF mov al, byte ptr [esp+0Ch+arg_0+7]
.text:0040C9B3 movzx esi, cl
.text:0040C9B6 mov ecx, esi
.text:0040C9B8 movzx edi, al
.text:0040C9BB shl ecx, 6
.text:0040C9BE xor ecx, edi
.text:0040C9C0 test cl, 0C0h
.text:0040C9C3 jnz short loc_40CA0D
.text:0040C9C5 mov ecx, esi
.text:0040C9C7 movzx esi, dh
.text:0040C9CA shl ecx, 4
.text:0040C9CD xor ecx, esi
.text:0040C9CF test cl, 0C0h
.text:0040C9D2 jnz short loc_40CA0D
.text:0040C9D4 movzx cx, bh
.text:0040C9D8 mov esi, 100h
.text:0040C9DD imul cx, si
.text:0040C9E1 movzx si, byte ptr [esp+0Ch+arg_0+3]
.text:0040C9E7 add cx, si
.text:0040C9EA mov esi, [esp+0Ch+arg_C]
.text:0040C9EE mov [esi], cx
.text:0040C9F1 mov ecx, [esp+0Ch+arg_10]
.text:0040C9F5 mov dl, dh
.text:0040C9F7 and dl, 3Fh
.text:0040C9FA mov [ecx], dl
.text:0040C9FC mov edx, [esp+0Ch+arg_14]
.text:0040CA00 pop edi
.text:0040CA01 and al, 3Fh
.text:0040CA03 pop esi
.text:0040CA04 mov [edx], al
.text:0040CA06 mov eax, 1
.text:0040CA0B pop ebx
.text:0040CA0C retn
|
|