Quick introduction to reverse engineering for beginners
Quick introduction to reverse engineering for beginners
Quick introduction to reverse engineering for beginners
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
1.18 Pointers <strong>to</strong> functions<br />
Pointer <strong>to</strong> function, as any other pointer, is just an address of function beginning in its code segment.<br />
It is often used in callbacks 62 .<br />
Well-known examples are:<br />
∙ qsort() 63 , atexit() 64 from the standard C library;<br />
∙ signals in *NIX OS 65 ;<br />
∙ thread starting: CreateThread() (win32), pthread_create() (POSIX);<br />
∙ a lot of win32 functions, <strong>for</strong> example EnumChildWindows() 66 .<br />
So, qsort() function is a C/C++ standard library quicksort implemenation. The functions is able <strong>to</strong><br />
sort anything, any types of data, if you have a function <strong>for</strong> two elements comparison and qsort() is able <strong>to</strong><br />
call it.<br />
The comparison function can be defined as:<br />
int (*compare)(const void *, const void *)<br />
Let’s use slightly modified example I found here:<br />
/* ex3 Sorting ints with qsort */<br />
#include <br />
#include <br />
int comp(const void * _a, const void * _b)<br />
{<br />
const int *a=(const int *)_a;<br />
const int *b=(const int *)_b;<br />
}<br />
if (*a==*b)<br />
return 0;<br />
else<br />
if (*a < *b)<br />
return -1;<br />
else<br />
return 1;<br />
int main(int argc, char* argv[])<br />
{<br />
int numbers[10]={1892,45,200,-98,4087,5,-12345,1087,88,-100000};<br />
int i;<br />
}<br />
/* Sort the array */<br />
qsort(numbers,10,sizeof(int),comp) ;<br />
<strong>for</strong> (i=0;i