use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method generateValuesFile.
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;
}
((ResValuesXmlSerializable) res.getValue()).serializeToResValuesXml(serial, res);
}
serial.endTag(null, "resources");
serial.newLine();
serial.endDocument();
serial.flush();
outStream.close();
} catch (IOException | DirectoryException ex) {
throw new AndrolibException("Could not generate: " + valuesFile.getPath(), ex);
}
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method loadFrameworkPkg.
public ResPackage loadFrameworkPkg(ResTable resTable, int id, String frameTag) throws AndrolibException {
File apk = getFrameworkApk(id, frameTag);
LOGGER.info("Loading resource table from file: " + apk);
ResPackage[] pkgs = getResPackagesFromApk(new ExtFile(apk), resTable, true);
ResPackage pkg;
if (pkgs.length > 1) {
pkg = selectPkgWithMostResSpecs(pkgs);
} else if (pkgs.length == 0) {
throw new AndrolibException("Arsc files with zero or multiple packages");
} else {
pkg = pkgs[0];
}
if (pkg.getId() != id) {
throw new AndrolibException("Expected pkg of id: " + String.valueOf(id) + ", got: " + pkg.getId());
}
resTable.addPackage(pkg, false);
return pkg;
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method decodeManifestWithResources.
public void decodeManifestWithResources(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 {
inApk = apkFile.getDirectory();
out = new FileDirectory(outDir);
LOGGER.info("Decoding AndroidManifest.xml with resources...");
fileDecoder.decodeManifest(inApk, "AndroidManifest.xml", out, "AndroidManifest.xml");
// Remove versionName / versionCode (aapt API 16)
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
adjustPackageManifest(resTable, outDir.getAbsolutePath() + File.separator + "AndroidManifest.xml");
ResXmlPatcher.removeManifestVersions(new File(outDir.getAbsolutePath() + File.separator + "AndroidManifest.xml"));
mPackageId = String.valueOf(resTable.getPackageId());
}
} catch (DirectoryException ex) {
throw new AndrolibException(ex);
}
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method detectWhetherAppIsFramework.
public boolean detectWhetherAppIsFramework(File appDir) throws AndrolibException {
File publicXml = new File(appDir, "res/values/public.xml");
if (!publicXml.exists()) {
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");
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method emptyFrameworkDirectory.
public void emptyFrameworkDirectory() throws AndrolibException {
File dir = getFrameworkDir();
File apk;
apk = new File(dir, "1.apk");
if (!apk.exists()) {
LOGGER.warning("Can't empty framework directory, no file found at: " + apk.getAbsolutePath());
} else {
try {
if (apk.exists() && dir.listFiles().length > 1 && !apkOptions.forceDeleteFramework) {
LOGGER.warning("More than default framework detected. Please run command with `--force` parameter to wipe framework directory.");
} else {
for (File file : dir.listFiles()) {
if (file.isFile() && file.getName().endsWith(".apk")) {
LOGGER.info("Removing " + file.getName() + " framework file...");
file.delete();
}
}
}
} catch (NullPointerException e) {
throw new AndrolibException(e);
}
}
}
Aggregations