Commit 261ba464 authored by Skylot's avatar Skylot

resources: support text chuck in binary xml (fix #84)

parent 2ab7524e
......@@ -95,4 +95,23 @@ public class StringUtils {
}
return sb.toString();
}
public static String escapeXML(String str) {
int len = str.length();
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++) {
char c = str.charAt(i);
switch (c) {
case '&': sb.append("&amp;"); break;
case '<': sb.append("&lt;"); break;
case '>': sb.append("&gt;"); break;
case '"': sb.append("&quot;"); break;
case '\'': sb.append("&apos;"); break;
default:
sb.append(c);
break;
}
}
return sb.toString();
}
}
......@@ -6,6 +6,7 @@ import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.nodes.DexNode;
import jadx.core.dex.nodes.FieldNode;
import jadx.core.dex.nodes.RootNode;
import jadx.core.utils.StringUtils;
import jadx.core.utils.exceptions.JadxRuntimeException;
import jadx.core.xmlgen.entry.ValuesParser;
......@@ -123,6 +124,9 @@ public class BinaryXMLParser extends CommonBinaryParser {
case RES_XML_START_NAMESPACE_TYPE:
parseNameSpace();
break;
case RES_XML_CDATA_TYPE:
parseCData();
break;
case RES_XML_END_NAMESPACE_TYPE:
parseNameSpaceEnd();
break;
......@@ -181,6 +185,27 @@ public class BinaryXMLParser extends CommonBinaryParser {
nsURI = strings[endURI];
}
private void parseCData() throws IOException {
if (is.readInt16() != 0x10) {
die("CDATA header is not 0x10");
}
if (is.readInt32() != 0x1C) {
die("CDATA header chunk is not 0x1C");
}
int lineNumber = is.readInt32();
is.skip(4);
int strIndex = is.readInt32();
String str = strings[strIndex];
writer.startLine().addIndent();
writer.attachSourceLine(lineNumber);
writer.add(StringUtils.escapeXML(str.trim())); // TODO: wrap into CDATA for easier reading
int size = is.readInt16();
is.skip(size - 2);
}
private void parseElement() throws IOException {
if (firstElement) {
firstElement = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment