intreadUnsignedLeb128(constu1**pStream){constu1*ptr=*pStream;intresult=*(ptr++);if(result>0x7f){intcur=*(ptr++);result=(result&0x7f)|((cur&0x7f)<<7);if(cur>0x7f){cur=*(ptr++);result|=(cur&0x7f)<<14;if(cur>0x7f){cur=*(ptr++);result|=(cur&0x7f)<<21;if(cur>0x7f){/*
* Note: We don't check to see if cur is out of
* range here, meaning we tolerate garbage in the
* high four-order bits.
*/cur=*(ptr++);result|=cur<<28;}}}}*pStream=ptr;returnresult;}
intreadSignedLeb128(constu1**pStream){constu1*ptr=*pStream;intresult=*(ptr++);if(result<=0x7f){result=(result<<25)>>25;}else{intcur=*(ptr++);result=(result&0x7f)|((cur&0x7f)<<7);if(cur<=0x7f){result=(result<<18)>>18;}else{cur=*(ptr++);result|=(cur&0x7f)<<14;if(cur<=0x7f){result=(result<<11)>>11;}else{cur=*(ptr++);result|=(cur&0x7f)<<21;if(cur<=0x7f){result=(result<<4)>>4;}else{/*
* Note: We don't check to see if cur is out of
* range here, meaning we tolerate garbage in the
* high four-order bits.
*/cur=*(ptr++);result|=cur<<28;}}}}*pStream=ptr;returnresult;}
typedefstructDexFile{/* directly-mapped "opt" header */constDexOptHeader*pOptHeader;/* pointers to directly-mapped structs and arrays in base DEX */constDexHeader*pHeader;constDexStringId*pStringIds;constDexTypeId*pTypeIds;constDexFieldId*pFieldIds;constDexMethodId*pMethodIds;constDexProtoId*pProtoIds;constDexClassDef*pClassDefs;constDexLink*pLinkData;/*
* These are mapped out of the "auxillary" section, and may not be
* included in the file.
*/constDexClassLookup*pClassLookup;constvoid*pRegisterMapPool;// RegisterMapClassPool
/* points to start of DEX file data */constu1*baseAddr;/* track memory overhead for auxillary structures */intoverhead;/* additional app-specific data structures associated with the DEX *///void* auxData;
}DexFile;
//http://androidxref.com/2.3.7/xref/dalvik/libdex/DexFile.h
//描述了方法的详细信息以及方法中的指令内容
typedefstructDexCode{u2registersSize;//使用寄存器的个数
u2insSize;//参数的个数
u2outsSize;//调用其他方法时使用的寄存器的个数
u2triesSize;//try/catch语句的个数
u4debugInfoOff;//指向调试信息的偏移量
u4insnsSize;//指令集的个数,以2字节为单位
u2insns[1];//指令集
/* followed by optional u2 padding *//* followed by try_item[triesSize] *//* followed by uleb128 handlersSize *//* followed by catch_handler_item[handlersSize] */}DexCode;
//http://androidxref.com/5.0.0_r2/xref/art/runtime/oat.h
structOatHeader{uint8_tmagic_[4];uint8_tversion_[4];uint32_tadler32_checksum_;InstructionSetinstruction_set_;InstructionSetFeaturesinstruction_set_features_;uint32_tdex_file_count_;//OAT中包含Dex文件的个数
uint32_texecutable_offset_;uint32_tinterpreter_to_interpreter_bridge_offset_;uint32_tinterpreter_to_compiled_code_bridge_offset_;uint32_tjni_dlsym_lookup_offset_;uint32_tportable_imt_conflict_trampoline_offset_;uint32_tportable_resolution_trampoline_offset_;uint32_tportable_to_interpreter_bridge_offset_;uint32_tquick_generic_jni_trampoline_offset_;uint32_tquick_imt_conflict_trampoline_offset_;uint32_tquick_resolution_trampoline_offset_;uint32_tquick_to_interpreter_bridge_offset_;// The amount that the image this oat is associated with has been patched.
int32_timage_patch_delta_;uint32_timage_file_location_oat_checksum_;uint32_timage_file_location_oat_data_begin_;uint32_tkey_value_store_size_;uint8_tkey_value_store_[0];// note variable width data at end
};