Search in sources :

Example 66 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 67 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 68 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 69 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)

Example 70 with JadxRuntimeException

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

the class IfMakerHelper method getCrossBlock.

private static BlockNode getCrossBlock(BlockNode first, BlockNode second) {
    if (isSameBlocks(first, second)) {
        return second;
    }
    BlockNode firstSkip = BlockUtils.skipSyntheticSuccessor(first);
    if (isSameBlocks(firstSkip, second)) {
        return second;
    }
    BlockNode secondSkip = BlockUtils.skipSyntheticSuccessor(second);
    if (isSameBlocks(firstSkip, secondSkip) || isSameBlocks(first, secondSkip)) {
        return secondSkip;
    }
    throw new JadxRuntimeException("Unexpected merge pattern");
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) 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