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.

mov edx, DWORD PTR _t$[ebp]<br />

or edx, -2147483648 ; 80000000H - set minus sign<br />

mov DWORD PTR _t$[ebp], edx<br />

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

shr eax, 23 ; 00000017H - drop significand<br />

and eax, 255 ; 000000ffH - leave here only exponent<br />

add eax, 2 ; add 2 <strong>to</strong> it<br />

and eax, 255 ; 000000ffH<br />

shl eax, 23 ; 00000017H - shift result <strong>to</strong> place of bits 30:23<br />

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

and ecx, -2139095041 ; 807fffffH - drop exponent<br />

or ecx, eax ; add original value without exponent with new calculated<br />

explonent<br />

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

push 4<br />

lea edx, DWORD PTR _t$[ebp]<br />

push edx<br />

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

push eax<br />

call _memcpy<br />

add esp, 12 ; 0000000cH<br />

fld DWORD PTR _f$[ebp]<br />

mov esp, ebp<br />

pop ebp<br />

ret 0<br />

?f@@YAMM@Z ENDP ; f<br />

Redundant <strong>for</strong> a bit. If it compiled with /Ox flag there are no memcpy() call, f variable is used directly.<br />

But it’s easier <strong>to</strong> understand it all considering unoptimized version.<br />

What GCC 4.4.1 with -O3 will do?<br />

; f(float)<br />

public _Z1ff<br />

_Z1ff proc near<br />

var_4 = dword ptr -4<br />

arg_0 = dword ptr 8<br />

push ebp<br />

mov ebp, esp<br />

sub esp, 4<br />

mov eax, [ebp+arg_0]<br />

or eax, 80000000h ; set minus sign<br />

mov edx, eax<br />

and eax, 807FFFFFh ; leave only significand and exponent in EAX<br />

shr edx, 23 ; prepare exponent<br />

add edx, 2 ; add 2<br />

movzx edx, dl ; clear all bits except 7:0 in EAX<br />

shl edx, 23 ; shift new calculated exponent <strong>to</strong> its place<br />

or eax, edx ; add newe exponent and original value without exponent<br />

77

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

Saved successfully!

Ooh no, something went wrong!