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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| void *readbuf; uLong offset_start = 0; uLong offset_end = 0; int now_count = 0;
char key[11] = "jjmatch123";
HOOK_DEF(int,read,int fd,void *buf,int count){
off_t offset = lseek(fd,0,SEEK_CUR);
if(offset_end!=0&&offset_start!=0){ if(offset<=offset_end&&offset>=offset_start){ readbuf = buf; now_count = count; } }
int ret = orig_read(fd,buf,count);
InitZIPfileInfo(fd,count,buf,offset);
return ret; }
int InitZIPfileInfo(int fd,int count,void *buf,uLong offset){
if(fd == 0 || count != 30){ return 0; }
if(sizeof(ZIPfile) != 30){ LOGE("[AssetBundleDecryptor::InitZIPfileInfo] sizeof(ZIPfile) is not 30!"); return -1; }
ZIPfile *ziphead = static_cast<ZIPfile *>(buf);
if(ziphead->frSignature[0] == 0x50 && ziphead->frSignature[1] == 0x4b && ziphead->frSignature[2] == 0x03 && ziphead->frSignature[3] == 0x04 ){
char *filename= (char *)malloc(sizeof(char)*ziphead->frFileNameLength+1);
int off = lseek(fd,0,SEEK_CUR);
int ret = orig_read(fd,filename,ziphead->frFileNameLength);
if(ret == -1){ LOGE("[AssetBundleDecryptor::InitZIPfileInfo] read error %s",strerror(errno)); return -1; }
LOGD("[AssetBundleDecryptor::InitZIPfileInfo] FileName %*s",ziphead->frFileNameLength,filename);
if(strstr(filename,"mod.ab") != NULL){
LOGD("[AssetBundleDecryptor::InitZIPfileInfo] zipfile info UncompressedSize:0x%x,compressedSize:0x%x,ExtraFieldLength:0x%x,FileNameLength:0x%x", ziphead->frUncompressedSize,ziphead->frCompressedSize,ziphead->frExtraFieldLength,ziphead->frFileNameLength);
offset_start = offset+count+ziphead->frExtraFieldLength+ziphead->frFileNameLength; offset_end = offset_start + ziphead->frCompressedSize;
LOGD("[AssetBundleDecryptor::InitZIPfileInfo] init success !\n offset_start %d ,offset_end %d",offset_start,offset_end);
} lseek(fd, off, SEEK_SET);
if(filename!=NULL) free(filename);
}else{ LOGD("[AssetBundleDecryptor::InitZIPfileInfo] is not ziphead"); return 0; }
return 1;
}
HOOK_DEF(int,inflate,z_streamp strm, int flush){
void *input = strm->next_in; Bytef *output = strm->next_out; u_long outlen = strm->avail_out;
int ret = orig_inflate(strm,flush);
outlen = outlen - strm->avail_out;
if(input>=readbuf&&input<=((int *)readbuf+now_count )){
if(readbuf == input){
if(strstr((char *)output,"AAAAAAA") != NULL){
}
return ret; } }
int num = strm->total_out - outlen -7;
if(outlen == 1024) return ret;
for(int i = 0; i<outlen;i++){ output[i] = output[i] ^ key[(num +i)%10];
} } return ret; }
void AssetBundleDecryptor::registerHook() {
LOGD("in registerHook pid %d",getpid());
std::string libpath = get_libpath(); libpath.append("libunity.so");
LOGD("libunity : %s",libpath.data());
void *handle = dlopen(libpath.data(),RTLD_LAZY);
xhook_register(libpath.data(),"inflate",(void*)new_inflate,(void **)&orig_inflate);
xhook_register("libc.so","read",(void*)new_read,(void **)&orig_read);
}
|