提交 99768940 编写于 作者: S Skylot

core: skip decoding for plain text xml (fix #82)

上级 76a0608a
......@@ -53,6 +53,7 @@ public final class ResourcesLoader {
}
ZipFile zipFile = null;
InputStream inputStream = null;
Object result = null;
try {
zipFile = new ZipFile(zipRef.getZipFile());
ZipEntry entry = zipFile.getEntry(zipRef.getEntryName());
......@@ -60,7 +61,7 @@ public final class ResourcesLoader {
throw new IOException("Zip entry not found: " + zipRef);
}
inputStream = new BufferedInputStream(zipFile.getInputStream(entry));
return decoder.decode(entry.getSize(), inputStream);
result = decoder.decode(entry.getSize(), inputStream);
} catch (Exception e) {
throw new JadxException("Error decode: " + zipRef.getEntryName(), e);
} finally {
......@@ -75,6 +76,7 @@ public final class ResourcesLoader {
LOG.debug("Error close zip file: {}", zipRef, e);
}
}
return result;
}
static CodeWriter loadContent(final JadxDecompiler jadxRef, final ResourceFile rf) {
......@@ -148,7 +150,7 @@ public final class ResourcesLoader {
// LOG.debug("Add resource entry: {}, size: {}", name, entry.getSize());
}
private static CodeWriter loadToCodeWriter(InputStream is) throws IOException {
public static CodeWriter loadToCodeWriter(InputStream is) throws IOException {
CodeWriter cw = new CodeWriter();
ByteArrayOutputStream baos = new ByteArrayOutputStream(READ_BUFFER_SIZE);
byte[] buffer = new byte[READ_BUFFER_SIZE];
......
package jadx.core.xmlgen;
import jadx.api.ResourcesLoader;
import jadx.core.codegen.CodeWriter;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.nodes.DexNode;
......@@ -81,22 +82,30 @@ public class BinaryXMLParser extends CommonBinaryParser {
}
public synchronized CodeWriter parse(InputStream inputStream) throws IOException {
is = new ParserStream(inputStream);
if (!isBinaryXml()) {
return ResourcesLoader.loadToCodeWriter(inputStream);
}
writer = new CodeWriter();
writer.add("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
is = new ParserStream(inputStream);
firstElement = true;
decode();
writer.finish();
return writer;
}
void decode() throws IOException {
if (is.readInt16() != 0x0003) {
die("Version is not 3");
}
if (is.readInt16() != 0x0008) {
die("Size of header is not 8");
private boolean isBinaryXml() throws IOException {
is.mark(4);
int v = is.readInt16(); // version
int h = is.readInt16(); // header size
if (v == 0x0003 && h == 0x0008) {
return true;
}
is.reset();
return false;
}
void decode() throws IOException {
int size = is.readInt32();
while (is.getPos() < size) {
int type = is.readInt16();
......
......@@ -132,6 +132,17 @@ public class ParserStream {
checkPos(expectedOffset, error);
}
public void mark(int len) throws IOException {
if (!input.markSupported()) {
throw new IOException("Mark not supported for input stream " + input.getClass());
}
input.mark(len);
}
public void reset() throws IOException {
input.reset();
}
@Override
public String toString() {
return "pos: 0x" + Long.toHexString(readPos);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册