Skip to content

Commit

Permalink
fix: adjust limits to skip processing of large methods (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Nov 10, 2020
1 parent 0deafb7 commit e054ea6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion jadx-core/src/main/java/jadx/core/codegen/MethodGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;");
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down

1 comment on commit e054ea6

@sladen
Copy link

@sladen sladen commented on e054ea6 Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit prevents eyeballing code in the case that decompilation fails; with this patch, jadx is preventing observation of what is going on: see #1079 (comment)

Please sign in to comment.