1+ #include <sys/syscall.h>
2+ #include <unistd.h>
3+
4+
5+ #define TRACE_FLAG 511
6+ #define MAX_HOOK_NUM 1000
7+ #define SET_TRACE_SUCCESS 1000
8+ #define SET_TRACE_ERROR 1001
9+
10+ enum trace_info {
11+ SET_TARGET_FILE ,
12+ SET_MODULE_BASE ,
13+ SET_FUN_INFO ,
14+ FIX_ORI_INS ,
15+ SET_TARGET_UPROBE ,
16+ SET_TARGET_UID ,
17+ CLEAR_UPROBE ,
18+ };
19+
20+ // unsigned long start, size_t len, unsigned char *vec
21+
22+ int set_module_base (unsigned long module_base ){
23+ int ret = syscall (__NR_mincore ,module_base ,TRACE_FLAG + SET_MODULE_BASE ,"" );
24+ return ret ;
25+ }
26+
27+ int set_target_uid (uid_t uid ){
28+ int ret = syscall (__NR_mincore ,uid ,TRACE_FLAG + SET_TARGET_UID ,"" );
29+ return ret ;
30+ }
31+
32+ int set_target_file (char * file_name ){
33+ int ret = syscall (__NR_mincore ,0 ,TRACE_FLAG + SET_TARGET_FILE ,file_name );
34+ return ret ;
35+ }
36+
37+ int set_fun_info (unsigned long uprobe_offset ,unsigned long fun_offset ,char * fun_name ,char * fix_insn ){
38+ int insert_key_ret = syscall (__NR_mincore ,fun_offset ,TRACE_FLAG + SET_FUN_INFO ,fun_name );
39+ if (insert_key_ret == SET_TRACE_SUCCESS ){
40+ if (fix_insn ){
41+ int fix_insn_ret = syscall (__NR_mincore ,uprobe_offset ,TRACE_FLAG + FIX_ORI_INS ,fix_insn );
42+ if (fix_insn_ret == SET_TRACE_ERROR ){
43+ return SET_TRACE_ERROR ;
44+ }
45+ }
46+ int ret = syscall (__NR_mincore ,uprobe_offset ,TRACE_FLAG + SET_TARGET_UPROBE ,"" );
47+ return ret ;
48+ }
49+ return SET_TRACE_ERROR ;
50+ }
51+
52+ int clear_all_uprobes (){
53+ int ret = syscall (__NR_mincore ,0 ,TRACE_FLAG + CLEAR_UPROBE ,"" );
54+ return ret ;
55+ }
0 commit comments