2012-09-20 03:27:35 +02:00
|
|
|
/**
|
2014-10-24 01:14:48 +02:00
|
|
|
* Copyright 2014 Ryszard Wiśniewski <brut.alll@gmail.com>
|
2012-09-20 03:27:35 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package brut.androlib.res;
|
|
|
|
|
|
|
|
import brut.androlib.AndrolibException;
|
2014-11-02 03:07:02 +01:00
|
|
|
import brut.androlib.ApkOptions;
|
2012-09-20 03:27:35 +02:00
|
|
|
import brut.androlib.err.CantFindFrameworkResException;
|
|
|
|
import brut.androlib.res.data.*;
|
|
|
|
import brut.androlib.res.decoder.*;
|
|
|
|
import brut.androlib.res.decoder.ARSCDecoder.ARSCData;
|
|
|
|
import brut.androlib.res.decoder.ARSCDecoder.FlagsOffset;
|
|
|
|
import brut.androlib.res.util.*;
|
|
|
|
import brut.androlib.res.xml.ResValuesXmlSerializable;
|
|
|
|
import brut.common.BrutException;
|
|
|
|
import brut.directory.*;
|
|
|
|
import brut.util.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import java.util.zip.*;
|
2012-12-19 02:40:42 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
import javax.xml.parsers.ParserConfigurationException;
|
2013-06-12 17:04:28 +02:00
|
|
|
import javax.xml.transform.*;
|
2012-12-19 02:40:42 +01:00
|
|
|
import javax.xml.transform.dom.DOMSource;
|
|
|
|
import javax.xml.transform.stream.StreamResult;
|
|
|
|
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.NamedNodeMap;
|
|
|
|
import org.w3c.dom.Node;
|
|
|
|
|
2012-09-20 03:27:35 +02:00
|
|
|
import org.apache.commons.io.IOUtils;
|
2012-12-19 02:40:42 +01:00
|
|
|
import org.xml.sax.SAXException;
|
2012-09-20 03:27:35 +02:00
|
|
|
import org.xmlpull.v1.XmlSerializer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
|
|
|
*/
|
|
|
|
final public class AndrolibResources {
|
2013-06-20 15:03:20 +02:00
|
|
|
public ResTable getResTable(ExtFile apkFile) throws AndrolibException {
|
|
|
|
return getResTable(apkFile, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ResTable getResTable(ExtFile apkFile, boolean loadMainPkg)
|
|
|
|
throws AndrolibException {
|
|
|
|
ResTable resTable = new ResTable(this);
|
|
|
|
if (loadMainPkg) {
|
|
|
|
loadMainPkg(resTable, apkFile);
|
|
|
|
}
|
|
|
|
return resTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ResPackage loadMainPkg(ResTable resTable, ExtFile apkFile)
|
|
|
|
throws AndrolibException {
|
|
|
|
LOGGER.info("Loading resource table...");
|
2014-09-23 15:24:45 +02:00
|
|
|
ResPackage[] pkgs = getResPackagesFromApk(apkFile, resTable, sKeepBroken);
|
2013-06-20 15:03:20 +02:00
|
|
|
ResPackage pkg = null;
|
|
|
|
|
|
|
|
switch (pkgs.length) {
|
|
|
|
case 1:
|
|
|
|
pkg = pkgs[0];
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (pkgs[0].getName().equals("android")) {
|
|
|
|
LOGGER.warning("Skipping \"android\" package group");
|
|
|
|
pkg = pkgs[1];
|
2014-10-03 18:31:43 +02:00
|
|
|
break;
|
2013-06-20 15:03:20 +02:00
|
|
|
} else if (pkgs[0].getName().equals("com.htc")) {
|
|
|
|
LOGGER.warning("Skipping \"htc\" package group");
|
|
|
|
pkg = pkgs[1];
|
2014-10-03 18:31:43 +02:00
|
|
|
break;
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
2014-10-03 18:31:43 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
pkg = selectPkgWithMostResSpecs(pkgs);
|
2013-06-20 15:03:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pkg == null) {
|
2014-10-03 18:31:43 +02:00
|
|
|
throw new AndrolibException("arsc files with zero packages or no arsc file found.");
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resTable.addPackage(pkg, true);
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
|
2014-10-03 18:31:43 +02:00
|
|
|
public ResPackage selectPkgWithMostResSpecs(ResPackage[] pkgs)
|
|
|
|
throws AndrolibException {
|
|
|
|
int id = 0;
|
|
|
|
int value = 0;
|
|
|
|
|
|
|
|
for (ResPackage resPackage : pkgs) {
|
|
|
|
if (resPackage.getResSpecCount() > value && ! resPackage.getName().equalsIgnoreCase("android")) {
|
|
|
|
value = resPackage.getResSpecCount();
|
|
|
|
id = resPackage.getId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if id is still 0, we only have one pkgId which is "android" -> 1
|
|
|
|
return (id == 0) ? pkgs[0] : pkgs[1];
|
|
|
|
}
|
|
|
|
|
2014-09-23 15:24:45 +02:00
|
|
|
public ResPackage loadFrameworkPkg(ResTable resTable, int id, String frameTag)
|
|
|
|
throws AndrolibException {
|
2013-06-20 15:03:20 +02:00
|
|
|
File apk = getFrameworkApk(id, frameTag);
|
|
|
|
|
|
|
|
LOGGER.info("Loading resource table from file: " + apk);
|
2014-09-23 15:24:45 +02:00
|
|
|
ResPackage[] pkgs = getResPackagesFromApk(new ExtFile(apk), resTable, true);
|
2013-06-20 15:03:20 +02:00
|
|
|
|
2014-10-03 18:31:43 +02:00
|
|
|
ResPackage pkg;
|
|
|
|
if (pkgs.length > 1) {
|
|
|
|
pkg = selectPkgWithMostResSpecs(pkgs);
|
|
|
|
} else if (pkgs.length == 0) {
|
2014-09-23 15:24:45 +02:00
|
|
|
throw new AndrolibException("Arsc files with zero or multiple packages");
|
2014-10-03 18:31:43 +02:00
|
|
|
} else {
|
|
|
|
pkg = pkgs[0];
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pkg.getId() != id) {
|
2014-09-23 15:24:45 +02:00
|
|
|
throw new AndrolibException("Expected pkg of id: " + String.valueOf(id) + ", got: " + pkg.getId());
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resTable.addPackage(pkg, false);
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void decodeManifest(ResTable resTable, ExtFile apkFile, File outDir)
|
|
|
|
throws AndrolibException {
|
|
|
|
|
|
|
|
Duo<ResFileDecoder, AXmlResourceParser> duo = getManifestFileDecoder();
|
|
|
|
ResFileDecoder fileDecoder = duo.m1;
|
|
|
|
|
|
|
|
// Set ResAttrDecoder
|
|
|
|
duo.m2.setAttrDecoder(new ResAttrDecoder());
|
|
|
|
ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder();
|
|
|
|
|
|
|
|
// Fake ResPackage
|
|
|
|
attrDecoder.setCurrentPackage(new ResPackage(resTable, 0, null));
|
|
|
|
|
|
|
|
Directory inApk, out;
|
|
|
|
try {
|
|
|
|
inApk = apkFile.getDirectory();
|
|
|
|
out = new FileDirectory(outDir);
|
|
|
|
|
|
|
|
LOGGER.info("Decoding AndroidManifest.xml with only framework resources...");
|
2014-09-23 15:24:45 +02:00
|
|
|
fileDecoder.decodeManifest(inApk, "AndroidManifest.xml", out, "AndroidManifest.xml");
|
2013-06-20 15:03:20 +02:00
|
|
|
|
|
|
|
} catch (DirectoryException ex) {
|
|
|
|
throw new AndrolibException(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void remove_application_debug(String filePath)
|
|
|
|
throws AndrolibException {
|
|
|
|
|
|
|
|
// change application:debug to true
|
|
|
|
try {
|
2013-11-15 19:08:21 +01:00
|
|
|
Document doc = loadDocument(filePath);
|
2013-06-20 15:03:20 +02:00
|
|
|
Node application = doc.getElementById("application");
|
|
|
|
|
|
|
|
// load attr
|
|
|
|
NamedNodeMap attr = application.getAttributes();
|
|
|
|
Node debugAttr = attr.getNamedItem("debug");
|
|
|
|
|
|
|
|
// remove application:debug
|
|
|
|
if (debugAttr != null) {
|
|
|
|
attr.removeNamedItem("debug");
|
|
|
|
}
|
|
|
|
|
2013-11-15 19:08:21 +01:00
|
|
|
saveDocument(filePath, doc);
|
2013-05-12 17:15:36 +02:00
|
|
|
|
2013-06-12 17:29:16 +02:00
|
|
|
} catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
|
2013-05-12 17:15:36 +02:00
|
|
|
}
|
|
|
|
}
|
2013-02-16 14:32:39 +01:00
|
|
|
|
2013-06-20 15:03:20 +02:00
|
|
|
public void adjust_package_manifest(ResTable resTable, String filePath)
|
|
|
|
throws AndrolibException {
|
2012-12-19 02:40:42 +01:00
|
|
|
|
2014-01-07 17:59:37 +01:00
|
|
|
// compare resources.arsc package name to the one present in AndroidManifest
|
2014-03-19 22:23:45 +01:00
|
|
|
ResPackage resPackage = resTable.getCurrentResPackage();
|
2014-01-07 17:59:37 +01:00
|
|
|
mPackageOriginal = resPackage.getName();
|
|
|
|
mPackageRenamed = resTable.getPackageRenamed();
|
2013-02-13 04:12:17 +01:00
|
|
|
|
2014-01-07 17:59:37 +01:00
|
|
|
resTable.setPackageId(resPackage.getId());
|
|
|
|
resTable.setPackageOriginal(mPackageOriginal);
|
|
|
|
|
2014-03-19 22:23:45 +01:00
|
|
|
// 1) Check if mPackageOriginal === mPackageRenamed
|
|
|
|
// 2) Check if mPackageOriginal is ignored via IGNORED_PACKAGES
|
|
|
|
// 2a) If its ignored, make sure the mPackageRenamed isn't explicitly allowed
|
2014-03-09 23:47:43 +01:00
|
|
|
if (mPackageOriginal.equalsIgnoreCase(mPackageRenamed) ||
|
2014-03-19 22:23:45 +01:00
|
|
|
(Arrays.asList(IGNORED_PACKAGES).contains(mPackageOriginal) &&
|
|
|
|
! Arrays.asList(ALLOWED_PACKAGES).contains(mPackageRenamed))) {
|
2013-06-20 15:03:20 +02:00
|
|
|
LOGGER.info("Regular manifest package...");
|
|
|
|
} else {
|
|
|
|
try {
|
2014-03-19 22:23:45 +01:00
|
|
|
LOGGER.info("Renamed manifest package found! Replacing " + mPackageRenamed + " with " + mPackageOriginal);
|
2013-11-15 19:08:21 +01:00
|
|
|
Document doc = loadDocument(filePath);
|
2012-12-19 02:40:42 +01:00
|
|
|
|
2013-06-20 15:03:20 +02:00
|
|
|
// Get the manifest line
|
|
|
|
Node manifest = doc.getFirstChild();
|
2012-12-19 02:40:42 +01:00
|
|
|
|
2013-06-20 15:03:20 +02:00
|
|
|
// update package attribute
|
|
|
|
NamedNodeMap attr = manifest.getAttributes();
|
|
|
|
Node nodeAttr = attr.getNamedItem("package");
|
2014-01-07 17:59:37 +01:00
|
|
|
nodeAttr.setNodeValue(mPackageOriginal);
|
2013-11-15 19:08:21 +01:00
|
|
|
saveDocument(filePath, doc);
|
2013-02-13 04:12:17 +01:00
|
|
|
|
2013-06-12 17:29:16 +02:00
|
|
|
} catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
|
2013-05-12 17:15:36 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2013-04-01 00:13:10 +02:00
|
|
|
public void remove_manifest_versions(String filePath)
|
|
|
|
throws AndrolibException {
|
|
|
|
|
|
|
|
File f = new File(filePath);
|
|
|
|
|
|
|
|
if (f.exists()) {
|
|
|
|
try {
|
2013-11-15 19:08:21 +01:00
|
|
|
Document doc = loadDocument(filePath);
|
2013-04-01 00:13:10 +02:00
|
|
|
Node manifest = doc.getFirstChild();
|
|
|
|
|
|
|
|
// load attr
|
|
|
|
NamedNodeMap attr = manifest.getAttributes();
|
|
|
|
Node vCode = attr.getNamedItem("android:versionCode");
|
|
|
|
Node vName = attr.getNamedItem("android:versionName");
|
|
|
|
|
|
|
|
// remove versionCode
|
|
|
|
if (vCode != null) {
|
|
|
|
attr.removeNamedItem("android:versionCode");
|
|
|
|
}
|
|
|
|
if (vName != null) {
|
|
|
|
attr.removeNamedItem("android:versionName");
|
|
|
|
}
|
2013-11-15 19:08:21 +01:00
|
|
|
saveDocument(filePath, doc);
|
2013-04-01 00:13:10 +02:00
|
|
|
|
2013-06-12 17:29:16 +02:00
|
|
|
} catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
|
2013-04-01 00:13:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-15 19:08:21 +01:00
|
|
|
private Document loadDocument(String filename)
|
|
|
|
throws IOException, SAXException, ParserConfigurationException {
|
|
|
|
|
|
|
|
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
|
|
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
2014-09-23 15:24:45 +02:00
|
|
|
return docBuilder.parse(filename);
|
2013-11-15 19:08:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void saveDocument(String filename, Document doc)
|
|
|
|
throws IOException, SAXException, ParserConfigurationException, TransformerException {
|
|
|
|
|
|
|
|
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(filename));
|
|
|
|
transformer.transform(source, result);
|
|
|
|
}
|
|
|
|
|
2014-12-26 15:08:50 +01:00
|
|
|
public void decodeManifestWithResources(ResTable resTable, ExtFile apkFile, File outDir)
|
2013-06-20 15:03:20 +02:00
|
|
|
throws AndrolibException {
|
2014-12-26 15:08:50 +01:00
|
|
|
|
2013-06-20 15:03:20 +02:00
|
|
|
Duo<ResFileDecoder, AXmlResourceParser> duo = getResFileDecoder();
|
|
|
|
ResFileDecoder fileDecoder = duo.m1;
|
|
|
|
ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder();
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2014-09-23 15:24:45 +02:00
|
|
|
attrDecoder.setCurrentPackage(resTable.listMainPackages().iterator().next());
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2013-06-20 15:03:20 +02:00
|
|
|
Directory inApk, in = null, out;
|
|
|
|
try {
|
|
|
|
inApk = apkFile.getDirectory();
|
|
|
|
out = new FileDirectory(outDir);
|
|
|
|
LOGGER.info("Decoding AndroidManifest.xml with resources...");
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2014-09-23 15:24:45 +02:00
|
|
|
fileDecoder.decodeManifest(inApk, "AndroidManifest.xml", out, "AndroidManifest.xml");
|
2013-02-13 04:12:17 +01:00
|
|
|
|
2013-04-01 00:13:10 +02:00
|
|
|
// Remove versionName / versionCode (aapt API 16)
|
2013-11-15 20:07:07 +01:00
|
|
|
if (!resTable.getAnalysisMode()) {
|
|
|
|
|
|
|
|
// check for a mismatch between resources.arsc package and the package listed in AndroidManifest
|
|
|
|
// also remove the android::versionCode / versionName from manifest for rebuild
|
|
|
|
// this is a required change to prevent aapt warning about conflicting versions
|
|
|
|
// it will be passed as a parameter to aapt like "--min-sdk-version" via apktool.yml
|
|
|
|
adjust_package_manifest(resTable, outDir.getAbsolutePath() + File.separator + "AndroidManifest.xml");
|
|
|
|
remove_manifest_versions(outDir.getAbsolutePath() + File.separator + "AndroidManifest.xml");
|
2014-01-07 17:59:37 +01:00
|
|
|
mPackageId = String.valueOf(resTable.getPackageId());
|
2013-06-12 17:04:28 +02:00
|
|
|
}
|
2014-12-26 15:08:50 +01:00
|
|
|
} catch (DirectoryException ex) {
|
|
|
|
throw new AndrolibException(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void decode(ResTable resTable, ExtFile apkFile, File outDir)
|
|
|
|
throws AndrolibException {
|
|
|
|
Duo<ResFileDecoder, AXmlResourceParser> duo = getResFileDecoder();
|
|
|
|
ResFileDecoder fileDecoder = duo.m1;
|
|
|
|
ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder();
|
|
|
|
|
|
|
|
attrDecoder.setCurrentPackage(resTable.listMainPackages().iterator().next());
|
|
|
|
Directory inApk, in = null, out;
|
|
|
|
|
|
|
|
try {
|
|
|
|
out = new FileDirectory(outDir);
|
|
|
|
|
|
|
|
inApk = apkFile.getDirectory();
|
2013-06-20 15:03:20 +02:00
|
|
|
if (inApk.containsDir("res")) {
|
|
|
|
in = inApk.getDir("res");
|
|
|
|
}
|
|
|
|
out = out.createDir("res");
|
|
|
|
} catch (DirectoryException ex) {
|
|
|
|
throw new AndrolibException(ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtMXSerializer xmlSerializer = getResXmlSerializer();
|
|
|
|
for (ResPackage pkg : resTable.listMainPackages()) {
|
|
|
|
attrDecoder.setCurrentPackage(pkg);
|
|
|
|
|
|
|
|
LOGGER.info("Decoding file-resources...");
|
|
|
|
for (ResResource res : pkg.listFiles()) {
|
|
|
|
fileDecoder.decode(res, in, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGGER.info("Decoding values */* XMLs...");
|
|
|
|
for (ResValuesFile valuesFile : pkg.listValuesFiles()) {
|
|
|
|
generateValuesFile(valuesFile, out, xmlSerializer);
|
|
|
|
}
|
|
|
|
generatePublicXml(pkg, out, xmlSerializer);
|
|
|
|
}
|
|
|
|
|
|
|
|
AndrolibException decodeError = duo.m2.getFirstError();
|
|
|
|
if (decodeError != null) {
|
|
|
|
throw decodeError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSdkInfo(Map<String, String> map) {
|
|
|
|
if (map != null) {
|
|
|
|
mMinSdkVersion = map.get("minSdkVersion");
|
|
|
|
mTargetSdkVersion = map.get("targetSdkVersion");
|
|
|
|
mMaxSdkVersion = map.get("maxSdkVersion");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVersionInfo(Map<String, String> map) {
|
|
|
|
if (map != null) {
|
2013-09-13 00:46:14 +02:00
|
|
|
mVersionCode = map.get("versionCode");
|
|
|
|
mVersionName = map.get("versionName");
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPackageInfo(Map<String, String> map) {
|
|
|
|
if (map != null) {
|
2014-01-07 20:08:48 +01:00
|
|
|
mPackageRenamed = map.get("rename-manifest-package");
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
}
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2013-06-20 15:03:20 +02:00
|
|
|
public void setPackageId(Map<String, String> map) {
|
2013-05-12 17:15:36 +02:00
|
|
|
if (map != null) {
|
2014-01-07 20:08:48 +01:00
|
|
|
mPackageId = map.get("forced-package-id");
|
2013-05-12 17:15:36 +02:00
|
|
|
}
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
2013-03-17 15:37:46 +01:00
|
|
|
|
2014-11-02 03:07:02 +01:00
|
|
|
public void aaptPackage(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include)
|
2013-03-29 20:49:04 +01:00
|
|
|
throws AndrolibException {
|
|
|
|
|
|
|
|
boolean customAapt = false;
|
2014-11-02 03:07:02 +01:00
|
|
|
String aaptPath = apkOptions.aaptPath;
|
2013-03-29 20:49:04 +01:00
|
|
|
List<String> cmd = new ArrayList<String>();
|
|
|
|
|
|
|
|
// path for aapt binary
|
2014-09-23 15:24:45 +02:00
|
|
|
if (! aaptPath.isEmpty()) {
|
2013-03-29 20:49:04 +01:00
|
|
|
File aaptFile = new File(aaptPath);
|
|
|
|
if (aaptFile.canRead() && aaptFile.exists()) {
|
|
|
|
aaptFile.setExecutable(true);
|
|
|
|
cmd.add(aaptFile.getPath());
|
|
|
|
customAapt = true;
|
|
|
|
|
2014-11-02 03:07:02 +01:00
|
|
|
if (apkOptions.verbose) {
|
2014-01-07 17:59:37 +01:00
|
|
|
LOGGER.info(aaptFile.getPath() + " being used as aapt location.");
|
2013-03-29 20:49:04 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOGGER.warning("aapt location could not be found. Defaulting back to default");
|
|
|
|
|
|
|
|
try {
|
|
|
|
cmd.add(getAaptBinaryFile().getAbsolutePath());
|
|
|
|
} catch (BrutException ignored) {
|
|
|
|
cmd.add("aapt");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
cmd.add(getAaptBinaryFile().getAbsolutePath());
|
|
|
|
} catch (BrutException ignored) {
|
|
|
|
cmd.add("aapt");
|
|
|
|
}
|
|
|
|
}
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2013-06-20 15:03:20 +02:00
|
|
|
cmd.add("p");
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2014-11-02 03:07:02 +01:00
|
|
|
if (apkOptions.verbose) { // output aapt verbose
|
2013-06-20 15:03:20 +02:00
|
|
|
cmd.add("-v");
|
|
|
|
}
|
2014-11-02 03:07:02 +01:00
|
|
|
if (apkOptions.updateFiles) {
|
2013-06-20 15:03:20 +02:00
|
|
|
cmd.add("-u");
|
|
|
|
}
|
2014-11-02 03:07:02 +01:00
|
|
|
if (apkOptions.debugMode) { // inject debuggable="true" into manifest
|
2013-06-20 15:03:20 +02:00
|
|
|
cmd.add("--debug-mode");
|
|
|
|
}
|
2013-03-29 20:49:04 +01:00
|
|
|
|
|
|
|
// force package id so that some frameworks build with correct id
|
|
|
|
// disable if user adds own aapt (can't know if they have this feature)
|
2014-11-02 03:07:02 +01:00
|
|
|
if (mPackageId != null && ! customAapt) {
|
2013-06-20 15:03:20 +02:00
|
|
|
cmd.add("--forced-package-id");
|
|
|
|
cmd.add(mPackageId);
|
|
|
|
}
|
|
|
|
if (mMinSdkVersion != null) {
|
|
|
|
cmd.add("--min-sdk-version");
|
|
|
|
cmd.add(mMinSdkVersion);
|
|
|
|
}
|
|
|
|
if (mTargetSdkVersion != null) {
|
|
|
|
cmd.add("--target-sdk-version");
|
|
|
|
cmd.add(mTargetSdkVersion);
|
|
|
|
}
|
|
|
|
if (mMaxSdkVersion != null) {
|
|
|
|
cmd.add("--max-sdk-version");
|
|
|
|
cmd.add(mMaxSdkVersion);
|
|
|
|
|
|
|
|
// if we have max sdk version, set --max-res-version
|
|
|
|
// so we can ignore anything over that during build.
|
|
|
|
cmd.add("--max-res-version");
|
|
|
|
cmd.add(mMaxSdkVersion);
|
|
|
|
}
|
|
|
|
if (mPackageRenamed != null) {
|
|
|
|
cmd.add("--rename-manifest-package");
|
|
|
|
cmd.add(mPackageRenamed);
|
|
|
|
}
|
|
|
|
if (mVersionCode != null) {
|
|
|
|
cmd.add("--version-code");
|
|
|
|
cmd.add(mVersionCode);
|
|
|
|
}
|
|
|
|
if (mVersionName != null) {
|
|
|
|
cmd.add("--version-name");
|
|
|
|
cmd.add(mVersionName);
|
|
|
|
}
|
|
|
|
cmd.add("-F");
|
|
|
|
cmd.add(apkFile.getAbsolutePath());
|
|
|
|
|
2014-11-02 03:07:02 +01:00
|
|
|
if (apkOptions.isFramework) {
|
2013-06-20 15:03:20 +02:00
|
|
|
cmd.add("-x");
|
|
|
|
}
|
|
|
|
|
2014-11-02 03:07:02 +01:00
|
|
|
if (! apkOptions.resourcesAreCompressed) {
|
2013-06-20 15:03:20 +02:00
|
|
|
cmd.add("-0");
|
|
|
|
cmd.add("arsc");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (include != null) {
|
|
|
|
for (File file : include) {
|
|
|
|
cmd.add("-I");
|
|
|
|
cmd.add(file.getPath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resDir != null) {
|
|
|
|
cmd.add("-S");
|
|
|
|
cmd.add(resDir.getAbsolutePath());
|
|
|
|
}
|
|
|
|
if (manifest != null) {
|
|
|
|
cmd.add("-M");
|
|
|
|
cmd.add(manifest.getAbsolutePath());
|
|
|
|
}
|
|
|
|
if (assetDir != null) {
|
|
|
|
cmd.add("-A");
|
|
|
|
cmd.add(assetDir.getAbsolutePath());
|
|
|
|
}
|
|
|
|
if (rawDir != null) {
|
|
|
|
cmd.add(rawDir.getAbsolutePath());
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
OS.exec(cmd.toArray(new String[0]));
|
2014-11-02 03:07:02 +01:00
|
|
|
if (apkOptions.verbose) {
|
2013-05-12 17:15:36 +02:00
|
|
|
LOGGER.info("command ran: ");
|
|
|
|
LOGGER.info(cmd.toString());
|
|
|
|
}
|
2013-06-20 15:03:20 +02:00
|
|
|
} catch (BrutException ex) {
|
|
|
|
throw new AndrolibException(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean detectWhetherAppIsFramework(File appDir)
|
|
|
|
throws AndrolibException {
|
|
|
|
File publicXml = new File(appDir, "res/values/public.xml");
|
2014-09-23 15:24:45 +02:00
|
|
|
if (! publicXml.exists()) {
|
2013-06-20 15:03:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterator<String> it;
|
|
|
|
try {
|
|
|
|
it = IOUtils.lineIterator(new FileReader(new File(appDir,
|
|
|
|
"res/values/public.xml")));
|
|
|
|
} catch (FileNotFoundException ex) {
|
|
|
|
throw new AndrolibException(
|
|
|
|
"Could not detect whether app is framework one", ex);
|
|
|
|
}
|
|
|
|
it.next();
|
|
|
|
it.next();
|
|
|
|
return it.next().contains("0x01");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void tagSmaliResIDs(ResTable resTable, File smaliDir)
|
|
|
|
throws AndrolibException {
|
|
|
|
new ResSmaliUpdater().tagResIDs(resTable, smaliDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateSmaliResIDs(ResTable resTable, File smaliDir)
|
|
|
|
throws AndrolibException {
|
|
|
|
new ResSmaliUpdater().updateResIDs(resTable, smaliDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Duo<ResFileDecoder, AXmlResourceParser> getResFileDecoder() {
|
|
|
|
ResStreamDecoderContainer decoders = new ResStreamDecoderContainer();
|
|
|
|
decoders.setDecoder("raw", new ResRawStreamDecoder());
|
|
|
|
decoders.setDecoder("9patch", new Res9patchStreamDecoder());
|
|
|
|
|
|
|
|
AXmlResourceParser axmlParser = new AXmlResourceParser();
|
|
|
|
axmlParser.setAttrDecoder(new ResAttrDecoder());
|
2014-09-23 15:24:45 +02:00
|
|
|
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser, getResXmlSerializer()));
|
2013-06-20 15:03:20 +02:00
|
|
|
|
2014-09-23 15:24:45 +02:00
|
|
|
return new Duo<ResFileDecoder, AXmlResourceParser>(new ResFileDecoder(decoders), axmlParser);
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Duo<ResFileDecoder, AXmlResourceParser> getManifestFileDecoder() {
|
|
|
|
ResStreamDecoderContainer decoders = new ResStreamDecoderContainer();
|
|
|
|
|
|
|
|
AXmlResourceParser axmlParser = new AXmlResourceParser();
|
|
|
|
|
2014-09-23 15:24:45 +02:00
|
|
|
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser,getResXmlSerializer()));
|
2013-06-20 15:03:20 +02:00
|
|
|
|
2014-09-23 15:24:45 +02:00
|
|
|
return new Duo<ResFileDecoder, AXmlResourceParser>(new ResFileDecoder(decoders), axmlParser);
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ExtMXSerializer getResXmlSerializer() {
|
|
|
|
ExtMXSerializer serial = new ExtMXSerializer();
|
2014-09-23 15:24:45 +02:00
|
|
|
serial.setProperty(ExtXmlSerializer.PROPERTY_SERIALIZER_INDENTATION, " ");
|
|
|
|
serial.setProperty(ExtXmlSerializer.PROPERTY_SERIALIZER_LINE_SEPARATOR, System.getProperty("line.separator"));
|
2013-06-20 15:03:20 +02:00
|
|
|
serial.setProperty(ExtXmlSerializer.PROPERTY_DEFAULT_ENCODING, "utf-8");
|
|
|
|
serial.setDisabledAttrEscape(true);
|
|
|
|
return serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void generateValuesFile(ResValuesFile valuesFile, Directory out,
|
|
|
|
ExtXmlSerializer serial) throws AndrolibException {
|
|
|
|
try {
|
|
|
|
OutputStream outStream = out.getFileOutput(valuesFile.getPath());
|
|
|
|
serial.setOutput((outStream), null);
|
|
|
|
serial.startDocument(null, null);
|
|
|
|
serial.startTag(null, "resources");
|
|
|
|
|
|
|
|
for (ResResource res : valuesFile.listResources()) {
|
|
|
|
if (valuesFile.isSynthesized(res)) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-23 15:24:45 +02:00
|
|
|
((ResValuesXmlSerializable) res.getValue()).serializeToResValuesXml(serial, res);
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
serial.endTag(null, "resources");
|
|
|
|
serial.newLine();
|
|
|
|
serial.endDocument();
|
|
|
|
serial.flush();
|
|
|
|
outStream.close();
|
2014-09-23 15:24:45 +02:00
|
|
|
} catch (IOException | DirectoryException ex) {
|
|
|
|
throw new AndrolibException("Could not generate: " + valuesFile.getPath(), ex);
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void generatePublicXml(ResPackage pkg, Directory out,
|
|
|
|
XmlSerializer serial) throws AndrolibException {
|
|
|
|
try {
|
|
|
|
OutputStream outStream = out.getFileOutput("values/public.xml");
|
|
|
|
serial.setOutput(outStream, null);
|
|
|
|
serial.startDocument(null, null);
|
|
|
|
serial.startTag(null, "resources");
|
|
|
|
|
|
|
|
for (ResResSpec spec : pkg.listResSpecs()) {
|
|
|
|
serial.startTag(null, "public");
|
|
|
|
serial.attribute(null, "type", spec.getType().getName());
|
|
|
|
serial.attribute(null, "name", spec.getName());
|
2014-09-23 15:24:45 +02:00
|
|
|
serial.attribute(null, "id", String.format("0x%08x", spec.getId().id));
|
2013-06-20 15:03:20 +02:00
|
|
|
serial.endTag(null, "public");
|
|
|
|
}
|
|
|
|
|
|
|
|
serial.endTag(null, "resources");
|
|
|
|
serial.endDocument();
|
|
|
|
serial.flush();
|
|
|
|
outStream.close();
|
2014-09-23 15:24:45 +02:00
|
|
|
} catch (IOException | DirectoryException ex) {
|
|
|
|
throw new AndrolibException("Could not generate public.xml file", ex);
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-23 15:24:45 +02:00
|
|
|
private ResPackage[] getResPackagesFromApk(ExtFile apkFile,ResTable resTable, boolean keepBroken)
|
|
|
|
throws AndrolibException {
|
2013-06-20 15:03:20 +02:00
|
|
|
try {
|
2014-09-23 15:24:45 +02:00
|
|
|
return ARSCDecoder.decode(apkFile.getDirectory().getFileInput("resources.arsc"),false,
|
|
|
|
keepBroken, resTable).getPackages();
|
2013-06-20 15:03:20 +02:00
|
|
|
} catch (DirectoryException ex) {
|
2014-09-23 15:24:45 +02:00
|
|
|
throw new AndrolibException("Could not load resources.arsc from file: " + apkFile, ex);
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public File getFrameworkApk(int id, String frameTag)
|
|
|
|
throws AndrolibException {
|
|
|
|
File dir = getFrameworkDir();
|
|
|
|
File apk;
|
|
|
|
|
|
|
|
if (frameTag != null) {
|
|
|
|
apk = new File(dir, String.valueOf(id) + '-' + frameTag + ".apk");
|
|
|
|
if (apk.exists()) {
|
|
|
|
return apk;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
apk = new File(dir, String.valueOf(id) + ".apk");
|
|
|
|
if (apk.exists()) {
|
|
|
|
return apk;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == 1) {
|
2014-09-23 15:24:45 +02:00
|
|
|
try (InputStream in = AndrolibResources.class.getResourceAsStream("/brut/androlib/android-framework.jar");
|
|
|
|
OutputStream out = new FileOutputStream(apk)) {
|
2013-06-20 15:03:20 +02:00
|
|
|
IOUtils.copy(in, out);
|
|
|
|
return apk;
|
|
|
|
} catch (IOException ex) {
|
|
|
|
throw new AndrolibException(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new CantFindFrameworkResException(id);
|
|
|
|
}
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2014-11-02 03:07:02 +01:00
|
|
|
public void installFramework(File frameFile) throws AndrolibException {
|
|
|
|
installFramework(frameFile, apkOptions.frameworkTag);
|
|
|
|
}
|
|
|
|
|
2013-04-30 14:55:33 +02:00
|
|
|
public void installFramework(File frameFile, String tag)
|
|
|
|
throws AndrolibException {
|
|
|
|
InputStream in = null;
|
2015-01-21 14:12:26 +01:00
|
|
|
ZipOutputStream out = null;
|
2013-04-30 14:55:33 +02:00
|
|
|
try {
|
2015-01-21 14:12:26 +01:00
|
|
|
ZipFile zip = new ZipFile(frameFile);
|
|
|
|
ZipEntry entry = zip.getEntry("resources.arsc");
|
2013-04-30 14:55:33 +02:00
|
|
|
|
|
|
|
if (entry == null) {
|
|
|
|
throw new AndrolibException("Can't find resources.arsc file");
|
|
|
|
}
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2013-04-30 14:55:33 +02:00
|
|
|
in = zip.getInputStream(entry);
|
|
|
|
byte[] data = IOUtils.toByteArray(in);
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2014-09-23 15:24:45 +02:00
|
|
|
ARSCData arsc = ARSCDecoder.decode(new ByteArrayInputStream(data), true, true);
|
2013-04-30 14:55:33 +02:00
|
|
|
publicizeResources(data, arsc.getFlagsOffsets());
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2013-04-30 14:55:33 +02:00
|
|
|
File outFile = new File(getFrameworkDir(), String.valueOf(arsc
|
|
|
|
.getOnePackage().getId())
|
|
|
|
+ (tag == null ? "" : '-' + tag)
|
|
|
|
+ ".apk");
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2015-01-21 14:12:26 +01:00
|
|
|
out = new ZipOutputStream(new FileOutputStream(outFile));
|
2013-04-30 14:55:33 +02:00
|
|
|
out.setMethod(ZipOutputStream.STORED);
|
|
|
|
CRC32 crc = new CRC32();
|
|
|
|
crc.update(data);
|
2015-01-21 14:12:26 +01:00
|
|
|
entry = new ZipEntry("resources.arsc");
|
2013-04-30 14:55:33 +02:00
|
|
|
entry.setSize(data.length);
|
|
|
|
entry.setCrc(crc.getValue());
|
2015-01-21 14:12:26 +01:00
|
|
|
out.putNextEntry(entry);
|
2013-04-30 14:55:33 +02:00
|
|
|
out.write(data);
|
2013-04-30 14:53:17 +02:00
|
|
|
zip.close();
|
2013-04-30 14:55:33 +02:00
|
|
|
LOGGER.info("Framework installed to: " + outFile);
|
|
|
|
} catch (IOException ex) {
|
|
|
|
throw new AndrolibException(ex);
|
|
|
|
} finally {
|
|
|
|
if (in != null) {
|
|
|
|
try {
|
|
|
|
in.close();
|
|
|
|
} catch (IOException ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (out != null) {
|
|
|
|
try {
|
|
|
|
out.close();
|
|
|
|
} catch (IOException ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-14 04:14:41 +01:00
|
|
|
|
2013-06-20 15:03:20 +02:00
|
|
|
public void publicizeResources(File arscFile) throws AndrolibException {
|
|
|
|
byte[] data = new byte[(int) arscFile.length()];
|
|
|
|
|
2014-09-23 15:24:45 +02:00
|
|
|
try(InputStream in = new FileInputStream(arscFile);
|
|
|
|
OutputStream out = new FileOutputStream(arscFile)) {
|
2013-06-20 15:03:20 +02:00
|
|
|
in.read(data);
|
|
|
|
publicizeResources(data);
|
|
|
|
out.write(data);
|
2014-09-23 15:24:45 +02:00
|
|
|
} catch (IOException ex){
|
2013-06-20 15:03:20 +02:00
|
|
|
throw new AndrolibException(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void publicizeResources(byte[] arsc) throws AndrolibException {
|
2014-09-23 15:24:45 +02:00
|
|
|
publicizeResources(arsc, ARSCDecoder.decode(new ByteArrayInputStream(arsc), true, true).getFlagsOffsets());
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void publicizeResources(byte[] arsc, FlagsOffset[] flagsOffsets)
|
|
|
|
throws AndrolibException {
|
|
|
|
for (FlagsOffset flags : flagsOffsets) {
|
|
|
|
int offset = flags.offset + 3;
|
|
|
|
int end = offset + 4 * flags.count;
|
|
|
|
while (offset < end) {
|
|
|
|
arsc[offset] |= (byte) 0x40;
|
|
|
|
offset += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private File getFrameworkDir() throws AndrolibException {
|
|
|
|
String path;
|
|
|
|
|
|
|
|
// if a framework path was specified on the command line, use it
|
2014-11-02 03:07:02 +01:00
|
|
|
if (apkOptions.frameworkFolderLocation != null) {
|
|
|
|
path = apkOptions.frameworkFolderLocation;
|
2013-06-20 15:03:20 +02:00
|
|
|
} else if (OSDetection.isMacOSX()) {
|
2014-09-23 15:24:45 +02:00
|
|
|
path = System.getProperty("user.home") + File.separatorChar + "Library" + File.separatorChar +
|
|
|
|
"apktool" + File.separatorChar + "framework";
|
2013-06-20 15:03:20 +02:00
|
|
|
} else {
|
|
|
|
path = System.getProperty("user.home") + File.separatorChar + "apktool" + File.separatorChar + "framework";
|
|
|
|
}
|
|
|
|
|
|
|
|
File dir = new File(path);
|
2014-09-23 15:32:04 +02:00
|
|
|
|
2014-11-02 03:07:02 +01:00
|
|
|
if (dir.getParentFile() != null && dir.getParentFile().isFile()) {
|
2014-09-23 15:32:04 +02:00
|
|
|
System.err.println("Please remove file at " + dir.getParentFile());
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! dir.exists()) {
|
|
|
|
if (! dir.mkdirs()) {
|
2014-11-02 03:07:02 +01:00
|
|
|
if (apkOptions.frameworkFolderLocation != null) {
|
2014-09-23 15:24:45 +02:00
|
|
|
System.err.println("Can't create Framework directory: " + dir);
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
throw new AndrolibException("Can't create directory: " + dir);
|
|
|
|
}
|
|
|
|
}
|
2014-09-23 15:32:04 +02:00
|
|
|
|
2013-06-20 15:03:20 +02:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Using a prebuilt aapt and forcing its use, allows us to prevent bugs from older aapt's
|
2013-03-29 20:42:35 +01:00
|
|
|
* along with having a finer control over the build procedure.
|
|
|
|
*
|
2013-03-29 20:45:54 +01:00
|
|
|
* Aapt can still be overridden via --aapt/-a on build, but specific features will be disabled
|
|
|
|
*
|
2013-06-20 15:03:20 +02:00
|
|
|
* @url https://github.com/iBotPeaches/platform_frameworks_base
|
|
|
|
* @throws AndrolibException
|
|
|
|
*/
|
|
|
|
public File getAaptBinaryFile() throws AndrolibException {
|
|
|
|
try {
|
|
|
|
if (OSDetection.isMacOSX()) {
|
2014-09-23 15:24:45 +02:00
|
|
|
mAaptBinary = Jar.getResourceAsFile("/prebuilt/aapt/macosx/aapt");
|
2013-06-20 15:03:20 +02:00
|
|
|
} else if (OSDetection.isUnix()) {
|
2014-09-23 15:24:45 +02:00
|
|
|
mAaptBinary = Jar.getResourceAsFile("/prebuilt/aapt/linux/aapt");
|
2013-06-20 15:03:20 +02:00
|
|
|
} else if (OSDetection.isWindows()) {
|
2014-09-23 15:24:45 +02:00
|
|
|
mAaptBinary = Jar.getResourceAsFile("/prebuilt/aapt/windows/aapt.exe");
|
2013-06-20 15:03:20 +02:00
|
|
|
} else {
|
2013-09-18 04:44:57 +02:00
|
|
|
LOGGER.warning("Unknown Operating System: " + OSDetection.returnOS());
|
2013-06-20 15:03:20 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (BrutException ex) {
|
|
|
|
throw new AndrolibException(ex);
|
|
|
|
}
|
2014-09-23 14:56:28 +02:00
|
|
|
if (mAaptBinary.setExecutable(true)) {
|
|
|
|
return mAaptBinary;
|
|
|
|
}
|
|
|
|
|
|
|
|
System.err.println("Can't set aapt binary as executable");
|
|
|
|
throw new AndrolibException("Can't set aapt binary as executable");
|
2013-06-20 15:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public File getAndroidResourcesFile() throws AndrolibException {
|
|
|
|
try {
|
2014-09-23 15:24:45 +02:00
|
|
|
return Jar.getResourceAsFile("/brut/androlib/android-framework.jar");
|
2013-06-20 15:03:20 +02:00
|
|
|
} catch (BrutException ex) {
|
|
|
|
throw new AndrolibException(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-02 03:07:02 +01:00
|
|
|
public ApkOptions apkOptions;
|
2013-06-20 15:03:20 +02:00
|
|
|
|
|
|
|
// TODO: dirty static hack. I have to refactor decoding mechanisms.
|
|
|
|
public static boolean sKeepBroken = false;
|
|
|
|
|
2014-08-16 17:17:15 +02:00
|
|
|
private final static Logger LOGGER = Logger.getLogger(AndrolibResources.class.getName());
|
2013-06-20 15:03:20 +02:00
|
|
|
|
|
|
|
private String mMinSdkVersion = null;
|
|
|
|
private String mMaxSdkVersion = null;
|
|
|
|
private String mTargetSdkVersion = null;
|
|
|
|
private String mVersionCode = null;
|
|
|
|
private String mVersionName = null;
|
|
|
|
private String mPackageRenamed = null;
|
2014-01-07 17:59:37 +01:00
|
|
|
private String mPackageOriginal = null;
|
|
|
|
private String mPackageId = null;
|
|
|
|
|
2013-06-20 15:03:20 +02:00
|
|
|
private File mAaptBinary = null;
|
2012-09-20 03:27:35 +02:00
|
|
|
|
2014-03-09 23:47:43 +01:00
|
|
|
private final static String[] IGNORED_PACKAGES = new String[] {
|
2014-10-05 19:33:47 +02:00
|
|
|
"android", "com.htc", "miui", "com.lge", "com.lge.internal", "yi" };
|
2014-03-19 22:23:45 +01:00
|
|
|
|
|
|
|
private final static String[] ALLOWED_PACKAGES = new String[] {
|
|
|
|
"com.miui" };
|
2012-10-11 17:26:00 +02:00
|
|
|
}
|