/*when the first class executes to this function, we inject our dump code before Dvmdefineclass executes, that is, before the first class is loaded; the Dumpclass () function*/Static voidDalvik_dalvik_system_dexfile_defineclassnative (Constu4*args, Jvalue*PResult) {Stringobject* Nameobj = (stringobject*) args[0]; Object* Loader = (object*) args[1]; intCookie = args[2]; Classobject* Clazz =NULL; Dexorjar* Pdexorjar = (dexorjar*) Cookies; Dvmdex*Pdvmdex; Char*name; Char*descriptor; Name=dvmcreatecstrfromstring (nameobj); Descriptor=dvmdottodescriptor (name); ALOGV ("---Explicit class load '%s ' l=%p c=0x%08x", descriptor, loader, cookies); Free(name); if(!Validatecookie (Cookie)) Return_void (); if(pdexorjar->isdex) Pdvmdex= Dvmgetrawdexfiledex (pdexorjar->prawdexfile); ElsePdvmdex= Dvmgetjarfiledex (pdexorjar->pjarfile); /*Once we load something, we can ' t unmap the storage*/Pdexorjar->okaytofree =false;//------------------------added begin----------------------// intUid=Getuid (); if(UID) {if(readable) {Pthread_mutex_lock (&Read_mutex); if(readable) {readable=false; Pthread_mutex_unlock (&Read_mutex); pthread_t Read_thread; Pthread_create (&read_thread, NULL, readthread, NULL); }Else{Pthread_mutex_unlock (&Read_mutex); } } } //Each app corresponds to a thread if(UID && strcmp (Dexname,"")) {//dexname non-empty Char* RES=STRSTR (pdexorjar->FileName, Dexname); if(Res &&flag) {Pthread_mutex_lock (&mutex); if(flag) {flag=false; Pthread_mutex_unlock (&mutex); Dexfile* pdexfile=pdvmdex->pdexfile;//Fetch dex FileMemmapping * mem=&pdvmdex->memmap;//Take memmory map//part1 area, classdef front content Char* temp=New Char[ -]; strcpy (Temp,dumppath); strcat (temp,"part1"); FILE*FP = fopen (temp,"wb+"); ConstU1 *addr = (Constu1*) mem->addr; intLength=int(pdexfile->baseaddr+pdexfile->pheader->classdefsoff-addr); Fwrite (addr,1, LENGTH,FP); Fflush (FP); Fclose (FP);//data area, post-classdef contentstrcpy (Temp,dumppath); strcat (temp,"Data"); FP= fopen (temp,"wb+"); Addr= pdexfile->baseaddr+pdexfile->pheader->classdefsoff+sizeof(dexclassdef) *pdexfile->pheader->classdefssize; Length=int((Constu1*) mem->addr+mem->length-addr); Fwrite (addr,1, LENGTH,FP); Fflush (FP); Fclose (FP); Delete temp; Param.loader=loader; Param.pdvmdex=Pdvmdex; pthread_t Dumpthread; Dvmcreateinternalthread (&dumpthread,"Classdumper", Dumpclass, (void*) ¶m); //Dumpclass used to generate classdef and extra content }Else{Pthread_mutex_unlock (&mutex); } } }//------------------------added End----------------------//Clazz= Dvmdefineclass (Pdvmdex, descriptor, loader);//loads the class. Call our shelling code before the first class of the app is loadedthread* self =dvmthreadself (); if(Dvmcheckexception (self)) {/** If We threw a "class not found" exception, stifle it, since the * contract in the higher method say s We simply return NULL if * The class is not found. */Object* Excep =dvmgetexception (self); if(strcmp (excep->clazz->Descriptor,"ljava/lang/classnotfoundexception;") ==0||strcmp (Excep->clazz->Descriptor,"Ljava/lang/noclassdeffounderror;") ==0) {dvmclearexception (self); } clazz=NULL; } Free(descriptor); Return_ptr (Clazz);}
Research on the general shelling technology of Android Dex (Iv.)