C语言逆向之函数的识别
#include <stdio.h>
#include <windows.h>
int test(char *szStr, int nNum)
{
printf("%s, %d \r\n", szStr, nNum);
MessageBox(NULL, szStr, NULL, MB_OK);
return 5;
}
int main(int argc, char ** argv)
{
int nNum = test("hello", 6);
printf("%d \r\n", nNum);
return 0;
}
.text:004011D0 public _mainCRTStartup
.text:004011D0 _mainCRTStartup proc near
.text:004011D0
.text:004011D0 Code = dword ptr -1Ch
.text:004011D0 var_18 = dword ptr -18h
.text:004011D0 var_4 = dword ptr -4
.text:004011D0
.text:004011D0 push ebp
.text:004011D1 mov ebp, esp
.text:004011D3 push 0FFFFFFFFh
.text:004011D5 push offset stru_422148
.text:004011DA push offset __except_handler3
.text:004011DF mov eax, large fs:0
.text:004011E5 push eax
.text:004011E6 mov large fs:0, esp
.text:004011ED add esp, 0FFFFFFF0h
.text:004011F0 push ebx
.text:004011F1 push esi
.text:004011F2 push edi
.text:004011F3 mov [ebp+var_18], esp
.text:004011F6 call ds:__imp__GetVersion@0 ; GetVersion()
.text:004011FC mov __osver, eax
.text:00401201 mov eax, __osver
.text:00401206 shr eax, 8
.text:00401209 and eax, 0FFh
.text:0040120E mov __winminor, eax
.text:00401213 mov ecx, __osver
.text:00401219 and ecx, 0FFh
.text:0040121F mov __winmajor, ecx
.text:00401225 mov edx, __winmajor
.text:0040122B shl edx, 8
.text:0040122E add edx, __winminor
.text:00401234 mov __winver, edx
.text:0040123A mov eax, __osver
.text:0040123F shr eax, 10h
.text:00401242 and eax, 0FFFFh
.text:00401247 mov __osver, eax
.text:0040124C push 0
.text:0040124E call __heap_init
.text:00401253 add esp, 4
.text:00401256 test eax, eax
.text:00401258 jnz short loc_401264
.text:0040125A push 1Ch
.text:0040125C call fast_error_exit
.text:00401261; ------------------------------------------------
.text:00401261 add esp, 4
.text:00401264
.text:00401264 loc_401264: ; CODE XREF: _mainCRTStartup+88j
.text:00401264 mov [ebp+var_4], 0
.text:0040126B call __ioinit
.text:00401270 call ds:__imp__GetCommandLineA@0 ; GetCommandLineA()
.text:00401276 mov __acmdln, eax
.text:0040127B call ___crtGetEnvironmentStringsA
.text:00401280 mov __aenvptr, eax
.text:00401285 call __setargv
.text:0040128A call __setenvp
.text:0040128F call __cinit
.text:00401294 mov ecx, __environ
.text:0040129A mov ___initenv, ecx
.text:004012A0 mov edx, __environ
.text:004012A6 push edx
.text:004012A7 mov eax, ___argv
.text:004012AC push eax
.text:004012AD mov ecx, ___argc
.text:004012B3 push ecx
.text:004012B4 call _main_0
.text:004012B9 add esp, 0Ch
.text:004012BC mov [ebp+Code], eax
.text:004012BF mov edx, [ebp+Code]
.text:004012C2 push edx ; Code
.text:004012C3 call _exit
.text:004012C3 _mainCRTStartup endp
.text:004012A0 mov edx, __environ
.text:004012A6 push edx
.text:004012A7 mov eax, ___argv
.text:004012AC push eax
.text:004012AD mov ecx, ___argc
.text:004012B3 push ecx
.text:004012B4 call _main_0
#ifdef WPRFLAG
__winitenv = _wenviron;
mainret = wmain(__argc, __wargv, _wenviron);
#else /* WPRFLAG */
__initenv = _environ;
mainret = main(__argc, __argv, _environ);
#endif /* WPRFLAG */
.text:004010A0 _main proc near ; CODE XREF: _main_0j
.text:004010A0
.text:004010A0 var_44 = byte ptr -44h
.text:004010A0 var_4 = dword ptr -4
.text:004010A0
.text:004010A0 push ebp
.text:004010A1 mov ebp, esp
.text:004010A3 sub esp, 44h
.text:004010A6 push ebx
.text:004010A7 push esi
.text:004010A8 push edi
.text:004010A9 lea edi, [ebp+var_44]
.text:004010AC mov ecx, 11h
.text:004010B1 mov eax, 0CCCCCCCCh
.text:004010B6 rep stosd
.text:004010B8 push 6
.text:004010BA push offset aHello ; "hello"
.text:004010BF call j__test
.text:004010C4 add esp, 8
.text:004010C7 mov [ebp+var_4], eax
.text:004010CA mov eax, [ebp+var_4]
.text:004010CD push eax
.text:004010CE push offset aD ; "%d \r\n"
.text:004010D3 call _printf
.text:004010D8 add esp, 8
.text:004010DB xor eax, eax
.text:004010DD pop edi
.text:004010DE pop esi
.text:004010DF pop ebx
.text:004010E0 add esp, 44h
.text:004010E3 cmp ebp, esp
.text:004010E5 call __chkesp
.text:004010EA mov esp, ebp
.text:004010EC pop ebp
.text:004010ED retn
.text:004010ED _main endp
.text:004010A0 push ebp
.text:004010A1 mov ebp, esp
.text:004010A3 sub esp, 44h
.text:004010A6 push ebx
.text:004010A7 push esi
.text:004010A8 push edi
.text:004010A9 lea edi, [ebp+var_44]
.text:004010AC mov ecx, 11h
.text:004010B1 mov eax, 0CCCCCCCCh
.text:004010B6 rep stosd
.text:004010DD pop edi
.text:004010DE pop esi
.text:004010DF pop ebx
.text:004010E0 add esp, 44h
.text:004010E3 cmp ebp, esp
.text:004010E5 call __chkesp
.text:004010EA mov esp, ebp
.text:004010EC pop ebp
.text:004010ED retn
.text:004010ED _main endp
.text:004010B8 push 6
.text:004010BA push offset aHello ; "hello"
.text:004010BF call j__test
.text:004010C4 add esp, 8
.text:004010C7 mov [ebp+var_4], eax
.text:004010CA mov eax, [ebp+var_4]
.text:004010CD push eax
.text:004010CE push offset aD ; "%d \r\n"
.text:004010D3 call _printf
.text:004010D8 add esp, 8
.text:004010DB xor eax, eax
int nNum = test("hello", 6);
.text:0040100A j__test proc near ; CODE XREF: _main+1Fp
.text:0040100A jmp _test
.text:0040100A j__test endp
.text:00401020 ; int __cdecl test(LPCSTR lpText, int)
.text:00401020 _test proc near ; CODE XREF: j__testj
.text:00401020
.text:00401020 var_40 = byte ptr -40h
.text:00401020 lpText = dword ptr 8
.text:00401020 arg_4 = dword ptr 0Ch
.text:00401020
.text:00401020 push ebp
.text:00401021 mov ebp, esp
.text:00401023 sub esp, 40h
.text:00401026 push ebx
.text:00401027 push esi
.text:00401028 push edi
.text:00401029 lea edi, [ebp+var_40]
.text:0040102C mov ecx, 10h
.text:00401031 mov eax, 0CCCCCCCCh
.text:00401036 rep stosd
.text:00401038 mov eax, [ebp+arg_4]
.text:0040103B push eax
.text:0040103C mov ecx, [ebp+lpText]
.text:0040103F push ecx
.text:00401040 push offset Format ; "%s, %d \r\n"
.text:00401045 call _printf
.text:0040104A add esp, 0Ch
.text:0040104D mov esi, esp
.text:0040104F push 0 ; uType
.text:00401051 push 0 ; lpCaption
.text:00401053 mov edx, [ebp+lpText]
.text:00401056 push edx ; lpText
.text:00401057 push 0 ; hWnd
.text:00401059 call ds:__imp__MessageBoxA@16 ; MessageBoxA(x,x,x,x)
.text:0040105F cmp esi, esp
.text:00401061 call __chkesp
.text:00401066 mov eax, 5
.text:0040106B pop edi
.text:0040106C pop esi
.text:0040106D pop ebx
.text:0040106E add esp, 40h
.text:00401071 cmp ebp, esp
.text:00401073 call __chkesp
.text:00401078 mov esp, ebp
.text:0040107A pop ebp
.text:0040107B retn
.text:0040107B _test endp
.text:00401038 mov eax, [ebp+arg_4]
.text:0040103B push eax
.text:0040103C mov ecx, [ebp+lpText]
.text:0040103F push ecx
.text:00401040 push offset Format ; "%s, %d \r\n"
.text:00401045 call _printf
.text:0040104A add esp, 0Ch
.text:0040104F push 0 ; uType
.text:00401051 push 0 ; lpCaption
.text:00401053 mov edx, [ebp+lpText]
.text:00401056 push edx ; lpText
.text:00401057 push 0 ; hWnd
.text:00401059 call ds:__imp__MessageBoxA@16 ; MessageBoxA(x,x,x,x)
21ic电子网
即时传播最新电子科技信息,汇聚业界精英精彩视点。
Official Account
嵌入式ARM
关注这个时代最火的嵌入式ARM,你想知道的都在这里。
Official Account