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.

and eax, 3<br />

push eax<br />

push OFFSET $SG15438 ; ’processor_type=%d’, 0aH, 00H<br />

call _printf<br />

mov ecx, esi<br />

shr ecx, 16 ; 00000010H<br />

and ecx, 15 ; 0000000fH<br />

push ecx<br />

push OFFSET $SG15439 ; ’extended_model_id=%d’, 0aH, 00H<br />

call _printf<br />

shr esi, 20 ; 00000014H<br />

and esi, 255 ; 000000ffH<br />

push esi<br />

push OFFSET $SG15440 ; ’extended_family_id=%d’, 0aH, 00H<br />

call _printf<br />

add esp, 48 ; 00000030H<br />

pop esi<br />

xor eax, eax<br />

pop ebx<br />

add esp, 16 ; 00000010H<br />

ret 0<br />

_main ENDP<br />

SHR instruction shifting value in EAX by number of bits should be skipped, e.g., we ignore some bits at<br />

right.<br />

AND instruction clearing not needed bits at left, or, in other words, leave only those bits in EAX we need<br />

now.<br />

Let’s try GCC 4.4.1 with -O3 option.<br />

main proc near ; DATA XREF: _start+17<br />

push ebp<br />

mov ebp, esp<br />

and esp, 0FFFFFFF0h<br />

push esi<br />

mov esi, 1<br />

push ebx<br />

mov eax, esi<br />

sub esp, 18h<br />

cpuid<br />

mov esi, eax<br />

and eax, 0Fh<br />

mov [esp+8], eax<br />

mov dword ptr [esp+4], offset aSteppingD ; "stepping=%d\n"<br />

mov dword ptr [esp], 1<br />

call ___printf_chk<br />

mov eax, esi<br />

shr eax, 4<br />

and eax, 0Fh<br />

mov [esp+8], eax<br />

mov dword ptr [esp+4], offset aModelD ; "model=%d\n"<br />

mov dword ptr [esp], 1<br />

74

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

Saved successfully!

Ooh no, something went wrong!