Search in sources :

Example 11 with JadxRuntimeException

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

the class ClsSet method load.

public void load(File input) throws IOException, DecodeException {
    String name = input.getName();
    InputStream inputStream = new FileInputStream(input);
    try {
        if (name.endsWith(CLST_EXTENSION)) {
            load(inputStream);
        } else if (name.endsWith(".jar")) {
            ZipInputStream in = new ZipInputStream(inputStream);
            try {
                ZipEntry entry = in.getNextEntry();
                while (entry != null) {
                    if (entry.getName().endsWith(CLST_EXTENSION)) {
                        load(in);
                    }
                    entry = in.getNextEntry();
                }
            } finally {
                close(in);
            }
        } else {
            throw new JadxRuntimeException("Unknown file format: " + name);
        }
    } finally {
        close(inputStream);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) DataInputStream(java.io.DataInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) FileInputStream(java.io.FileInputStream)

Example 12 with JadxRuntimeException

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

the class ClspGraph method addApp.

public void addApp(List<ClassNode> classes) {
    if (nameMap == null) {
        throw new JadxRuntimeException("Classpath must be loaded first");
    }
    int size = classes.size();
    NClass[] nClasses = new NClass[size];
    int k = 0;
    for (ClassNode cls : classes) {
        nClasses[k++] = addClass(cls);
    }
    for (int i = 0; i < size; i++) {
        nClasses[i].setParents(ClsSet.makeParentsArray(classes.get(i), nameMap));
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 13 with JadxRuntimeException

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

the class AnnotationGen method encodeValue.

// TODO: refactor this boilerplate code
public void encodeValue(CodeWriter code, Object val) {
    if (val == null) {
        code.add("null");
        return;
    }
    if (val instanceof String) {
        code.add(getStringUtils().unescapeString((String) val));
    } else if (val instanceof Integer) {
        code.add(TypeGen.formatInteger((Integer) val));
    } else if (val instanceof Character) {
        code.add(getStringUtils().unescapeChar((Character) val));
    } else if (val instanceof Boolean) {
        code.add(Boolean.TRUE.equals(val) ? "true" : "false");
    } else if (val instanceof Float) {
        code.add(TypeGen.formatFloat((Float) val));
    } else if (val instanceof Double) {
        code.add(TypeGen.formatDouble((Double) val));
    } else if (val instanceof Long) {
        code.add(TypeGen.formatLong((Long) val));
    } else if (val instanceof Short) {
        code.add(TypeGen.formatShort((Short) val));
    } else if (val instanceof Byte) {
        code.add(TypeGen.formatByte((Byte) val));
    } else if (val instanceof ArgType) {
        classGen.useType(code, (ArgType) val);
        code.add(".class");
    } else if (val instanceof FieldInfo) {
        // must be a static field
        FieldInfo field = (FieldInfo) val;
        InsnGen.makeStaticFieldAccess(code, field, classGen);
    } else if (val instanceof Iterable) {
        code.add('{');
        Iterator<?> it = ((Iterable) val).iterator();
        while (it.hasNext()) {
            Object obj = it.next();
            encodeValue(code, obj);
            if (it.hasNext()) {
                code.add(", ");
            }
        }
        code.add('}');
    } else if (val instanceof Annotation) {
        formatAnnotation(code, (Annotation) val);
    } else {
        // TODO: also can be method values
        throw new JadxRuntimeException("Can't decode value: " + val + " (" + val.getClass() + ")");
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) Annotation(jadx.core.dex.attributes.annotations.Annotation) Iterator(java.util.Iterator) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 14 with JadxRuntimeException

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

the class JadxDecompiler method getSaveExecutor.

private ExecutorService getSaveExecutor(boolean saveSources, boolean saveResources) {
    if (root == null) {
        throw new JadxRuntimeException("No loaded files");
    }
    int threadsCount = args.getThreadsCount();
    LOG.debug("processing threads count: {}", threadsCount);
    LOG.info("processing ...");
    ExecutorService executor = Executors.newFixedThreadPool(threadsCount);
    File sourcesOutDir;
    File resOutDir;
    if (args.isExportAsGradleProject()) {
        ExportGradleProject export = new ExportGradleProject(root, outDir);
        export.init();
        sourcesOutDir = export.getSrcOutDir();
        resOutDir = export.getResOutDir();
    } else {
        sourcesOutDir = outDir;
        resOutDir = outDir;
    }
    if (saveSources) {
        appendSourcesSave(executor, sourcesOutDir);
    }
    if (saveResources) {
        appendResourcesSave(executor, resOutDir);
    }
    return executor;
}
Also used : ExportGradleProject(jadx.core.export.ExportGradleProject) ExecutorService(java.util.concurrent.ExecutorService) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) InputFile(jadx.core.utils.files.InputFile) File(java.io.File)

Example 15 with JadxRuntimeException

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

the class ProcessTryCatchRegions method searchTryCatchDominators.

private static void searchTryCatchDominators(MethodNode mth, Map<BlockNode, TryCatchBlock> tryBlocksMap) {
    Set<TryCatchBlock> tryBlocks = new HashSet<TryCatchBlock>();
    // collect all try/catch blocks
    for (BlockNode block : mth.getBasicBlocks()) {
        CatchAttr c = block.get(AType.CATCH_BLOCK);
        if (c != null) {
            tryBlocks.add(c.getTryBlock());
        }
    }
    // for each try block search nearest dominator block
    for (TryCatchBlock tb : tryBlocks) {
        if (tb.getHandlersCount() == 0) {
            LOG.warn("No exception handlers in catch block, method: {}", mth);
            continue;
        }
        BitSet bs = new BitSet(mth.getBasicBlocks().size());
        for (ExceptionHandler excHandler : tb.getHandlers()) {
            SplitterBlockAttr splitter = excHandler.getHandlerBlock().get(AType.SPLITTER_BLOCK);
            if (splitter != null) {
                BlockNode block = splitter.getBlock();
                bs.set(block.getId());
            }
        }
        List<BlockNode> domBlocks = BlockUtils.bitSetToBlocks(mth, bs);
        BlockNode domBlock;
        if (domBlocks.size() != 1) {
            domBlock = BlockUtils.getTopBlock(domBlocks);
            if (domBlock == null) {
                throw new JadxRuntimeException("Exception block dominator not found, method:" + mth + ". bs: " + domBlocks);
            }
        } else {
            domBlock = domBlocks.get(0);
        }
        TryCatchBlock prevTB = tryBlocksMap.put(domBlock, tb);
        if (prevTB != null) {
            ErrorsCounter.methodError(mth, "Failed to process nested try/catch");
        }
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler) SplitterBlockAttr(jadx.core.dex.trycatch.SplitterBlockAttr) BitSet(java.util.BitSet) TryCatchBlock(jadx.core.dex.trycatch.TryCatchBlock) CatchAttr(jadx.core.dex.trycatch.CatchAttr) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) HashSet(java.util.HashSet)

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