Search in sources :

Example 21 with DexReader

use of org.jf.dexlib2.dexbacked.DexReader in project smali by JesusFreke.

the class CdexDebugOffsetTable method annotate.

@Nonnull
public static void annotate(@Nonnull DexAnnotator annotator, DexBuffer buffer) {
    DexReader reader = buffer.readerAt(annotator.getCursor());
    SectionAnnotator debugInfoAnnotator = annotator.getAnnotator(ItemType.DEBUG_INFO_ITEM);
    int methodCount = annotator.dexFile.getMethodSection().size();
    for (int methodIndex = 0; methodIndex < methodCount; methodIndex += 16) {
        annotator.annotate(0, "Offset chuck for methods %d-%d", methodIndex, Math.min(methodIndex + 16, methodCount));
        annotator.indent();
        int bitmask = reader.readUbyte() << 8;
        bitmask |= reader.readUbyte();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 16; i++) {
            sb.append((bitmask >> i) & 1);
        }
        annotator.annotate(2, "bitmask: 0b%s", sb.reverse());
        int debugOffset = ((CDexBackedDexFile) annotator.dexFile).getDebugInfoBase();
        for (int i = 0; i < 16; i++) {
            if ((bitmask & 1) != 0) {
                int offsetDelta = reader.readBigUleb128();
                debugOffset += offsetDelta;
                annotator.annotateTo(reader.getOffset(), "[method_id: %d]: offset_delta: %d  (offset=0x%x)", methodIndex + i, offsetDelta, debugOffset);
                debugInfoAnnotator.setItemIdentity(debugOffset, annotator.dexFile.getMethodSection().get(methodIndex + i).toString());
            }
            bitmask >>= 1;
        }
        annotator.deindent();
    }
}
Also used : DexReader(org.jf.dexlib2.dexbacked.DexReader) CDexBackedDexFile(org.jf.dexlib2.dexbacked.CDexBackedDexFile) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)15 DexReader (org.jf.dexlib2.dexbacked.DexReader)9 Nullable (javax.annotation.Nullable)7 AnnotatedBytes (org.jf.dexlib2.util.AnnotatedBytes)7 AnnotationsDirectory (org.jf.dexlib2.dexbacked.util.AnnotationsDirectory)5 VariableSizeLookaheadIterator (org.jf.dexlib2.dexbacked.util.VariableSizeLookaheadIterator)5 Instruction (org.jf.dexlib2.iface.instruction.Instruction)3 Opcode (org.jf.dexlib2.Opcode)2 DexBackedInstruction (org.jf.dexlib2.dexbacked.instruction.DexBackedInstruction)2 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)2 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)2 ImmutableFieldReference (org.jf.dexlib2.immutable.reference.ImmutableFieldReference)2 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)2 ExceptionWithContext (org.jf.util.ExceptionWithContext)2 File (java.io.File)1 CDexBackedDexFile (org.jf.dexlib2.dexbacked.CDexBackedDexFile)1 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)1 DexBackedFieldReference (org.jf.dexlib2.dexbacked.reference.DexBackedFieldReference)1 DexBackedMethodReference (org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference)1 EncodedArrayItemIterator (org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator)1