Package org.jf.dexlib2.iface

Examples of org.jf.dexlib2.iface.ClassDef


        Assert.assertEquals("I", field.getName());
    }

    @Test
    public void testImplicitFieldLiteral() throws RecognitionException, IOException {
        ClassDef classDef = SmaliTestUtils.compileSmali("" +
                ".class public LHelloWorld;\n" +
                ".super Ljava/lang/Object;\n" +
                ".field public static field1:Ljava/lang/reflect/Field; = someField:I\n" +
                ".field public static field2:Ljava/lang/reflect/Field; = V:I\n" +
                ".field public static field3:Ljava/lang/reflect/Field; = I:I\n");

        Map<String, Field> fields = Maps.newHashMap();
        for (Field field: classDef.getFields()) {
            fields.put(field.getName(), field);
        }

        Field field = fields.get("field1");
        Assert.assertNotNull(field);
        Assert.assertNotNull(field.getInitialValue());
        Assert.assertEquals(ValueType.FIELD, field.getInitialValue().getValueType());
        FieldEncodedValue fieldEncodedValue = (FieldEncodedValue)field.getInitialValue();
        Assert.assertEquals(classDef.getType(), fieldEncodedValue.getValue().getDefiningClass());
        Assert.assertEquals("someField", fieldEncodedValue.getValue().getName());

        field = fields.get("field2");
        Assert.assertNotNull(field);
        Assert.assertNotNull(field.getInitialValue());
        Assert.assertEquals(ValueType.FIELD, field.getInitialValue().getValueType());
        fieldEncodedValue = (FieldEncodedValue)field.getInitialValue();
        Assert.assertEquals(classDef.getType(), fieldEncodedValue.getValue().getDefiningClass());
        Assert.assertEquals("V", fieldEncodedValue.getValue().getName());

        field = fields.get("field3");
        Assert.assertNotNull(field);
        Assert.assertNotNull(field.getInitialValue());
        Assert.assertEquals(ValueType.FIELD, field.getInitialValue().getValueType());
        fieldEncodedValue = (FieldEncodedValue)field.getInitialValue();
        Assert.assertEquals(classDef.getType(), fieldEncodedValue.getValue().getDefiningClass());
        Assert.assertEquals("I", fieldEncodedValue.getValue().getName());
    }
View Full Code Here


     * If this class is not defined, then this will throw an UnresolvedClassException
     *
     * @return True if this class is an interface
     */
    public boolean isInterface() {
        ClassDef classDef = getClassDef();
        return (classDef.getAccessFlags() & AccessFlags.INTERFACE.getValue()) != 0;
    }
View Full Code Here

        loadPrimitiveType("D");
        loadPrimitiveType("L");

        for (DexFile dexFile: dexFiles) {
            for (ClassDef classDef: dexFile.getClasses()) {
                ClassDef prev = availableClasses.get(classDef.getType());
                if (prev == null) {
                    availableClasses.put(classDef.getType(), classDef);
                }
            }
        }
View Full Code Here

    @Nonnull private LoadingCache<String, TypeProto> loadedClasses = CacheBuilder.newBuilder().build(classLoader);

    @Nonnull
    public ClassDef getClassDef(String type) {
        ClassDef ret = availableClasses.get(type);
        if (ret == null) {
            throw new UnresolvedClassException("Could not resolve class %s", type);
        }
        return ret;
    }
View Full Code Here

        int accessFlags = 0;

        boolean resolved = false;
        TypeProto typeProto = classPath.getClass(className);
        if (typeProto instanceof ClassProto) {
            ClassDef classDef = ((ClassProto)typeProto).getClassDef();
            for (Method method: classDef.getMethods()) {
                if (method.equals(methodRef)) {
                    resolved = true;
                    accessFlags = method.getAccessFlags();
                    break;
                }
View Full Code Here

        if (accessedMember != null) {
            return accessedMember;
        }

        String type = methodReference.getDefiningClass();
        ClassDef classDef = classDefMap.get(type);
        if (classDef == null) {
            return null;
        }

        Method matchedMethod = null;
        MethodImplementation matchedMethodImpl = null;
        for (Method method: classDef.getMethods()) {
            MethodImplementation methodImpl = method.getImplementation();
            if (methodImpl != null) {
                if (methodReferenceEquals(method, methodReference)) {
                    matchedMethod = method;
                    matchedMethodImpl = methodImpl;
View Full Code Here

                methodImpl);

        ClassDef classDef = new ImmutableClassDef("Lblah;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null,
                null, null, null, null, null, ImmutableList.of(method));

        DexFile dexFile = new ImmutableDexFile(ImmutableList.of(classDef));

        ClassPath classPath = ClassPath.fromClassPath(ImmutableList.<String>of(), ImmutableList.<String>of(), dexFile,
                15);
        InlineMethodResolver inlineMethodResolver = new CustomInlineMethodResolver(classPath, "Lblah;->blah()V");
        MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classPath, method, inlineMethodResolver);
View Full Code Here

                methodImpl);

        ClassDef classDef = new ImmutableClassDef("Lblah;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null,
                null, null, null, null, ImmutableList.of(method), null);

        DexFile dexFile = new ImmutableDexFile(ImmutableList.of(classDef));

        ClassPath classPath = ClassPath.fromClassPath(ImmutableList.<String>of(), ImmutableList.<String>of(), dexFile,
                15);
        InlineMethodResolver inlineMethodResolver = new CustomInlineMethodResolver(classPath, "Lblah;->blah()V");
        MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classPath, method, inlineMethodResolver);
View Full Code Here

                methodImpl);

        ClassDef classDef = new ImmutableClassDef("Lblah;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null,
                null, null, null, null, ImmutableList.of(method), null);

        DexFile dexFile = new ImmutableDexFile(ImmutableList.of(classDef));

        ClassPath classPath = ClassPath.fromClassPath(ImmutableList.<String>of(), ImmutableList.<String>of(), dexFile,
                15);
        InlineMethodResolver inlineMethodResolver = new CustomInlineMethodResolver(classPath, "Lblah;->blah()V");
        MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classPath, method, inlineMethodResolver);
View Full Code Here

                        writer.writeUshort(offset);
                        exceptionHandlerOffsetMap.put(tryBlock.getExceptionHandlers(), offset);

                        // check if the last exception handler is a catch-all and adjust the size accordingly
                        int ehSize = tryBlock.getExceptionHandlers().size();
                        ExceptionHandler ehLast = tryBlock.getExceptionHandlers().get(ehSize-1);
                        if (ehLast.getExceptionType() == null) {
                            ehSize = ehSize * (-1) + 1;
                        }

                        // now let's layout the exception handlers, assuming that catch-all is always last
                        DexDataWriter.writeSleb128(ehBuf, ehSize);
View Full Code Here

TOP

Related Classes of org.jf.dexlib2.iface.ClassDef

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.