1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
void dumpInstruction(DexFile* pDexFile, const DexCode* pCode, int insnIdx,int insnWidth, const DecodedInstruction* pDecInsn) { const u2* insns = pCode->insns; int i; printf("%06zx:", ((u1*)insns - pDexFile->baseAddr) + insnIdx * 2); for (i = 0; i < 8; i++) if (i < insnWidth) { if (i == 7) printf(" ... "); else { const u1* bytePtr = (const u1*)&insns[insnIdx + i]; printf(" %02x%02x", bytePtr[0], bytePtr[1]); }; } else fputs(" ", stdout); if (pDecInsn->opcode == OP_NOP) { u2 instr = get2LE((const u1*)&insns[insnIdx]); if (instr == kPackedSwitchSignature) printf("|%04x: packed-switch-data (%d units)",insnIdx, insnWidth); else if (instr == kSparseSwitchSignature) printf("|%04x: sparse-switch-data (%d units)",insnIdx, insnWidth); else if (instr == kArrayDataSignature) printf("|%04x: array-data (%d units)",insnIdx, insnWidth); else printf("|%04x: nop // spacer", insnIdx); } else printf("|%04x: %s", insnIdx, dexGetOpcodeName(pDecInsn->opcode)); char* indexBuf = NULL; if (pDecInsn->indexType != kIndexNone) indexBuf = indexString(pDexFile, pDecInsn, 200); switch (dexGetFormatFromOpcode(pDecInsn->opcode)) { case kFmt10x: break; case kFmt12x: printf(" v%d, v%d", pDecInsn->vA, pDecInsn->vB); break; case kFmt11n: printf(" v%d, #int %d // #%x",pDecInsn->vA, (s4)pDecInsn->vB, (u1)pDecInsn->vB); break; case kFmt11x: printf(" v%d", pDecInsn->vA); break; case kFmt10t: case kFmt20t: { s4 targ = (s4)pDecInsn->vA; printf(" %04x // %c%04x", insnIdx + targ, (targ < 0) ? '-' : '+', (targ < 0) ? -targ : targ); }; break; case kFmt22x: printf(" v%d, v%d", pDecInsn->vA, pDecInsn->vB); break; case kFmt21t: { s4 targ = (s4)pDecInsn->vB; printf(" v%d, %04x // %c%04x", pDecInsn->vA, insnIdx + targ, (targ < 0) ? '-' : '+', (targ < 0) ? -targ : targ); }; break; case kFmt21s: printf(" v%d, #int %d // #%x",pDecInsn->vA, (s4)pDecInsn->vB, (u2)pDecInsn->vB); break; case kFmt21h: if (pDecInsn->opcode == OP_CONST_HIGH16) { s4 value = pDecInsn->vB << 16; printf(" v%d, #int %d // #%x", pDecInsn->vA, value, (u2)pDecInsn->vB); } else { s8 value = ((s8)pDecInsn->vB) << 48; printf(" v%d, #long %" PRId64 " // #%x", pDecInsn->vA, value, (u2)pDecInsn->vB); }; break; case kFmt21c: case kFmt31c: printf(" v%d, %s", pDecInsn->vA, indexBuf); break; case kFmt23x: printf(" v%d, v%d, v%d", pDecInsn->vA, pDecInsn->vB, pDecInsn->vC); break; case kFmt22b: printf(" v%d, v%d, #int %d // #%02x",pDecInsn->vA, pDecInsn->vB, (s4)pDecInsn->vC, (u1)pDecInsn->vC); break; case kFmt22t: { s4 targ = (s4)pDecInsn->vC; printf(" v%d, v%d, %04x // %c%04x", pDecInsn->vA, pDecInsn->vB, insnIdx + targ, (targ < 0) ? '-' : '+', (targ < 0) ? -targ : targ); }; break; case kFmt22s: printf(" v%d, v%d, #int %d // #%04x",pDecInsn->vA, pDecInsn->vB, (s4)pDecInsn->vC, (u2)pDecInsn->vC); break; case kFmt22c: case kFmt22cs: printf(" v%d, v%d, %s", pDecInsn->vA, pDecInsn->vB, indexBuf); break; case kFmt30t: printf(" #%08x", pDecInsn->vA); break; case kFmt31i: { union { float f; u4 i; } conv; conv.i = pDecInsn->vB; printf(" v%d, #float %f // #%08x", pDecInsn->vA, conv.f, pDecInsn->vB); }; break; case kFmt31t: printf(" v%d, %08x // +%08x",pDecInsn->vA, insnIdx + pDecInsn->vB, pDecInsn->vB); break; case kFmt32x: printf(" v%d, v%d", pDecInsn->vA, pDecInsn->vB); break; case kFmt35c: case kFmt35ms: case kFmt35mi: { fputs(" {", stdout); for (i = 0; i < (int)pDecInsn->vA; i++) if (i == 0) printf("v%d", pDecInsn->arg[i]); else printf(", v%d", pDecInsn->arg[i]); printf("}, %s", indexBuf); }; break; case kFmt3rc: case kFmt3rms: case kFmt3rmi: {
fputs(" {", stdout); for (i = 0; i < (int)pDecInsn->vA; i++) if (i == 0) printf("v%d", pDecInsn->vC + i); else printf(", v%d", pDecInsn->vC + i); printf("}, %s", indexBuf); }; break; case kFmt51l: { union { double d; u8 j; } conv; conv.j = pDecInsn->vB_wide; printf(" v%d, #double %f // #%016" PRIx64, pDecInsn->vA, conv.d, pDecInsn->vB_wide); }; break; case kFmt00x: break; case kFmt45cc: { fputs(" {", stdout); printf("v%d", pDecInsn->vC); for (int i = 0; i < (int)pDecInsn->vA - 1; ++i) printf(", v%d", pDecInsn->arg[i]); printf("}, %s", indexBuf); }; break; case kFmt4rcc: { fputs(" {", stdout); printf("v%d", pDecInsn->vC); for (int i = 1; i < (int)pDecInsn->vA; ++i) printf(", v%d", pDecInsn->vC + i); printf("}, %s", indexBuf); }; break; default: printf(" ???"); break; }; putchar('\n'); free(indexBuf); return; };
|