@@ -21,6 +21,10 @@ char module_path[PATH_MAX];
2121static uint64_t il2cpp_base = 0 ;
2222int hook_fun_num=0 ;
2323std::map<long ,std::string> fun_name_dict;
24+ unsigned long start_addrs[MAX_VMA_NUM];
25+ unsigned long end_addrs[MAX_VMA_NUM];
26+ unsigned long vma_base[MAX_VMA_NUM];
27+ int vma_num=0 ;
2428
2529void init_il2cpp_api (void *handle) {
2630#define DO_API (r, n, p ) { \
@@ -110,9 +114,16 @@ void hook_all_fun(){
110114 for (auto it = fun_name_dict.begin (); it != fun_name_dict.end (); ++it) {
111115 unsigned long fun_offset = it->first ;
112116 std::string fun_name = it->second ;
113- int set_uprobe_ret = set_fun_info (fun_offset,(char *)fun_name.c_str ());
117+ unsigned long fun_addr = il2cpp_base+fun_offset;
118+ unsigned long uprobe_offset;
119+ for (int i=0 ;i<vma_num;i++){
120+ if (fun_addr>start_addrs[i] && fun_addr<end_addrs[i]){
121+ uprobe_offset = fun_addr-start_addrs[i]+vma_base[i];
122+ }
123+ }
124+ int set_uprobe_ret = set_fun_info (uprobe_offset,fun_offset,(char *)fun_name.c_str ());
114125 if (set_uprobe_ret!=SET_TRACE_SUCCESS){
115- LOGE (" set uprobe in fun_name:%s,fun_offset:0x%llx" ,fun_name.c_str (),fun_offset);
126+ LOGE (" error set uprobe in fun_name:%s,fun_offset:0x%llx,uprobe_offset:%llx " ,fun_name.c_str (),fun_offset,uprobe_offset );
116127 }
117128 }
118129 LOGD (" success hook fun num:%d" ,hook_fun_num);
@@ -154,6 +165,40 @@ void trace_type_info(Il2CppMetadataType type_info,char *clazzName) {
154165 check_all_methods (klass,clazzName);
155166}
156167
168+ bool init_vma (){
169+ FILE *f;
170+ char buf[256 ];
171+ f = fopen (" /proc/self/maps" ," r" );
172+ if (!f){
173+ return false ;
174+ }
175+ while (fgets (buf,256 ,f)!=NULL ){
176+ unsigned long tstart,tend,tbase;
177+ char permissions[5 ];
178+ int major,minor;
179+ unsigned long inode;
180+ char path[256 ];
181+
182+ int fields = sscanf (buf," %lx-%lx %4s %lx %x:%x %lu %s" ,&tstart,&tend,permissions,&tbase,&major,&minor,&inode,path);
183+ if (fields==8 ){
184+ if (strcmp (path,module_path)==0 ){
185+ // LOGD("start:%lx,end:%lx,permissions:%s,tbase:%lx\n",tstart,tend,permissions,tbase);
186+ if (permissions[2 ]==' x' ){
187+ start_addrs[vma_num] = tstart;
188+ end_addrs[vma_num] = tend;
189+ vma_base[vma_num] = tbase;
190+ vma_num++;
191+ }
192+ }
193+ }
194+
195+ }
196+ fclose (f);
197+ if (vma_num==0 ){
198+ return false ;
199+ }
200+ return true ;
201+ }
157202
158203void start_trace (char * data_dir_path){
159204 char trace_file_path[PATH_MAX];
@@ -164,6 +209,12 @@ void start_trace(char* data_dir_path){
164209 return ;
165210 }
166211 LOGD (" success get il2cpp api fun" );
212+ bool parse_ret = init_vma ();
213+ if (!parse_ret){
214+ LOGE (" can not get vma info" );
215+ return ;
216+ }
217+
167218
168219 int set_module_base_ret = set_module_base (il2cpp_base);
169220 int set_target_file_ret = set_target_file (module_path);
0 commit comments