Search in sources :

Example 26 with JadxRuntimeException

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

the class ClsSet method load.

public void load(RootNode root) {
    List<ClassNode> list = root.getClasses(true);
    Map<String, NClass> names = new HashMap<String, NClass>(list.size());
    int k = 0;
    for (ClassNode cls : list) {
        String clsRawName = cls.getRawName();
        if (cls.getAccessFlags().isPublic()) {
            NClass nClass = new NClass(clsRawName, k);
            if (names.put(clsRawName, nClass) != null) {
                throw new JadxRuntimeException("Duplicate class: " + clsRawName);
            }
            k++;
        } else {
            names.put(clsRawName, null);
        }
    }
    classes = new NClass[k];
    k = 0;
    for (ClassNode cls : list) {
        if (cls.getAccessFlags().isPublic()) {
            NClass nClass = getCls(cls.getRawName(), names);
            if (nClass == null) {
                throw new JadxRuntimeException("Missing class: " + cls);
            }
            nClass.setParents(makeParentsArray(cls, names));
            classes[k] = nClass;
            k++;
        }
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) HashMap(java.util.HashMap) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 27 with JadxRuntimeException

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

the class ClsSet method save.

void save(File output) throws IOException {
    FileUtils.makeDirsForFile(output);
    BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(output));
    try {
        String outputName = output.getName();
        if (outputName.endsWith(CLST_EXTENSION)) {
            save(outputStream);
        } else if (outputName.endsWith(".jar")) {
            ZipOutputStream out = new ZipOutputStream(outputStream);
            try {
                out.putNextEntry(new ZipEntry(CLST_PKG_PATH + "/" + CLST_FILENAME));
                save(out);
            } finally {
                close(out);
            }
        } else {
            throw new JadxRuntimeException("Unknown file format: " + outputName);
        }
    } finally {
        close(outputStream);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 28 with JadxRuntimeException

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

the class JadxDecompiler method save.

private void save(boolean saveSources, boolean saveResources) {
    try {
        ExecutorService ex = getSaveExecutor(saveSources, saveResources);
        ex.shutdown();
        ex.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException e) {
        throw new JadxRuntimeException("Save interrupted", e);
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 29 with JadxRuntimeException

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

the class ModVisitor method makeFilledArrayInsn.

private static InsnNode makeFilledArrayInsn(MethodNode mth, FillArrayNode insn) {
    ArgType insnArrayType = insn.getResult().getType();
    ArgType insnElementType = insnArrayType.getArrayElement();
    ArgType elType = insn.getElementType();
    if (!elType.isTypeKnown() && insnElementType.isPrimitive()) {
        if (elType.contains(insnElementType.getPrimitiveType())) {
            elType = insnElementType;
        }
    }
    if (!elType.equals(insnElementType) && !insnArrayType.equals(ArgType.OBJECT)) {
        ErrorsCounter.methodError(mth, "Incorrect type for fill-array insn " + InsnUtils.formatOffset(insn.getOffset()) + ", element type: " + elType + ", insn element type: " + insnElementType);
    }
    if (!elType.isTypeKnown()) {
        LOG.warn("Unknown array element type: {} in mth: {}", elType, mth);
        elType = insnElementType.isTypeKnown() ? insnElementType : elType.selectFirst();
        if (elType == null) {
            throw new JadxRuntimeException("Null array element type");
        }
    }
    insn.mergeElementType(mth.dex(), elType);
    elType = insn.getElementType();
    List<LiteralArg> list = insn.getLiteralArgs();
    InsnNode filledArr = new FilledNewArrayNode(elType, list.size());
    filledArr.setResult(insn.getResult());
    for (LiteralArg arg : list) {
        FieldNode f = mth.getParentClass().getConstFieldByLiteralArg(arg);
        if (f != null) {
            InsnNode fGet = new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0);
            filledArr.addArg(InsnArg.wrapArg(fGet));
        } else {
            filledArr.addArg(arg);
        }
    }
    return filledArr;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) FieldNode(jadx.core.dex.nodes.FieldNode) FilledNewArrayNode(jadx.core.dex.instructions.FilledNewArrayNode) LiteralArg(jadx.core.dex.instructions.args.LiteralArg) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode)

Example 30 with JadxRuntimeException

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

the class CodeShrinker method canMoveBetweenBlocks.

private static boolean canMoveBetweenBlocks(InsnNode assignInsn, BlockNode assignBlock, BlockNode useBlock, InsnNode useInsn) {
    if (!BlockUtils.isPathExists(assignBlock, useBlock)) {
        return false;
    }
    List<RegisterArg> argsList = ArgsInfo.getArgs(assignInsn);
    BitSet args = new BitSet();
    for (RegisterArg arg : argsList) {
        args.set(arg.getRegNum());
    }
    boolean startCheck = false;
    for (InsnNode insn : assignBlock.getInstructions()) {
        if (startCheck && (!insn.canReorder() || ArgsInfo.usedArgAssign(insn, args))) {
            return false;
        }
        if (insn == assignInsn) {
            startCheck = true;
        }
    }
    Set<BlockNode> pathsBlocks = BlockUtils.getAllPathsBlocks(assignBlock, useBlock);
    pathsBlocks.remove(assignBlock);
    pathsBlocks.remove(useBlock);
    for (BlockNode block : pathsBlocks) {
        for (InsnNode insn : block.getInstructions()) {
            if (!insn.canReorder() || ArgsInfo.usedArgAssign(insn, args)) {
                return false;
            }
        }
    }
    for (InsnNode insn : useBlock.getInstructions()) {
        if (insn == useInsn) {
            return true;
        }
        if (!insn.canReorder() || ArgsInfo.usedArgAssign(insn, args)) {
            return false;
        }
    }
    throw new JadxRuntimeException("Can't process instruction move : " + assignBlock);
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) EmptyBitSet(jadx.core.utils.EmptyBitSet) BitSet(java.util.BitSet) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Aggregations

JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)35 BlockNode (jadx.core.dex.nodes.BlockNode)14 InsnNode (jadx.core.dex.nodes.InsnNode)8 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)6 ArrayList (java.util.ArrayList)6 ArgType (jadx.core.dex.instructions.args.ArgType)5 BitSet (java.util.BitSet)5 SSAVar (jadx.core.dex.instructions.args.SSAVar)4 PhiInsn (jadx.core.dex.instructions.PhiInsn)3 InsnArg (jadx.core.dex.instructions.args.InsnArg)3 ClassNode (jadx.core.dex.nodes.ClassNode)3 IContainer (jadx.core.dex.nodes.IContainer)3 IRegion (jadx.core.dex.nodes.IRegion)3 File (java.io.File)3 ZipEntry (java.util.zip.ZipEntry)3 LoopInfo (jadx.core.dex.attributes.nodes.LoopInfo)2 PhiListAttr (jadx.core.dex.attributes.nodes.PhiListAttr)2 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)2 FieldNode (jadx.core.dex.nodes.FieldNode)2 IBlock (jadx.core.dex.nodes.IBlock)2