Commit c242a62b authored by YASME-Tim's avatar YASME-Tim

Write xml to a given output file instead of stdout.

parent 6c91bce6
...@@ -14,7 +14,7 @@ public class JadxCLI { ...@@ -14,7 +14,7 @@ public class JadxCLI {
private static final Logger LOG = LoggerFactory.getLogger(JadxCLI.class); private static final Logger LOG = LoggerFactory.getLogger(JadxCLI.class);
public static void main(String[] args) throws JadxException { public static void main(String[] args) throws JadxException {
BinaryXMLParser bxp = new BinaryXMLParser(args[0]); BinaryXMLParser bxp = new BinaryXMLParser(args[0],args[1]);
bxp.parse(); bxp.parse();
System.exit(4); System.exit(4);
try { try {
......
...@@ -9,6 +9,7 @@ import java.io.FileNotFoundException; ...@@ -9,6 +9,7 @@ import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.io.PrintWriter;
public class BinaryXMLParser { public class BinaryXMLParser {
private byte[] bytes; private byte[] bytes;
...@@ -16,8 +17,14 @@ public class BinaryXMLParser { ...@@ -16,8 +17,14 @@ public class BinaryXMLParser {
private int count; private int count;
private String nsPrefix="ERROR"; private String nsPrefix="ERROR";
private int numtabs=-1; private int numtabs=-1;
public BinaryXMLParser(String xmlfilepath) { PrintWriter writer;
System.out.println(xmlfilepath); public BinaryXMLParser(String xmlfilepath, String xmloutfilepath) {
//System.out.println(xmlfilepath);
try {
writer = new PrintWriter(xmloutfilepath,"UTF-8");
} catch(FileNotFoundException fnfe) { die("FNFE"); }
catch(UnsupportedEncodingException uee) { die("UEE"); }
if(null==writer) die("null==writer");
File manifest = new File(xmlfilepath); File manifest = new File(xmlfilepath);
if(null==manifest) die("null==manifest"); if(null==manifest) die("null==manifest");
bytes = new byte[(int) manifest.length()]; bytes = new byte[(int) manifest.length()];
...@@ -55,6 +62,7 @@ public class BinaryXMLParser { ...@@ -55,6 +62,7 @@ public class BinaryXMLParser {
else die("Type: " + Integer.toHexString(type) + " not yet implemented"); else die("Type: " + Integer.toHexString(type) + " not yet implemented");
//System.out.println("COUNT: "+Integer.toHexString(count)); //System.out.println("COUNT: "+Integer.toHexString(count));
} }
writer.close();
//die("Done"); //die("Done");
} }
...@@ -88,7 +96,7 @@ public class BinaryXMLParser { ...@@ -88,7 +96,7 @@ public class BinaryXMLParser {
System.arraycopy(bytes, count, str, 0, strlen*2); System.arraycopy(bytes, count, str, 0, strlen*2);
count+=strlen*2; count+=strlen*2;
strings[i] = new String(str, Charset.forName("UTF-16LE")); strings[i] = new String(str, Charset.forName("UTF-16LE"));
System.out.println("index i["+i+"] string: " + strings[i]); //System.out.println("index i["+i+"] string: " + strings[i]);
count+=2; count+=2;
} }
} }
...@@ -96,12 +104,12 @@ public class BinaryXMLParser { ...@@ -96,12 +104,12 @@ public class BinaryXMLParser {
private void parseResourceMap() { private void parseResourceMap() {
if(cInt16(bytes, count) != 0x8) die("Header size of resmap is not 8!"); if(cInt16(bytes, count) != 0x8) die("Header size of resmap is not 8!");
int rhsize = cInt32(bytes, count); int rhsize = cInt32(bytes, count);
System.out.println("RHeader Size: " + rhsize); //System.out.println("RHeader Size: " + rhsize);
int[] ids = new int[(rhsize-8)/4]; int[] ids = new int[(rhsize-8)/4];
for(int i=0; i<ids.length; i++) { for(int i=0; i<ids.length; i++) {
ids[i]=cInt32(bytes, count); ids[i]=cInt32(bytes, count);
System.out.println("i["+i+"] ID: "+ids[i]); //System.out.println("i["+i+"] ID: "+ids[i]);
System.out.println("Hex: 0x0" + Integer.toHexString(ids[i]) + " should be: " + strings[i]); //System.out.println("Hex: 0x0" + Integer.toHexString(ids[i]) + " should be: " + strings[i]);
} }
} }
...@@ -114,10 +122,10 @@ public class BinaryXMLParser { ...@@ -114,10 +122,10 @@ public class BinaryXMLParser {
int comment = cInt32(bytes, count); int comment = cInt32(bytes, count);
//System.out.println("Comment: 0x" + Integer.toHexString(comment)); //System.out.println("Comment: 0x" + Integer.toHexString(comment));
int beginPrefix = cInt32(bytes, count); int beginPrefix = cInt32(bytes, count);
System.out.println("Prefix: " + strings[beginPrefix]); //System.out.println("Prefix: " + strings[beginPrefix]);
nsPrefix = strings[beginPrefix]; nsPrefix = strings[beginPrefix];
int beginURI = cInt32(bytes, count); int beginURI = cInt32(bytes, count);
System.out.println("URI: " + strings[beginURI]); //System.out.println("URI: " + strings[beginURI]);
//System.out.println("COUNT: "+Integer.toHexString(count)); //System.out.println("COUNT: "+Integer.toHexString(count));
} }
...@@ -130,10 +138,10 @@ public class BinaryXMLParser { ...@@ -130,10 +138,10 @@ public class BinaryXMLParser {
int comment = cInt32(bytes, count); int comment = cInt32(bytes, count);
//System.out.println("Comment: 0x" + Integer.toHexString(comment)); //System.out.println("Comment: 0x" + Integer.toHexString(comment));
int endPrefix = cInt32(bytes, count); int endPrefix = cInt32(bytes, count);
System.out.println("Prefix: " + strings[endPrefix]); //System.out.println("Prefix: " + strings[endPrefix]);
nsPrefix = strings[endPrefix]; nsPrefix = strings[endPrefix];
int endURI = cInt32(bytes, count); int endURI = cInt32(bytes, count);
System.out.println("URI: " + strings[endURI]); //System.out.println("URI: " + strings[endURI]);
} }
private void parseElement() { private void parseElement() {
...@@ -150,8 +158,8 @@ public class BinaryXMLParser { ...@@ -150,8 +158,8 @@ public class BinaryXMLParser {
//System.out.println("Namespace: 0x" + Integer.toHexString(startNS)); //System.out.println("Namespace: 0x" + Integer.toHexString(startNS));
int startNSName = cInt32(bytes, count); // what to do with this id? int startNSName = cInt32(bytes, count); // what to do with this id?
//System.out.println("Namespace name: " + strings[startNSName]); //System.out.println("Namespace name: " + strings[startNSName]);
for(int i=0; i<numtabs; i++) System.out.print("\t"); for(int i=0; i<numtabs; i++) writer.print("\t");
System.out.print("<" + strings[startNSName]); writer.print("<" + strings[startNSName]);
int attributeStart = cInt16(bytes, count); int attributeStart = cInt16(bytes, count);
if(attributeStart != 0x14) die("startNS's attributeStart is not 0x14"); if(attributeStart != 0x14) die("startNS's attributeStart is not 0x14");
int attributeSize = cInt16(bytes, count); int attributeSize = cInt16(bytes, count);
...@@ -164,7 +172,7 @@ public class BinaryXMLParser { ...@@ -164,7 +172,7 @@ public class BinaryXMLParser {
//System.out.println("startNS: classIndex: " + classIndex); //System.out.println("startNS: classIndex: " + classIndex);
int styleIndex = cInt16(bytes, count); int styleIndex = cInt16(bytes, count);
//System.out.println("startNS: styleIndex: " + styleIndex); //System.out.println("startNS: styleIndex: " + styleIndex);
if(attributeCount>0) System.out.print(" "); if(attributeCount>0) writer.print(" ");
for(int i=0; i<attributeCount; i++) { for(int i=0; i<attributeCount; i++) {
int attributeNS = cInt32(bytes, count); int attributeNS = cInt32(bytes, count);
int attributeName = cInt32(bytes, count); int attributeName = cInt32(bytes, count);
...@@ -184,19 +192,19 @@ public class BinaryXMLParser { ...@@ -184,19 +192,19 @@ public class BinaryXMLParser {
System.out.println("ai["+i+"] dt: " + attrValDataType); System.out.println("ai["+i+"] dt: " + attrValDataType);
System.out.println("ai["+i+"] d: " + attrValData); System.out.println("ai["+i+"] d: " + attrValData);
*/ */
if(attributeNS != -1) System.out.print(nsPrefix+":"); if(attributeNS != -1) writer.print(nsPrefix+":");
if(attrValDataType==0x3) System.out.print(strings[attributeName] + "=\"" + strings[attrValData]+"\""); if(attrValDataType==0x3) writer.print(strings[attributeName] + "=\"" + strings[attrValData]+"\"");
else if(attrValDataType==0x10) System.out.print(strings[attributeName] + "=\"" + attrValData+"\""); else if(attrValDataType==0x10) writer.print(strings[attributeName] + "=\"" + attrValData+"\"");
else if(attrValDataType==0x12) { else if(attrValDataType==0x12) {
// TODO: data is always -1, FIXME // TODO: data is always -1, FIXME
if(attrValData==0) System.out.print(strings[attributeName] + "=\"false\""); if(attrValData==0) writer.print(strings[attributeName] + "=\"false\"");
else if(attrValData==1 || attrValData==-1) System.out.print(strings[attributeName] + "=\"true\""); else if(attrValData==1 || attrValData==-1) writer.print(strings[attributeName] + "=\"true\"");
else System.out.print(strings[attributeName] + "=\"UNKNOWN\""); else writer.print(strings[attributeName] + "=\"UNKNOWN\"");
} }
else System.out.print(strings[attributeName] + " = UNKNOWN DATA TYPE: " + attrValDataType); else writer.print(strings[attributeName] + " = UNKNOWN DATA TYPE: " + attrValDataType);
System.out.print(" "); writer.print(" ");
} }
System.out.println(">"); writer.println(">");
} }
private void parseElementEnd() { private void parseElementEnd() {
...@@ -209,10 +217,10 @@ public class BinaryXMLParser { ...@@ -209,10 +217,10 @@ public class BinaryXMLParser {
//System.out.println("Comment: 0x" + Integer.toHexString(comment)); //System.out.println("Comment: 0x" + Integer.toHexString(comment));
int elementNS = cInt32(bytes, count); int elementNS = cInt32(bytes, count);
int elementName = cInt32(bytes, count); int elementName = cInt32(bytes, count);
for(int i=0; i<numtabs; i++) System.out.print("\t"); for(int i=0; i<numtabs; i++) writer.print("\t");
System.out.print("</"); writer.print("</");
if(elementNS != -1) System.out.print(strings[elementNS]+":"); if(elementNS != -1) writer.print(strings[elementNS]+":");
System.out.println(strings[elementName]+">"); writer.println(strings[elementName]+">");
numtabs-=1; numtabs-=1;
} }
......
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