diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/AttrList.java b/jadx-core/src/main/java/jadx/core/dex/attributes/AttrList.java index d378b7e3e..86e18ffa4 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/AttrList.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/AttrList.java @@ -3,6 +3,7 @@ package jadx.core.dex.attributes; import java.util.ArrayList; import java.util.List; +import jadx.core.codegen.CodeWriter; import jadx.core.utils.Utils; public class AttrList implements IAttribute { @@ -25,6 +26,6 @@ public class AttrList implements IAttribute { @Override public String toString() { - return Utils.listToString(list, "\n"); + return Utils.listToString(list, CodeWriter.NL); } } diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/JadxError.java b/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/JadxError.java index d42cfdd0f..6b8667516 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/JadxError.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/JadxError.java @@ -4,6 +4,7 @@ import java.util.Objects; import org.jetbrains.annotations.NotNull; +import jadx.core.codegen.CodeWriter; import jadx.core.utils.Utils; public class JadxError implements Comparable { @@ -58,7 +59,7 @@ public class JadxError implements Comparable { str.append(cause.getClass()); str.append(':'); str.append(cause.getMessage()); - str.append('\n'); + str.append(CodeWriter.NL); str.append(Utils.getStackTrace(cause)); } return str.toString(); diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/LocalVarsDebugInfoAttr.java b/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/LocalVarsDebugInfoAttr.java index c4efe9235..ad2966e84 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/LocalVarsDebugInfoAttr.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/LocalVarsDebugInfoAttr.java @@ -7,6 +7,8 @@ import jadx.core.dex.attributes.IAttribute; import jadx.core.dex.visitors.debuginfo.LocalVar; import jadx.core.utils.Utils; +import static jadx.core.codegen.CodeWriter.NL; + public class LocalVarsDebugInfoAttr implements IAttribute { private final List localVars; @@ -25,6 +27,6 @@ public class LocalVarsDebugInfoAttr implements IAttribute { @Override public String toString() { - return "Debug Info:\n " + Utils.listToString(localVars, "\n "); + return "Debug Info:" + NL + " " + Utils.listToString(localVars, NL + " "); } } diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/PhiListAttr.java b/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/PhiListAttr.java index cba4c9010..d4bf9f34a 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/PhiListAttr.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/nodes/PhiListAttr.java @@ -7,6 +7,8 @@ import jadx.core.dex.attributes.AType; import jadx.core.dex.attributes.IAttribute; import jadx.core.dex.instructions.PhiInsn; +import static com.google.common.base.Ascii.NL; + public class PhiListAttr implements IAttribute { private final List list = new LinkedList<>(); @@ -28,7 +30,7 @@ public class PhiListAttr implements IAttribute { sb.append('r').append(phiInsn.getResult().getRegNum()).append(' '); } for (PhiInsn phiInsn : list) { - sb.append("\n ").append(phiInsn).append(' ').append(phiInsn.getAttributesString()); + sb.append(NL).append(" ").append(phiInsn).append(' ').append(phiInsn.getAttributesString()); } return sb.toString(); } diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java b/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java index 86fee5ce1..58012dc4b 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java @@ -10,6 +10,7 @@ import org.jetbrains.annotations.Nullable; import com.android.dx.io.instructions.DecodedInstruction; +import jadx.core.codegen.CodeWriter; import jadx.core.dex.attributes.AFlag; import jadx.core.dex.attributes.nodes.LineAttrNode; import jadx.core.dex.instructions.InsnType; @@ -408,9 +409,9 @@ public class InsnNode extends LineAttrNode { sb.append(argsStr); } else { // wrap args - String separator = "\n "; + String separator = CodeWriter.NL + " "; sb.append(separator).append(Utils.listToString(arguments, separator)); - sb.append('\n'); + sb.append(CodeWriter.NL); } } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/MethodInvokeVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/MethodInvokeVisitor.java index acd725e23..d44559752 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/MethodInvokeVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/MethodInvokeVisitor.java @@ -28,6 +28,8 @@ import jadx.core.dex.visitors.typeinference.TypeCompareEnum; import jadx.core.utils.Utils; import jadx.core.utils.exceptions.JadxRuntimeException; +import static jadx.core.codegen.CodeWriter.NL; + @JadxVisitor( name = "MethodInvokeVisitor", desc = "Process additional info for method invocation (overload, vararg)", @@ -249,13 +251,13 @@ public class MethodInvokeVisitor extends AbstractVisitor { if (argsCount == 1) { return mthDetails.getArgTypes(); } - // TODO: try to minimize casts count - parentMth.addComment("JADX DEBUG: Failed to find minimal casts for resolve overloaded methods, cast all args instead" - + "\n method: " + mthDetails - + "\n arg types: " + compilerVarTypes - + "\n candidates:\n " + Utils.listToString(overloadedMethods, "\n ")); + + NL + " method: " + mthDetails + + NL + " arg types: " + compilerVarTypes + + NL + " candidates:" + + NL + " " + Utils.listToString(overloadedMethods, NL + " ")); + // not resolved -> cast all args return mthDetails.getArgTypes(); } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/DebugInfoParseVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/DebugInfoParseVisitor.java index 3bc4368ae..185ab03a3 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/DebugInfoParseVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/DebugInfoParseVisitor.java @@ -20,6 +20,8 @@ import jadx.core.utils.ErrorsCounter; import jadx.core.utils.Utils; import jadx.core.utils.exceptions.JadxException; +import static jadx.core.codegen.CodeWriter.NL; + @JadxVisitor( name = "Debug Info Parser", desc = "Parse debug information (variable names and types, instruction lines)", @@ -42,7 +44,7 @@ public class DebugInfoParseVisitor extends AbstractVisitor { } catch (Exception e) { mth.addComment("JADX WARNING: Error to parse debug info: " + ErrorsCounter.formatMsg(mth, e.getMessage()) - + '\n' + Utils.getStackTrace(e)); + + NL + Utils.getStackTrace(e)); } } diff --git a/jadx-core/src/main/java/jadx/core/utils/DebugChecks.java b/jadx-core/src/main/java/jadx/core/utils/DebugChecks.java index 409d9ea41..3a1b3b28a 100644 --- a/jadx-core/src/main/java/jadx/core/utils/DebugChecks.java +++ b/jadx-core/src/main/java/jadx/core/utils/DebugChecks.java @@ -21,6 +21,8 @@ import jadx.core.dex.visitors.PrepareForCodeGen; import jadx.core.dex.visitors.RenameVisitor; import jadx.core.utils.exceptions.JadxRuntimeException; +import static jadx.core.codegen.CodeWriter.NL; + /** * Check invariants and information consistency for registers and SSA variables */ @@ -86,7 +88,8 @@ public class DebugChecks { List useList = sVar.getUseList(); boolean assignReg = insn.getResult() == reg; if (!assignReg && !Utils.containsInListByRef(useList, reg)) { - throw new JadxRuntimeException("Incorrect use list in ssa var: " + sVar + ", register not listed.\n insn: " + insn); + throw new JadxRuntimeException("Incorrect use list in ssa var: " + sVar + ", register not listed." + + NL + " insn: " + insn); } for (RegisterArg useArg : useList) { checkRegisterArg(mth, useArg); @@ -107,8 +110,8 @@ public class DebugChecks { } BlockNode parentInsnBlock = BlockUtils.getBlockByInsn(mth, parentInsn); if (parentInsnBlock == null) { - parentInsnBlock = BlockUtils.getBlockByInsn(mth, parentInsn); - throw new JadxRuntimeException("Parent insn not found in blocks tree for: " + reg + ",\n insn: " + parentInsn); + throw new JadxRuntimeException("Parent insn not found in blocks tree for: " + reg + + NL + " insn: " + parentInsn); } } } diff --git a/jadx-core/src/main/java/jadx/core/utils/DebugUtils.java b/jadx-core/src/main/java/jadx/core/utils/DebugUtils.java index 8947f731e..217e78a38 100644 --- a/jadx-core/src/main/java/jadx/core/utils/DebugUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/DebugUtils.java @@ -31,6 +31,8 @@ import jadx.core.dex.visitors.regions.TracedRegionVisitor; import jadx.core.utils.exceptions.CodegenException; import jadx.core.utils.exceptions.JadxException; +import static jadx.core.codegen.CodeWriter.NL; + @Deprecated @TestOnly public class DebugUtils { @@ -98,7 +100,7 @@ public class DebugUtils { CodeWriter cw = new CodeWriter(); cw.startLine('|').add(mth.toString()); printRegion(mth, region, cw, "| ", printInsns); - LOG.debug("\n{}", cw.finish().getCodeStr()); + LOG.debug("{}{}", NL, cw.finish().getCodeStr()); } private static void printRegion(MethodNode mth, IRegion region, CodeWriter cw, String indent, boolean printInsns) { @@ -126,7 +128,7 @@ public class DebugUtils { ig.makeInsn(insn, code); String codeStr = code.finish().getCodeStr(); - List insnStrings = Arrays.stream(codeStr.split(CodeWriter.NL)) + List insnStrings = Arrays.stream(codeStr.split(NL)) .filter(StringUtils::notBlank) .map(s -> "|> " + s) .collect(Collectors.toList()); @@ -148,7 +150,7 @@ public class DebugUtils { private static void printWithAttributes(CodeWriter cw, String indent, String codeStr, IAttributeNode attrNode) { String str = attrNode.isAttrStorageEmpty() ? codeStr : codeStr + ' ' + attrNode.getAttributesString(); - List attrStrings = Arrays.stream(str.split(CodeWriter.NL)) + List attrStrings = Arrays.stream(str.split(NL)) .filter(StringUtils::notBlank) .collect(Collectors.toList()); Iterator it = attrStrings.iterator(); diff --git a/jadx-core/src/main/java/jadx/core/utils/InsnRemover.java b/jadx-core/src/main/java/jadx/core/utils/InsnRemover.java index 97baa0e1c..d5ff17af0 100644 --- a/jadx-core/src/main/java/jadx/core/utils/InsnRemover.java +++ b/jadx-core/src/main/java/jadx/core/utils/InsnRemover.java @@ -20,6 +20,8 @@ import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.MethodNode; import jadx.core.utils.exceptions.JadxRuntimeException; +import static jadx.core.codegen.CodeWriter.NL; + /** * Helper class for correct instructions removing, * can be used while iterating over instructions list @@ -130,10 +132,10 @@ public class InsnRemover { return; } if (Consts.DEBUG) { // TODO: enable this - throw new JadxRuntimeException("Can't remove SSA var, still in use, count: " + useCount - + ", list:\n " + ssaVar.getUseList().stream() + throw new JadxRuntimeException("Can't remove SSA var, still in use, count: " + useCount + ", list:" + + NL + " " + ssaVar.getUseList().stream() .map(arg -> arg + " from " + arg.getParentInsn()) - .collect(Collectors.joining("\n "))); + .collect(Collectors.joining(NL + " "))); } } @@ -168,8 +170,10 @@ public class InsnRemover { } } if (!found && Consts.DEBUG) { // TODO: enable this - throw new JadxRuntimeException("Can't remove insn:\n " + rem - + "\nnot found in list:\n " + Utils.listToString(insns, "\n ")); + throw new JadxRuntimeException("Can't remove insn:" + + NL + " " + rem + + NL + " not found in list:" + + NL + " " + Utils.listToString(insns, NL + " ")); } } } diff --git a/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java b/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java index 6b1cf9ee2..27c3bf188 100644 --- a/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java +++ b/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java @@ -26,6 +26,7 @@ import jadx.core.utils.exceptions.DecodeException; import jadx.core.utils.exceptions.JadxException; import jadx.core.utils.exceptions.JadxRuntimeException; +import static jadx.core.codegen.CodeWriter.NL; import static jadx.core.utils.files.FileUtils.isApkFile; import static jadx.core.utils.files.FileUtils.isZipDexFile; @@ -197,7 +198,7 @@ public class InputFile { } return pathList; } catch (Exception e) { - throw new DecodeException("java class to dex conversion error:\n " + e.getMessage(), e); + throw new DecodeException("java class to dex conversion error:" + NL + " " + e.getMessage(), e); } finally { if (j2d.isError()) { LOG.warn("dx message: {}", j2d.getDxErrors()); diff --git a/jadx-gui/src/main/java/jadx/gui/treemodel/JResource.java b/jadx-gui/src/main/java/jadx/gui/treemodel/JResource.java index 569f28e0b..72932a374 100644 --- a/jadx-gui/src/main/java/jadx/gui/treemodel/JResource.java +++ b/jadx-gui/src/main/java/jadx/gui/treemodel/JResource.java @@ -17,11 +17,14 @@ import jadx.api.ResourceFileContent; import jadx.api.ResourceType; import jadx.api.ResourcesLoader; import jadx.api.impl.SimpleCodeInfo; +import jadx.core.utils.Utils; import jadx.core.xmlgen.ResContainer; import jadx.gui.utils.NLS; import jadx.gui.utils.OverlayIcon; import jadx.gui.utils.UiUtils; +import static jadx.core.codegen.CodeWriter.NL; + public class JResource extends JLoadableNode implements Comparable { private static final long serialVersionUID = -201018424302612434L; @@ -151,7 +154,7 @@ public class JResource extends JLoadableNode implements Comparable { return ResourcesLoader.loadToCodeWriter(is); }); } catch (Exception e) { - return new SimpleCodeInfo("Failed to load resource file: \n" + jadx.core.utils.Utils.getStackTrace(e)); + return new SimpleCodeInfo("Failed to load resource file:" + NL + Utils.getStackTrace(e)); } case DECODED_DATA: diff --git a/jadx-gui/src/main/java/jadx/gui/ui/ImagePanel.java b/jadx-gui/src/main/java/jadx/gui/ui/ImagePanel.java index f3d64a029..7693d3a12 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/ImagePanel.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/ImagePanel.java @@ -18,6 +18,8 @@ import jadx.core.xmlgen.ResContainer; import jadx.gui.treemodel.JResource; import jadx.gui.ui.codearea.AbstractCodeArea; +import static jadx.core.codegen.CodeWriter.NL; + public class ImagePanel extends ContentPanel { private static final long serialVersionUID = 4071356367073142688L; @@ -30,7 +32,7 @@ public class ImagePanel extends ContentPanel { add(imageViewer.getComponent()); } catch (Exception e) { RSyntaxTextArea textArea = AbstractCodeArea.getDefaultArea(panel.getMainWindow()); - textArea.setText("Image load error: \n" + Utils.getStackTrace(e)); + textArea.setText("Image load error:" + NL + Utils.getStackTrace(e)); add(textArea); } }