Search in sources :

Example 6 with ReferenceType

use of org.jf.dexlib2.ReferenceType 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).getType());
                        break;
                    case ReferenceType.FIELD:
                        dexPool.fieldSection.intern((FieldReference) reference);
                        break;
                    case ReferenceType.METHOD:
                        dexPool.methodSection.intern((MethodReference) reference);
                        break;
                    case ReferenceType.CALL_SITE:
                        dexPool.callSiteSection.intern((CallSiteReference) 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.", 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)

Example 7 with ReferenceType

use of org.jf.dexlib2.ReferenceType in project smali by JesusFreke.

the class ListReferencesCommand method run.

@Override
public void run() {
    if (help || inputList == null || inputList.isEmpty()) {
        usage();
        return;
    }
    if (inputList.size() > 1) {
        System.err.println("Too many files specified");
        usage();
        return;
    }
    String input = inputList.get(0);
    loadDexFile(input);
    BaksmaliFormatter formatter = new BaksmaliFormatter();
    for (Reference reference : dexFile.getReferences(referenceType)) {
        System.out.println(formatter.getReference(reference));
    }
}
Also used : Reference(org.jf.dexlib2.iface.reference.Reference) BaksmaliFormatter(org.jf.baksmali.formatter.BaksmaliFormatter)

Aggregations

ReferenceType (net.opengis.gml.x32.ReferenceType)4 DefaultTVPMeasurementMetadataDocument (net.opengis.waterml.x20.DefaultTVPMeasurementMetadataDocument)2 TVPDefaultMetadataPropertyType (net.opengis.waterml.x20.TVPDefaultMetadataPropertyType)2 XmlObject (org.apache.xmlbeans.XmlObject)2 Instruction (org.jf.dexlib2.iface.instruction.Instruction)2 ReferenceInstruction (org.jf.dexlib2.iface.instruction.ReferenceInstruction)2 ExceptionWithContext (org.jf.util.ExceptionWithContext)2 Test (org.junit.Test)2 NamedValueType (net.opengis.om.x20.NamedValueType)1 BaksmaliFormatter (org.jf.baksmali.formatter.BaksmaliFormatter)1 MutableMethodImplementation (org.jf.dexlib2.builder.MutableMethodImplementation)1 ExceptionHandler (org.jf.dexlib2.iface.ExceptionHandler)1 OneRegisterInstruction (org.jf.dexlib2.iface.instruction.OneRegisterInstruction)1 VariableRegisterInstruction (org.jf.dexlib2.iface.instruction.VariableRegisterInstruction)1 Reference (org.jf.dexlib2.iface.reference.Reference)1 LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 NamedValue (org.n52.shetland.ogc.om.NamedValue)1 DefaultPointMetadata (org.n52.shetland.ogc.om.series.wml.DefaultPointMetadata)1 DefaultTVPMeasurementMetadata (org.n52.shetland.ogc.om.series.wml.DefaultTVPMeasurementMetadata)1