Java Code Examples for org.jf.dexlib2.iface.Method#getName()

The following examples show how to use org.jf.dexlib2.iface.Method#getName() . 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: MetaObjectDex.java    From android-classyshark with Apache License 2.0 6 votes vote down vote up
@Override
public MethodInfo[] getDeclaredMethods() {
    Iterable<? extends Method> implMethods = classDef.getMethods();
    List<MethodInfo> result = new ArrayList<>();

    for (Method method : implMethods) {
        if (!isConstructor(method)) {
            MethodInfo mi = new MethodInfo();
            mi.parameterTypes = convertParameters(method.getParameters());
            mi.annotations = convertAnnotations(method.getAnnotations());
            mi.modifiers = method.getAccessFlags();
            mi.name = method.getName();
            mi.exceptionTypes = new ExceptionInfo[0];
            mi.returnType = DexlibAdapter.getTypeName(method.getReturnType());

            result.add(mi);
        }
    }

    MethodInfo[] array = new MethodInfo[result.size()];
    return result.toArray(array);
}
 
Example 2
Source File: ImmutableMethod.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableMethod of(Method method) {
    if (method instanceof ImmutableMethod) {
        return (ImmutableMethod)method;
    }
    return new ImmutableMethod(
            method.getDefiningClass(),
            method.getName(),
            method.getParameters(),
            method.getReturnType(),
            method.getAccessFlags(),
            method.getAnnotations(),
            method.getImplementation());
}
 
Example 3
Source File: FastPatchTool.java    From atlas with Apache License 2.0 5 votes vote down vote up
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();

}
 
Example 4
Source File: ImmutableMethod.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableMethod of(Method method) {
    if (method instanceof ImmutableMethod) {
        return (ImmutableMethod)method;
    }
    return new ImmutableMethod(
            method.getDefiningClass(),
            method.getName(),
            method.getParameters(),
            method.getReturnType(),
            method.getAccessFlags(),
            method.getAnnotations(),
            method.getImplementation());
}
 
Example 5
Source File: ImmutableMethod.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public static ImmutableMethod of(Method method) {
    if (method instanceof ImmutableMethod) {
        return (ImmutableMethod)method;
    }
    return new ImmutableMethod(
            method.getDefiningClass(),
            method.getName(),
            method.getParameters(),
            method.getReturnType(),
            method.getAccessFlags(),
            method.getAnnotations(),
            method.getImplementation());
}
 
Example 6
Source File: SmaliClassDetailLoader.java    From PATDroid with Apache License 2.0 5 votes vote down vote up
private MethodInfo translateMethod(ClassInfo ci, Method method, IdentityHashMap<MethodInfo, MethodImplementation> collector) {
    final ClassInfo retType = Dalvik.findOrCreateClass(ci.scope, method.getReturnType());
    final ImmutableList<ClassInfo> paramTypes = findOrCreateClasses(ci.scope, method.getParameterTypes());
    final MethodSignature signature = new MethodSignature(method.getName(), paramTypes);
    final FullMethodSignature fullSignature = new FullMethodSignature(retType, signature);
    final int accessFlags = translateAccessFlags(method.getAccessFlags());
    final MethodInfo mi = new MethodInfo(ci, fullSignature, accessFlags, AccessFlags.SYNTHETIC.isSet(method.getAccessFlags()));
    Log.msg("Translating method: %s", mi.toString());
    collector.put(mi, method.getImplementation());
    return mi;
}
 
Example 7
Source File: ControlFlowGraph.java    From CFGScanDroid with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: ImmutableMethod.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableMethod of(Method method) {
    if (method instanceof ImmutableMethod) {
        return (ImmutableMethod)method;
    }
    return new ImmutableMethod(
            method.getDefiningClass(),
            method.getName(),
            method.getParameters(),
            method.getReturnType(),
            method.getAccessFlags(),
            method.getAnnotations(),
            method.getImplementation());
}
 
Example 9
Source File: MethodReIClassDef.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public Method reMethod(Method method) {
    String newType = null;
    boolean isBasic = false;
    boolean isInit = false;
    boolean changeOpcode = false;
    String methodName = method.getName();
    String returnType = method.getReturnType();
    MethodImplementation methodImplementation = method.getImplementation();
    List<? extends MethodParameter> paramters = method.getParameters();
    if (methodName.equals("<init>") || methodName.equals("<cinit>")) {
        isInit = true;
    }


    if (basicType.containsKey(returnType)) {
        newType = returnType;
        isBasic = true;
    } else {
        newType = classProcessor.classProcess(DefineUtils.getDalvikClassName(returnType)).className;
    }

    String[] argsOringn = new String[paramters.size()];
    String[] args = new String[paramters.size()];
    for (int i = 0; i < paramters.size(); i++) {
        //型参数不混淆
        if (basicType.containsKey(paramters.get(i).getType())) {
            argsOringn[i] = basicType.get(paramters.get(i).getType());
            args[i] = argsOringn[i];
            continue;
        }
        argsOringn[i] = DefineUtils.getDalvikClassName(paramters.get(i).getType());
        args[i] = classProcessor.classProcess(DefineUtils.getDalvikClassName(paramters.get(i).getType())).className;
    }
    String type = method.getReturnType();
    
    return new ImmutableMethod(reType,
            classProcessor.methodProcess(isInit ? methodName :
                    DefineUtils.getDalvikClassName(method.getDefiningClass()), methodName, isBasic ? basicType.get(returnType) : DefineUtils.getDalvikClassName(returnType), StringUtils.join(argsOringn, ",")).methodName,
            reParameters(paramters),
            isBasic ? newType:
                    DefineUtils.getDefineClassName(newType,type.startsWith("[")),
                method.getAccessFlags(),
            getAnnotation(method.getAnnotations()),
            reMethodImpl(methodImplementation));

}
 
Example 10
Source File: DexBody.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param code the codeitem that is contained in this body
 * @param method the method that is associated with this body
 */
public DexBody(DexFile dexFile, Method method, RefType declaringClassType) {
    MethodImplementation code = method.getImplementation();
    if (code == null)
        throw new RuntimeException("error: no code for method "+ method.getName());
    this.declaringClassType = declaringClassType;
    tries = code.getTryBlocks();
    methodSignature = method.getDefiningClass() +": "+ method.getReturnType() +" "+ method.getName() +"(";
    for (MethodParameter mp: method.getParameters())
        methodSignature += mp.getType() +",";

    List<? extends CharSequence> paramTypes = method.getParameterTypes();
    if (paramTypes != null) {
        parameterTypes = new ArrayList<Type>();
        for (CharSequence type : paramTypes)
            parameterTypes.add(DexType.toSoot(type.toString()));
    } else {
    	parameterTypes = Collections.emptyList();
    }
    
    isStatic = Modifier.isStatic(method.getAccessFlags());
    numRegisters = code.getRegisterCount();
    numParameterRegisters = MethodUtil.getParameterRegisterCount(method);
    if (!isStatic)
        numParameterRegisters--;

    instructions = new ArrayList<DexlibAbstractInstruction>();
    instructionAtAddress = new HashMap<Integer, DexlibAbstractInstruction>();

    registerLocals = new Local[numRegisters];

    int address = 0;
    
    for (Instruction instruction : code.getInstructions()) {
        DexlibAbstractInstruction dexInstruction = fromInstruction(instruction, address);
        instructions.add(dexInstruction);
        instructionAtAddress.put(address, dexInstruction);
        Debug.printDbg(" put instruction '", dexInstruction ,"' at 0x", Integer.toHexString(address));
        address += instruction.getCodeUnits();
    }
    
    // Check taken from Android's dalvik/libdex/DexSwapVerify.cpp
    if (numParameterRegisters > numRegisters)
    	throw new RuntimeException("Malformed dex file: insSize (" + numParameterRegisters
    			+ ") > registersSize (" + numRegisters + ")");
    
    for (DebugItem di: code.getDebugItems()) {
        if (di instanceof ImmutableLineNumber) {
            ImmutableLineNumber ln = (ImmutableLineNumber)di;
            DexlibAbstractInstruction ins = instructionAtAddress(ln.getCodeAddress());
            if (ins == null) {
            	Debug.printDbg("Line number tag pointing to invalid offset: " + ln.getCodeAddress());
            	continue;
            }
            ins.setLineNumber(ln.getLineNumber());
            Debug.printDbg("Add line number tag " + ln.getLineNumber() + " for instruction: "
                    + instructionAtAddress(ln.getCodeAddress()));
        }
    }

    this.dexFile = dexFile;
}
 
Example 11
Source File: SyntheticAccessorsInspector.java    From android-classyshark with Apache License 2.0 3 votes vote down vote up
public List<String> getSyntheticAccessors() {

        LinkedList<String> result = new LinkedList<>();

        Set<? extends ClassDef> allClasses = dxFile.getClasses();

        for (ClassDef classDef : allClasses) {


            Iterator<? extends Method> allMethodsIter = classDef.getMethods().iterator();

            while (allMethodsIter.hasNext()) {

                Method element = allMethodsIter.next();

                String name = element.getName();

                String nClassName = classDef.getType();

                if (name.contains("access$")) {

                    String cleanClassName = DexlibAdapter.getClassStringFromDex(nClassName);

                    if (!result.contains(cleanClassName)) {
                        result.add(cleanClassName);
                    }
                }
            }
        }

        return result;
    }