feat(res): disable XML pretty print (PR #2087)

Co-authored-by: bagipro <bugi@bugi>
This commit is contained in:
bagipro
2024-01-23 00:01:38 +09:00
committed by GitHub
parent a19aec9d9f
commit e73612b4d2
4 changed files with 24 additions and 3 deletions
+1
View File
@@ -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
@@ -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 class JadxCLIArgs {
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 class JadxCLIArgs {
return exportAsGradleProject;
}
public boolean isSkipXmlPrettyPrint() {
return skipXmlPrettyPrint;
}
public boolean isRenameCaseSensitive() {
return renameFlags.contains(RenameEnum.CASE);
}
@@ -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 class JadxArgs implements Closeable {
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 class JadxArgs implements Closeable {
+ ", replaceConsts=" + replaceConsts
+ ", respectBytecodeAccModifiers=" + respectBytecodeAccModifiers
+ ", exportAsGradleProject=" + exportAsGradleProject
+ ", skipXmlPrettyPrint=" + skipXmlPrettyPrint
+ ", fsCaseSensitive=" + fsCaseSensitive
+ ", renameFlags=" + renameFlags
+ ", outputFormat=" + outputFormat
@@ -37,8 +37,6 @@ import jadx.core.xmlgen.entry.ValuesParser;
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;
@@ -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();
@@ -279,7 +280,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
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);
}