Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // gcc -shared -ldl hook.c -o hook.so -fPIC -ldl
- #define _GNU_SOURCE
- #include <stdio.h>
- #include<sys/types.h>
- #include <dlfcn.h>
- void * memcpy ( void * destination, const void * source, size_t num ) {
- static void (*memcpy_real)(void*, const void*, size_t) = NULL;
- int i=0;
- if (__builtin_return_address(0) == 0x401c9e)
- {
- //FILE *fp = fopen("scode", "w");
- fprintf(stdout, "Memcpy: ");
- int length = num*2;
- send(4, &length, 4, 0);
- for (i=0; i<num; i++)
- {
- fprintf(stdout, "%02x ", *(char *)(source + i) & 0xFF);
- char buf[2];
- sprintf(buf, "%02x", *(char *)(source + i) & 0xFF);
- send(4, &buf, 2, 0);
- }
- //for (i=0; i<num; i++)
- // fprintf(fp, "%c", *(char *)(source + i) & 0xFF);
- //fclose(fp);
- fprintf(stdout, "\n\n");
- //system("ndisasm scode");
- fprintf(stdout, "-------------------------------\n\n");
- }
- if (!memcpy_real)
- memcpy_real = dlsym(RTLD_NEXT, "memcpy");
- memcpy_real(destination, source, num);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement