Search in sources :

Example 1 with BuilderInstruction35c

use of org.jf.dexlib2.builder.instruction.BuilderInstruction35c in project atlas by alibaba.

the class PatchMethodTool method modifyMethodAndFix.

private static MethodImplementation modifyMethodAndFix(@Nonnull MethodImplementation implementation, Method method) {
    MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
    System.out.println(mutableImplementation.getRegisterCount());
    List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
    mutableImplementation.addInstruction(0, new BuilderInstruction21c(Opcode.CONST_STRING, 0, new ImmutableStringReference("AndFix:" + method.getDefiningClass().replace("/", "."))));
    mutableImplementation.addInstruction(1, new BuilderInstruction35c(Opcode.INVOKE_STATIC, 1, 0, 0, 0, 0, 0, new ImmutableMethodReference("Landroid/util/Log;", "e", Lists.newArrayList("Ljava/lang/String;", "Ljava/lang/String;"), "I")));
    return mutableImplementation;
}
Also used : ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) BuilderInstruction(org.jf.dexlib2.builder.BuilderInstruction) BuilderInstruction35c(org.jf.dexlib2.builder.instruction.BuilderInstruction35c) BuilderInstruction21c(org.jf.dexlib2.builder.instruction.BuilderInstruction21c) MutableMethodImplementation(org.jf.dexlib2.builder.MutableMethodImplementation) ImmutableStringReference(org.jf.dexlib2.immutable.reference.ImmutableStringReference)

Example 2 with BuilderInstruction35c

use of org.jf.dexlib2.builder.instruction.BuilderInstruction35c in project atlas by alibaba.

the class PatchMethodTool method modifyMethodTpatch.

private static MethodImplementation modifyMethodTpatch(@Nonnull MethodImplementation implementation, Method method) {
    MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
    System.out.println(mutableImplementation.getRegisterCount());
    List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
    boolean isModified = false;
    for (int i = 0; i < instructions.size(); i++) {
        isModified = false;
        if (instructions.get(i).getOpcode() == Opcode.INVOKE_DIRECT) {
            if (!isModified) {
                mutableImplementation.addInstruction(i++, new BuilderInstruction21c(Opcode.CONST_STRING, 0, new ImmutableStringReference("tpatch:" + method.getDefiningClass().replace("/", "."))));
                mutableImplementation.addInstruction(i++, new BuilderInstruction35c(Opcode.INVOKE_STATIC, 1, 0, 0, 0, 0, 0, new ImmutableMethodReference("Landroid/util/Log;", "e", Lists.newArrayList("Ljava/lang/String;", "Ljava/lang/String;"), "I")));
                isModified = true;
                break;
            }
        }
    //            mutableImplementation.addInstruction(instructions.get(i));
    }
    return mutableImplementation;
}
Also used : ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) BuilderInstruction(org.jf.dexlib2.builder.BuilderInstruction) BuilderInstruction35c(org.jf.dexlib2.builder.instruction.BuilderInstruction35c) BuilderInstruction21c(org.jf.dexlib2.builder.instruction.BuilderInstruction21c) MutableMethodImplementation(org.jf.dexlib2.builder.MutableMethodImplementation) ImmutableStringReference(org.jf.dexlib2.immutable.reference.ImmutableStringReference)

Example 3 with BuilderInstruction35c

use of org.jf.dexlib2.builder.instruction.BuilderInstruction35c in project atlas by alibaba.

the class PatchMethodTool method modifyMethodAndFix.

private static MethodImplementation modifyMethodAndFix(@Nonnull MethodImplementation implementation, Method method) {
    MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
    System.out.println(mutableImplementation.getRegisterCount());
    List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
    mutableImplementation.addInstruction(0, new BuilderInstruction21c(Opcode.CONST_STRING, 0, new ImmutableStringReference("AndFix:" + method.getDefiningClass().replace("/", "."))));
    mutableImplementation.addInstruction(1, new BuilderInstruction35c(Opcode.INVOKE_STATIC, 1, 0, 0, 0, 0, 0, new ImmutableMethodReference("Landroid/util/Log;", "e", Lists.newArrayList("Ljava/lang/String;", "Ljava/lang/String;"), "I")));
    return mutableImplementation;
}
Also used : ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) BuilderInstruction(org.jf.dexlib2.builder.BuilderInstruction) BuilderInstruction35c(org.jf.dexlib2.builder.instruction.BuilderInstruction35c) BuilderInstruction21c(org.jf.dexlib2.builder.instruction.BuilderInstruction21c) MutableMethodImplementation(org.jf.dexlib2.builder.MutableMethodImplementation) ImmutableStringReference(org.jf.dexlib2.immutable.reference.ImmutableStringReference)

Example 4 with BuilderInstruction35c

use of org.jf.dexlib2.builder.instruction.BuilderInstruction35c in project atlas by alibaba.

the class PatchMethodTool method modifyMethodTpatch.

private static MethodImplementation modifyMethodTpatch(@Nonnull MethodImplementation implementation, Method method) {
    MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
    System.out.println(mutableImplementation.getRegisterCount());
    List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
    boolean isModified = false;
    for (int i = 0; i < instructions.size(); i++) {
        isModified = false;
        if (instructions.get(i).getOpcode() == Opcode.INVOKE_DIRECT) {
            if (!isModified) {
                mutableImplementation.addInstruction(i++, new BuilderInstruction21c(Opcode.CONST_STRING, 0, new ImmutableStringReference("tpatch:" + method.getDefiningClass().replace("/", "."))));
                mutableImplementation.addInstruction(i++, new BuilderInstruction35c(Opcode.INVOKE_STATIC, 1, 0, 0, 0, 0, 0, new ImmutableMethodReference("Landroid/util/Log;", "e", Lists.newArrayList("Ljava/lang/String;", "Ljava/lang/String;"), "I")));
                isModified = true;
                break;
            }
        }
    // mutableImplementation.addInstruction(instructions.get(i));
    }
    return mutableImplementation;
}
Also used : ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) BuilderInstruction(org.jf.dexlib2.builder.BuilderInstruction) BuilderInstruction35c(org.jf.dexlib2.builder.instruction.BuilderInstruction35c) BuilderInstruction21c(org.jf.dexlib2.builder.instruction.BuilderInstruction21c) MutableMethodImplementation(org.jf.dexlib2.builder.MutableMethodImplementation) ImmutableStringReference(org.jf.dexlib2.immutable.reference.ImmutableStringReference)

Example 5 with BuilderInstruction35c

use of org.jf.dexlib2.builder.instruction.BuilderInstruction35c 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)

Aggregations

BuilderInstruction35c (org.jf.dexlib2.builder.instruction.BuilderInstruction35c)5 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)5 BuilderInstruction (org.jf.dexlib2.builder.BuilderInstruction)4 MutableMethodImplementation (org.jf.dexlib2.builder.MutableMethodImplementation)4 BuilderInstruction21c (org.jf.dexlib2.builder.instruction.BuilderInstruction21c)4 ImmutableStringReference (org.jf.dexlib2.immutable.reference.ImmutableStringReference)4 File (java.io.File)1 MethodImplementationBuilder (org.jf.dexlib2.builder.MethodImplementationBuilder)1 DexFile (org.jf.dexlib2.iface.DexFile)1 ImmutableDexFile (org.jf.dexlib2.immutable.ImmutableDexFile)1 ImmutableCallSiteReference (org.jf.dexlib2.immutable.reference.ImmutableCallSiteReference)1 ImmutableMethodHandleReference (org.jf.dexlib2.immutable.reference.ImmutableMethodHandleReference)1 ImmutableMethodProtoReference (org.jf.dexlib2.immutable.reference.ImmutableMethodProtoReference)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 Test (org.junit.Test)1