Search in sources :

Example 16 with MethodInfo

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

the class SignatureProcessor method checkArgTypes.

private List<ArgType> checkArgTypes(MethodNode mth, SignatureParser sp, List<ArgType> parsedArgTypes) {
    MethodInfo mthInfo = mth.getMethodInfo();
    List<ArgType> mthArgTypes = mthInfo.getArgumentsTypes();
    int len = parsedArgTypes.size();
    if (len != mthArgTypes.size()) {
        if (mth.getParentClass().getAccessFlags().isEnum()) {
            // ignore for enums
            return null;
        }
        if (mthInfo.isConstructor() && !mthArgTypes.isEmpty() && !parsedArgTypes.isEmpty()) {
            // add synthetic arg for outer class (see test TestGeneric8)
            ArrayList<ArgType> newArgTypes = new ArrayList<>(parsedArgTypes);
            newArgTypes.add(0, mthArgTypes.get(0));
            if (newArgTypes.size() == mthArgTypes.size()) {
                return newArgTypes;
            }
        }
        mth.addDebugComment("Incorrect args count in method signature: " + sp.getSignature());
        return null;
    }
    for (int i = 0; i < len; i++) {
        ArgType parsedType = parsedArgTypes.get(i);
        ArgType mthArgType = mthArgTypes.get(i);
        if (!validateParsedType(parsedType, mthArgType)) {
            mth.addWarnComment("Incorrect types in method signature: " + sp.getSignature());
            return null;
        }
    }
    return parsedArgTypes;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ArrayList(java.util.ArrayList) MethodInfo(jadx.core.dex.info.MethodInfo)

Example 17 with MethodInfo

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

the class DeboxingVisitor method checkForReplace.

private InsnNode checkForReplace(InvokeNode insnNode) {
    if (insnNode.getInvokeType() != InvokeType.STATIC || insnNode.getResult() == null) {
        return null;
    }
    MethodInfo callMth = insnNode.getCallMth();
    if (valueOfMths.contains(callMth)) {
        RegisterArg resArg = insnNode.getResult();
        InsnArg arg = insnNode.getArg(0);
        if (arg.isLiteral()) {
            ArgType primitiveType = callMth.getArgumentsTypes().get(0);
            ArgType boxType = callMth.getReturnType();
            if (isNeedExplicitCast(resArg, primitiveType, boxType)) {
                arg.add(AFlag.EXPLICIT_PRIMITIVE_TYPE);
            }
            arg.setType(primitiveType);
            boolean forbidInline;
            if (canChangeTypeToPrimitive(resArg)) {
                resArg.setType(primitiveType);
                forbidInline = false;
            } else {
                forbidInline = true;
            }
            InsnNode constInsn = new InsnNode(InsnType.CONST, 1);
            constInsn.addArg(arg);
            constInsn.setResult(resArg);
            if (forbidInline) {
                constInsn.add(AFlag.DONT_INLINE);
            }
            return constInsn;
        }
    }
    return null;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg) MethodInfo(jadx.core.dex.info.MethodInfo)

Example 18 with MethodInfo

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

the class InlineMethods method updateUsageInfo.

private void updateUsageInfo(MethodNode mth, MethodNode inlinedMth, InsnNode insn) {
    inlinedMth.getUseIn().remove(mth);
    insn.visitInsns(innerInsn -> {
        // TODO: share code with UsageInfoVisitor
        switch(innerInsn.getType()) {
            case INVOKE:
            case CONSTRUCTOR:
                MethodInfo callMth = ((BaseInvokeNode) innerInsn).getCallMth();
                MethodNode callMthNode = mth.root().resolveMethod(callMth);
                if (callMthNode != null) {
                    callMthNode.setUseIn(ListUtils.safeReplace(callMthNode.getUseIn(), inlinedMth, mth));
                    replaceClsUsage(mth, inlinedMth, callMthNode.getParentClass());
                }
                break;
            case IGET:
            case IPUT:
            case SPUT:
            case SGET:
                FieldInfo fieldInfo = (FieldInfo) ((IndexInsnNode) innerInsn).getIndex();
                FieldNode fieldNode = mth.root().resolveField(fieldInfo);
                if (fieldNode != null) {
                    fieldNode.setUseIn(ListUtils.safeReplace(fieldNode.getUseIn(), inlinedMth, mth));
                    replaceClsUsage(mth, inlinedMth, fieldNode.getParentClass());
                }
                break;
        }
    });
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) FieldNode(jadx.core.dex.nodes.FieldNode) BaseInvokeNode(jadx.core.dex.instructions.BaseInvokeNode) MethodInfo(jadx.core.dex.info.MethodInfo) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 19 with MethodInfo

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

the class EnumVisitor method removeEnumMethods.

private void removeEnumMethods(ClassNode cls, ArgType clsType, FieldNode valuesField) {
    String valuesMethod = "values()" + TypeGen.signature(ArgType.array(clsType));
    FieldInfo valuesFieldInfo = valuesField.getFieldInfo();
    // remove compiler generated methods
    for (MethodNode mth : cls.getMethods()) {
        MethodInfo mi = mth.getMethodInfo();
        if (mi.isClassInit()) {
            continue;
        }
        String shortId = mi.getShortId();
        if (mi.isConstructor()) {
            if (isDefaultConstructor(mth, shortId)) {
                mth.add(AFlag.DONT_GENERATE);
            }
            markArgsForSkip(mth);
        } else if (shortId.equals(valuesMethod) || usesValuesField(mth, valuesFieldInfo) || simpleValueOfMth(mth, clsType)) {
            mth.add(AFlag.DONT_GENERATE);
        }
    }
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) MethodInfo(jadx.core.dex.info.MethodInfo) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 20 with MethodInfo

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

the class AnonymousClassVisitor method getArgsToFieldsMapping.

private static Map<InsnArg, FieldNode> getArgsToFieldsMapping(MethodNode mth, List<InsnNode> usedInsns) {
    MethodInfo callMth = mth.getMethodInfo();
    ClassNode cls = mth.getParentClass();
    List<RegisterArg> argList = mth.getArgRegs();
    ClassNode outerCls = mth.getUseIn().get(0).getParentClass();
    int startArg = 0;
    if (callMth.getArgsCount() != 0 && callMth.getArgumentsTypes().get(0).equals(outerCls.getClassInfo().getType())) {
        startArg = 1;
    }
    Map<InsnArg, FieldNode> map = new LinkedHashMap<>();
    int argsCount = argList.size();
    for (int i = startArg; i < argsCount; i++) {
        RegisterArg arg = argList.get(i);
        InsnNode useInsn = getParentInsnSkipMove(arg);
        if (useInsn == null) {
            return Collections.emptyMap();
        }
        switch(useInsn.getType()) {
            case IPUT:
                FieldNode fieldNode = cls.searchField((FieldInfo) ((IndexInsnNode) useInsn).getIndex());
                if (fieldNode == null || !fieldNode.getAccessFlags().isSynthetic()) {
                    return Collections.emptyMap();
                }
                map.put(arg, fieldNode);
                usedInsns.add(useInsn);
                break;
            case CONSTRUCTOR:
                ConstructorInsn superConstr = (ConstructorInsn) useInsn;
                if (!superConstr.isSuper()) {
                    return Collections.emptyMap();
                }
                usedInsns.add(useInsn);
                break;
            default:
                return Collections.emptyMap();
        }
    }
    return map;
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) FieldNode(jadx.core.dex.nodes.FieldNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) MethodInfo(jadx.core.dex.info.MethodInfo) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) ConstructorInsn(jadx.core.dex.instructions.mods.ConstructorInsn) LinkedHashMap(java.util.LinkedHashMap)

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