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.

Chapter 4<br />

Tasks<br />

There are two questions almost <strong>for</strong> every task, if otherwise isn’t specified:<br />

1) What this function does? Answer in one-sentence <strong>for</strong>m.<br />

2) Rewrite this function in<strong>to</strong> C/C++.<br />

Hints and solutions are in the appendix of this brochure.<br />

4.1 Easy level<br />

4.1.1 Task 1.1<br />

This is standard C library function. Source code taken from OpenWatcom. Compiled in MSVC 2010.<br />

_TEXT SEGMENT<br />

_input$ = 8 ; size = 1<br />

_f PROC<br />

push ebp<br />

mov ebp, esp<br />

movsx eax, BYTE PTR _input$[ebp]<br />

cmp eax, 97 ; 00000061H<br />

jl SHORT $LN1@f<br />

movsx ecx, BYTE PTR _input$[ebp]<br />

cmp ecx, 122 ; 0000007aH<br />

jg SHORT $LN1@f<br />

movsx edx, BYTE PTR _input$[ebp]<br />

sub edx, 32 ; 00000020H<br />

mov BYTE PTR _input$[ebp], dl<br />

$LN1@f:<br />

mov al, BYTE PTR _input$[ebp]<br />

pop ebp<br />

ret 0<br />

_f ENDP<br />

_TEXT ENDS<br />

It is the same code compiled by GCC 4.4.1 with -O3 option (maximum optimization):<br />

_f proc near<br />

input = dword ptr 8<br />

push ebp<br />

mov ebp, esp<br />

movzx eax, byte ptr [ebp+input]<br />

lea edx, [eax-61h]<br />

124

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

Saved successfully!

Ooh no, something went wrong!