#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
static
char
*testChar =
"test hook!!"
;
typedef
char
* (*p_strcat)(
void
*dest,
const
void
*src);
static
p_strcat _p_s = NULL;
void
call_strcat() {
char
test[100];
strcat
(test,
"test"
);
printf
(
"call_strcat -> test=%s\n"
, test);
}
char
* my_strcat(
void
*dest,
const
void
*src) {
printf
(
"testChar=%s\n"
, testChar);
return
testChar;
}
int
main(
void
) {
printf
(
"my_strcat=%p,&my_strcat= %p\n"
, my_strcat, &my_strcat);
printf
(
"address of strcat=%p\n"
, (
int
*)
strcat
);
void
*handle;
handle = dlopen(
" /lib/x86_64-linux-gnu/libc.so.6"
,
RTLD_LAZY | RTLD_GLOBAL);
p_strcat p_s_aa = (p_strcat)dlsym(handle,
"strcat"
);
printf
(
"to p -> p_s_aa=%p,*p_s_aa=%p\n"
, p_s_aa, *p_s_aa);
p_strcat *p_s_bb = (p_strcat*) dlsym(handle,
"strcat"
);
printf
(
"to p* -> p_s_bb=%p,*p_s_bb=%p\n"
, p_s_bb, *p_s_bb);
p_strcat * p_p_s = &_p_s;
*p_p_s = *p_s_bb;
char
arr[20];
_p_s(arr,
"hhee"
);
printf
(
"arr=%s\n"
, arr);
*p_s_bb = my_strcat;
printf
(
"bb p_s_bb=%p,*p_s_bb=%p\n"
, p_s_bb, *p_s_bb);
call_strcat();
dlclose(handle);
return
0;
}