-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestA.c
53 lines (42 loc) · 1.16 KB
/
testA.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include "elf_hook.h"
#define LIBFUNC_PATH "./libfunc.so" //position dependent code
char* wrapfunc(char* A, char* B, uint32_t length);
char* hook(char* A, char* B, uint32_t length);
void set_hook(void * handle) {
void *base = NULL;
if (NULL == handle) {
fprintf(stderr, "Failed to open \"%s\"! %s\n", LIBFUNC_PATH, dlerror()); exit(1);
}
if(get_module_base_address(LIBFUNC_PATH, handle, &base)) {
fprintf(stderr, "Failed to get module base addresses\n");
exit(1);
}
printf("base: %p\n", base);
void *orig = elf_hook(LIBFUNC_PATH, base, "func", hook);
if (NULL == orig) {
fprintf(stderr, "Redirection failed!\n");
exit(1);
}
}
int main() {
uint32_t length = 3;
char *A = malloc(length*sizeof(int32_t));
char *B = malloc(length*sizeof(int32_t));
int i;
for ( i=0; i<length; i++ ) {
((int32_t*)A)[i]= rand() % 100;
((int32_t*)B)[i] = rand() % 100;
}
wrapfunc(A, B, length);
void *handle = dlopen(LIBFUNC_PATH, RTLD_LAZY);
printf("----\n");
set_hook(handle);
printf("----\n");
wrapfunc(A, B, length);
dlclose(handle);
return 0;
}