Package org.jf.dexlib2.iface

Examples of org.jf.dexlib2.iface.ClassDef


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

    @Test
    public void testExplicitMethodReferences() 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" +
                "    invoke-static {p0}, LHelloWorld;->toString()V\n" +
View Full Code Here


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

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

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

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

                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

                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

                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

                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

* 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

        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

        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

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.