use of jadx.core.dex.attributes.nodes.JadxError in project jadx by skylot.
the class CustomStringConcat method buildStringConcat.
public static InsnNode buildStringConcat(InsnData insn, boolean isRange, List<EncodedValue> values) {
try {
int argsCount = values.size() - 3 + insn.getRegsCount();
InsnNode concat = new InsnNode(InsnType.STR_CONCAT, argsCount);
String recipe = (String) values.get(3).getValue();
processRecipe(recipe, concat, values, insn);
int resReg = insn.getResultReg();
if (resReg != -1) {
concat.setResult(InsnArg.reg(resReg, ArgType.STRING));
}
return concat;
} catch (Exception e) {
InsnNode nop = new InsnNode(InsnType.NOP, 0);
nop.add(AFlag.SYNTHETIC);
nop.addAttr(AType.JADX_ERROR, new JadxError("Failed to process dynamic string concat: " + e.getMessage(), e));
return nop;
}
}
use of jadx.core.dex.attributes.nodes.JadxError in project jadx by skylot.
the class MethodGen method addFallbackInsns.
public static void addFallbackInsns(ICodeWriter code, MethodNode mth, InsnNode[] insnArr, FallbackOption option) {
int startIndent = code.getIndent();
InsnGen insnGen = new InsnGen(getFallbackMethodGen(mth), true);
InsnNode prevInsn = null;
for (InsnNode insn : insnArr) {
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()) + ':');
code.incIndent();
}
if (insn.getType() == InsnType.NOP) {
continue;
}
try {
boolean escapeComment = isCommentEscapeNeeded(insn, option);
if (escapeComment) {
code.decIndent();
code.startLine("*/");
code.startLine("// ");
} else {
code.startLineWithNum(insn.getSourceLine());
}
InsnCodeOffset.attach(code, insn);
RegisterArg resArg = insn.getResult();
if (resArg != null) {
ArgType varType = resArg.getInitType();
if (varType.isTypeKnown()) {
code.add(varType.toString()).add(' ');
}
}
insnGen.makeInsn(insn, code, InsnGen.Flags.INLINE);
if (escapeComment) {
code.startLine("/*");
code.incIndent();
}
CatchAttr catchAttr = insn.get(AType.EXC_CATCH);
if (catchAttr != null) {
code.add(" // " + catchAttr);
}
CodeGenUtils.addCodeComments(code, mth, insn);
} catch (Exception e) {
LOG.debug("Error generate fallback instruction: ", e.getCause());
code.setIndent(startIndent);
code.startLine("// error: " + insn);
}
prevInsn = insn;
}
}
use of jadx.core.dex.attributes.nodes.JadxError in project jadx by skylot.
the class ErrorsCounter method addError.
private synchronized <N extends IDexNode & IAttributeNode> String addError(N node, String error, @Nullable Throwable e) {
errorNodes.add(node);
errorsCount++;
String msg = formatMsg(node, error);
if (PRINT_MTH_SIZE && node instanceof MethodNode) {
msg = "[" + ((MethodNode) node).getInsnsCount() + "] " + msg;
}
if (e == null) {
LOG.error(msg);
} else if (e instanceof StackOverflowError) {
LOG.error("{}, error: StackOverflowError", msg);
} else if (e instanceof JadxOverflowException) {
// don't print full stack trace
String details = e.getMessage();
e = new JadxOverflowException(details);
if (details == null || details.isEmpty()) {
LOG.error("{}", msg);
} else {
LOG.error("{}, details: {}", msg, details);
}
} else {
LOG.error(msg, e);
}
node.addAttr(AType.JADX_ERROR, new JadxError(error, e));
return msg;
}
use of jadx.core.dex.attributes.nodes.JadxError in project jadx by skylot.
the class InsnDecoder method process.
public InsnNode[] process(ICodeReader codeReader) {
InsnNode[] instructions = new InsnNode[codeReader.getUnitsCount()];
codeReader.visitInstructions(rawInsn -> {
int offset = rawInsn.getOffset();
InsnNode insn;
try {
rawInsn.decode();
insn = decode(rawInsn);
} catch (Exception 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;
}
use of jadx.core.dex.attributes.nodes.JadxError in project jadx by skylot.
the class MethodGen method addFallbackMethodCode.
public void addFallbackMethodCode(ICodeWriter code, FallbackOption fallbackOption) {
if (fallbackOption != FALLBACK_MODE) {
// preserve error before unload
List<JadxError> errors = mth.getAll(AType.JADX_ERROR);
try {
// load original instructions
mth.unload();
mth.load();
for (IDexTreeVisitor visitor : Jadx.getFallbackPassesList()) {
DepthTraversal.visit(visitor, mth);
}
errors.forEach(err -> mth.addAttr(AType.JADX_ERROR, err));
} catch (Exception e) {
LOG.error("Error reload instructions in fallback mode:", e);
code.startLine("// Can't load method instructions: " + e.getMessage());
return;
} finally {
errors.forEach(err -> mth.addAttr(AType.JADX_ERROR, err));
}
}
InsnNode[] insnArr = mth.getInstructions();
if (insnArr == null) {
code.startLine("// Can't load method instructions.");
return;
}
if (fallbackOption == COMMENTED_DUMP && mth.getCommentsLevel() != CommentsLevel.DEBUG) {
long insnCountEstimate = Stream.of(insnArr).filter(Objects::nonNull).filter(insn -> insn.getType() != InsnType.NOP).count();
if (insnCountEstimate > 100) {
code.incIndent();
code.startLine("Method dump skipped, instructions count: " + insnArr.length);
if (code.isMetadataSupported()) {
code.startLine("To view this dump change 'Code comments level' option to 'DEBUG'");
} else {
code.startLine("To view this dump add '--comments-level debug' option");
}
code.decIndent();
return;
}
}
code.incIndent();
if (mth.getThisArg() != null) {
code.startLine(nameGen.useArg(mth.getThisArg())).add(" = this;");
}
addFallbackInsns(code, mth, insnArr, fallbackOption);
code.decIndent();
}
Aggregations