fixes issue 469, added -m / --match-original

fixes xml output not having newline after xml declaration
This commit is contained in:
Connor Tumbleson 2013-06-12 10:04:28 -05:00
parent 9f03d7d35c
commit 832978a549
5 changed files with 49 additions and 8 deletions

View File

@ -141,6 +141,9 @@ public class Main {
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
decoder.setFrameworkDir(cli.getOptionValue("p"));
}
if (cli.hasOption("m") || cli.hasOption("match-original")) {
decoder.setAnalysisMode(true, false);
}
if (cli.hasOption("o") || cli.hasOption("output")) {
decoder.setOutDir(new File(cli.getOptionValue("o")));
} else {
@ -281,6 +284,10 @@ public class Main {
.withDescription("Decode in debug mode. Check project page for more info.")
.create("d");
Option analysisOption = OptionBuilder.withLongOpt("-match-original")
.withDescription("Keeps files to closest to original as possible. Prevents rebuild.")
.create("m");
Option debugLinePrefix = OptionBuilder.withLongOpt("debug-line-prefix")
.withDescription("Smali line prefix when decoding in debug mode. Default is \"a=0;// \".")
.hasArg(true)
@ -368,6 +375,7 @@ public class Main {
DecodeOptions.addOption(debugDecOption);
DecodeOptions.addOption(noDbgOption);
DecodeOptions.addOption(keepResOption);
DecodeOptions.addOption(analysisOption);
BuildOptions.addOption(debugBuiOption);
BuildOptions.addOption(aaptOption);
@ -408,6 +416,7 @@ public class Main {
for (Object op : frameOptions.getOptions()) {
allOptions.addOption((Option)op);
}
allOptions.addOption(analysisOption);
allOptions.addOption(debugLinePrefix);
allOptions.addOption(debugDecOption);
allOptions.addOption(noDbgOption);

View File

@ -65,6 +65,7 @@ public class ApkDecoder {
public void decode() throws AndrolibException, IOException {
File outDir = getOutDir();
setAnalysisMode(mAnalysisMode, true);
if (!mForceDelete && outDir.exists()) {
throw new OutDirExistsException();
@ -157,6 +158,18 @@ public class ApkDecoder {
mDebug = debug;
}
public void setAnalysisMode(boolean mode, boolean pass) throws AndrolibException{
mAnalysisMode = mode;
// only set mResTable, once it exists
if (pass) {
if (mResTable == null) {
mResTable = getResTable();
}
mResTable.setAnalysisMode(mode);
}
}
public void setDebugLinePrefix(String debugLinePrefix) {
mDebugLinePrefix = debugLinePrefix;
}
@ -339,4 +352,5 @@ public class ApkDecoder {
private String mFrameworkDir = null;
private boolean mBakDeb = true;
private boolean mCompressResources = false;
private boolean mAnalysisMode = false;
}

View File

@ -37,10 +37,7 @@ import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
@ -179,6 +176,8 @@ final public class AndrolibResources {
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE,"yes");
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(filePath));
transformer.transform(source, result);
@ -221,7 +220,9 @@ final public class AndrolibResources {
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE,"yes");
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(filePath));
transformer.transform(source, result);
@ -261,6 +262,8 @@ final public class AndrolibResources {
// save manifest
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE,"yes");
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(filePath));
transformer.transform(source, result);
@ -295,8 +298,10 @@ final public class AndrolibResources {
+ File.separator + "AndroidManifest.xml");
// Remove versionName / versionCode (aapt API 16)
remove_manifest_versions(outDir.getAbsolutePath()
+ File.separator + "/AndroidManifest.xml");
if (resTable.getAnalysisMode() == false) {
remove_manifest_versions(outDir.getAbsolutePath()
+ File.separator + "/AndroidManifest.xml");
}
if (inApk.containsDir("res")) {
in = inApk.getDir("res");

View File

@ -34,6 +34,7 @@ public class ResTable {
private final Set<ResPackage> mFramePackages = new LinkedHashSet<ResPackage>();
private String mFrameTag;
private boolean mAnalysisMode = false;
private Map<String, String> mSdkInfo = new LinkedHashMap<String, String>();
private Map<String, String> mPackageInfo = new LinkedHashMap<String, String>();
@ -121,6 +122,10 @@ public class ResTable {
public void setFrameTag(String tag) {
mFrameTag = tag;
}
public void setAnalysisMode(boolean mode) {
mAnalysisMode = mode;
}
public void clearSdkInfo() {
mSdkInfo.clear();
@ -154,6 +159,10 @@ public class ResTable {
return mSdkInfo;
}
public boolean getAnalysisMode() {
return mAnalysisMode;
}
public Map<String, String> getUnknownFiles() {
return mUnknownFiles;
}

View File

@ -132,7 +132,11 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
}
}
}
return true;
if (resTable.getAnalysisMode() == true) {
return false;
} else {
return true;
}
}
};