Search in sources :

Example 1 with ImmutableMethodHandleReference

use of org.jf.dexlib2.immutable.reference.ImmutableMethodHandleReference in project smali by JesusFreke.

the class CallSiteTest method testBuilderCallSite.

@Test
public void testBuilderCallSite() throws IOException {
    DexBuilder dexBuilder = new DexBuilder(Opcodes.forArtVersion(111));
    BuilderCallSiteReference callSite = dexBuilder.internCallSite(new ImmutableCallSiteReference("call_site_1", new ImmutableMethodHandleReference(MethodHandleType.INVOKE_STATIC, new ImmutableMethodReference("Lcls1;", "loader", ImmutableList.of("Ljava/lang/invoke/Lookup;", "Ljava/lang/String;", "Ljava/lang/invoke/MethodType;"), "Ljava/lang/invoke/CallSite;")), "someMethod", new ImmutableMethodProtoReference(ImmutableList.of(), "V"), ImmutableList.of()));
    MethodImplementationBuilder methodImplementationBuilder = new MethodImplementationBuilder(10);
    methodImplementationBuilder.addInstruction(new BuilderInstruction35c(Opcode.INVOKE_CUSTOM, 0, 0, 0, 0, 0, 0, callSite));
    BuilderMethod method = dexBuilder.internMethod("Lcls1;", "method1", null, "V", 0, ImmutableSet.of(), ImmutableSet.of(), methodImplementationBuilder.getMethodImplementation());
    dexBuilder.internClassDef("Lcls1;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, ImmutableSet.of(), null, ImmutableList.of(method));
    File tempFile = File.createTempFile("dex", ".dex");
    dexBuilder.writeTo(new FileDataStore(tempFile));
    verifyDexFile(DexFileFactory.loadDexFile(tempFile, Opcodes.forArtVersion(111)));
}
Also used : ImmutableMethodProtoReference(org.jf.dexlib2.immutable.reference.ImmutableMethodProtoReference) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) ImmutableMethodHandleReference(org.jf.dexlib2.immutable.reference.ImmutableMethodHandleReference) BuilderInstruction35c(org.jf.dexlib2.builder.instruction.BuilderInstruction35c) BuilderMethod(org.jf.dexlib2.writer.builder.BuilderMethod) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) File(java.io.File) DexFile(org.jf.dexlib2.iface.DexFile) FileDataStore(org.jf.dexlib2.writer.io.FileDataStore) BuilderCallSiteReference(org.jf.dexlib2.writer.builder.BuilderCallSiteReference) MethodImplementationBuilder(org.jf.dexlib2.builder.MethodImplementationBuilder) DexBuilder(org.jf.dexlib2.writer.builder.DexBuilder) ImmutableCallSiteReference(org.jf.dexlib2.immutable.reference.ImmutableCallSiteReference) Test(org.junit.Test)

Example 2 with ImmutableMethodHandleReference

use of org.jf.dexlib2.immutable.reference.ImmutableMethodHandleReference in project smali by JesusFreke.

the class CallSiteTest method testPoolCallSite.

@Test
public void testPoolCallSite() throws IOException {
    ClassDef class1 = new ImmutableClassDef("Lcls1;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, null, null, Lists.<Method>newArrayList(new ImmutableMethod("Lcls1", "method1", ImmutableList.of(), "V", AccessFlags.PUBLIC.getValue(), null, null, new ImmutableMethodImplementation(10, ImmutableList.of(new ImmutableInstruction35c(Opcode.INVOKE_CUSTOM, 0, 0, 0, 0, 0, 0, new ImmutableCallSiteReference("call_site_1", new ImmutableMethodHandleReference(MethodHandleType.INVOKE_STATIC, new ImmutableMethodReference("Lcls1", "loader", ImmutableList.of("Ljava/lang/invoke/Lookup;", "Ljava/lang/String;", "Ljava/lang/invoke/MethodType;"), "Ljava/lang/invoke/CallSite;")), "someMethod", new ImmutableMethodProtoReference(ImmutableList.of(), "V"), ImmutableList.of()))), null, null))));
    File tempFile = File.createTempFile("dex", ".dex");
    DexFileFactory.writeDexFile(tempFile.getPath(), new ImmutableDexFile(Opcodes.forArtVersion(111), ImmutableList.of(class1)));
    verifyDexFile(DexFileFactory.loadDexFile(tempFile, Opcodes.forArtVersion(111)));
}
Also used : ImmutableMethodProtoReference(org.jf.dexlib2.immutable.reference.ImmutableMethodProtoReference) ImmutableClassDef(org.jf.dexlib2.immutable.ImmutableClassDef) ClassDef(org.jf.dexlib2.iface.ClassDef) ImmutableMethod(org.jf.dexlib2.immutable.ImmutableMethod) ImmutableClassDef(org.jf.dexlib2.immutable.ImmutableClassDef) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) ImmutableInstruction35c(org.jf.dexlib2.immutable.instruction.ImmutableInstruction35c) ImmutableMethodHandleReference(org.jf.dexlib2.immutable.reference.ImmutableMethodHandleReference) ImmutableMethodImplementation(org.jf.dexlib2.immutable.ImmutableMethodImplementation) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) File(java.io.File) DexFile(org.jf.dexlib2.iface.DexFile) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) ImmutableCallSiteReference(org.jf.dexlib2.immutable.reference.ImmutableCallSiteReference) Test(org.junit.Test)

Aggregations

File (java.io.File)2 DexFile (org.jf.dexlib2.iface.DexFile)2 ImmutableDexFile (org.jf.dexlib2.immutable.ImmutableDexFile)2 ImmutableCallSiteReference (org.jf.dexlib2.immutable.reference.ImmutableCallSiteReference)2 ImmutableMethodHandleReference (org.jf.dexlib2.immutable.reference.ImmutableMethodHandleReference)2 ImmutableMethodProtoReference (org.jf.dexlib2.immutable.reference.ImmutableMethodProtoReference)2 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)2 Test (org.junit.Test)2 MethodImplementationBuilder (org.jf.dexlib2.builder.MethodImplementationBuilder)1 BuilderInstruction35c (org.jf.dexlib2.builder.instruction.BuilderInstruction35c)1 ClassDef (org.jf.dexlib2.iface.ClassDef)1 ImmutableClassDef (org.jf.dexlib2.immutable.ImmutableClassDef)1 ImmutableMethod (org.jf.dexlib2.immutable.ImmutableMethod)1 ImmutableMethodImplementation (org.jf.dexlib2.immutable.ImmutableMethodImplementation)1 ImmutableInstruction35c (org.jf.dexlib2.immutable.instruction.ImmutableInstruction35c)1 BuilderCallSiteReference (org.jf.dexlib2.writer.builder.BuilderCallSiteReference)1 BuilderMethod (org.jf.dexlib2.writer.builder.BuilderMethod)1 DexBuilder (org.jf.dexlib2.writer.builder.DexBuilder)1 FileDataStore (org.jf.dexlib2.writer.io.FileDataStore)1