Skip to content

Commit

Permalink
fix(res): add missing namespace declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
nitram84 committed Feb 15, 2024
1 parent 0c33d72 commit a8b9740
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
private final Map<Integer, String> resNames;
private Map<String, String> nsMap;
private Set<String> nsMapGenerated;
private Set<String> definedNamespaces;
private final Map<String, String> tagAttrDeobfNames = new HashMap<>();

private ICodeWriter writer;
Expand Down Expand Up @@ -78,11 +79,13 @@ public synchronized ICodeInfo parse(InputStream inputStream) throws IOException
}
nsMapGenerated = new HashSet<>();
nsMap = new HashMap<>();
definedNamespaces = new HashSet<>();
writer = rootNode.makeCodeWriter();
writer.add("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
firstElement = true;
decode();
nsMap = null;
definedNamespaces = null;
ICodeInfo codeInfo = writer.finish();
this.classNameCache = null; // reset class name cache
return codeInfo;
Expand Down Expand Up @@ -269,15 +272,18 @@ private void parseElement() throws IOException {
int idIndex = is.readInt16();
int classIndex = is.readInt16();
int styleIndex = is.readInt16();
if ("manifest".equals(currentTag) || writer.getIndent() == 0) {
if ("manifest".equals(currentTag) || writer.getIndent() == 0 || definedNamespaces.size() != nsMap.size()) {
for (Map.Entry<String, String> entry : nsMap.entrySet()) {
String nsValue = getValidTagAttributeName(entry.getValue());
writer.add(" xmlns");
if (nsValue != null && !nsValue.trim().isEmpty()) {
writer.add(':');
writer.add(nsValue);
if (!definedNamespaces.contains(entry.getKey())) {
definedNamespaces.add(entry.getKey());
String nsValue = getValidTagAttributeName(entry.getValue());
writer.add(" xmlns");
if (nsValue != null && !nsValue.trim().isEmpty()) {
writer.add(':');
writer.add(nsValue);
}
writer.add("=\"").add(StringUtils.escapeXML(entry.getKey())).add('"');
}
writer.add("=\"").add(StringUtils.escapeXML(entry.getKey())).add('"');
}
}
boolean attrNewLine = attributeCount != 1 && this.attrNewLine;
Expand Down

0 comments on commit a8b9740

Please sign in to comment.