fix: improve error reporting for instruction decode failure (#1046)
This commit is contained in:
@@ -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()) + ':');
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <T, R> List<R> collectionMap(Collection<T> list, Function<T, R> mapFunc) {
|
||||
|
||||
Reference in New Issue
Block a user