Search in sources :

Example 91 with JadxRuntimeException

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

the class JadxDecompiler method getJavaClassByNode.

@Nullable("For not generated classes")
@ApiStatus.Internal
public JavaClass getJavaClassByNode(ClassNode cls) {
    JavaClass javaClass = classesMap.get(cls);
    if (javaClass != null && javaClass.getClassNode() == cls) {
        return javaClass;
    }
    // load parent class if inner
    ClassNode parentClass = cls.getTopParentClass();
    if (parentClass.contains(AFlag.DONT_GENERATE)) {
        return null;
    }
    if (parentClass != cls) {
        JavaClass parentJavaClass = classesMap.get(parentClass);
        if (parentJavaClass == null) {
            getClasses();
            parentJavaClass = classesMap.get(parentClass);
        }
        loadJavaClass(parentJavaClass);
        javaClass = classesMap.get(cls);
        if (javaClass != null) {
            return javaClass;
        }
    }
    // class or parent classes can be excluded from generation
    if (cls.hasNotGeneratedParent()) {
        return null;
    }
    throw new JadxRuntimeException("JavaClass not found by ClassNode: " + cls);
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) Nullable(org.jetbrains.annotations.Nullable)

Example 92 with JadxRuntimeException

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

the class JadxDecompiler method appendSourcesSave.

private void appendSourcesSave(List<Runnable> tasks, File outDir) {
    Predicate<String> classFilter = args.getClassFilter();
    List<JavaClass> classes = getClasses();
    List<JavaClass> processQueue = new ArrayList<>(classes.size());
    for (JavaClass cls : classes) {
        if (cls.getClassNode().contains(AFlag.DONT_GENERATE)) {
            continue;
        }
        if (classFilter != null && !classFilter.test(cls.getFullName())) {
            continue;
        }
        processQueue.add(cls);
    }
    List<List<JavaClass>> batches;
    try {
        batches = decompileScheduler.buildBatches(processQueue);
    } catch (Exception e) {
        throw new JadxRuntimeException("Decompilation batches build failed", e);
    }
    for (List<JavaClass> decompileBatch : batches) {
        tasks.add(() -> {
            for (JavaClass cls : decompileBatch) {
                try {
                    ICodeInfo code = cls.getCodeInfo();
                    SaveCode.save(outDir, cls.getClassNode(), code);
                } catch (Exception e) {
                    LOG.error("Error saving class: {}", cls, e);
                }
            }
        });
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 93 with JadxRuntimeException

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

the class InsnDecoder method invoke.

private InsnNode invoke(InsnData insn, InvokeType type, boolean isRange) {
    IMethodRef mthRef = InsnDataUtils.getMethodRef(insn);
    if (mthRef == null) {
        throw new JadxRuntimeException("Failed to load method reference for insn: " + insn);
    }
    MethodInfo mthInfo = MethodInfo.fromRef(root, mthRef);
    return new InvokeNode(mthInfo, insn, type, isRange);
}
Also used : IMethodRef(jadx.api.plugins.input.data.IMethodRef) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) MethodInfo(jadx.core.dex.info.MethodInfo)

Example 94 with JadxRuntimeException

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

the class CustomLambdaCall method buildLambdaMethodCall.

public static InvokeCustomNode buildLambdaMethodCall(MethodNode mth, InsnData insn, boolean isRange, List<EncodedValue> values) {
    IMethodHandle callMthHandle = (IMethodHandle) values.get(4).getValue();
    if (callMthHandle.getType().isField()) {
        throw new JadxRuntimeException("Not yet supported");
    }
    InvokeCustomNode resNode = buildMethodCall(mth, insn, isRange, values, callMthHandle);
    int resReg = insn.getResultReg();
    if (resReg != -1) {
        resNode.setResult(InsnArg.reg(resReg, mth.getReturnType()));
    }
    return resNode;
}
Also used : IMethodHandle(jadx.api.plugins.input.data.IMethodHandle) InvokeCustomNode(jadx.core.dex.instructions.InvokeCustomNode) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 95 with JadxRuntimeException

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

the class BlockNode method lock.

public void lock() {
    try {
        List<BlockNode> successorsList = successors;
        successors = lockList(successorsList);
        cleanSuccessors = successorsList == cleanSuccessors ? this.successors : lockList(cleanSuccessors);
        predecessors = lockList(predecessors);
        dominatesOn = lockList(dominatesOn);
        if (domFrontier == null) {
            throw new JadxRuntimeException("Dominance frontier not set for block: " + this);
        }
    } catch (Exception e) {
        throw new JadxRuntimeException("Failed to lock block: " + this, e);
    }
}
Also used : JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

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