Package org.jf.dexlib2.analysis

Examples of org.jf.dexlib2.analysis.ClassPath


        List<Task> switchPayloadTasks = Lists.newArrayList();
        index = 0;
        for (final Instruction instruction: methodImplementation.getInstructions()) {
            final MethodLocation location = instructionList.get(index);
            final Opcode opcode = instruction.getOpcode();
            if (opcode == Opcode.PACKED_SWITCH_PAYLOAD || opcode == Opcode.SPARSE_SWITCH_PAYLOAD) {
                switchPayloadTasks.add(new Task() {
                    @Override public void perform() {
                        convertAndSetInstruction(location, codeAddressToIndex, instruction);
                    }
View Full Code Here


            opcode == Opcode.THROW_VERIFICATION_ERROR;
    }

    @Override
    public boolean writeTo(IndentingWriter writer) throws IOException {
        Opcode opcode = instruction.getOpcode();
        String verificationErrorName = null;
        String referenceString = null;

        boolean commentOutInstruction = false;

        if (instruction instanceof Instruction20bc) {
            int verificationError = ((Instruction20bc)instruction).getVerificationError();
            verificationErrorName = VerificationError.getVerificationErrorName(verificationError);
            if (verificationErrorName == null) {
                writer.write("#was invalid verification error type: ");
                writer.printSignedIntAsDec(verificationError);
                writer.write("\n");
                verificationErrorName = "generic-error";
            }
        }

        if (instruction instanceof ReferenceInstruction) {
            ReferenceInstruction referenceInstruction = (ReferenceInstruction)instruction;
            try {
                Reference reference = referenceInstruction.getReference();

                String classContext = null;
                if (methodDef.classDef.options.useImplicitReferences) {
                    classContext = methodDef.method.getDefiningClass();
                }

                referenceString = ReferenceUtil.getReferenceString(reference, classContext);
                assert referenceString != null;
            } catch (InvalidItemIndex ex) {
                writer.write("#");
                writer.write(ex.getMessage());
                writer.write("\n");
                commentOutInstruction = true;

                referenceString = String.format("%s@%d",
                    ReferenceType.toString(referenceInstruction.getReferenceType()),
                    ex.getInvalidIndex());
            } catch (ReferenceType.InvalidReferenceTypeException ex) {
                writer.write("#invalid reference type: ");
                writer.printSignedIntAsDec(ex.getReferenceType());
                commentOutInstruction = true;

                referenceString = "invalid_reference";
            }
        }

        if (instruction instanceof Instruction31t) {
            Opcode payloadOpcode;
            switch (instruction.getOpcode()) {
                case PACKED_SWITCH:
                    payloadOpcode = Opcode.PACKED_SWITCH_PAYLOAD;
                    break;
                case SPARSE_SWITCH:
View Full Code Here

    public LabelMethodItem getLabel() {
        return label;
    }

    private String getLabelPrefix() {
        Opcode opcode = instruction.getOpcode();
        switch (opcode.format) {
            case Format10t:
            case Format20t:
            case Format30t:
                return "goto_";
View Full Code Here

        DexFile dexFile = DexFileFactory.loadDexFile(findResource(dexFilePath), 15);

        baksmaliOptions options = new baksmaliOptions();
        if (registerInfo) {
            options.registerInfo = baksmaliOptions.ALL | baksmaliOptions.FULLMERGE;
            options.classPath = new ClassPath();
        }
        options.useImplicitReferences = false;

        for (ClassDef classDef: dexFile.getClasses()) {
            StringWriter stringWriter = new StringWriter();
View Full Code Here

        ClassDef threeClassDef = TestUtils.makeClassDef("Ltest/three;", "Ltest/two;");

        ImmutableSet<ClassDef> classes = ImmutableSet.<ClassDef>of(
                objectClassDef, oneClassDef, twoClassDef, threeClassDef);

        ClassPath classPath = new ClassPath(new ImmutableDexFile(classes));

        TypeProto objectClassProto = classPath.getClass("Ljava/lang/Object;");
        TypeProto oneClassProto = classPath.getClass("Ltest/one;");
        TypeProto twoClassProto = classPath.getClass("Ltest/two;");
        TypeProto threeClassProto = classPath.getClass("Ltest/three;");

        Assert.assertEquals(
                ImmutableList.<TypeProto>of(),
                ImmutableList.copyOf(TypeProtoUtils.getSuperclassChain(objectClassProto)));
View Full Code Here

        // Ltest/one; isn't defined

        ClassDef twoClassDef = TestUtils.makeClassDef("Ltest/two;", "Ltest/one;");
        ClassDef threeClassDef = TestUtils.makeClassDef("Ltest/three;", "Ltest/two;");
        ImmutableSet<ClassDef> classes = ImmutableSet.<ClassDef>of(twoClassDef, threeClassDef);
        ClassPath classPath = new ClassPath(new ImmutableDexFile(classes));

        TypeProto unknownClassProto = classPath.getUnknownClass();
        TypeProto oneClassProto = classPath.getClass("Ltest/one;");
        TypeProto twoClassProto = classPath.getClass("Ltest/two;");
        TypeProto threeClassProto = classPath.getClass("Ltest/three;");

        Assert.assertEquals(
                ImmutableList.<TypeProto>of(oneClassProto, unknownClassProto),
                ImmutableList.copyOf(TypeProtoUtils.getSuperclassChain(twoClassProto)));
View Full Code Here

        };
    }

    public static TypeReference rewriteTypeReference(@Nonnull final Rewriter<String> typeRewriter,
                                                     @Nonnull final TypeReference typeReference) {
        return new BaseTypeReference() {
            @Nonnull @Override public String getType() {
                return typeRewriter.rewrite(typeReference.getType());
            }
        };
    }
View Full Code Here

        final String exceptionType = getExceptionType();
        if (exceptionType == null) {
            return null;
        }

        return new BaseTypeReference() {
            @Nonnull @Override public String getType() {
                return exceptionType;
            }
        };
    }
View Full Code Here

                            }
                        }
                    }

                    if (needsFix) {
                        MutableMethodImplementation mutableMethodImplementation =
                                classSection.makeMutableMethodImplementation(methodKey);
                        fixInstructions(mutableMethodImplementation);

                        instructions = mutableMethodImplementation.getInstructions();
                        tryBlocks = mutableMethodImplementation.getTryBlocks();
                        debugItems = mutableMethodImplementation.getDebugItems();
                    }
                }

                int debugItemOffset = writeDebugItem(offsetWriter, debugWriter,
                        classSection.getParameterNames(methodKey), debugItems);
View Full Code Here

    @Test
    public void testFixOffsets() {
        MethodImplementationBuilder builder = new MethodImplementationBuilder(1);

        Label firstGotoTarget = builder.getLabel("firstGotoTarget");
        builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, firstGotoTarget));

        builder.addLineNumber(1);

        for (int i=0; i<250; i++) {
            builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
        }

        builder.addLabel("tryStart");

        builder.addLineNumber(2);

        for (int i=0; i<250; i++) {
            builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
        }

        builder.addLineNumber(3);

        Label secondGotoTarget = builder.getLabel("secondGotoTarget");
        builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, secondGotoTarget));


        builder.addLineNumber(4);
        builder.addLabel("handler");
View Full Code Here

TOP

Related Classes of org.jf.dexlib2.analysis.ClassPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.