Skip to content

Commit

Permalink
feat(res): disable XML pretty print (PR #2087)
Browse files Browse the repository at this point in the history
Co-authored-by: bagipro <bugi@bugi>
  • Loading branch information
bagipro and bagipro authored Jan 22, 2024
1 parent a19aec9 commit e73612b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -504,6 +508,10 @@ public boolean isExportAsGradleProject() {
return exportAsGradleProject;
}

public boolean isSkipXmlPrettyPrint() {
return skipXmlPrettyPrint;
}

public boolean isRenameCaseSensitive() {
return renameFlags.contains(RenameEnum.CASE);
}
Expand Down
11 changes: 11 additions & 0 deletions jadx-core/src/main/java/jadx/api/JadxArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -733,6 +743,7 @@ public String toString() {
+ ", replaceConsts=" + replaceConsts
+ ", respectBytecodeAccModifiers=" + respectBytecodeAccModifiers
+ ", exportAsGradleProject=" + exportAsGradleProject
+ ", skipXmlPrettyPrint=" + skipXmlPrettyPrint
+ ", fsCaseSensitive=" + fsCaseSensitive
+ ", renameFlags=" + renameFlags
+ ", outputFormat=" + outputFormat
Expand Down
7 changes: 4 additions & 3 deletions jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, String> resNames;
private Map<String, String> nsMap;
private Set<String> nsMapGenerated;
Expand All @@ -59,8 +57,11 @@ public class BinaryXMLParser extends CommonBinaryParser {

private Map<String, ClassNode> 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();
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e73612b

Please sign in to comment.