1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int add(int a, int b)
{
//printf("Something wrong??");
return a + b;
}
void helper()
{
}
int main()
{
int pSource = (int)add;
int size = (int)helper - pSource;
char *byteCode = (char*)malloc(size);
int (*newAdd1)(int a, int b);
int (*newAdd2)(int a, int b);
memcpy(byteCode, (void*)pSource, size);
newAdd1 = (int(*)(int a, int b))byteCode;
newAdd2 = (int(*)(int a, int b))byteCode;
printf("pSource : %d\n", pSource);
printf("size : %d\n", size);
printf("\nadd(original): %d\n", add(1, 2));
printf("newAdd1 : %d\n", newAdd1(3, 4));
printf("newAdd2 : %d\n", newAdd2(5, 6));
free(byteCode);
}
| |