Java Code Examples for org.jf.dexlib2.iface.reference.MethodReference#getDefiningClass()

The following examples show how to use org.jf.dexlib2.iface.reference.MethodReference#getDefiningClass() . 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: ReferenceUtil.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static String getMethodDescriptor(MethodReference methodReference, boolean useImplicitReference) {
    StringBuilder sb = new StringBuilder();
    if (!useImplicitReference) {
        String clazz = methodReference.getDefiningClass();//TypeGenUtil.newType(methodReference.getDefiningClass());
        sb.append(clazz);
        sb.append("->");
    }
    sb.append(methodReference.getName());
    sb.append('(');
    for (CharSequence paramType : methodReference.getParameterTypes()) {
        sb.append(paramType);
    }
    sb.append(')');
    sb.append(methodReference.getReturnType());
    return sb.toString();
}
 
Example 2
Source File: ImmutableMethodReference.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 3
Source File: DexDiffInfo.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static void addUsedMethods(MethodReference methodReference) {
        String className = methodReference.getDefiningClass();
//        if (Build.addClasses.contains(className.substring(1, className.length() - 1).replace('/', '.'))){
//            return;
//        }
        String method = methodReference.getName();
        String params;
        if (APatchTool.mappingMap == null) {
            params = methodReference.getParameterTypes().toString().replace(',', '|').replaceAll(" ", "");
        } else {
            params = getParamsType(methodReference.getParameterTypes());
        }


        System.out.println("add used method:" + className + "->" + method + ":" + params
                + " " + methodReference.getReturnType());

        String record = className.substring(1, className.length() - 1).replace('/', '.') + ":" +
                method + ":" + params + ":" + methodReference.getReturnType();
        if (Build.usedMethods.contains(record)) {
            return;
        }
        if (p.matcher(className).find()) {
            return;
        }
        Build.usedMethods.add(record);
    }
 
Example 4
Source File: ImmutableMethodReference.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 5
Source File: MethodInvocationInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return the SootMethodRef for the invoked method.
 *
 * @param invType The invocation type
 */
private SootMethodRef getSootMethodRef(InvocationType invType) {
	if (methodRef != null)
		return methodRef;
	
    MethodReference mItem = (MethodReference) ((ReferenceInstruction) instruction).getReference();
    String tItem = mItem.getDefiningClass();

    String className = tItem;
    Debug.printDbg("tItem: ", tItem ," class name: ", className);
      if (className.startsWith("[")) {
        className = "java.lang.Object";
      } else {
        className = dottedClassName (tItem);
      }

    SootClass sc = SootResolver.v().makeClassRef(className);
    if (invType == InvocationType.Interface && sc.isPhantom())
    	sc.setModifiers(sc.getModifiers() | Modifier.INTERFACE);
    String methodName = mItem.getName();

    Type returnType = DexType.toSoot(mItem.getReturnType());
    List<Type> parameterTypes = new ArrayList<Type>();
    List<? extends CharSequence> paramTypes = mItem.getParameterTypes();
    if (paramTypes != null)
        for (CharSequence type : paramTypes)
            parameterTypes.add(DexType.toSoot(type.toString()));

    Debug.printDbg("sc: ", sc);
    Debug.printDbg("methodName: ", methodName);
    Debug.printDbg("parameterTypes: ");
    for (Type t: parameterTypes)
      Debug.printDbg(" t: ", t);
    Debug.printDbg("returnType: ", returnType);
    Debug.printDbg("isStatic: ", invType == InvocationType.Static);
    methodRef = Scene.v().makeMethodRef(sc, methodName, parameterTypes, returnType,
    		invType == InvocationType.Static);
    
    return methodRef;
}
 
Example 6
Source File: ImmutableMethodReference.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 7
Source File: ImmutableMethodReference.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 8
Source File: MethodPool.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Nonnull @Override public CharSequence getDefiningClass(@Nonnull MethodReference methodReference) {
    return methodReference.getDefiningClass();
}
 
Example 9
Source File: SyntheticAccessorResolver.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Nullable
public AccessedMember getAccessedMember(@Nonnull MethodReference methodReference) {
    String methodDescriptor = ReferenceUtil.getMethodDescriptor(methodReference);

    AccessedMember accessedMember = resolvedAccessors.get(methodDescriptor);
    if (accessedMember != null) {
        return accessedMember;
    }

    String type = methodReference.getDefiningClass();
    ClassDef classDef = classDefMap.get(type);
    if (classDef == null) {
        return null;
    }

    Method matchedMethod = null;
    MethodImplementation matchedMethodImpl = null;
    for (Method method: classDef.getMethods()) {
        MethodImplementation methodImpl = method.getImplementation();
        if (methodImpl != null) {
            if (methodReferenceEquals(method, methodReference)) {
                matchedMethod = method;
                matchedMethodImpl = methodImpl;
                break;
            }
        }
    }

    if (matchedMethod == null) {
        return null;
    }

    //A synthetic accessor will be marked synthetic
    if (!AccessFlags.SYNTHETIC.isSet(matchedMethod.getAccessFlags())) {
        return null;
    }

    List<Instruction> instructions = ImmutableList.copyOf(matchedMethodImpl.getInstructions());

    int accessType = SyntheticAccessorFSM.test(instructions);

    if (accessType >= 0) {
        AccessedMember member =
                new AccessedMember(accessType, ((ReferenceInstruction)instructions.get(0)).getReference());
        resolvedAccessors.put(methodDescriptor, member);
        return member;
    }
    return null;
}
 
Example 10
Source File: MethodPool.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
@Nonnull @Override public CharSequence getDefiningClass(@Nonnull MethodReference methodReference) {
    return methodReference.getDefiningClass();
}
 
Example 11
Source File: SyntheticAccessorResolver.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
@Nullable
public AccessedMember getAccessedMember(@Nonnull MethodReference methodReference) {
    String methodDescriptor = ReferenceUtil.getMethodDescriptor(methodReference);

    AccessedMember accessedMember = resolvedAccessors.get(methodDescriptor);
    if (accessedMember != null) {
        return accessedMember;
    }

    String type = methodReference.getDefiningClass();
    ClassDef classDef = classDefMap.get(type);
    if (classDef == null) {
        return null;
    }

    Method matchedMethod = null;
    MethodImplementation matchedMethodImpl = null;
    for (Method method: classDef.getMethods()) {
        MethodImplementation methodImpl = method.getImplementation();
        if (methodImpl != null) {
            if (methodReferenceEquals(method, methodReference)) {
                matchedMethod = method;
                matchedMethodImpl = methodImpl;
                break;
            }
        }
    }

    if (matchedMethod == null) {
        return null;
    }

    //A synthetic accessor will be marked synthetic
    if (!AccessFlags.SYNTHETIC.isSet(matchedMethod.getAccessFlags())) {
        return null;
    }

    List<Instruction> instructions = ImmutableList.copyOf(matchedMethodImpl.getInstructions());

    int accessType = SyntheticAccessorFSM.test(instructions);

    if (accessType >= 0) {
        AccessedMember member =
                new AccessedMember(accessType, ((ReferenceInstruction)instructions.get(0)).getReference());
        resolvedAccessors.put(methodDescriptor, member);
        return member;
    }
    return null;
}
 
Example 12
Source File: MethodPool.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
@Nonnull @Override public CharSequence getDefiningClass(@Nonnull MethodReference methodReference) {
    return methodReference.getDefiningClass();
}
 
Example 13
Source File: SyntheticAccessorResolver.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
@Nullable
public AccessedMember getAccessedMember(@Nonnull MethodReference methodReference) {
    String methodDescriptor = ReferenceUtil.getMethodDescriptor(methodReference);

    AccessedMember accessedMember = resolvedAccessors.get(methodDescriptor);
    if (accessedMember != null) {
        return accessedMember;
    }

    String type = methodReference.getDefiningClass();
    ClassDef classDef = classDefMap.get(type);
    if (classDef == null) {
        return null;
    }

    Method matchedMethod = null;
    MethodImplementation matchedMethodImpl = null;
    for (Method method: classDef.getMethods()) {
        MethodImplementation methodImpl = method.getImplementation();
        if (methodImpl != null) {
            if (methodReferenceEquals(method, methodReference)) {
                matchedMethod = method;
                matchedMethodImpl = methodImpl;
                break;
            }
        }
    }

    if (matchedMethod == null) {
        return null;
    }

    //A synthetic accessor will be marked synthetic
    if (!AccessFlags.SYNTHETIC.isSet(matchedMethod.getAccessFlags())) {
        return null;
    }

    List<Instruction> instructions = ImmutableList.copyOf(matchedMethodImpl.getInstructions());

    int accessType = SyntheticAccessorFSM.test(instructions);

    if (accessType >= 0) {
        AccessedMember member =
                new AccessedMember(accessType, ((ReferenceInstruction)instructions.get(0)).getReference());
        resolvedAccessors.put(methodDescriptor, member);
        return member;
    }
    return null;
}
 
Example 14
Source File: MethodPool.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Nonnull @Override public CharSequence getDefiningClass(@Nonnull MethodReference methodReference) {
    return methodReference.getDefiningClass();
}
 
Example 15
Source File: SyntheticAccessorResolver.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Nullable
public AccessedMember getAccessedMember(@Nonnull MethodReference methodReference) {
    String methodDescriptor = ReferenceUtil.getMethodDescriptor(methodReference);

    AccessedMember accessedMember = resolvedAccessors.get(methodDescriptor);
    if (accessedMember != null) {
        return accessedMember;
    }

    String type = methodReference.getDefiningClass();
    ClassDef classDef = classDefMap.get(type);
    if (classDef == null) {
        return null;
    }

    Method matchedMethod = null;
    MethodImplementation matchedMethodImpl = null;
    for (Method method: classDef.getMethods()) {
        MethodImplementation methodImpl = method.getImplementation();
        if (methodImpl != null) {
            if (methodReferenceEquals(method, methodReference)) {
                matchedMethod = method;
                matchedMethodImpl = methodImpl;
                break;
            }
        }
    }

    if (matchedMethod == null) {
        return null;
    }

    //A synthetic accessor will be marked synthetic
    if (!AccessFlags.SYNTHETIC.isSet(matchedMethod.getAccessFlags())) {
        return null;
    }

    List<Instruction> instructions = ImmutableList.copyOf(matchedMethodImpl.getInstructions());

    int accessType = SyntheticAccessorFSM.test(instructions);

    if (accessType >= 0) {
        AccessedMember member =
                new AccessedMember(accessType, ((ReferenceInstruction)instructions.get(0)).getReference());
        resolvedAccessors.put(methodDescriptor, member);
        return member;
    }
    return null;
}