Quick introduction to reverse engineering for beginners
Quick introduction to reverse engineering for beginners
Quick introduction to reverse engineering for beginners
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
if speed is important.<br />
Let’s consider CPUID 57 instruction example. This instruction return in<strong>for</strong>mation about current CPU and<br />
its features.<br />
If EAX is set <strong>to</strong> 1 be<strong>for</strong>e instruction execution, CPUID will return this in<strong>for</strong>mation packed in<strong>to</strong> EAX register:<br />
3:0 Stepping<br />
7:4 Model<br />
11:8 Family<br />
13:12 Processor Type<br />
19:16 Extended Model<br />
27:20 Extended Family<br />
MSVC 2010 has CPUID macro, but GCC 4.4.1 — hasn’t. So let’s make this function by yourself <strong>for</strong> GCC,<br />
using its built-in assembler 58 .<br />
#include <br />
#ifdef __GNUC__<br />
static inline void cpuid(int code, int *a, int *b, int *c, int *d) {<br />
asm volatile("cpuid":"=a"(*a),"=b"(*b),"=c"(*c),"=d"(*d):"a"(code));<br />
}<br />
#endif<br />
#ifdef _MSC_VER<br />
#include <br />
#endif<br />
struct CPUID_1_EAX<br />
{<br />
unsigned int stepping:4;<br />
unsigned int model:4;<br />
unsigned int family_id:4;<br />
unsigned int processor_type:2;<br />
unsigned int reserved1:2;<br />
unsigned int extended_model_id:4;<br />
unsigned int extended_family_id:8;<br />
unsigned int reserved2:4;<br />
};<br />
int main()<br />
{<br />
struct CPUID_1_EAX *tmp;<br />
int b[4];<br />
#ifdef _MSC_VER<br />
__cpuid(b,1);<br />
#endif<br />
#ifdef __GNUC__<br />
cpuid (1, &b[0], &b[1], &b[2], &b[3]);<br />
#endif<br />
tmp=(struct CPUID_1_EAX *)&b[0];<br />
57 http://en.wikipedia.org/wiki/CPUID<br />
58 More about internal GCC assembler<br />
72