Package org.jf.dexlib2.iface.reference

Examples of org.jf.dexlib2.iface.reference.MethodReference


            Assert.assertNotNull(methodImpl);

            for (Instruction instruction: methodImpl.getInstructions()) {
                Opcode opcode = instruction.getOpcode();
                if (opcode == Opcode.INVOKE_STATIC || opcode == Opcode.INVOKE_STATIC_RANGE) {
                    MethodReference accessorMethod =
                            (MethodReference)((ReferenceInstruction) instruction).getReference();

                    SyntheticAccessorResolver.AccessedMember accessedMember = sar.getAccessedMember(accessorMethod);

                    Assert.assertNotNull(String.format("Could not resolve accessor for %s_%s", type, operation),
View Full Code Here


            if (!classDef.options.noAccessorComments && (instruction instanceof ReferenceInstruction)) {
                Opcode opcode = instruction.getOpcode();

                if (opcode.referenceType == ReferenceType.METHOD) {
                    MethodReference methodReference = null;
                    try {
                        methodReference = (MethodReference)((ReferenceInstruction)instruction).getReference();
                    } catch (InvalidItemIndex ex) {
                        // just ignore it for now. We'll deal with it later, when processing the instructions
                        // themselves
                    }

                    if (methodReference != null &&
                            SyntheticAccessorResolver.looksLikeSyntheticAccessor(methodReference.getName())) {
                        SyntheticAccessorResolver.AccessedMember accessedMember =
                                classDef.options.syntheticAccessorResolver.getAccessedMember(methodReference);
                        if (accessedMember != null) {
                            methodItems.add(new SyntheticAccessCommentMethodItem(accessedMember, currentCodeAddress));
                        }
View Full Code Here

        List<Instruction> instructions = Lists.newArrayList(methodImpl.getInstructions());

        Instruction35c instruction = (Instruction35c)instructions.get(0);
        Assert.assertNotNull(instruction);
        Assert.assertEquals(Opcode.INVOKE_STATIC, instruction.getOpcode());
        MethodReference method = (MethodReference)instruction.getReference();
        Assert.assertEquals(classDef.getType(), method.getDefiningClass());
        Assert.assertEquals("toString", method.getName());

        instruction = (Instruction35c)instructions.get(1);
        Assert.assertNotNull(instruction);
        Assert.assertEquals(Opcode.INVOKE_STATIC, instruction.getOpcode());
        method = (MethodReference)instruction.getReference();
        Assert.assertEquals(classDef.getType(), method.getDefiningClass());
        Assert.assertEquals("V", method.getName());

        instruction = (Instruction35c)instructions.get(2);
        Assert.assertNotNull(instruction);
        Assert.assertEquals(Opcode.INVOKE_STATIC, instruction.getOpcode());
        method = (MethodReference)instruction.getReference();
        Assert.assertEquals(classDef.getType(), method.getDefiningClass());
        Assert.assertEquals("I", method.getName());
    }
View Full Code Here

        //constructor (<init>) method, which changes the uninitialized reference (and any register that the same
        //uninit reference has been copied to) to an initialized reference

        ReferenceInstruction instruction = (ReferenceInstruction)analyzedInstruction.instruction;

        MethodReference methodReference = (MethodReference)instruction.getReference();

        if (!methodReference.getName().equals("<init>")) {
            return;
        }

        RegisterType objectRegisterType = analyzedInstruction.getPreInstructionRegisterType(objectRegister);
View Full Code Here

            return false;
        }

        assert objectRegisterTypeProto != null;

        MethodReference resolvedMethod;
        if (isSuper) {
            // invoke-super is only used for the same class that we're currently in
            TypeProto typeProto = classPath.getClass(method.getDefiningClass());
            TypeProto superType;

            String superclassType = typeProto.getSuperclass();
            if (superclassType != null) {
                superType = classPath.getClass(superclassType);
            } else {
                // This is either java.lang.Object, or an UnknownClassProto
                superType = typeProto;
            }

            resolvedMethod = superType.getMethodByVtableIndex(methodIndex);
        } else{
            resolvedMethod = objectRegisterTypeProto.getMethodByVtableIndex(methodIndex);
        }

        if (resolvedMethod == null) {
            throw new AnalysisException("Could not resolve the method in class %s at index %d",
                    objectRegisterType.type.getType(), methodIndex);
        }

        // no need to check class access for invoke-super. A class can obviously access its superclass.
        ClassDef thisClass = classPath.getClassDef(method.getDefiningClass());

        if (!isSuper && !canAccessClass(thisClass, classPath.getClassDef(resolvedMethod.getDefiningClass()))) {

            // the class is not accessible. So we start looking at objectRegisterTypeProto (which may be different
            // than resolvedMethod.getDefiningClass()), and walk up the class hierarchy.
            ClassDef methodClass = classPath.getClassDef(objectRegisterTypeProto.getType());
            while (!canAccessClass(thisClass, methodClass)) {
                String superclass = methodClass.getSuperclass();
                if (superclass == null) {
                    throw new ExceptionWithContext("Couldn't find accessible class while resolving method %s",
                            ReferenceUtil.getMethodDescriptor(resolvedMethod, true));
                }

                methodClass = classPath.getClassDef(superclass);
            }

            // methodClass is now the first accessible class found. Now. we need to make sure that the method is
            // actually valid for this class
            MethodReference newResolvedMethod =
                    classPath.getClass(methodClass.getType()).getMethodByVtableIndex(methodIndex);
            if (newResolvedMethod == null) {
                // TODO: fix NPE here
                throw new ExceptionWithContext("Couldn't find accessible class while resolving method %s",
                        ReferenceUtil.getMethodDescriptor(resolvedMethod, true));
View Full Code Here

        }

        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();
                }
View Full Code Here

    }

    @Override
    public boolean equals(@Nullable Object o) {
        if (o instanceof AnnotationEncodedValue) {
            AnnotationEncodedValue other = (AnnotationEncodedValue)o;
            return getType().equals(other.getType()) &&
                    getElements().equals(other.getElements());
        }
        return false;
    }
View Full Code Here

    @Override
    public int compareTo(@Nonnull EncodedValue o) {
        int res = Ints.compare(getValueType(), o.getValueType());
        if (res != 0) return res;
        AnnotationEncodedValue other = (AnnotationEncodedValue)o;
        res = getType().compareTo(other.getType());
        if (res != 0) return res;
        return CollectionUtils.compareAsSet(getElements(), other.getElements());
    }
View Full Code Here

        }
        if (signatureAnnotation == null) {
            return null;
        }

        ArrayEncodedValue signatureValues = null;
        for (AnnotationElement annotationElement: signatureAnnotation.getElements()) {
            if (annotationElement.getName().equals("value")) {
                EncodedValue encodedValue = annotationElement.getValue();
                if (encodedValue.getValueType() != ValueType.ARRAY) {
                    return null;
                }
                signatureValues = (ArrayEncodedValue)encodedValue;
                break;
            }
        }
        if (signatureValues == null) {
            return null;
        }

        StringBuilder sb = new StringBuilder();
        for (EncodedValue signatureValue: signatureValues.getValue()) {
            if (signatureValue.getValueType() != ValueType.STRING) {
                return null;
            }
            sb.append(((StringEncodedValue)signatureValue).getValue());
        }
View Full Code Here

        }

        ArrayEncodedValue signatureValues = null;
        for (AnnotationElement annotationElement: signatureAnnotation.getElements()) {
            if (annotationElement.getName().equals("value")) {
                EncodedValue encodedValue = annotationElement.getValue();
                if (encodedValue.getValueType() != ValueType.ARRAY) {
                    return null;
                }
                signatureValues = (ArrayEncodedValue)encodedValue;
                break;
            }
View Full Code Here

TOP

Related Classes of org.jf.dexlib2.iface.reference.MethodReference

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.