Search in sources :

Example 11 with TypeReference

use of org.jf.dexlib2.iface.reference.TypeReference in project smali by JesusFreke.

the class ClassPool method internCode.

private void internCode(@Nonnull Method method) {
    // this also handles parameter names, which aren't directly tied to the MethodImplementation, even though the debug items are
    boolean hasInstruction = false;
    MethodImplementation methodImpl = method.getImplementation();
    if (methodImpl != null) {
        for (Instruction instruction : methodImpl.getInstructions()) {
            hasInstruction = true;
            if (instruction instanceof ReferenceInstruction) {
                Reference reference = ((ReferenceInstruction) instruction).getReference();
                switch(instruction.getOpcode().referenceType) {
                    case ReferenceType.STRING:
                        dexPool.stringSection.intern((StringReference) reference);
                        break;
                    case ReferenceType.TYPE:
                        dexPool.typeSection.intern((TypeReference) reference);
                        break;
                    case ReferenceType.FIELD:
                        dexPool.fieldSection.intern((FieldReference) reference);
                        break;
                    case ReferenceType.METHOD:
                        dexPool.methodSection.intern((MethodReference) reference);
                        break;
                    default:
                        throw new ExceptionWithContext("Unrecognized reference type: %d", instruction.getOpcode().referenceType);
                }
            }
        }
        List<? extends TryBlock> tryBlocks = methodImpl.getTryBlocks();
        if (!hasInstruction && tryBlocks.size() > 0) {
            throw new ExceptionWithContext("Method %s has no instructions, but has try blocks.", ReferenceUtil.getMethodDescriptor(method));
        }
        for (TryBlock<? extends ExceptionHandler> tryBlock : methodImpl.getTryBlocks()) {
            for (ExceptionHandler handler : tryBlock.getExceptionHandlers()) {
                dexPool.typeSection.internNullable(handler.getExceptionType());
            }
        }
    }
}
Also used : MutableMethodImplementation(org.jf.dexlib2.builder.MutableMethodImplementation) ExceptionWithContext(org.jf.util.ExceptionWithContext) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction)

Aggregations

TypeReference (org.jf.dexlib2.iface.reference.TypeReference)10 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)5 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)5 Opcode (org.jf.dexlib2.Opcode)4 ReferenceInstruction (org.jf.dexlib2.iface.instruction.ReferenceInstruction)3 Instruction22c (org.jf.dexlib2.iface.instruction.formats.Instruction22c)3 Reference (org.jf.dexlib2.iface.reference.Reference)3 ImmutableFieldReference (org.jf.dexlib2.immutable.reference.ImmutableFieldReference)3 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)3 BaseMethodReference (org.jf.dexlib2.base.reference.BaseMethodReference)2 Instruction (org.jf.dexlib2.iface.instruction.Instruction)2 Instruction20bc (org.jf.dexlib2.iface.instruction.formats.Instruction20bc)2 StringReference (org.jf.dexlib2.iface.reference.StringReference)2 ExceptionWithContext (org.jf.util.ExceptionWithContext)2 MethodDefinition (com.taobao.android.baksmali.adaptors.MethodDefinition)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 ReferenceType (org.jf.dexlib2.ReferenceType)1 MutableMethodImplementation (org.jf.dexlib2.builder.MutableMethodImplementation)1 InvalidItemIndex (org.jf.dexlib2.dexbacked.DexBackedDexFile.InvalidItemIndex)1