Research on the general shelling technology of Android Dex (Iv.)

Source: Internet
Author: User
Tags strcmp

/*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*) &param); //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.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.