/* add dump .....*/
char key_str[20] = "jiajiatest";
int fd=open("/data/local/tmp/resolve_class_config",O_RDONLY,0666);
if(fd!=-1){
int len = read(fd,key_str,19);
key_str[len-1] = '\x00';
key_str[len] = '\x00';
close(fd);
}
ALOGI("The key_str ---> %s----referrer->descriptor--->%s--", key_str, referrer->descriptor);
if(strstr(referrer->descriptor, key_str)){
char task_name[] = "task_name";
char *logbuf = new char[1024];
char path[50] = {0};
sprintf(path, "/data/local/tmp/%s_dump_%d", key_str, getpid());
FILE *fpw = fopen(path, "awb+");
for(int i=0; i < referrer->directMethodCount; i++){
Method* md = &referrer->directMethods[i];
const char* mName_d = md->name;
const u2 insSize_d = md->insSize;
const u2* insns_d = md->insns;
const u2 methodldx_d = md->methodIndex;
u4 insns_d_size = dvmGetMethodInsnsSize(md);
// ALOGI("hacklh_md---->%p, i-->%d, directMethodCount-->%d", md, i,referrer->directMethodCount);
sprintf(logbuf,"-------------- (KL)resolving [class=%s, method=%s, methodIndex=%u, insSize=%u, insns_d=%x, codeSize=%d] in pid: %d(name: %s)",referrer->descriptor,mName_d,methodldx_d,insSize_d,(u4)insns_d, insns_d_size,getpid() , task_name);
LOGD("%s",logbuf);
if(fpw != NULL){
fwrite(logbuf,1,strlen(logbuf),fpw);
fflush(fpw);
fwrite((u1*)insns_d,1,insns_d_size*2, fpw);
fflush(fpw);
}else{
LOGD("——(KL)open %s fail!", path);
}
}
for(int i=0; i < referrer->virtualMethodCount; i++){
Method* mv = &referrer->virtualMethods[i];
const char* mName_v = mv->name;
const u2 insSize_v = mv->insSize;
const u2* insns_v = mv->insns;
const u2 methodIdx_v = mv->methodIndex;
u4 insns_v_size = dvmGetMethodInsnsSize(mv);
sprintf(logbuf,"-------------- (KL)resolving [class=%s, method=%s, methodIndex=%u, insSize=%u, insns_d=%x, codeSize=%d] in pid: %d(name: %s)",referrer->descriptor,mName_v,methodIdx_v,insSize_v,(u4)insns_v, insns_v_size,getpid() , task_name);
LOGD("%s",logbuf);
if(fpw != NULL){
fwrite(logbuf,1,strlen(logbuf),fpw);
fflush(fpw);
fwrite((u1*)insns_v,1,insns_v_size*2, fpw);
fflush(fpw);
}else{
LOGD("%s","——(KL)open file fail!");
}
}
if(fpw != NULL){
fclose(fpw);
}
delete logbuf;
/* add end .....*/