Quick introduction to reverse engineering for beginners
Quick introduction to reverse engineering for beginners
Quick introduction to reverse engineering for beginners
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
mov eax, ecx<br />
mov ecx, DWORD PTR _a$[esp-4]<br />
mov DWORD PTR [eax], ecx<br />
mov DWORD PTR [eax+4], edx<br />
ret 8<br />
??0c@@QAE@HH@Z ENDP ; c::c<br />
?dump@c@@QAEXXZ PROC ; c::dump, COMDAT<br />
; _this$ = ecx<br />
mov eax, DWORD PTR [ecx+4]<br />
mov ecx, DWORD PTR [ecx]<br />
push eax<br />
push ecx<br />
push OFFSET ??_C@_07NJBDCIEC@?$CFd?$DL?5?$CFd?6?$AA@<br />
call _printf<br />
add esp, 12 ; 0000000cH<br />
ret 0<br />
?dump@c@@QAEXXZ ENDP ; c::dump<br />
That’s all. One more thing <strong>to</strong> say is that stack pointer after second construc<strong>to</strong>r calling wasn’t corrected<br />
with add esp, X. Please also note that, construc<strong>to</strong>r has ret 8 instead of RET at the end.<br />
That’s all because here used thiscall 2.5.4 calling convention, the method of passing values through the<br />
stack, which is, <strong>to</strong>gether with stdcall 2.5.2 method, offers <strong>to</strong> correct stack <strong>to</strong> callee rather then <strong>to</strong> caller. ret<br />
x instruction adding X <strong>to</strong> ESP, then passes control <strong>to</strong> caller function.<br />
See also section about calling conventions 2.5.<br />
It’s also should be noted that compiler deciding when <strong>to</strong> call construc<strong>to</strong>r and destruc<strong>to</strong>r — but that’s<br />
we already know from C++ language basics.<br />
1.16.1 GCC<br />
It’s almost the same situation in GCC 4.4.1, with few exceptions.<br />
public main<br />
main proc near ; DATA XREF: _start+17<br />
var_20 = dword ptr -20h<br />
var_1C = dword ptr -1Ch<br />
var_18 = dword ptr -18h<br />
var_10 = dword ptr -10h<br />
var_8 = dword ptr -8<br />
push ebp<br />
mov ebp, esp<br />
and esp, 0FFFFFFF0h<br />
sub esp, 20h<br />
lea eax, [esp+20h+var_8]<br />
mov [esp+20h+var_20], eax<br />
call _ZN1cC1Ev<br />
mov [esp+20h+var_18], 6<br />
mov [esp+20h+var_1C], 5<br />
lea eax, [esp+20h+var_10]<br />
mov [esp+20h+var_20], eax<br />
call _ZN1cC1Eii<br />
lea eax, [esp+20h+var_8]<br />
mov [esp+20h+var_20], eax<br />
82