MethodImplementation methodImpl = method.getImplementation(); if (methodImpl != null) { methodImpl = new BuilderMutableMethodImplementation(dexBuilder, methodImpl); method.getDefiningClass(), method.getName(), method.getParameters(), method.getReturnType(), method.getAccessFlags(), method.getAnnotations(), methodImpl );
private String buildDescriptor(Method method) { StringBuilder sb = new StringBuilder(); sb.append('('); method.getParameterTypes().forEach(sb::append); sb.append(')'); sb.append(method.getReturnType()); return sb.toString(); }
protected List<Type> getParameterTypes(final Method method) { // retrieve all parameter types List<Type> parameterTypes = new ArrayList<Type>(); if (method.getParameters() != null) { List<? extends CharSequence> parameters = method.getParameterTypes(); for (CharSequence t : parameters) { Type type = DexType.toSoot(t.toString()); parameterTypes.add(type); } } return parameterTypes; }
private void visitMethod(ClassDef classDef, Method method, MethodVisitor mv) { mv.visitCode(); String methodName = method.getName(); if (methodName.equals("<clinit>")) { visitClInitStub(mv); } else if (methodName.equals("<init>")) { visitInitStub(classDef, mv); } else if (methodName.equals("hashCode") && method.getReturnType().equals("I")) { visitCallObjectHashCode(mv); } else { visitMethodStub(mv); } // Do this at the end so ASM can calculate max stack and locals sizes mv.visitMaxs(0, 0); mv.visitEnd(); }
private void listClassVtable(ClassProto classProto) throws IOException { List<Method> methods = classProto.getVtable(); String className = "Class " + classProto.getType() + " extends " + classProto.getSuperclass() + " : " + methods.size() + " methods\n"; System.out.write(className.getBytes()); for (int i = 0; i < methods.size(); i++) { Method method = methods.get(i); String methodString = i + ":" + method.getDefiningClass() + "->" + method.getName() + "("; for (CharSequence parameter : method.getParameterTypes()) { methodString += parameter; } methodString += ")" + method.getReturnType() + "\n"; System.out.write(methodString.getBytes()); } System.out.write("\n".getBytes()); }
MethodImplementation code = method.getImplementation(); if (code == null) { throw new RuntimeException("error: no code for method " + method.getName()); List<? extends MethodParameter> parameters = method.getParameters(); if (parameters != null) { parameterNames = new ArrayList<String>(); parameterTypes = new ArrayList<Type>(); for (MethodParameter param : method.getParameters()) { parameterNames.add(param.getName()); parameterTypes.add(DexType.toSoot(param.getType())); isStatic = Modifier.isStatic(method.getAccessFlags()); numRegisters = code.getRegisterCount(); numParameterRegisters = MethodUtil.getParameterRegisterCount(method);
@Nullable @Override public MethodImplementation getImplementation() { return method.getImplementation(); } }
boolean hasDefaultConstructor = false; for (Method method : methods) { int access = method.getAccessFlags(); String name = method.getName(); String desc = buildDescriptor(method); String signature = null; String[] exceptions = buildExceptions(method); MethodVisitor mv = classWriter.visitMethod(access, name, desc, signature, exceptions); if (method.getImplementation() != null) { if (method.getName().equals("<init>") && desc.equals("()V")) { hasDefaultConstructor = true;
if (!AccessFlags.ABSTRACT.isSet(interfaceMethod.getAccessFlags())) { ClassProto existingInterface = (ClassProto)classPath.getClass( defaultMethods.get(defaultMethodIndex).getDefiningClass()); if (!existingInterface.implementsInterface(interfaceMethod.getDefiningClass())) { Method removedMethod = defaultMethods.remove(defaultMethodIndex); defaultConflictMethods.add(removedMethod); if (!AccessFlags.ABSTRACT.isSet(interfaceMethod.getAccessFlags())) { mirandaMethods.get(mirandaMethodIndex).getDefiningClass()); if (!existingInterface.implementsInterface(interfaceMethod.getDefiningClass())) { Method oldMethod = mirandaMethods.remove(mirandaMethodIndex); int methodOrderValue = methodOrder.get(oldMethod); if (!AccessFlags.ABSTRACT.isSet(interfaceMethod.getAccessFlags())) { defaultMethods.add(interfaceMethod); methodOrder.put(interfaceMethod, methodOrder.size());
/** * Retrieve the SootMethod equivalent of this method * * @return the SootMethod of this method */ public SootMethod makeSootMethod(final Method method) { int accessFlags = method.getAccessFlags(); // get the name of the method String name = method.getName(); List<SootClass> thrownExceptions = getThrownExceptions(method); List<Type> parameterTypes = getParameterTypes(method); // retrieve the return type of this method Type returnType = DexType.toSoot(method.getReturnType()); // Build soot method by all available parameters SootMethod sm = declaringClass.getMethodUnsafe(name, parameterTypes, returnType); if (sm == null) { sm = Scene.v().makeSootMethod(name, parameterTypes, returnType, accessFlags, thrownExceptions); } // if the method is abstract or native, no code needs to be transformed int flags = method.getAccessFlags(); if (Modifier.isAbstract(flags) || Modifier.isNative(flags)) { return sm; } if (Options.v().oaat() && declaringClass.resolvingLevel() <= SootClass.SIGNATURES) { return sm; } // sets the method source by adding its body as the active body sm.setSource(createMethodSource(method)); return sm; }
@Nonnull @Override public String getName() { return method.getName(); }
public ControlFlowGraph(Method method) { this(getFlatMethod(method)); String definingClass = method.getDefiningClass(); this.identifier = definingClass + "." + method.getName() + "()" + method.getReturnType(); // this.identifier = definingClass.substring(definingClass.lastIndexOf("/")+1) + method.getName() + "(" + method.getReturnType() + ")"; this.identifier = this.identifier.replace(";", ""); this.shortIdentifier = identifier.substring(definingClass.lastIndexOf("/")+1); }
private boolean methodSignaturesMatch(@Nonnull Method a, @Nonnull Method b) { return (a.getName().equals(b.getName()) && a.getReturnType().equals(b.getReturnType()) && a.getParameters().equals(b.getParameters())); }
/** * Checks if the interface method overrides the virtual or interface method2 * @param method A Method from an interface * @param method2 A Method from an interface or a class * @return true if the interface method overrides the virtual or interface method2 */ private boolean interfaceMethodOverrides(@Nonnull Method method, @Nonnull Method method2) { ClassProto classProto = (ClassProto)classPath.getClass(method2.getDefiningClass()); if (classProto.isInterface()) { ClassProto targetClassProto = (ClassProto)classPath.getClass(method.getDefiningClass()); return targetClassProto.implementsInterface(method2.getDefiningClass()); } else { return false; } }
@Override public int getAccessFlags() { return method.getAccessFlags(); }
@Nonnull @Override public Set<? extends Annotation> getAnnotations() { return method.getAnnotations(); }
@Nonnull @Override public List<? extends MethodParameter> getParameters() { return method.getParameters(); }
private String getMethodFullName(Method method) { StringBuilder stringBuilder = new StringBuilder(); String methodName = method.getName(); stringBuilder.append(methodName).append("("); for (CharSequence c:method.getParameterTypes()){ stringBuilder.append(c); } stringBuilder.append(")").append(method.getReturnType()); return stringBuilder.toString(); }
private void verifyDexFile(DexFile dexFile) { Assert.assertEquals(1, dexFile.getClasses().size()); ClassDef cls = Lists.newArrayList(dexFile.getClasses()).get(0); Assert.assertEquals("Lcls1;", cls.getType()); Assert.assertEquals(1, Lists.newArrayList(cls.getMethods()).size()); Method method = Iterators.getNext(cls.getMethods().iterator(), null); Assert.assertEquals("method1", method.getName()); Assert.assertEquals(1, Lists.newArrayList(method.getImplementation().getInstructions()).size()); Instruction instruction = Lists.newArrayList(method.getImplementation().getInstructions().iterator()).get(0); Assert.assertEquals(Opcode.INVOKE_CUSTOM, instruction.getOpcode()); Assert.assertTrue(((Instruction35c) instruction).getReference() instanceof CallSiteReference); } }
private void internDebug(@Nonnull Method method) { for (MethodParameter param: method.getParameters()) { String paramName = param.getName(); if (paramName != null) { dexPool.stringSection.intern(paramName); } } MethodImplementation methodImpl = method.getImplementation(); if (methodImpl != null) { for (DebugItem debugItem: methodImpl.getDebugItems()) { switch (debugItem.getDebugItemType()) { case DebugItemType.START_LOCAL: StartLocal startLocal = (StartLocal)debugItem; dexPool.stringSection.internNullable(startLocal.getName()); dexPool.typeSection.internNullable(startLocal.getType()); dexPool.stringSection.internNullable(startLocal.getSignature()); break; case DebugItemType.SET_SOURCE_FILE: dexPool.stringSection.internNullable(((SetSourceFile) debugItem).getSourceFile()); break; } } } }