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 786d0a63e..a31c20422 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java +++ b/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java @@ -16,6 +16,7 @@ import jadx.core.Jadx; import jadx.core.dex.attributes.AFlag; import jadx.core.dex.attributes.AType; import jadx.core.dex.attributes.annotations.MethodParameters; +import jadx.core.dex.attributes.nodes.JadxError; import jadx.core.dex.attributes.nodes.JumpInfo; import jadx.core.dex.attributes.nodes.MethodOverrideAttr; import jadx.core.dex.info.AccessInfo; @@ -323,6 +324,12 @@ public class MethodGen { if (insn == null) { continue; } + if (insn.contains(AType.JADX_ERROR)) { + for (JadxError error : insn.getAll(AType.JADX_ERROR)) { + code.startLine("// ").add(error.getError()); + } + continue; + } if (option != BLOCK_DUMP && needLabel(insn, prevInsn)) { code.decIndent(); code.startLine(getLabelName(insn.getOffset()) + ':'); diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java b/jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java index 0c54bf5b7..703003e42 100644 --- a/jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java +++ b/jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java @@ -9,6 +9,8 @@ import jadx.api.plugins.input.insns.InsnData; import jadx.api.plugins.input.insns.custom.IArrayPayload; import jadx.api.plugins.input.insns.custom.ISwitchPayload; import jadx.core.Consts; +import jadx.core.dex.attributes.AType; +import jadx.core.dex.attributes.nodes.JadxError; import jadx.core.dex.info.FieldInfo; import jadx.core.dex.info.MethodInfo; import jadx.core.dex.instructions.args.ArgType; @@ -40,11 +42,12 @@ public class InsnDecoder { try { rawInsn.decode(); insn = decode(rawInsn); - insn.setOffset(offset); } catch (Exception e) { - LOG.error("Failed to decode insn: " + rawInsn + ", method: " + method, e); + method.addError("Failed to decode insn: " + rawInsn + ", method: " + method, e); insn = new InsnNode(InsnType.NOP, 0); + insn.addAttr(AType.JADX_ERROR, new JadxError("decode failed: " + e.getMessage(), e)); } + insn.setOffset(offset); instructions[offset] = insn; }); return instructions; diff --git a/jadx-core/src/main/java/jadx/core/utils/Utils.java b/jadx-core/src/main/java/jadx/core/utils/Utils.java index 45cb361e4..c965fdb21 100644 --- a/jadx-core/src/main/java/jadx/core/utils/Utils.java +++ b/jadx-core/src/main/java/jadx/core/utils/Utils.java @@ -182,6 +182,17 @@ public class Utils { } prevElement = stackTraceElement; } + // stop condition not found -> just cut tail to any jadx class + for (int i = length - 1; i >= 0; i--) { + String clsName = stackTrace[i].getClassName(); + if (clsName.startsWith("jadx.")) { + if (clsName.startsWith("jadx.tests.")) { + continue; + } + th.setStackTrace(Arrays.copyOfRange(stackTrace, 0, i)); + return; + } + } } public static List collectionMap(Collection list, Function mapFunc) {