Search in sources :

Example 11 with MethodInfo

use of jadx.core.dex.info.MethodInfo in project jadx by skylot.

the class Deobfuscator method getMethodAlias.

@Nullable
private String getMethodAlias(MethodNode mth) {
    if (mth.contains(AFlag.DONT_RENAME)) {
        return null;
    }
    MethodInfo methodInfo = mth.getMethodInfo();
    if (methodInfo.isClassInit() || methodInfo.isConstructor()) {
        return null;
    }
    String alias = getAssignedAlias(methodInfo);
    if (alias != null) {
        return alias;
    }
    if (shouldRename(mth.getName())) {
        return makeMethodAlias(mth);
    }
    return null;
}
Also used : MethodInfo(jadx.core.dex.info.MethodInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with MethodInfo

use of jadx.core.dex.info.MethodInfo in project jadx by skylot.

the class ClsSet method readMethod.

private ClspMethod readMethod(DataInputStream in, ClassInfo clsInfo) throws IOException {
    String name = readString(in);
    List<ArgType> argTypes = readArgTypesList(in);
    ArgType retType = readArgType(in);
    List<ArgType> genericArgTypes = readArgTypesList(in);
    if (genericArgTypes.isEmpty() || Objects.equals(genericArgTypes, argTypes)) {
        genericArgTypes = argTypes;
    }
    ArgType genericRetType = readArgType(in);
    if (Objects.equals(genericRetType, retType)) {
        genericRetType = retType;
    }
    List<ArgType> typeParameters = readArgTypesList(in);
    int accFlags = in.readInt();
    List<ArgType> throwList = readArgTypesList(in);
    MethodInfo methodInfo = MethodInfo.fromDetails(root, clsInfo, name, argTypes, retType);
    return new ClspMethod(methodInfo, genericArgTypes, genericRetType, typeParameters, throwList, accFlags);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) MethodInfo(jadx.core.dex.info.MethodInfo)

Example 13 with MethodInfo

use of jadx.core.dex.info.MethodInfo in project jadx by skylot.

the class MethodInvokeVisitor method processInvoke.

private void processInvoke(MethodNode parentMth, BaseInvokeNode invokeInsn) {
    MethodInfo callMth = invokeInsn.getCallMth();
    if (callMth.getArgsCount() == 0) {
        return;
    }
    IMethodDetails mthDetails = root.getMethodUtils().getMethodDetails(invokeInsn);
    if (mthDetails == null) {
        if (Consts.DEBUG) {
            parentMth.addDebugComment("Method info not found: " + callMth);
        }
        processUnknown(invokeInsn);
    } else {
        if (mthDetails.isVarArg()) {
            ArgType last = Utils.last(mthDetails.getArgTypes());
            if (last != null && last.isArray()) {
                invokeInsn.add(AFlag.VARARG_CALL);
            }
        }
        processOverloaded(parentMth, invokeInsn, mthDetails);
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) MethodInfo(jadx.core.dex.info.MethodInfo) IMethodDetails(jadx.core.dex.nodes.IMethodDetails)

Example 14 with MethodInfo

use of jadx.core.dex.info.MethodInfo in project jadx by skylot.

the class MethodInvokeVisitor method getTypeVarsMapping.

private Map<ArgType, ArgType> getTypeVarsMapping(BaseInvokeNode invokeInsn) {
    MethodInfo callMthInfo = invokeInsn.getCallMth();
    ArgType declClsType = callMthInfo.getDeclClass().getType();
    ArgType callClsType = getClsCallType(invokeInsn, declClsType);
    TypeUtils typeUtils = root.getTypeUtils();
    Map<ArgType, ArgType> clsTypeVars = typeUtils.getTypeVariablesMapping(callClsType);
    Map<ArgType, ArgType> mthTypeVars = typeUtils.getTypeVarMappingForInvoke(invokeInsn);
    return Utils.mergeMaps(clsTypeVars, mthTypeVars);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) MethodInfo(jadx.core.dex.info.MethodInfo) TypeUtils(jadx.core.dex.nodes.utils.TypeUtils)

Example 15 with MethodInfo

use of jadx.core.dex.info.MethodInfo in project jadx by skylot.

the class MethodInvokeVisitor method processOverloaded.

private void processOverloaded(MethodNode parentMth, BaseInvokeNode invokeInsn, IMethodDetails mthDetails) {
    MethodInfo callMth = invokeInsn.getCallMth();
    ArgType callCls = getCallClassFromInvoke(parentMth, invokeInsn, callMth);
    List<IMethodDetails> overloadMethods = root.getMethodUtils().collectOverloadedMethods(callCls, callMth);
    if (overloadMethods.isEmpty()) {
        // not overloaded
        return;
    }
    // resolve generic type variables
    Map<ArgType, ArgType> typeVarsMapping = getTypeVarsMapping(invokeInsn);
    IMethodDetails effectiveMthDetails = resolveTypeVars(mthDetails, typeVarsMapping);
    List<IMethodDetails> effectiveOverloadMethods = new ArrayList<>(overloadMethods.size() + 1);
    for (IMethodDetails overloadMethod : overloadMethods) {
        effectiveOverloadMethods.add(resolveTypeVars(overloadMethod, typeVarsMapping));
    }
    effectiveOverloadMethods.add(effectiveMthDetails);
    // search cast types to resolve overloading
    int argsOffset = invokeInsn.getFirstArgOffset();
    List<ArgType> compilerVarTypes = collectCompilerVarTypes(invokeInsn, argsOffset);
    List<ArgType> castTypes = searchCastTypes(parentMth, effectiveMthDetails, effectiveOverloadMethods, compilerVarTypes);
    applyArgsCast(invokeInsn, argsOffset, compilerVarTypes, castTypes);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ArrayList(java.util.ArrayList) MethodInfo(jadx.core.dex.info.MethodInfo) IMethodDetails(jadx.core.dex.nodes.IMethodDetails)

Aggregations

MethodInfo (jadx.core.dex.info.MethodInfo)39 MethodNode (jadx.core.dex.nodes.MethodNode)13 ArgType (jadx.core.dex.instructions.args.ArgType)10 InvokeNode (jadx.core.dex.instructions.InvokeNode)9 InsnArg (jadx.core.dex.instructions.args.InsnArg)9 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)8 InsnNode (jadx.core.dex.nodes.InsnNode)8 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)6 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)6 ClassInfo (jadx.core.dex.info.ClassInfo)4 FieldInfo (jadx.core.dex.info.FieldInfo)4 ClassNode (jadx.core.dex.nodes.ClassNode)4 FieldNode (jadx.core.dex.nodes.FieldNode)4 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)4 ArrayList (java.util.ArrayList)4 BaseInvokeNode (jadx.core.dex.instructions.BaseInvokeNode)3 IMethodRef (jadx.api.plugins.input.data.IMethodRef)2 InvokeType (jadx.core.dex.instructions.InvokeType)2 IMethodDetails (jadx.core.dex.nodes.IMethodDetails)2 HashSet (java.util.HashSet)2