diff --git a/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java b/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java index 4c5c9b4d953..8aed8616aa5 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java +++ b/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java @@ -290,6 +290,10 @@ public void addFallbackMethodCode(CodeWriter code, FallbackOption fallbackOption code.startLine("// Can't load method instructions."); return; } + if (insnArr.length > 100) { + code.startLine("// Method dump skipped, instructions count: " + insnArr.length); + return; + } code.incIndent(); if (mth.getThisArg() != null) { code.startLine(nameGen.useArg(mth.getThisArg())).add(" = this;"); @@ -305,6 +309,7 @@ public enum FallbackOption { } public static void addFallbackInsns(CodeWriter code, MethodNode mth, InsnNode[] insnArr, FallbackOption option) { + int startIndent = code.getIndent(); InsnGen insnGen = new InsnGen(getFallbackMethodGen(mth), true); boolean attachInsns = mth.root().getArgs().isJsonOutput(); InsnNode prevInsn = null; @@ -349,8 +354,9 @@ public static void addFallbackInsns(CodeWriter code, MethodNode mth, InsnNode[] if (catchAttr != null) { code.add(" // " + catchAttr); } - } catch (CodegenException e) { + } catch (Exception e) { LOG.debug("Error generate fallback instruction: ", e.getCause()); + code.setIndent(startIndent); code.startLine("// error: " + insn); } prevInsn = insn; diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/DepthTraversal.java b/jadx-core/src/main/java/jadx/core/dex/visitors/DepthTraversal.java index 76235c25fb9..6f9fe85ea9c 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/DepthTraversal.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/DepthTraversal.java @@ -1,5 +1,6 @@ package jadx.core.dex.visitors; +import jadx.core.dex.attributes.AType; import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.MethodNode; import jadx.core.utils.DebugChecks; @@ -19,6 +20,9 @@ public static void visit(IDexTreeVisitor visitor, ClassNode cls) { public static void visit(IDexTreeVisitor visitor, MethodNode mth) { try { + if (mth.contains(AType.JADX_ERROR)) { + return; + } visitor.visit(mth); if (DebugChecks.checksEnabled) { DebugChecks.runChecksAfterVisitor(mth, visitor); diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockProcessor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockProcessor.java index 0f9c929edcd..1c7d697e619 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockProcessor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockProcessor.java @@ -69,8 +69,7 @@ private static void processBlocksTree(MethodNode mth) { updateExitBlocks(mth); if (i++ > 100) { - mth.addWarn("CFG modification limit reached, blocks count: " + mth.getBasicBlocks().size()); - break; + throw new JadxRuntimeException("CFG modification limit reached, blocks count: " + mth.getBasicBlocks().size()); } } checkForUnreachableBlocks(mth); diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeSearch.java b/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeSearch.java index c54db5d23fa..b2c587d9a65 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeSearch.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeSearch.java @@ -34,6 +34,7 @@ public class TypeSearch { private static final Logger LOG = LoggerFactory.getLogger(TypeSearch.class); + private static final int VARS_PROCESS_LIMIT = 5_000; private static final int CANDIDATES_COUNT_LIMIT = 10; private static final int SEARCH_ITERATION_LIMIT = 1_000_000; @@ -50,6 +51,11 @@ public TypeSearch(MethodNode mth) { } public boolean run() { + if (mth.getSVars().size() > VARS_PROCESS_LIMIT) { + mth.addWarnComment("Multi-variable search skipped. Vars limit reached: " + mth.getSVars().size() + + " (expected less than " + VARS_PROCESS_LIMIT + ")"); + return false; + } mth.getSVars().forEach(this::fillTypeCandidates); mth.getSVars().forEach(this::collectConstraints);