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.

version 2.1 of the License, or (at your option) any later version.<br />

The GNU C Library is distributed in the hope that it will be useful,<br />

but WITHOUT ANY WARRANTY; without even the implied warranty of<br />

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br />

Lesser General Public License <strong>for</strong> more details.<br />

You should have received a copy of the GNU Lesser General Public<br />

License along with the GNU C Library; if not, write <strong>to</strong> the Free<br />

Software Foundation, Inc., 59 Temple Place, Suite 330, Bos<strong>to</strong>n, MA<br />

02111-1307 USA. */<br />

/* If you consider tuning this algorithm, you should consult first:<br />

Engineering a sort function; Jon Bentley and M. Douglas McIlroy;<br />

Software - Practice and Experience; Vol. 23 (11), 1249-1265, 1993. */<br />

#include <br />

#include <br />

#include <br />

#include <br />

typedef int (*__compar_d_fn_t) (__const void *, __const void *, void *);<br />

/* Byte-wise swap two items of size SIZE. */<br />

#define SWAP(a, b, size) \<br />

do \<br />

{ \<br />

register size_t __size = (size); \<br />

register char *__a = (a), *__b = (b); \<br />

do \<br />

{ \<br />

char __tmp = *__a; \<br />

*__a++ = *__b; \<br />

*__b++ = __tmp; \<br />

} while (--__size > 0); \<br />

} while (0)<br />

/* Discontinue quicksort algorithm when partition gets below this size.<br />

This particular magic number was chosen <strong>to</strong> work best on a Sun 4/260. */<br />

#define MAX_THRESH 4<br />

/* Stack node declarations used <strong>to</strong> s<strong>to</strong>re unfulfilled partition obligations. */<br />

typedef struct<br />

{<br />

char *lo;<br />

char *hi;<br />

} stack_node;<br />

/* The next 4 #defines implement a very fast in-line stack abstraction. */<br />

/* The stack needs log (<strong>to</strong>tal_elements) entries (we could even subtract<br />

log(MAX_THRESH)). Since <strong>to</strong>tal_elements has type size_t, we get as<br />

upper bound <strong>for</strong> log (<strong>to</strong>tal_elements):<br />

bits per byte (CHAR_BIT) * sizeof(size_t). */<br />

#define STACK_SIZE (CHAR_BIT * sizeof(size_t))<br />

204

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

Saved successfully!

Ooh no, something went wrong!