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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1.8.2 A lot of cases<br />

If switch() statement contain a lot of case’s, it is not very handy <strong>for</strong> compiler <strong>to</strong> emit <strong>to</strong>o large code with<br />

a lot JE/JNE instructions.<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 />

case 3: printf ("three\n"); break;<br />

case 4: printf ("four\n"); break;<br />

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

};<br />

};<br />

We got (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], 4<br />

ja SHORT $LN1@f<br />

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

jmp DWORD PTR $LN11@f[ecx*4]<br />

$LN6@f:<br />

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

call _printf<br />

add esp, 4<br />

jmp SHORT $LN9@f<br />

$LN5@f:<br />

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

call _printf<br />

add esp, 4<br />

jmp SHORT $LN9@f<br />

$LN4@f:<br />

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

call _printf<br />

add esp, 4<br />

jmp SHORT $LN9@f<br />

$LN3@f:<br />

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

call _printf<br />

add esp, 4<br />

jmp SHORT $LN9@f<br />

$LN2@f:<br />

push OFFSET $SG747 ; ’four’, 0aH, 00H<br />

call _printf<br />

add esp, 4<br />

24

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

Saved successfully!

Ooh no, something went wrong!