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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| ret (*orig_ ret new_
HOOK_DEF(int,fileopen,char * pathname,int flags){
int fd = orig_fileopen(pathname,flags); if(strstr(pathname,"global-metadata.dat")){ LOGD("file open %s fd %d",pathname,fd); return Decrypt_il2cpp(fd); } return orig_fileopen(pathname,flags);
}
int Decrypt_il2cpp(int fd){ int flen; struct stat statbuff; if(fstat(fd, &statbuff) < 0){ LOGE("fstat error :%s",strerror(errno)); }else{ flen = statbuff.st_size; } LOGD("file size :%d",flen); if(flen <= 0){ return -1; } int remain = flen % 4096 ? 1 : 0; int map_size = (flen / 4096 + remain) * 4096; void *data_buffer = (char *) malloc(map_size); if (data_buffer == NULL) { LOGD("[MpsHook_open] data buffer malloc failed"); return NULL; } memset(data_buffer, 0, map_size); int data_size = orig_read(fd,data_buffer,flen);
if (data_size > 0) {
LOGD("[MpsHook_open] read buffer %d->%d", data_size, map_size);//2530873->2531328
data_size = map_size;
} else {
LOGD("[MpsHook_open] read buffer failed!! %s",strerror(errno));
} lseek(fd, 0, SEEK_SET); //do decrypt LOGD("data_buffer %p %s",data_buffer,data_buffer); char key[9] = "password"; size_t len = 0; metadata_buffer = xxtea_decrypt(((char *)data_buffer+9),flen-9,key,&len); metadata_size = len;
LOGD("[oook] res: %p %s",len,metadata_buffer);
char filepath[1024] = ""; sprintf(filepath,"%s/replace.dat",path); // 创建的文件权限需要注意
if(access(filepath,F_OK)!=0){ LOGD("replace.dat not find"); FILE *fp = fopen(filepath,"wb+"); if(fp==NULL){ LOGE("creat file faild %s",strerror(errno)); } else{ LOGD("creat file success"); fclose(fp); } } LOGD("%s",filepath); int replace_fd = orig_fileopen(filepath,O_RDWR); LOGD("replace_fd %d",replace_fd); if(replace_fd<0){ LOGE("open file %s faild err:%s",filepath,strerror(errno)); }else{ int wlen = write(replace_fd,metadata_buffer,metadata_size);
if(wlen<0){ LOGE("write file %s faild err:%s ",filepath,strerror(errno)); }
} metadata_fd = replace_fd; orig_close(fd);
return replace_fd;
}
HOOK_DEF(int,close,int fd){
if(fd == metadata_fd){ LOGD("close fd %d",fd); metadata_fd = -2; char file[1024] = ""; strcpy(file,path); strcat(file,"/replace.dat"); if(remove(file) == 0){ LOGD("remove file %s",file); } else{ LOGE("remove file %s faild",file); } } return orig_close(fd); }
|