use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method getFrameworkApk.
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) {
try (InputStream in = AndrolibResources.class.getResourceAsStream("/brut/androlib/android-framework.jar");
OutputStream out = new FileOutputStream(apk)) {
IOUtils.copy(in, out);
return apk;
} catch (IOException ex) {
throw new AndrolibException(ex);
}
}
throw new CantFindFrameworkResException(id);
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method decode.
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();
out = out.createDir("res");
if (inApk.containsDir("res")) {
in = inApk.getDir("res");
}
if (in == null && inApk.containsDir("r")) {
in = inApk.getDir("r");
}
if (in == null && inApk.containsDir("R")) {
in = inApk.getDir("R");
}
} 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;
}
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method generatePublicXml.
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());
serial.attribute(null, "id", String.format("0x%08x", spec.getId().id));
serial.endTag(null, "public");
}
serial.endTag(null, "resources");
serial.endDocument();
serial.flush();
outStream.close();
} catch (IOException | DirectoryException ex) {
throw new AndrolibException("Could not generate public.xml file", ex);
}
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method publicizeResources.
public void publicizeResources(File arscFile) throws AndrolibException {
byte[] data = new byte[(int) arscFile.length()];
try (InputStream in = new FileInputStream(arscFile);
OutputStream out = new FileOutputStream(arscFile)) {
in.read(data);
publicizeResources(data);
out.write(data);
} catch (IOException ex) {
throw new AndrolibException(ex);
}
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method aaptPackage.
public void aaptPackage(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include) throws AndrolibException {
boolean customAapt = false;
String aaptPath = apkOptions.aaptPath;
List<String> cmd = new ArrayList<String>();
// path for aapt binary
if (!aaptPath.isEmpty()) {
File aaptFile = new File(aaptPath);
if (aaptFile.canRead() && aaptFile.exists()) {
aaptFile.setExecutable(true);
cmd.add(aaptFile.getPath());
customAapt = true;
if (apkOptions.verbose) {
LOGGER.info(aaptFile.getPath() + " being used as aapt location.");
}
} 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");
}
}
cmd.add("p");
if (apkOptions.verbose) {
// output aapt verbose
cmd.add("-v");
}
if (apkOptions.updateFiles) {
cmd.add("-u");
}
if (apkOptions.debugMode) {
// inject debuggable="true" into manifest
cmd.add("--debug-mode");
}
// disable if user adds own aapt (can't know if they have this feature)
if (mPackageId != null && !customAapt && !mSharedLibrary) {
cmd.add("--forced-package-id");
cmd.add(mPackageId);
}
if (mSharedLibrary) {
cmd.add("--shared-lib");
}
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("--no-version-vectors");
cmd.add("-F");
cmd.add(apkFile.getAbsolutePath());
if (apkOptions.isFramework) {
cmd.add("-x");
}
if (apkOptions.doNotCompress != null) {
for (String file : apkOptions.doNotCompress) {
cmd.add("-0");
cmd.add(file);
}
}
if (!apkOptions.resourcesAreCompressed) {
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]));
if (apkOptions.verbose) {
LOGGER.info("command ran: ");
LOGGER.info(cmd.toString());
}
} catch (BrutException ex) {
throw new AndrolibException(ex);
}
}
Aggregations