====== Reverse Engineering ====== ===== Calling conventions ===== A calling convention is an implementation-level (low-level) scheme for how subroutines receive parameters from their caller and how they return a result. Differences in various implementations include where parameters, return values and return addresses are placed, and how the tasks of preparing for a function call and cleaning up the environment afterward are divided between the caller and the callee. ==== Caller clean up ==== The caller cleans the arguments from the stack, which allows for variable argument lists. === cdecl (C declaration) === caller: push ebp mov ebp, esp push argN . . . push arg1 call function; return value in eax register. eax, ecx, edx may be modified add esp, args_size . . . pop ebp ret . . . function: . . . ret ==== Callee clean up ==== When the callee cleans the arguments from the stack it needs to be known at compile time how many bytes the stack needs to be adjusted. Therefore, these calling conventions are not compatible with variable argument lists. === stdcall === caller: push argN . . . push arg1 call function; return value in eax register. eax, ecx, edx may be modified . . . ret . . . function: push ebp mov ebp, esp sub esp, args_size . . . ret args_size ===== Control statements ===== ==== if-else ===== cmp ; if (condition) jxx ; if code // if code jmp end ; else ; else code // else code end: ==== if-else if ==== cmp jxx else_if ; if code jmp end else_if: cmp jxx end ; if_else code end: ==== if with && ==== cmp [var1], 100 ; if (var1 == 100 && var2 = 50) jne end cmp [var2], 50 jne end ; if code // if code end: ==== if with || ==== cmp [var1], 100 ; if (var == 100 || var2 == 50) je if_code cmp [var2], 50 je if_code if_code: ; if code // if code end: