From e73612b4d2d80168c4dc185acbb4df045b57855c Mon Sep 17 00:00:00 2001 From: bagipro <15173437+bagipro@users.noreply.github.com> Date: Tue, 23 Jan 2024 00:01:38 +0900 Subject: [PATCH] feat(res): disable XML pretty print (PR #2087) Co-authored-by: bagipro --- README.md | 1 + jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java | 8 ++++++++ jadx-core/src/main/java/jadx/api/JadxArgs.java | 11 +++++++++++ .../main/java/jadx/core/xmlgen/BinaryXMLParser.java | 7 ++++--- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f11a1df4580..6604650039f 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ options: 'simple' - simplified instructions (linear, with goto's) 'fallback' - raw instructions without modifications --show-bad-code - show inconsistent code (incorrectly decompiled) + --no-xml-pretty-print - do not prettify XML --no-imports - disable use of imports, always write entire package name --no-debug-info - disable debug info parsing and processing --add-debug-lines - add comments with debug line numbers if available diff --git a/jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java b/jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java index 47e2784dec5..a8f66babdf5 100644 --- a/jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java +++ b/jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java @@ -81,6 +81,9 @@ public class JadxCLIArgs { @Parameter(names = { "--show-bad-code" }, description = "show inconsistent code (incorrectly decompiled)") protected boolean showInconsistentCode = false; + @Parameter(names = { "--no-xml-pretty-print" }, description = "do not prettify XML") + protected boolean skipXmlPrettyPrint = false; + @Parameter(names = { "--no-imports" }, description = "disable use of imports, always write entire package name") protected boolean useImports = true; @@ -331,6 +334,7 @@ public JadxArgs toJadxArgs() { args.setEscapeUnicode(escapeUnicode); args.setRespectBytecodeAccModifiers(respectBytecodeAccessModifiers); args.setExportAsGradleProject(exportAsGradleProject); + args.setSkipXmlPrettyPrint(skipXmlPrettyPrint); args.setUseImports(useImports); args.setDebugInfo(debugInfo); args.setInsertDebugLines(addDebugLines); @@ -504,6 +508,10 @@ public boolean isExportAsGradleProject() { return exportAsGradleProject; } + public boolean isSkipXmlPrettyPrint() { + return skipXmlPrettyPrint; + } + public boolean isRenameCaseSensitive() { return renameFlags.contains(RenameEnum.CASE); } diff --git a/jadx-core/src/main/java/jadx/api/JadxArgs.java b/jadx-core/src/main/java/jadx/api/JadxArgs.java index 36edb9f737a..f86e973f441 100644 --- a/jadx-core/src/main/java/jadx/api/JadxArgs.java +++ b/jadx-core/src/main/java/jadx/api/JadxArgs.java @@ -124,6 +124,8 @@ public class JadxArgs implements Closeable { private boolean respectBytecodeAccModifiers = false; private boolean exportAsGradleProject = false; + private boolean skipXmlPrettyPrint = false; + private boolean fsCaseSensitive; public enum RenameEnum { @@ -512,6 +514,14 @@ public void setExportAsGradleProject(boolean exportAsGradleProject) { this.exportAsGradleProject = exportAsGradleProject; } + public boolean isSkipXmlPrettyPrint() { + return skipXmlPrettyPrint; + } + + public void setSkipXmlPrettyPrint(boolean skipXmlPrettyPrint) { + this.skipXmlPrettyPrint = skipXmlPrettyPrint; + } + public boolean isFsCaseSensitive() { return fsCaseSensitive; } @@ -733,6 +743,7 @@ public String toString() { + ", replaceConsts=" + replaceConsts + ", respectBytecodeAccModifiers=" + respectBytecodeAccModifiers + ", exportAsGradleProject=" + exportAsGradleProject + + ", skipXmlPrettyPrint=" + skipXmlPrettyPrint + ", fsCaseSensitive=" + fsCaseSensitive + ", renameFlags=" + renameFlags + ", outputFormat=" + outputFormat diff --git a/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java b/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java index b2a1f7d393b..c0df3b6276c 100644 --- a/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java +++ b/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java @@ -37,8 +37,6 @@ public class BinaryXMLParser extends CommonBinaryParser { private static final Logger LOG = LoggerFactory.getLogger(BinaryXMLParser.class); - private static final boolean ATTR_NEW_LINE = true; - private final Map resNames; private Map nsMap; private Set nsMapGenerated; @@ -59,8 +57,11 @@ public class BinaryXMLParser extends CommonBinaryParser { private Map classNameCache; + private final boolean attrNewLine; + public BinaryXMLParser(RootNode rootNode) { this.rootNode = rootNode; + this.attrNewLine = !rootNode.getArgs().isSkipXmlPrettyPrint(); try { ConstStorage constStorage = rootNode.getConstValues(); resNames = constStorage.getResourcesNames(); @@ -279,7 +280,7 @@ private void parseElement() throws IOException { writer.add("=\"").add(StringUtils.escapeXML(entry.getKey())).add('"'); } } - boolean attrNewLine = attributeCount != 1 && ATTR_NEW_LINE; + boolean attrNewLine = attributeCount != 1 && this.attrNewLine; for (int i = 0; i < attributeCount; i++) { parseAttribute(i, attrNewLine); }