Search in sources :

Example 56 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class InvokeCustomBuilder method build.

public static InsnNode build(MethodNode mth, InsnData insn, boolean isRange) {
    try {
        ICallSite callSite = InsnDataUtils.getCallSite(insn);
        if (callSite == null) {
            throw new JadxRuntimeException("Failed to get call site for insn: " + insn);
        }
        callSite.load();
        List<EncodedValue> values = callSite.getValues();
        if (CustomLambdaCall.isLambdaInvoke(values)) {
            return CustomLambdaCall.buildLambdaMethodCall(mth, insn, isRange, values);
        }
        if (CustomStringConcat.isStringConcat(values)) {
            return CustomStringConcat.buildStringConcat(insn, isRange, values);
        }
        // TODO: output raw dynamic call
        throw new JadxRuntimeException("Failed to process invoke-custom instruction: " + callSite);
    } catch (Exception e) {
        throw new JadxRuntimeException("'invoke-custom' instruction processing error: " + e.getMessage(), e);
    }
}
Also used : EncodedValue(jadx.api.plugins.input.data.annotations.EncodedValue) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) ICallSite(jadx.api.plugins.input.data.ICallSite) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 57 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class IntegrationTest method runSourceAutoCheck.

private boolean runSourceAutoCheck(String clsName) {
    if (sourceCompiler == null) {
        // no source code (smali case)
        return true;
    }
    Class<?> origCls;
    try {
        origCls = sourceCompiler.getClass(clsName);
    } catch (ClassNotFoundException e) {
        rethrow("Missing class: " + clsName, e);
        return true;
    }
    Method checkMth;
    try {
        checkMth = sourceCompiler.getMethod(origCls, CHECK_METHOD_NAME, new Class[] {});
    } catch (NoSuchMethodException e) {
        // ignore
        return true;
    }
    if (!checkMth.getReturnType().equals(void.class) || !Modifier.isPublic(checkMth.getModifiers()) || Modifier.isStatic(checkMth.getModifiers())) {
        fail("Wrong 'check' method");
        return true;
    }
    try {
        limitExecTime(() -> checkMth.invoke(origCls.getConstructor().newInstance()));
        System.out.println("Source check: PASSED");
    } catch (Throwable e) {
        throw new JadxRuntimeException("Source check failed", e);
    }
    return false;
}
Also used : JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) Method(java.lang.reflect.Method)

Example 58 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class BaseExternalTest method processCls.

private boolean processCls(@Nullable String mthPattern, ClassNode classNode) {
    classNode.load();
    boolean decompile = false;
    if (mthPattern == null) {
        decompile = true;
    } else {
        for (MethodNode mth : classNode.getMethods()) {
            if (isMthMatch(mth, mthPattern)) {
                decompile = true;
                break;
            }
        }
    }
    if (!decompile) {
        return false;
    }
    try {
        classNode.decompile();
    } catch (Exception e) {
        throw new JadxRuntimeException("Class process failed", e);
    }
    LOG.info("----------------------------------------------------------------");
    LOG.info("Print class: {} from: {}", classNode.getFullName(), classNode.getInputFileName());
    if (mthPattern != null) {
        printMethods(classNode, mthPattern);
    } else {
        LOG.info("Code: \n{}", classNode.getCode());
    }
    checkCode(classNode);
    return true;
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 59 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class RenameDialog method refreshState.

private void refreshState() {
    RootNode rootNode = mainWindow.getWrapper().getDecompiler().getRoot();
    new RenameVisitor().init(rootNode);
    JNodeCache nodeCache = cache.getNodeCache();
    JavaNode javaNode = node.getJavaNode();
    List<JavaNode> toUpdate = new ArrayList<>();
    if (source != null && source != node) {
        toUpdate.add(source.getJavaNode());
    }
    if (javaNode != null) {
        toUpdate.add(javaNode);
        toUpdate.addAll(javaNode.getUseIn());
        if (node instanceof JMethod) {
            toUpdate.addAll(((JMethod) node).getJavaMethod().getOverrideRelatedMethods());
        }
    } else if (node instanceof JPackage) {
        processPackage(toUpdate);
    } else {
        throw new JadxRuntimeException("Unexpected node type: " + node);
    }
    Set<JClass> updatedTopClasses = toUpdate.stream().map(JavaNode::getTopParentClass).map(nodeCache::makeFrom).filter(Objects::nonNull).collect(Collectors.toSet());
    LOG.debug("Classes to update: {}", updatedTopClasses);
    refreshTabs(mainWindow.getTabbedPane(), updatedTopClasses);
    if (!updatedTopClasses.isEmpty()) {
        mainWindow.getBackgroundExecutor().execute("Refreshing", () -> refreshClasses(updatedTopClasses), (status) -> {
            if (status == TaskStatus.CANCEL_BY_MEMORY) {
                mainWindow.showHeapUsageBar();
                UiUtils.errorMessage(this, NLS.str("message.memoryLow"));
            }
            if (node instanceof JPackage) {
                mainWindow.getTreeRoot().update();
            }
            mainWindow.reloadTree();
        });
    }
}
Also used : RootNode(jadx.core.dex.nodes.RootNode) JClass(jadx.gui.treemodel.JClass) ArrayList(java.util.ArrayList) JPackage(jadx.gui.treemodel.JPackage) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) RenameVisitor(jadx.core.dex.visitors.rename.RenameVisitor) JNodeCache(jadx.gui.utils.JNodeCache) JMethod(jadx.gui.treemodel.JMethod) JavaNode(jadx.api.JavaNode)

Example 60 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class RenameDialog method buildRename.

@NotNull
private JadxCodeRename buildRename(JNode node, String newName, Set<ICodeRename> renames) {
    if (node instanceof JMethod) {
        JavaMethod javaMethod = ((JMethod) node).getJavaMethod();
        List<JavaMethod> relatedMethods = javaMethod.getOverrideRelatedMethods();
        if (!relatedMethods.isEmpty()) {
            for (JavaMethod relatedMethod : relatedMethods) {
                renames.remove(new JadxCodeRename(JadxNodeRef.forMth(relatedMethod), ""));
            }
        }
        return new JadxCodeRename(JadxNodeRef.forMth(javaMethod), newName);
    }
    if (node instanceof JField) {
        return new JadxCodeRename(JadxNodeRef.forFld(((JField) node).getJavaField()), newName);
    }
    if (node instanceof JClass) {
        return new JadxCodeRename(JadxNodeRef.forCls(((JClass) node).getCls()), newName);
    }
    if (node instanceof JPackage) {
        return new JadxCodeRename(JadxNodeRef.forPkg(((JPackage) node).getFullName()), newName);
    }
    if (node instanceof JVariable) {
        JavaVariable javaVar = ((JVariable) node).getJavaVarNode();
        return new JadxCodeRename(JadxNodeRef.forMth(javaVar.getMth()), JadxCodeRef.forVar(javaVar), newName);
    }
    throw new JadxRuntimeException("Failed to build rename node for: " + node);
}
Also used : JVariable(jadx.gui.treemodel.JVariable) JField(jadx.gui.treemodel.JField) JavaVariable(jadx.api.JavaVariable) JClass(jadx.gui.treemodel.JClass) JPackage(jadx.gui.treemodel.JPackage) JavaMethod(jadx.api.JavaMethod) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) JMethod(jadx.gui.treemodel.JMethod) JadxCodeRename(jadx.api.data.impl.JadxCodeRename) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)115 BlockNode (jadx.core.dex.nodes.BlockNode)25 ArrayList (java.util.ArrayList)25 InsnNode (jadx.core.dex.nodes.InsnNode)24 ArgType (jadx.core.dex.instructions.args.ArgType)20 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)17 BitSet (java.util.BitSet)11 ClassNode (jadx.core.dex.nodes.ClassNode)10 MethodNode (jadx.core.dex.nodes.MethodNode)9 InsnArg (jadx.core.dex.instructions.args.InsnArg)8 SSAVar (jadx.core.dex.instructions.args.SSAVar)8 IOException (java.io.IOException)8 List (java.util.List)8 File (java.io.File)7 IRegion (jadx.core.dex.nodes.IRegion)6 Path (java.nio.file.Path)6 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)5 PhiInsn (jadx.core.dex.instructions.PhiInsn)5 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)5 FieldNode (jadx.core.dex.nodes.FieldNode)5