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.

9.1.5 Task 1.5<br />

Hint #1: Keep in mind that __v — global variable.<br />

Hint #2: That function is called in startup code, be<strong>for</strong>e main() execution.<br />

Solution: early Pentium CPU FDIV bug checking 1 .<br />

C source code:<br />

unsigned _v; // _v<br />

enum e {<br />

PROB_P5_DIV = 0x0001<br />

};<br />

void f( void ) // __verify_pentium_fdiv_bug<br />

{<br />

/*<br />

Verify we have got the Pentium FDIV problem.<br />

The volatiles are <strong>to</strong> scare the optimizer away.<br />

*/<br />

volatile double v1 = 4195835;<br />

volatile double v2 = 3145727;<br />

}<br />

if( (v1 - (v1/v2)*v2) > 1.0e-8 ) {<br />

_v |= PROB_P5_DIV;<br />

}<br />

9.1.6 Task 1.6<br />

Hint: it might be helpful <strong>to</strong> google a constant used here.<br />

Solution: TEA encryption algorithm 2 .<br />

C source code (taken from http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm):<br />

void f (unsigned int* v, unsigned int* k) {<br />

unsigned int v0=v[0], v1=v[1], sum=0, i; /* set up */<br />

unsigned int delta=0x9e3779b9; /* a key schedule constant */<br />

unsigned int k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* cache key */<br />

<strong>for</strong> (i=0; i < 32; i++) { /* basic cycle start */<br />

sum += delta;<br />

v0 += ((v15) + k1);<br />

v1 += ((v05) + k3);<br />

} /* end cycle */<br />

v[0]=v0; v[1]=v1;<br />

}<br />

9.1.7 Task 1.7<br />

Hint: the table contain pre-calculated values. It’s possible <strong>to</strong> implement the function without it, but it will<br />

work slower, though.<br />

Solution: this function <strong>reverse</strong> all bits in input 32-bit integer. It’s lib/bitrev.c from Linux kernel.<br />

C source code:<br />

1 http://en.wikipedia.org/wiki/Pentium_FDIV_bug<br />

2 Tiny Encryption Algorithm<br />

201

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

Saved successfully!

Ooh no, something went wrong!