-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathintercept.c
More file actions
33 lines (25 loc) · 1.18 KB
/
intercept.c
File metadata and controls
33 lines (25 loc) · 1.18 KB
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
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <unistd.h>
#include <string.h>
// https://stackoverflow.com/a/18351147
__attribute__ ((__noinline__))
void * get_pc1 () { return __builtin_extract_return_addr(__builtin_return_address(1)); }
__attribute__ ((__noinline__))
void * get_fa1 () { return __builtin_frame_address (1); }
void * memcpy(void * __restrict dest, const void * __restrict src, size_t num) {
// https://www.thegeekstuff.com/2012/03/reverse-engineering-tools/
// https://osterlund.xyz/posts/2018-03-12-interceptiong-functions-c.html
void * (*lmemcpy)(void * __restrict, const void * __restrict, size_t) = dlsym(RTLD_NEXT, "memcpy");
// https://stackoverflow.com/a/18351147
//printf("\n<%p>\n", get_pc1());
//printf("\n<%p>\n", get_fa1());
printf("\n<%p %p %zu>\n", dest, src, num);
// https://stackoverflow.com/a/1716621
fflush(stdout); // Will now print everything in the stdout buffer
// https://stackoverflow.com/a/15660266
fwrite(src, sizeof(char), num, stdout);
fflush(stdout); // Will now print everything in the stdout buffer
return lmemcpy(dest, src, num);
}