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.

};<br />

printf ("stepping=%d\n", tmp->stepping);<br />

printf ("model=%d\n", tmp->model);<br />

printf ("family_id=%d\n", tmp->family_id);<br />

printf ("processor_type=%d\n", tmp->processor_type);<br />

printf ("extended_model_id=%d\n", tmp->extended_model_id);<br />

printf ("extended_family_id=%d\n", tmp->extended_family_id);<br />

return 0;<br />

After CPUID will fill EAX/EBX/ECX/EDX, these registers will be reflected in b[] array. Then, we have a<br />

pointer <strong>to</strong> CPUID_1_EAX structure and we point it <strong>to</strong> EAX value from b[] array.<br />

In other words, we treat 32-bit int value as a structure.<br />

Then we read from the stucture.<br />

Let’s compile it in MSVC 2008 with /Ox option:<br />

_b$ = -16 ; size = 16<br />

_main PROC<br />

sub esp, 16 ; 00000010H<br />

push ebx<br />

xor ecx, ecx<br />

mov eax, 1<br />

cpuid<br />

push esi<br />

lea esi, DWORD PTR _b$[esp+24]<br />

mov DWORD PTR [esi], eax<br />

mov DWORD PTR [esi+4], ebx<br />

mov DWORD PTR [esi+8], ecx<br />

mov DWORD PTR [esi+12], edx<br />

mov esi, DWORD PTR _b$[esp+24]<br />

mov eax, esi<br />

and eax, 15 ; 0000000fH<br />

push eax<br />

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

call _printf<br />

mov ecx, esi<br />

shr ecx, 4<br />

and ecx, 15 ; 0000000fH<br />

push ecx<br />

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

call _printf<br />

mov edx, esi<br />

shr edx, 8<br />

and edx, 15 ; 0000000fH<br />

push edx<br />

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

call _printf<br />

mov eax, esi<br />

shr eax, 12 ; 0000000cH<br />

73

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

Saved successfully!

Ooh no, something went wrong!