Reverse Engineering for Beginners

(avery) #1

CHAPTER 19. MANIPULATING SPECIFIC BIT(S) CHAPTER 19. MANIPULATING SPECIFIC BIT(S)


ANDgot executed:


Figure 19.4:OllyDbg:ANDexecuted

The 10th bit was cleared (or, in other words, all bits were left except the 10th) and the final value now is
0x12344 478 (1001000110100010001 0 001111000).


Optimizing MSVC


If we compile it in MSVC with optimization turned on (/Ox), the code is even shorter:


Listing 19.11: Optimizing MSVC

_a$ = 8 ; size = 4
_f PROC
mov eax, DWORD PTR _a$[esp-4]
and eax, -513 ; fffffdffH
or eax, 16384 ; 00004000H
ret 0
_f ENDP


Non-optimizing GCC


Let’s try GCC 4.4.1 without optimization:


Listing 19.12: Non-optimizing GCC
public f
f proc near


var_4 = dword ptr -4
arg_0 = dword ptr 8


push ebp
mov ebp, esp
sub esp, 10h
mov eax, [ebp+arg_0]
mov [ebp+var_4], eax
or [ebp+var_4], 4000h
and [ebp+var_4], 0FFFFFDFFh
mov eax, [ebp+var_4]
leave
retn
f endp


There is a redundant code present, however, it is shorter than the MSVC version without optimization.


Now let’s try GCC with optimization turned on-O3:

Free download pdf