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.

jump_over:;<br />

/* Select median value from among LO, MID, and HI. Rearrange<br />

LO and HI so the three values are sorted. This lowers the<br />

probability of picking a pathological pivot value and<br />

skips a comparison <strong>for</strong> both the LEFT_PTR and RIGHT_PTR in<br />

the while loops. */<br />

char *mid = lo + size * ((hi - lo) / size >> 1);<br />

if ((*cmp) ((void *) mid, (void *) lo, arg) < 0)<br />

SWAP (mid, lo, size);<br />

if ((*cmp) ((void *) hi, (void *) mid, arg) < 0)<br />

SWAP (mid, hi, size);<br />

else<br />

go<strong>to</strong> jump_over;<br />

if ((*cmp) ((void *) mid, (void *) lo, arg) < 0)<br />

SWAP (mid, lo, size);<br />

left_ptr = lo + size;<br />

right_ptr = hi - size;<br />

/* Here’s the famous ‘‘collapse the walls’’ section of quicksort.<br />

Gotta like those tight inner loops! They are the main reason<br />

that this algorithm runs much faster than others. */<br />

do<br />

{<br />

while ((*cmp) ((void *) left_ptr, (void *) mid, arg) < 0)<br />

left_ptr += size;<br />

while ((*cmp) ((void *) mid, (void *) right_ptr, arg) < 0)<br />

right_ptr -= size;<br />

if (left_ptr < right_ptr)<br />

{<br />

SWAP (left_ptr, right_ptr, size);<br />

if (mid == left_ptr)<br />

mid = right_ptr;<br />

else if (mid == right_ptr)<br />

mid = left_ptr;<br />

left_ptr += size;<br />

right_ptr -= size;<br />

}<br />

else if (left_ptr == right_ptr)<br />

{<br />

left_ptr += size;<br />

right_ptr -= size;<br />

break;<br />

}<br />

}<br />

while (left_ptr

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

Saved successfully!

Ooh no, something went wrong!