private MethodReference buildMethodReference(java.lang.reflect.Method method) { String className = ClassNameUtils.toInternal(method.getDeclaringClass()); String name = method.getName(); List<String> parameterTypes = ClassNameUtils.toInternal(method.getParameterTypes()); String returnType = ClassNameUtils.toInternal(method.getReturnType()); ImmutableMethodReference immutableMethodRef = new ImmutableMethodReference(className, name, parameterTypes, returnType); MethodReference methodRef = manipulator.getDexBuilder().internMethodReference(immutableMethodRef); return methodRef; }
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(mRef); AnnotationElement methodElement = new ImmutableAnnotationElement("value", methodRef); return new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/EnclosingMethod;", Collections.singleton(methodElement)); }
protected static MethodReference toMethodReference(SootMethodRef m) { 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 methodRef; }
new ImmutableMethodReference(classString, methodNameString, paramTypeList, returnType));
type = (reference_type_descriptor86!=null?((smaliTreeWalker.reference_type_descriptor_return)reference_type_descriptor86).type:null); methodReference = new ImmutableMethodReference(type, (SIMPLE_NAME87!=null?SIMPLE_NAME87.getText():null), method_prototype88.getParameterTypes(), method_prototype88.getReturnType());
resolvedMethod = new ImmutableMethodReference(methodClass.getType(), resolvedMethod.getName(), resolvedMethod.getParameterTypes(), resolvedMethod.getReturnType());
@Nonnull public static ImmutableMethodReference of(@Nonnull MethodReference methodReference) { if (methodReference instanceof ImmutableMethodReference) { return (ImmutableMethodReference)methodReference; } return new ImmutableMethodReference( methodReference.getDefiningClass(), methodReference.getName(), methodReference.getParameterTypes(), methodReference.getReturnType()); }
@Nonnull public static ImmutableMethodReference of(@Nonnull MethodReference methodReference) { if (methodReference instanceof ImmutableMethodReference) { return (ImmutableMethodReference)methodReference; } return new ImmutableMethodReference( methodReference.getDefiningClass(), methodReference.getName(), methodReference.getParameterTypes(), methodReference.getReturnType()); }
@Nonnull public static ImmutableMethodReference of(@Nonnull MethodReference methodReference) { if (methodReference instanceof ImmutableMethodReference) { return (ImmutableMethodReference)methodReference; } return new ImmutableMethodReference( methodReference.getDefiningClass(), methodReference.getName(), methodReference.getParameterTypes(), methodReference.getReturnType()); }
Iterable<ImmutableMethodParameter> methodParams = ParamUtil.parseParamString(m.group(3)); String methodRet = m.group(4); ImmutableMethodReference methodRef = new ImmutableMethodReference(className, methodName, methodParams, methodRet);
Iterable<ImmutableMethodParameter> methodParams = ParamUtil.parseParamString(m.group(3)); String methodRet = m.group(4); ImmutableMethodReference methodRef = new ImmutableMethodReference(className, methodName, methodParams, methodRet);
Iterable<ImmutableMethodParameter> methodParams = ParamUtil.parseParamString(m.group(3)); String methodRet = m.group(4); ImmutableMethodReference methodRef = new ImmutableMethodReference(className, methodName, methodParams, methodRet);
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; }
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; }
@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, 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))); }
@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(), 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))); }
methodReference = new ImmutableMethodReference((reference_type_descriptor77!=null?((smaliTreeWalker.reference_type_descriptor_return)reference_type_descriptor77).type:null), (SIMPLE_NAME78!=null?SIMPLE_NAME78.getText():null), (method_prototype79!=null?((smaliTreeWalker.method_prototype_return)method_prototype79).parameters:null), (method_prototype79!=null?((smaliTreeWalker.method_prototype_return)method_prototype79).returnType:null));
type = (reference_type_descriptor86!=null?((smaliTreeWalker.reference_type_descriptor_return)reference_type_descriptor86).type:null); methodReference = new ImmutableMethodReference(type, (SIMPLE_NAME87!=null?SIMPLE_NAME87.getText():null), method_prototype88.getParameterTypes(), method_prototype88.getReturnType());
ReferenceUtil.getShortMethodDescriptor(resolvedMethod)); resolvedMethod = new ImmutableMethodReference(methodClass.getType(), resolvedMethod.getName(), resolvedMethod.getParameterTypes(), resolvedMethod.getReturnType());
resolvedMethod = new ImmutableMethodReference(methodClass.getType(), resolvedMethod.getName(), resolvedMethod.getParameterTypes(), resolvedMethod.getReturnType());