org.jf.dexlib2.immutable.reference.ImmutableMethodReference Java Examples

The following examples show how to use org.jf.dexlib2.immutable.reference.ImmutableMethodReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PatchMethodTool.java    From atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #2
Source File: PatchMethodTool.java    From atlas with Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example #3
Source File: DexPrinter.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private Annotation buildEnclosingMethodTag(EnclosingMethodTag t, Set<String> skipList) {
	if (!skipList.add("Ldalvik/annotation/EnclosingMethod;"))
		return null;
	
	if (t.getEnclosingMethod() == null)
		return null;

	String[] split1 = t.getEnclosingMethodSig().split("\\)");
 String parametersS = split1[0].replaceAll("\\(", "");
 String returnTypeS = split1[1];
 
 List<String> typeList = new ArrayList<String>();
    if (!parametersS.equals("")) {
        for (String p : Util.splitParameters(parametersS)) {
            if (!p.isEmpty())
            	typeList.add(p);
        }
    }
    
 ImmutableMethodReference mRef = new ImmutableMethodReference
 		(SootToDexUtils.getDexClassName(t.getEnclosingClass()),
 		t.getEnclosingMethod(), typeList, returnTypeS);
	ImmutableMethodEncodedValue methodRef = new ImmutableMethodEncodedValue
			(dexFile.internMethodReference(mRef));
	AnnotationElement methodElement = new ImmutableAnnotationElement("value", methodRef);
	
	return new ImmutableAnnotation(AnnotationVisibility.SYSTEM,
			"Ldalvik/annotation/EnclosingMethod;",
			Collections.singleton(methodElement));
}
 
Example #4
Source File: DexPrinter.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
protected static BuilderMethodReference toMethodReference
(SootMethodRef m, DexBuilder belongingDexFile) {
 	List<String> parameters = new ArrayList<String>();
 	for (Type t : m.parameterTypes())
 		parameters.add(SootToDexUtils.getDexTypeDescriptor(t));
 	MethodReference methodRef = new ImmutableMethodReference
 			(SootToDexUtils.getDexClassName(m.declaringClass().getName()),
 			m.name(),
 			parameters,
 			SootToDexUtils.getDexTypeDescriptor(m.returnType()));
 	return belongingDexFile.internMethodReference(methodRef);
 }