DEX 可视化查阅

 

参考: http://bbs.pediy.com/thread-208828.htm

 

010 Editor 下载地址: http://www.sweetscape.com/download/

 

  1 //--------------------------------------
  2 //--- 010 Editor v3.1.3 Binary Template
  3 //
  4 // File:
  5 // Author:
  6 // Revision:
  7 // Purpose:
  8 //--------------------------------------
  9 //configure
 10 local byte bShow_DexTypeList = 0;
 11  
 12 //enum
 13 enum { kSHA1DigestLen = 20,
 14        kSHA1DigestOutputLen = kSHA1DigestLen*2 +1 };
 15 /*
 16  * access flags and masks; the "standard" ones are all <= 0x4000
 17  *
 18  * Note: There are related declarations in vm/oo/Object.h in the ClassFlags
 19  * enum.
 20  */
 21 enum <uint> AccessFlags{
 22     ACC_PUBLIC       = 0x00000001,       // class, field, method, ic
 23     ACC_PRIVATE      = 0x00000002,       // field, method, ic
 24     ACC_PROTECTED    = 0x00000004,       // field, method, ic
 25     ACC_STATIC       = 0x00000008,       // field, method, ic
 26     ACC_FINAL        = 0x00000010,       // class, field, method, ic
 27     ACC_SYNCHRONIZED = 0x00000020,       // method (only allowed on natives)
 28     ACC_SUPER        = 0x00000020,       // class (not used in Dalvik)
 29     ACC_VOLATILE     = 0x00000040,       // field
 30     ACC_BRIDGE       = 0x00000040,       // method (1.5)
 31     ACC_TRANSIENT    = 0x00000080,       // field
 32     ACC_VARARGS      = 0x00000080,       // method (1.5)
 33     ACC_NATIVE       = 0x00000100,       // method
 34     ACC_INTERFACE    = 0x00000200,       // class, ic
 35     ACC_ABSTRACT     = 0x00000400,       // class, method, ic
 36     ACC_STRICT       = 0x00000800,       // method
 37     ACC_SYNTHETIC    = 0x00001000,       // field, method, ic
 38     ACC_ANNOTATION   = 0x00002000,       // class, ic (1.5)
 39     ACC_ENUM         = 0x00004000,       // class, field, ic (1.5)
 40     ACC_CONSTRUCTOR  = 0x00010000,       // method (Dalvik only)
 41     ACC_DECLARED_SYNCHRONIZED =
 42                        0x00020000,       // method (Dalvik only)
 43     ACC_CLASS_MASK =
 44         (ACC_PUBLIC | ACC_FINAL | ACC_INTERFACE | ACC_ABSTRACT
 45                 | ACC_SYNTHETIC | ACC_ANNOTATION | ACC_ENUM),
 46     ACC_INNER_CLASS_MASK =
 47         (ACC_CLASS_MASK | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC),
 48     ACC_FIELD_MASK =
 49         (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC | ACC_FINAL
 50                 | ACC_VOLATILE | ACC_TRANSIENT | ACC_SYNTHETIC | ACC_ENUM),
 51     ACC_METHOD_MASK =
 52         (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC | ACC_FINAL
 53                 | ACC_SYNCHRONIZED | ACC_BRIDGE | ACC_VARARGS | ACC_NATIVE
 54                 | ACC_ABSTRACT | ACC_STRICT | ACC_SYNTHETIC | ACC_CONSTRUCTOR
 55                 | ACC_DECLARED_SYNCHRONIZED),
 56 };
 57  
 58 //Dex Header
 59 struct DexHeader {
 60     unsigned char  magic[8];           /* includes version number */
 61     unsigned int   checksum;           /* adler32 checksum */
 62     unsigned char  signature[kSHA1DigestLen]; /* SHA-1 hash */
 63     unsigned int   fileSize;           /* length of entire file */
 64     unsigned int   headerSize;         /* offset to start of next section */
 65     unsigned int   endianTag;
 66     unsigned int   linkSize;
 67     unsigned int   linkOff;
 68     unsigned int   mapOff;
 69     unsigned int   stringIdsSize;
 70     unsigned int   stringIdsOff;
 71     unsigned int   typeIdsSize;
 72     unsigned int   typeIdsOff;
 73     unsigned int   protoIdsSize;
 74     unsigned int   protoIdsOff;
 75     unsigned int   fieldIdsSize;
 76     unsigned int   fieldIdsOff;
 77     unsigned int   methodIdsSize;
 78     unsigned int   methodIdsOff;
 79     unsigned int   classDefsSize;
 80     unsigned int   classDefsOff;
 81     unsigned int   dataSize;
 82     unsigned int   dataOff;
 83 };
 84  
 85 //******************** map list*******************
 86  
 87 /* map item type codes, DexMapItem.type used*/
 88 //DexHeader.mapOff  ---> pointer to data struct
 89 enum <ushort> kDexType{
 90     kDexTypeHeaderItem               = 0x0000,
 91     kDexTypeStringIdItem             = 0x0001,
 92     kDexTypeTypeIdItem               = 0x0002,
 93     kDexTypeProtoIdItem              = 0x0003,
 94     kDexTypeFieldIdItem              = 0x0004,
 95     kDexTypeMethodIdItem             = 0x0005,
 96     kDexTypeClassDefItem             = 0x0006,
 97     kDexTypeMapList                  = 0x1000,
 98     kDexTypeTypeList                 = 0x1001,
 99     kDexTypeAnnotationSetRefList     = 0x1002,
100     kDexTypeAnnotationSetItem        = 0x1003,
101     kDexTypeClassDataItem            = 0x2000,
102     kDexTypeCodeItem                 = 0x2001,
103     kDexTypeStringDataItem           = 0x2002,
104     kDexTypeDebugInfoItem            = 0x2003,
105     kDexTypeAnnotationItem           = 0x2004,
106     kDexTypeEncodedArrayItem         = 0x2005,
107     kDexTypeAnnotationsDirectoryItem = 0x2006,
108 };
109  
110 struct DexMapItem {
111     kDexType type;              /* type code (see kDexType* above) */
112     ushort  unused;
113     uint    size<format=decimal>;              /* count of items of the indicated type */
114     uint    offset;            /* file offset to the start of data */
115 };
116  
117 struct DexMapList
118 {
119     uint size<format=decimal>;               /* #of entries in list */   
120     //ref field DexMapList.size
121     DexMapItem list[size];   /* entries */
122 };
123  
124 //********************strings index table********************
125 /*
126  * Direct-mapped "string_id_item".
127  */
128 typedef struct
129 {
130     uint stringDataOff;      /* file offset to string_data_item */
131 }DexStringId<read=TemplateRead_StringId>;
132  
133 //********************types index table********************
134 /*
135  * Direct-mapped "type_id_item".
136  */
137 typedef struct
138 {
139     uint  descriptorIdx;      /* index into stringIds list for type descriptor */
140 }DexTypeId<read=TemplateRead_TypeId>;
141  
142 //********************protos index table********************
143  
144 /*
145  * Direct-mapped "type_item".
146  */
147 struct DexTypeItem {
148     ushort  typeIdx;            /* index into typeIds */
149 };
150  
151 /*
152  * Direct-mapped "type_list".
153  */
154 typedef struct  {
155     uint  size;               /* #of entries in list */
156     DexTypeItem list[size];    /* entries */
157 }DexTypeList<read=TemplateRead_TypeList>;
158  
159 /*
160  * Direct-mapped "proto_id_item".
161  */
162 typedef struct 
163 {
164     uint  shortyIdx;          /* index into stringIds for shorty descriptor */
165     uint  returnTypeIdx;      /* index into typeIds list for return type */
166     uint  parametersOff;      /* file offset to type_list for parameter types */ 
167     if(parametersOff > 0x70)
168     {
169         local int64 oldOffset = FTell(); 
170         FSeek(parametersOff);   
171         DexTypeList typeList_Params;
172         FSeek(oldOffset); 
173     }        
174 }DexProtoId<read=TemplateRead_ProtoId>;
175  
176  
177 //********************field index table********************
178 /*
179  * Direct-mapped "field_id_item".
180  */
181 typedef struct  {
182     ushort  classIdx;           /* index into typeIds list for defining class */
183     ushort  typeIdx;            /* index into typeIds for field type */
184     uint  nameIdx;            /* index into stringIds for field name */
185 }DexFieldId<read=TemplateRead_FieldId>;
186  
187 //********************method index table********************
188 /*
189  * Direct-mapped "method_id_item".
190  */
191 typedef struct  {
192     ushort  classIdx;           /* index into typeIds list for defining class */
193     ushort  protoIdx;           /* index into protoIds for method prototype */
194     uint  nameIdx;            /* index into stringIds for method name */
195 }DexMethodId<read=TemplateRead_MethodId>;
196  
197 //********************Class Define table********************
198  
199 /* expanded form of a class_data_item header */
200 struct DexClassDataHeader {
201     local int64 oldOffset = FTell();
202     local int64 currOffset = oldOffset; 
203     //Printf("oldOffset=%x,",oldOffset);
204     //Printf("currOffset=%x\n",currOffset);  
205     local int len = readUnsignedLeb128(currOffset);
206     //Printf("oldOffset=%x,",oldOffset);
207     //Printf("currOffset=%x,",currOffset);
208     //Printf("field size:%x,",currOffset - oldOffset);
209     //Printf("size:%x\n",len);
210     switch(currOffset - oldOffset)
211     {
212         case 1: ubyte staticFieldsSize<comment="uleb128 staticFieldsSize">; break;
213         case 2: ushort staticFieldsSize<comment="uleb128 staticFieldsSize">; break;
214         case 3: ubyte staticFieldsSize[3]<comment="uleb128 staticFieldsSize">; break;
215         case 4: uint staticFieldsSize<comment="uleb128 staticFieldsSize">; break;
216         case 5: ubyte staticFieldsSize[5]<comment="uleb128 staticFieldsSize">; break;
217     }   
218      
219     oldOffset = FTell();
220     currOffset = oldOffset;
221     //Printf("*******************************\n");
222     //Printf("oldOffset=%x,",oldOffset);
223     //Printf("currOffset=%x\n",currOffset);  
224     len = readUnsignedLeb128(currOffset);
225     //Printf("oldOffset=%x,",oldOffset);
226     //Printf("currOffset=%x,",currOffset);
227     //Printf("field size:%x,",currOffset - oldOffset);
228     //Printf("size:%x\n",len);
229     switch(currOffset - oldOffset)
230     {
231         case 1: ubyte instanceFieldsSize<comment="uleb128 instanceFieldsSize">; break;
232         case 2: ushort instanceFieldsSize<comment="uleb128 instanceFieldsSize">; break;
233         case 3: ubyte instanceFieldsSize[3]<comment="uleb128 instanceFieldsSize">; break;
234         case 4: uint instanceFieldsSize<comment="uleb128 instanceFieldsSize">; break;
235         case 5: ubyte instanceFieldsSize[5]<comment="uleb128 instanceFieldsSize">; break;
236     }       
237  
238  
239     oldOffset = FTell();
240     currOffset = oldOffset;
241     //Printf("*******************************\n");
242     //Printf("oldOffset=%x,",oldOffset);
243     //Printf("currOffset=%x\n",currOffset);  
244     len = readUnsignedLeb128(currOffset);
245     //Printf("oldOffset=%x,",oldOffset);
246     //Printf("currOffset=%x,",currOffset);
247     //Printf("field size:%x,",currOffset - oldOffset);
248     //Printf("size:%x\n",len);
249     switch(currOffset - oldOffset)
250     {
251         case 1: ubyte directMethodsSize<comment="uleb128 directMethodsSize">; break;
252         case 2: ushort directMethodsSize<comment="uleb128 directMethodsSize">; break;
253         case 3: ubyte directMethodsSize[3]<comment="uleb128 directMethodsSize">; break;
254         case 4: uint directMethodsSize<comment="uleb128 directMethodsSize">; break;
255         case 5: ubyte directMethodsSize[5]<comment="uleb128 directMethodsSize">; break;
256     }       
257      
258     oldOffset = FTell();
259     currOffset = oldOffset;
260     //Printf("*******************************\n");
261     //Printf("oldOffset=%x,",oldOffset);
262     //Printf("currOffset=%x\n",currOffset);  
263     len = readUnsignedLeb128(currOffset);
264     //Printf("oldOffset=%x,",oldOffset);
265     //Printf("currOffset=%x,",currOffset);
266     //Printf("field size:%x,",currOffset - oldOffset);
267     //Printf("size:%x\n",len);
268     switch(currOffset - oldOffset)
269     {
270         case 1: ubyte virtualMethodsSize<comment="uleb128 virtualMethodsSize">; break;
271         case 2: ushort virtualMethodsSize<comment="uleb128 virtualMethodsSize">; break;
272         case 3: ubyte virtualMethodsSize[3]<comment="uleb128 virtualMethodsSize">; break;
273         case 4: uint virtualMethodsSize<comment="uleb128 virtualMethodsSize">; break;
274         case 5: ubyte virtualMethodsSize[5]<comment="uleb128 virtualMethodsSize">; break;
275     }           
276 };
277  
278 /* expanded form of encoded_field */
279 struct DexField {
280     uint fieldIdx;    /* index to a field_id_item */
281     uint accessFlags;
282 };
283  
284 /* expanded form of encoded_method */
285 struct DexMethod {
286     uint methodIdx;    /* index to a method_id_item */
287     uint accessFlags;
288     uint codeOff;      /* file offset to a code_item */
289 };
290  
291 /* expanded form of class_data_item. Note: If a particular item is
292  * absent (e.g., no static fields), then the corresponding pointer
293  * is set to NULL. */
294 struct DexClassData {
295     DexClassDataHeader header;
296  
297     local int64 oldOffset = FTell();
298     local int64 currOffset = oldOffset; 
299     //Printf("oldOffset=%x,",oldOffset);
300     //Printf("currOffset=%x\n",currOffset);  
301     local int len = readUnsignedLeb128(currOffset);
302     //Printf("oldOffset=%x,",oldOffset);
303     //Printf("currOffset=%x,",currOffset);
304     //Printf("field size:%x,",currOffset - oldOffset);
305     //Printf("size:%x\n",len);
306     switch(currOffset - oldOffset)
307     {
308         case 1: ubyte staticFields<comment="uleb128 staticFields">; break;
309         case 2: ushort staticFields<comment="uleb128 staticFields">; break;
310         case 3: ubyte staticFields[3]<comment="uleb128 staticFields">; break;
311         case 4: uint staticFields<comment="uleb128 staticFields">; break;
312         case 5: ubyte staticFields[5]<comment="uleb128 staticFields">; break;
313     }
314  
315     oldOffset = FTell();
316     currOffset = oldOffset; 
317     //Printf("oldOffset=%x,",oldOffset);
318     //Printf("currOffset=%x\n",currOffset);  
319     len = readUnsignedLeb128(currOffset);
320     //Printf("oldOffset=%x,",oldOffset);
321     //Printf("currOffset=%x,",currOffset);
322     //Printf("field size:%x,",currOffset - oldOffset);
323     //Printf("size:%x\n",len);
324     switch(currOffset - oldOffset)
325     {
326         case 1: ubyte instanceFields<comment="uleb128 instanceFields">; break;
327         case 2: ushort instanceFields<comment="uleb128 instanceFields">; break;
328         case 3: ubyte instanceFields[3]<comment="uleb128 instanceFields">; break;
329         case 4: uint instanceFields<comment="uleb128 instanceFields">; break;
330         case 5: ubyte instanceFields[5]<comment="uleb128 instanceFields">; break;
331     }
332  
333     oldOffset = FTell();
334     currOffset = oldOffset; 
335     //Printf("oldOffset=%x,",oldOffset);
336     //Printf("currOffset=%x\n",currOffset);  
337     len = readUnsignedLeb128(currOffset);
338     //Printf("oldOffset=%x,",oldOffset);
339     //Printf("currOffset=%x,",currOffset);
340     //Printf("field size:%x,",currOffset - oldOffset);
341     //Printf("size:%x\n",len);
342     switch(currOffset - oldOffset)
343     {
344         case 1: ubyte directMethods<comment="uleb128 directMethods">; break;
345         case 2: ushort directMethods<comment="uleb128 directMethods">; break;
346         case 3: ubyte directMethods[3]<comment="uleb128 directMethods">; break;
347         case 4: uint directMethods<comment="uleb128 directMethods">; break;
348         case 5: ubyte directMethods[5]<comment="uleb128 directMethods">; break;
349     }
350      
351     oldOffset = FTell();
352     currOffset = oldOffset; 
353     //Printf("oldOffset=%x,",oldOffset);
354     //Printf("currOffset=%x\n",currOffset);  
355     len = readUnsignedLeb128(currOffset);
356     //Printf("oldOffset=%x,",oldOffset);
357     //Printf("currOffset=%x,",currOffset);
358     //Printf("field size:%x,",currOffset - oldOffset);
359     //Printf("size:%x\n",len);
360     switch(currOffset - oldOffset)
361     {
362         case 1: ubyte virtualMethods<comment="uleb128 virtualMethods">; break;
363         case 2: ushort virtualMethods<comment="uleb128 virtualMethods">; break;
364         case 3: ubyte virtualMethods[3]<comment="uleb128 virtualMethods">; break;
365         case 4: uint virtualMethods<comment="uleb128 virtualMethods">; break;
366         case 5: ubyte virtualMethods[5]<comment="uleb128 virtualMethods">; break;
367     }   
368     //DexField*          staticFields;  
369     //DexField*          instanceFields;
370     //DexMethod*         directMethods;
371     //DexMethod*         virtualMethods;
372 };
373  
374 /*
375  * Direct-mapped "class_def_item".
376  */
377 typedef struct  {
378     uint  classIdx;           /* index into typeIds for this class */
379     AccessFlags  accessFlags;
380     uint  superclassIdx;      /* index into typeIds for superclass */
381     uint  interfacesOff;      /* file offset to DexTypeList */
382     if(interfacesOff > 0 && interfacesOff != 0xFFFFFFFF)
383     {
384         local int64 oldOffset = FTell(); 
385         FSeek(interfacesOff);   
386         DexTypeList typeList_Interfaces;
387         FSeek(oldOffset); 
388     }
389     uint  sourceFileIdx;      /* index into stringIds for source file name */
390     uint  annotationsOff;     /* file offset to annotations_directory_item */
391     uint  classDataOff;       /* file offset to class_data_item */
392     if(classDataOff > 0 && classDataOff != 0xFFFFFFFF)
393     {
394         local int64 oldOff = FTell(); 
395         FSeek(classDataOff);   
396         DexClassData dexClassData;
397         FSeek(oldOff);
398     }
399     uint  staticValuesOff;    /* file offset to DexEncodedArray */
400     if(staticValuesOff > 0)
401     {
402         local int64 offset = FTell(); 
403         FSeek(staticValuesOff);   
404         //
405         FSeek(offset);
406     }
407 }DexClassDef<read=TemplateRead_ClassDefs>;
408  
409 /*
410  * Direct-mapped "annotations_directory_item".
411  */
412 struct DexAnnotationsDirectoryItem {
413     uint  classAnnotationsOff;  /* offset to DexAnnotationSetItem */
414     uint  fieldsSize;           /* count of DexFieldAnnotationsItem */
415     uint  methodsSize;          /* count of DexMethodAnnotationsItem */
416     uint  parametersSize;       /* count of DexParameterAnnotationsItem */
417     /* followed by DexFieldAnnotationsItem[fieldsSize] */
418     /* followed by DexMethodAnnotationsItem[methodsSize] */
419     /* followed by DexParameterAnnotationsItem[parametersSize] */
420 };
421  
422 void Dump_DexHeader(int64 startOffset)
423 {   
424     local int64 oldOffset = FTell();
425     FSeek(startOffset);
426     DexHeader dexHdr;
427     FSeek(oldOffset);
428  
429     Printf("file size: 0x%x\n", dexHdr.fileSize);
430     Printf("file header size: 0x%x\n", dexHdr.headerSize);
431     Printf("strings count: %d\n", dexHdr.stringIdsSize);
432     Printf("types count: %d\n", dexHdr.typeIdsSize);
433     Printf("proto count: %d\n", dexHdr.protoIdsSize);
434     Printf("fields count: %d\n", dexHdr.fieldIdsSize);
435     Printf("methods count: %d\n", dexHdr.methodIdsSize);
436     Printf("classDefs count: %d\n", dexHdr.classDefsSize);
437     Printf("data size count: %d\n", dexHdr.dataSize);
438     Printf("mapOff: 0x%x\n", dexHdr.mapOff);
439 }
440  
441 void Dump_MapList(int64 startOffset)
442 {
443     local int64 oldOffset = FTell();
444     FSeek(startOffset);
445     DexMapList mapList;
446     FSeek(oldOffset);  
447 }
448  
449  
450 void Dump_StringItems(int64 startOffset)
451 {
452     local int64 oldOffset = FTell();
453     FSeek(startOffset);
454     DexStringId dexStringId[dexHdr.stringIdsSize];
455     FSeek(oldOffset);  
456 }
457  
458 void Dump_TypeItems(int64 startOffset)
459 {
460     local int64 oldOffset = FTell();
461     FSeek(startOffset);
462     DexTypeId dexTypeId[dexHdr.typeIdsSize];
463     FSeek(oldOffset);  
464 }
465  
466 void Dump_ProtoItems(int64 startOffset)
467 {
468     local int64 oldOffset = FTell();
469     FSeek(startOffset);
470     DexProtoId dexProtoId[dexHdr.protoIdsSize]<optimize=true>;   
471  
472     FSeek(oldOffset);
473 }
474  
475 void Dump_FieldItems(int64 startOffset)
476 {
477     local int64 oldOffset = FTell();
478     FSeek(startOffset);  
479     DexFieldId dexFieldId[dexHdr.fieldIdsSize];
480     FSeek(oldOffset);
481 }
482  
483 void Dump_MethodItems(int64 startOffset)
484 {
485     local int64 oldOffset = FTell();
486     FSeek(startOffset);  
487     DexMethodId dexMethodId[dexHdr.methodIdsSize];
488     FSeek(oldOffset);
489 }
490  
491 void Dump_ClassDef(int64 startOffset)
492 {
493     local int64 oldOffset = FTell();
494     FSeek(startOffset);  
495     DexClassDef dexClassDef[dexHdr.classDefsSize]<optimize=false>;
496     FSeek(oldOffset);
497 }
498  
499 int readUnsignedLeb128(int64 &streamPos)
500 {   
501     local int result = ReadUByte(streamPos);// read first byte
502   streamPos++;
503    
504     if (result > 0x7f)
505   {
506         local int cur = ReadUByte(streamPos);   //read second byte
507     streamPos++;
508         result = (result & 0x7f) | ((cur & 0x7f) << 7);
509         if (cur > 0x7f)
510     {
511             cur = ReadUByte(streamPos);     //read third byte
512       streamPos++;
513             result |= (cur & 0x7f) << 14;
514             if (cur > 0x7f)
515       {
516                 cur = ReadUByte(streamPos); //read fourth byte
517         streamPos++;
518                 result |= (cur & 0x7f) << 21;
519                 if (cur > 0x7f)
520         {
521                     /*
522                      * Note: We don't check to see if cur is out of
523                      * range here, meaning we tolerate garbage in the
524                      * high four-order bits.
525                      */
526                     cur = ReadUByte(streamPos); //read fifth byte
527           streamPos++;
528                     result |= cur << 28;
529                 }
530             }
531         }
532     }
533      
534     return result;
535 }
536  
537 //display checker value
538 string TemplateRead_StringId(DexStringId &stringId)
539 {   
540     local string str = "";
541     local int64 offset = stringId.stringDataOff;
542     local int strLen = readUnsignedLeb128(offset); //--->>>Warning,only pause one string
543     str = ReadString(offset); 
544      
545     return str;
546 }
547  
548 string TemplateRead_TypeId(DexTypeId &typeId )
549 {   
550     local string str = "";
551     local int64 offset = dexStringId[typeId.descriptorIdx].stringDataOff;
552     local int strLen = readUnsignedLeb128(offset);
553     str = ReadString(offset);
554     str = TemplateRead_StringId(dexStringId[typeId.descriptorIdx]);
555     return str;
556 }
557  
558 string TemplateRead_ProtoId(DexProtoId &protoId )
559 {   
560     local int64 oldOffset = FTell();  
561     local string str = "";
562     local int i = 0, count = 0;
563     local short typeIdx = -1;
564      
565     if(protoId.parametersOff > 0)
566     {
567         local string method = TemplateRead_StringId(dexStringId[protoId.shortyIdx]);
568         local string retType = TemplateRead_TypeId(dexTypeId[protoId.returnTypeIdx]);
569         local string params = "";
570  
571         count = ReadInt(protoId.parametersOff);
572         while(i < count)
573         {
574             typeIdx = ReadShort(protoId.parametersOff + sizeof(int) +
575                             i * sizeof(short));
576             params += TemplateRead_TypeId(dexTypeId[typeIdx]);
577             i++;
578              
579             //function args delimiter
580             //if(i < count)
581                 //params += " , ";
582         }      
583          
584         //join: return + method + args
585         SPrintf(str, "<%s%s(%s)>",retType, method, params);
586     }   
587      
588     FSeek(oldOffset);
589     return str;
590 }
591  
592 string TemplateRead_FieldId(DexFieldId &fieldId)
593 {
594     local string classTypeName = "";
595     local string fieldTypeName = "";
596     local string fieldName = "";
597     local string result = "";
598  
599     classTypeName = TemplateRead_TypeId(dexTypeId[fieldId.classIdx]);
600     fieldTypeName = TemplateRead_TypeId(dexTypeId[fieldId.typeIdx]);
601     fieldName = TemplateRead_StringId(dexStringId[fieldId.nameIdx]);
602     result = classTypeName + "@" + fieldTypeName + "@" + fieldName;
603  
604     return result;
605 }
606  
607 string TemplateRead_MethodId(DexMethodId &methodId)
608 {
609     local string result = "";
610     local string classTypeName = "";
611     local string protoTypeName = "";
612     local string methodName = "";
613      
614     classTypeName = TemplateRead_TypeId(dexTypeId[methodId.classIdx]);
615     protoTypeName = TemplateRead_ProtoId(dexProtoId[methodId.protoIdx]);
616     methodName = TemplateRead_StringId(dexStringId[methodId.nameIdx]);
617     result = classTypeName + "@" + protoTypeName + "@" + methodName;
618  
619     return result;
620 }
621  
622 string TemplateRead_ClassDefs(DexClassDef &classDef)
623 {
624     local string result = "";
625     local string classTypeName = "";
626     local string superClassTypeName = "";
627     local string protoTypeName = "";
628     local string methodName = "";
629      
630      
631  
632     return result;
633 }
634  
635 string TemplateRead_TypeList(DexTypeList &typeList)
636 {
637     local string result = "", temp = "";
638     //local int i = 0;
639     //local int len = typeList.size;
640     //while(i < len)
641     //{
642         //SPrintf(temp, "%d,", typeList.list[i].typeIdx);
643         //typeList.list[i].typeIdx;
644         //dexTypeId[typeList.list[i].typeIdx];
645         //result += TemplateRead_TypeId(dexTypeId[typeList.list[i].typeIdx]);
646          
647         //SPrintf(temp, "index=%d,", i);
648         //result += temp;
649        // i++;
650     //}
651     //SPrintf(result, "size=%d", typeList.size);
652     return result;
653 }
654 //-------------------------->>>   start running   <<<--------------------------
655 Dump_DexHeader(0);
656 Dump_MapList(dexHdr.mapOff);
657 Dump_StringItems(dexHdr.stringIdsOff);
658 Dump_TypeItems(dexHdr.typeIdsOff);
659 Dump_ProtoItems(dexHdr.protoIdsOff);
660 Dump_FieldItems(dexHdr.fieldIdsOff);
661 Dump_MethodItems(dexHdr.methodIdsOff);
662 Dump_ClassDef(dexHdr.classDefsOff);

 

posted @ 2017-04-28 10:44  UDLD  阅读(493)  评论(0编辑  收藏  举报