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.4 scanf()<br />

Now let’s use scanf().<br />

int main()<br />

{<br />

int x;<br />

printf ("Enter X:\n");<br />

};<br />

scanf ("%d", &x);<br />

printf ("You entered %d...\n", x);<br />

return 0;<br />

OK, I agree, it is not clever <strong>to</strong> use scanf() <strong>to</strong>day. But I wanted <strong>to</strong> illustrate passing pointer <strong>to</strong> int.<br />

What we got after compiling in MSVC 2010:<br />

CONST SEGMENT<br />

$SG3831 DB ’Enter X:’, 0aH, 00H<br />

ORG $+2<br />

$SG3832 DB ’%d’, 00H<br />

ORG $+1<br />

$SG3833 DB ’You entered %d...’, 0aH, 00H<br />

CONST ENDS<br />

PUBLIC _main<br />

EXTRN _scanf:PROC<br />

EXTRN _printf:PROC<br />

; Function compile flags: /Odtp<br />

_TEXT SEGMENT<br />

_x$ = -4 ; size = 4<br />

_main PROC<br />

push ebp<br />

mov ebp, esp<br />

push ecx<br />

push OFFSET $SG3831<br />

call _printf<br />

add esp, 4<br />

lea eax, DWORD PTR _x$[ebp]<br />

push eax<br />

push OFFSET $SG3832<br />

call _scanf<br />

add esp, 8<br />

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

push ecx<br />

push OFFSET $SG3833<br />

call _printf<br />

add esp, 8<br />

xor eax, eax<br />

mov esp, ebp<br />

pop ebp<br />

ret 0<br />

_main ENDP<br />

_TEXT ENDS<br />

10

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

Saved successfully!

Ooh no, something went wrong!