Search in sources :

Example 1 with IMethodDetails

use of jadx.core.dex.nodes.IMethodDetails 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 2 with IMethodDetails

use of jadx.core.dex.nodes.IMethodDetails 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)

Example 3 with IMethodDetails

use of jadx.core.dex.nodes.IMethodDetails in project jadx by skylot.

the class FixAccessModifiers method fixMethodVisibility.

private static int fixMethodVisibility(MethodNode mth) {
    AccessInfo accessFlags = mth.getAccessFlags();
    if (accessFlags.isPublic()) {
        return -1;
    }
    MethodOverrideAttr overrideAttr = mth.get(AType.METHOD_OVERRIDE);
    if (overrideAttr != null && !overrideAttr.getOverrideList().isEmpty()) {
        // visibility can't be weaker
        IMethodDetails parentMD = overrideAttr.getOverrideList().get(0);
        AccessInfo parentAccInfo = new AccessInfo(parentMD.getRawAccessFlags(), AccessInfo.AFType.METHOD);
        if (accessFlags.isVisibilityWeakerThan(parentAccInfo)) {
            return parentAccInfo.getVisibility().rawValue();
        }
    }
    if (mth.getUseIn().isEmpty()) {
        return -1;
    }
    ClassNode thisTopParentCls = mth.getParentClass().getTopParentClass();
    for (MethodNode useMth : mth.getUseIn()) {
        ClassNode useInTPCls = useMth.getParentClass().getTopParentClass();
        if (!useInTPCls.equals(thisTopParentCls)) {
            return AccessFlags.PUBLIC;
        }
    }
    return -1;
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) MethodNode(jadx.core.dex.nodes.MethodNode) AccessInfo(jadx.core.dex.info.AccessInfo) MethodOverrideAttr(jadx.core.dex.attributes.nodes.MethodOverrideAttr) IMethodDetails(jadx.core.dex.nodes.IMethodDetails)

Example 4 with IMethodDetails

use of jadx.core.dex.nodes.IMethodDetails in project jadx by skylot.

the class ModVisitor method processAnonymousConstructor.

/**
 * For args in anonymous constructor invoke apply:
 * - forbid inline into constructor call
 * - make variables final (compiler require this implicitly)
 */
private static void processAnonymousConstructor(MethodNode mth, ConstructorInsn co) {
    IMethodDetails callMthDetails = mth.root().getMethodUtils().getMethodDetails(co);
    if (!(callMthDetails instanceof MethodNode)) {
        return;
    }
    MethodNode callMth = (MethodNode) callMthDetails;
    if (!callMth.contains(AFlag.ANONYMOUS_CONSTRUCTOR) || callMth.contains(AFlag.NO_SKIP_ARGS)) {
        return;
    }
    SkipMethodArgsAttr attr = callMth.get(AType.SKIP_MTH_ARGS);
    if (attr != null) {
        int argsCount = Math.min(callMth.getMethodInfo().getArgsCount(), co.getArgsCount());
        for (int i = 0; i < argsCount; i++) {
            if (attr.isSkip(i)) {
                anonymousCallArgMod(co.getArg(i));
            }
        }
    } else {
        // additional info not available apply mods to all args (the safest solution)
        co.getArguments().forEach(ModVisitor::anonymousCallArgMod);
    }
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) SkipMethodArgsAttr(jadx.core.dex.attributes.nodes.SkipMethodArgsAttr) IMethodDetails(jadx.core.dex.nodes.IMethodDetails)

Example 5 with IMethodDetails

use of jadx.core.dex.nodes.IMethodDetails in project jadx by skylot.

the class OverrideMethodVisitor method getMethodNodes.

@NotNull
private List<MethodNode> getMethodNodes(MethodNode mth, List<IMethodDetails> overrideList) {
    List<MethodNode> list = new ArrayList<>(1 + overrideList.size());
    list.add(mth);
    for (IMethodDetails md : overrideList) {
        if (md instanceof MethodNode) {
            list.add((MethodNode) md);
        }
    }
    return list;
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) ArrayList(java.util.ArrayList) IMethodDetails(jadx.core.dex.nodes.IMethodDetails) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IMethodDetails (jadx.core.dex.nodes.IMethodDetails)14 ArgType (jadx.core.dex.instructions.args.ArgType)7 MethodNode (jadx.core.dex.nodes.MethodNode)6 ArrayList (java.util.ArrayList)4 MethodOverrideAttr (jadx.core.dex.attributes.nodes.MethodOverrideAttr)3 MethodInfo (jadx.core.dex.info.MethodInfo)2 InsnArg (jadx.core.dex.instructions.args.InsnArg)2 ClassNode (jadx.core.dex.nodes.ClassNode)2 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)2 ClspClass (jadx.core.clsp.ClspClass)1 ClspMethod (jadx.core.clsp.ClspMethod)1 MethodBridgeAttr (jadx.core.dex.attributes.nodes.MethodBridgeAttr)1 MethodInlineAttr (jadx.core.dex.attributes.nodes.MethodInlineAttr)1 SkipMethodArgsAttr (jadx.core.dex.attributes.nodes.SkipMethodArgsAttr)1 AccessInfo (jadx.core.dex.info.AccessInfo)1 ClassInfo (jadx.core.dex.info.ClassInfo)1 BaseInvokeNode (jadx.core.dex.instructions.BaseInvokeNode)1 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1 InsnNode (jadx.core.dex.nodes.InsnNode)1