Search in sources :

Example 31 with MethodInfo

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

the class ProcessKotlinInternals method processInvoke.

private void processInvoke(MethodNode mth, InsnNode insn) {
    int argsCount = insn.getArgsCount();
    if (argsCount < 2) {
        return;
    }
    MethodInfo invokeMth = ((InvokeNode) insn).getCallMth();
    if (!kotlinVarNameSourceMethods.contains(invokeMth)) {
        return;
    }
    InsnArg firstArg = insn.getArg(0);
    if (!firstArg.isRegister()) {
        return;
    }
    RegisterArg varArg = (RegisterArg) firstArg;
    boolean renamed = false;
    if (argsCount == 2) {
        String str = getConstString(mth, insn, 1);
        if (str != null) {
            renamed = checkAndRename(varArg, str);
        }
    } else if (argsCount == 3) {
        // TODO: use second arg for rename class
        String str = getConstString(mth, insn, 2);
        if (str != null) {
            renamed = checkAndRename(varArg, str);
        }
    }
    if (renamed && hideInsns) {
        insn.add(AFlag.DONT_GENERATE);
    }
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg) InvokeNode(jadx.core.dex.instructions.InvokeNode) MethodInfo(jadx.core.dex.info.MethodInfo)

Example 32 with MethodInfo

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

the class FridaAction method generateMethodSnippet.

private String generateMethodSnippet(JMethod jMth) {
    JavaMethod javaMethod = jMth.getJavaMethod();
    MethodInfo methodInfo = javaMethod.getMethodNode().getMethodInfo();
    String methodName = methodInfo.getName();
    if (methodInfo.isConstructor()) {
        methodName = "$init";
    }
    String rawClassName = javaMethod.getDeclaringClass().getRawName();
    String shortClassName = javaMethod.getDeclaringClass().getName();
    String functionUntilImplementation;
    if (isOverloaded(javaMethod.getMethodNode())) {
        List<ArgType> methodArgs = methodInfo.getArgumentsTypes();
        String overloadStr = methodArgs.stream().map(this::parseArgType).collect(Collectors.joining(", "));
        functionUntilImplementation = String.format("%s.%s.overload(%s).implementation", shortClassName, methodName, overloadStr);
    } else {
        functionUntilImplementation = String.format("%s.%s.implementation", shortClassName, methodName);
    }
    String functionParametersString = Objects.requireNonNull(javaMethod.getTopParentClass().getCodeInfo()).getAnnotations().entrySet().stream().filter(e -> e.getKey().getLine() == jMth.getLine() && e.getValue() instanceof VarDeclareRef).sorted(Comparator.comparingInt(e -> e.getKey().getPos())).map(e -> ((VarDeclareRef) e.getValue()).getName()).collect(Collectors.joining(", "));
    String functionParameterAndBody = String.format("%s = function(%s){\n" + "    console.log('%s is called');\n" + "    let ret = this.%s(%s);\n" + "    console.log('%s ret value is ' + ret);\n" + "    return ret;\n" + "};", functionUntilImplementation, functionParametersString, methodName, methodName, functionParametersString, methodName);
    String finalFridaCode;
    if (isInitial.getOrDefault(rawClassName, true)) {
        String classSnippet = generateClassSnippet(jMth.getJParent());
        finalFridaCode = classSnippet + "\n" + functionParameterAndBody;
    } else {
        finalFridaCode = functionParameterAndBody;
    }
    return finalFridaCode;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ArgType(jadx.core.dex.instructions.args.ArgType) java.util(java.util) MethodNode(jadx.core.dex.nodes.MethodNode) LoggerFactory(org.slf4j.LoggerFactory) NLS(jadx.gui.utils.NLS) JField(jadx.gui.treemodel.JField) TypeGen(jadx.core.codegen.TypeGen) KeyStroke.getKeyStroke(javax.swing.KeyStroke.getKeyStroke) ClassNode(jadx.core.dex.nodes.ClassNode) UiUtils(jadx.gui.utils.UiUtils) JNode(jadx.gui.treemodel.JNode) JClass(jadx.gui.treemodel.JClass) VarDeclareRef(jadx.api.data.annotations.VarDeclareRef) JMethod(jadx.gui.treemodel.JMethod) Logger(org.slf4j.Logger) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) KeyEvent(java.awt.event.KeyEvent) JavaClass(jadx.api.JavaClass) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) MethodInfo(jadx.core.dex.info.MethodInfo) Nullable(org.jetbrains.annotations.Nullable) JavaMethod(jadx.api.JavaMethod) JavaField(jadx.api.JavaField) javax.swing(javax.swing) JavaMethod(jadx.api.JavaMethod) MethodInfo(jadx.core.dex.info.MethodInfo) VarDeclareRef(jadx.api.data.annotations.VarDeclareRef)

Example 33 with MethodInfo

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

the class EnumVisitor method extractEnumFieldsFromInvoke.

private List<EnumField> extractEnumFieldsFromInvoke(ClassNode cls, BlockNode staticBlock, InvokeNode invokeNode, List<InsnNode> toRemove) {
    MethodInfo callMth = invokeNode.getCallMth();
    MethodNode valuesMth = cls.root().resolveMethod(callMth);
    if (valuesMth == null || valuesMth.isVoidReturn()) {
        return null;
    }
    BlockNode returnBlock = Utils.getOne(valuesMth.getPreExitBlocks());
    InsnNode returnInsn = BlockUtils.getLastInsn(returnBlock);
    InsnNode wrappedInsn = getWrappedInsn(getSingleArg(returnInsn));
    if (wrappedInsn == null) {
        return null;
    }
    List<EnumField> enumFields = extractEnumFieldsFromInsn(cls, staticBlock, wrappedInsn, toRemove);
    if (enumFields != null) {
        valuesMth.add(AFlag.DONT_GENERATE);
    }
    return enumFields;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) EnumField(jadx.core.dex.attributes.nodes.EnumClassAttr.EnumField) MethodNode(jadx.core.dex.nodes.MethodNode) MethodInfo(jadx.core.dex.info.MethodInfo)

Example 34 with MethodInfo

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

the class CheckCode method visit.

@Override
public void visit(MethodNode mth) throws JadxException {
    MethodInfo mthInfo = mth.getMethodInfo();
    if (mthInfo.getArgumentsTypes().size() > 255) {
        // java spec don't allow more than 255 args
        if (canRemoveMethod(mth)) {
            mth.ignoreMethod();
        } else {
        // TODO: convert args to array
        }
    }
    checkInstructions(mth);
}
Also used : MethodInfo(jadx.core.dex.info.MethodInfo)

Example 35 with MethodInfo

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

the class ConstInlineVisitor method needExplicitCast.

private static boolean needExplicitCast(InsnNode insn, LiteralArg arg) {
    if (insn instanceof BaseInvokeNode) {
        BaseInvokeNode callInsn = (BaseInvokeNode) insn;
        MethodInfo callMth = callInsn.getCallMth();
        int offset = callInsn.getFirstArgOffset();
        int argIndex = insn.getArgIndex(arg);
        ArgType argType = callMth.getArgumentsTypes().get(argIndex - offset);
        if (argType.isPrimitive()) {
            arg.setType(argType);
            return argType.equals(ArgType.BYTE);
        }
    }
    return false;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) BaseInvokeNode(jadx.core.dex.instructions.BaseInvokeNode) MethodInfo(jadx.core.dex.info.MethodInfo)

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