23.03.2013 Views

Quick introduction to reverse engineering for beginners

Quick introduction to reverse engineering for beginners

Quick introduction to reverse engineering for beginners

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1.8 switch()/case/default<br />

1.8.1 Few number of cases<br />

void f (int a)<br />

{<br />

switch (a)<br />

{<br />

case 0: printf ("zero\n"); break;<br />

case 1: printf ("one\n"); break;<br />

case 2: printf ("two\n"); break;<br />

default: printf ("something unknown\n"); break;<br />

};<br />

};<br />

Result (MSVC 2010):<br />

tv64 = -4 ; size = 4<br />

_a$ = 8 ; size = 4<br />

_f PROC<br />

push ebp<br />

mov ebp, esp<br />

push ecx<br />

mov eax, DWORD PTR _a$[ebp]<br />

mov DWORD PTR tv64[ebp], eax<br />

cmp DWORD PTR tv64[ebp], 0<br />

je SHORT $LN4@f<br />

cmp DWORD PTR tv64[ebp], 1<br />

je SHORT $LN3@f<br />

cmp DWORD PTR tv64[ebp], 2<br />

je SHORT $LN2@f<br />

jmp SHORT $LN1@f<br />

$LN4@f:<br />

push OFFSET $SG739 ; ’zero’, 0aH, 00H<br />

call _printf<br />

add esp, 4<br />

jmp SHORT $LN7@f<br />

$LN3@f:<br />

push OFFSET $SG741 ; ’one’, 0aH, 00H<br />

call _printf<br />

add esp, 4<br />

jmp SHORT $LN7@f<br />

$LN2@f:<br />

push OFFSET $SG743 ; ’two’, 0aH, 00H<br />

call _printf<br />

add esp, 4<br />

jmp SHORT $LN7@f<br />

$LN1@f:<br />

push OFFSET $SG745 ; ’something unknown’, 0aH, 00H<br />

call _printf<br />

add esp, 4<br />

$LN7@f:<br />

mov esp, ebp<br />

pop ebp<br />

ret 0<br />

22

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!