Commit 4cb34394 authored by skylot's avatar skylot

Merge pull request #36 from YASME-Tim/xmlparser

Added first implementation of an AndroidManifest.xml Parser! ;)
parents e3696af8 aacb8329
......@@ -41,6 +41,7 @@ subprojects {
}
dependencies {
compile 'com.google.android:android:4.1.1.4'
compile 'org.slf4j:slf4j-api:1.7.7'
testCompile 'ch.qos.logback:logback-classic:1.1.2'
......
......@@ -8,10 +8,17 @@ import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import jadx.core.xmlgen.BinaryXMLParser;
public class JadxCLI {
private static final Logger LOG = LoggerFactory.getLogger(JadxCLI.class);
public static void main(String[] args) throws JadxException {
/*
BinaryXMLParser bxp = new BinaryXMLParser(args[0],args[1]);
bxp.parse();
System.exit(4);
*/
try {
JadxCLIArgs jadxArgs = new JadxCLIArgs();
if (processArgs(jadxArgs, args)) {
......
......@@ -47,6 +47,9 @@ public final class JadxCLIArgs implements IJadxArgs {
@Parameter(names = {"-h", "--help"}, description = "print this help", help = true)
protected boolean printHelp = false;
@Parameter(names = {"-x", "--xml"}, description = "try to decode the AndroidManifest.xml, save at current dir")
protected boolean xmlTest = false;
private final List<File> input = new ArrayList<File>(1);
private File outputDir;
......@@ -165,6 +168,11 @@ public final class JadxCLIArgs implements IJadxArgs {
}
@Override
public boolean isXMLTest() {
return xmlTest;
}
@Override
public int getThreadsCount() {
return threadsCount;
}
......
......@@ -38,4 +38,9 @@ public class DefaultJadxArgs implements IJadxArgs {
public boolean isVerbose() {
return false;
}
@Override
public boolean isXMLTest() {
return false;
}
}
......@@ -16,4 +16,6 @@ public interface IJadxArgs {
boolean isShowInconsistentCode();
boolean isVerbose();
boolean isXMLTest();
}
......@@ -11,6 +11,7 @@ import jadx.core.utils.exceptions.DecodeException;
import jadx.core.utils.exceptions.JadxException;
import jadx.core.utils.exceptions.JadxRuntimeException;
import jadx.core.utils.files.InputFile;
import jadx.core.xmlgen.BinaryXMLParser;
import java.io.File;
import java.io.IOException;
......@@ -202,6 +203,16 @@ public final class JadxDecompiler {
reset();
root = new RootNode();
LOG.info("loading ...");
if(this.args.isXMLTest()) {
InputFile inf = inputFiles.get(0);
try {
BinaryXMLParser bxp = new BinaryXMLParser(InputFile.loadXMLBuffer(inf.getFile()), "./AndroidManifest.xml");
//BinaryXMLParser bxp = new BinaryXMLParser(InputFile.loadXMLBuffer(inf.getFile()), "AndroidManifest.xml");
bxp.parse();
} catch(IOException ioe) {
LOG.info("Decompiling AndroidManifest.xml failed!");
}
}
root.load(inputFiles);
}
......
......@@ -74,6 +74,29 @@ public class InputFile {
}
}
public static byte[] loadXMLBuffer(File file) throws IOException { // FIXME: Public.. Please fix
ZipFile zf = new ZipFile(file);
ZipEntry xml = zf.getEntry("AndroidManifest.xml");
if(null == xml) {
zf.close();
return null;
}
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
InputStream in = null;
try {
in = zf.getInputStream(xml);
byte[] buffer = new byte[(int) xml.getSize()]; // FIXME: long->int conversion loss
int count;
while ((count = in.read(buffer)) != -1) {
bytesOut.write(buffer, 0, count);
}
} finally {
if(null != in) in.close();
zf.close();
}
return bytesOut.toByteArray();
}
private static Dex loadFromZip(File file) throws IOException {
ZipFile zf = new ZipFile(file);
ZipEntry dex = zf.getEntry("classes.dex");
......
This diff is collapsed.
......@@ -10,7 +10,6 @@ import javax.swing.Icon;
import javax.swing.tree.DefaultMutableTreeNode;
public abstract class JNode extends DefaultMutableTreeNode {
public static JNode makeFrom(JavaNode node) {
if (node instanceof JavaClass) {
JClass p = (JClass) makeFrom(node.getDeclaringClass());
......
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