Examples of ClassDef


Examples of org.jf.dexlib2.iface.ClassDef

                TextUtils.normalizeWhitespace(stringWriter.toString()));
    }

    @Test
    public void testImplicitFieldReferences() throws IOException, RecognitionException {
        ClassDef classDef = SmaliTestUtils.compileSmali("" +
                ".class public LHelloWorld;\n" +
                ".super Ljava/lang/Object;\n" +
                ".method public static main([Ljava/lang/String;)V\n" +
                "    .registers 1\n" +
                "    sget v0, LHelloWorld;->someField:I\n" +
View Full Code Here

Examples of org.jf.dexlib2.iface.ClassDef

                TextUtils.normalizeWhitespace(stringWriter.toString()));
    }

    @Test
    public void testExplicitFieldReferences() throws IOException, RecognitionException {
        ClassDef classDef = SmaliTestUtils.compileSmali("" +
                ".class public LHelloWorld;\n" +
                ".super Ljava/lang/Object;\n" +
                ".method public static main([Ljava/lang/String;)V\n" +
                "    .registers 1\n" +
                "    sget v0, LHelloWorld;->someField:I\n" +
View Full Code Here

Examples of org.jf.dexlib2.iface.ClassDef

                TextUtils.normalizeWhitespace(stringWriter.toString()));
    }

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

Examples of org.jf.dexlib2.iface.ClassDef

                TextUtils.normalizeWhitespace(stringWriter.toString()));
    }

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

Examples of org.jf.dexlib2.iface.ClassDef

* Tests for method/field references that use an implicit type
*/
public class ImplicitReferenceTest extends SmaliTestUtils {
    @Test
    public void testImplicitMethodReference() throws RecognitionException, IOException {
        ClassDef classDef = SmaliTestUtils.compileSmali("" +
                ".class public LHelloWorld;\n" +
                ".super Ljava/lang/Object;\n" +
                ".method public static main([Ljava/lang/String;)V\n" +
                "    .registers 1\n" +
                "    invoke-static {p0}, toString()V\n" +
                "    invoke-static {p0}, V()V\n" +
                "    invoke-static {p0}, I()V\n" +
                "    return-void\n" +
                ".end method");

        Method mainMethod = null;
        for (Method method: classDef.getMethods()) {
            if (method.getName().equals("main")) {
                mainMethod = method;
            }
        }
        Assert.assertNotNull(mainMethod);

        MethodImplementation methodImpl = mainMethod.getImplementation();
        Assert.assertNotNull(methodImpl);

        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

Examples of org.jf.dexlib2.iface.ClassDef

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

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

        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.METHOD, field.getInitialValue().getValueType());
        MethodEncodedValue methodEncodedValue = (MethodEncodedValue)field.getInitialValue();
        Assert.assertEquals(classDef.getType(), methodEncodedValue.getValue().getDefiningClass());
        Assert.assertEquals("toString", methodEncodedValue.getValue().getName());

        field = fields.get("field2");
        Assert.assertNotNull(field);
        Assert.assertNotNull(field.getInitialValue());
        Assert.assertEquals(ValueType.METHOD, field.getInitialValue().getValueType());
        methodEncodedValue = (MethodEncodedValue)field.getInitialValue();
        Assert.assertEquals(classDef.getType(), methodEncodedValue.getValue().getDefiningClass());
        Assert.assertEquals("V", methodEncodedValue.getValue().getName());

        field = fields.get("field3");
        Assert.assertNotNull(field);
        Assert.assertNotNull(field.getInitialValue());
        Assert.assertEquals(ValueType.METHOD, field.getInitialValue().getValueType());
        methodEncodedValue = (MethodEncodedValue)field.getInitialValue();
        Assert.assertEquals(classDef.getType(), methodEncodedValue.getValue().getDefiningClass());
        Assert.assertEquals("I", methodEncodedValue.getValue().getName());

        field = fields.get("field4");
        Assert.assertNotNull(field);
        Assert.assertNotNull(field.getInitialValue());
View Full Code Here

Examples of org.jf.dexlib2.iface.ClassDef

        Assert.assertEquals("I", typeEncodedValue.getValue());
    }

    @Test
    public void testImplicitFieldReference() throws RecognitionException, IOException {
        ClassDef classDef = SmaliTestUtils.compileSmali("" +
                ".class public LHelloWorld;\n" +
                ".super Ljava/lang/Object;\n" +
                ".method public static main([Ljava/lang/String;)V\n" +
                "    .registers 1\n" +
                "    sget-object v0, someField:I\n" +
                "    sget-object v0, V:I\n" +
                "    sget-object v0, I:I\n" +
                "    return-void\n" +
                ".end method");

        Method mainMethod = null;
        for (Method method: classDef.getMethods()) {
            if (method.getName().equals("main")) {
                mainMethod = method;
            }
        }
        Assert.assertNotNull(mainMethod);

        MethodImplementation methodImpl = mainMethod.getImplementation();
        Assert.assertNotNull(methodImpl);

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

        Instruction21c instruction = (Instruction21c)instructions.get(0);
        Assert.assertNotNull(instruction);
        Assert.assertEquals(Opcode.SGET_OBJECT, instruction.getOpcode());
        FieldReference field = (FieldReference)instruction.getReference();
        Assert.assertEquals(classDef.getType(), field.getDefiningClass());
        Assert.assertEquals("someField", field.getName());

        instruction = (Instruction21c)instructions.get(1);
        Assert.assertNotNull(instruction);
        Assert.assertEquals(Opcode.SGET_OBJECT, instruction.getOpcode());
        field = (FieldReference)instruction.getReference();
        Assert.assertEquals(classDef.getType(), field.getDefiningClass());
        Assert.assertEquals("V", field.getName());

        instruction = (Instruction21c)instructions.get(2);
        Assert.assertNotNull(instruction);
        Assert.assertEquals(Opcode.SGET_OBJECT, instruction.getOpcode());
        field = (FieldReference)instruction.getReference();
        Assert.assertEquals(classDef.getType(), field.getDefiningClass());
        Assert.assertEquals("I", field.getName());
    }
View Full Code Here

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

Examples of org.jf.dexlib2.iface.ClassDef

     * 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

Examples of org.jf.dexlib2.iface.ClassDef

        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
TOP
Copyright © 2018 www.massapi.com. 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.