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 ;
1+ #include <sys/syscall.h>
2+ #include <unistd.h>
3+
4+
5+ #define TRACE_FLAG 511
6+ #define MAX_HOOK_NUM 2000
7+ #define SET_TRACE_SUCCESS 1000
8+ #define SET_TRACE_ERROR 1001
9+
10+ enum trace_info {
11+ SET_TRACE_INFO ,
12+ SET_FUN_INFO ,
13+ CLEAR_UPROBE ,
14+ };
15+
16+ struct trace_init_info {
17+ uid_t uid ;
18+ unsigned long module_base ;
19+ char * tfile_name ;
20+ char * fix_file_name ;
21+ };
22+
23+ struct uprobe_item_info {
24+ unsigned long uprobe_offset ;
25+ unsigned long fun_offset ;
26+ char * fun_name ;
27+ };
28+
29+ int clear_all_uprobes (){
30+ int ret = syscall (__NR_mincore ,0 ,TRACE_FLAG + CLEAR_UPROBE ,"" );
31+ return ret ;
32+ }
33+
34+ int trace_init (trace_init_info * base_info ){
35+ clear_all_uprobes ();
36+ int ret = syscall (__NR_mincore ,0 ,TRACE_FLAG + SET_TRACE_INFO ,base_info );
37+ return ret ;
38+ }
39+
40+ int set_fun_info (uprobe_item_info * uprobe_item ){
41+ int ret = syscall (__NR_mincore ,0 ,TRACE_FLAG + SET_FUN_INFO ,uprobe_item );
42+ return ret ;
5543}
0 commit comments