use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class SmaliBuilder method buildFile.
private void buildFile(String fileName, DexBuilder dexBuilder) throws AndrolibException, IOException {
File inFile = new File(mSmaliDir, fileName);
InputStream inStream = new FileInputStream(inFile);
if (fileName.endsWith(".smali")) {
try {
if (!SmaliMod.assembleSmaliFile(inFile, dexBuilder, false, false)) {
throw new AndrolibException("Could not smali file: " + fileName);
}
} catch (IOException | RecognitionException ex) {
throw new AndrolibException(ex);
}
} else {
LOGGER.warning("Unknown file type, ignoring: " + inFile);
}
inStream.close();
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class SmaliDecoder method decode.
private void decode() throws AndrolibException {
try {
baksmaliOptions options = new baksmaliOptions();
// options
options.deodex = false;
options.outputDirectory = mOutDir.toString();
options.noParameterRegisters = false;
options.useLocalsDirective = true;
options.useSequentialLabels = true;
options.outputDebugInfo = mBakDeb;
options.addCodeOffsets = false;
options.jobs = -1;
options.noAccessorComments = false;
options.registerInfo = 0;
options.ignoreErrors = false;
options.inlineResolver = null;
options.checkPackagePrivateAccess = false;
// set jobs automatically
options.jobs = Runtime.getRuntime().availableProcessors();
if (options.jobs > 6) {
options.jobs = 6;
}
// create the dex
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(mApkFile, mDexFile, mApi, false);
if (dexFile.isOdexFile()) {
throw new AndrolibException("Warning: You are disassembling an odex file without deodexing it.");
}
if (dexFile instanceof DexBackedOdexFile) {
options.inlineResolver = InlineMethodResolver.createInlineMethodResolver(((DexBackedOdexFile) dexFile).getOdexVersion());
}
baksmali.disassembleDexFile(dexFile, options);
} catch (IOException ex) {
throw new AndrolibException(ex);
}
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method getAaptBinaryFile.
/**
* Using a prebuilt aapt and forcing its use, allows us to prevent bugs from older aapt's
* along with having a finer control over the build procedure.
*
* Aapt can still be overridden via --aapt/-a on build, but specific features will be disabled
*
* @url https://github.com/iBotPeaches/platform_frameworks_base
* @throws AndrolibException
*/
public File getAaptBinaryFile() throws AndrolibException {
File aaptBinary;
try {
if (OSDetection.isMacOSX()) {
if (OSDetection.is64Bit()) {
aaptBinary = Jar.getResourceAsFile("/prebuilt/aapt/macosx/64/aapt");
} else {
aaptBinary = Jar.getResourceAsFile("/prebuilt/aapt/macosx/32/aapt");
}
} else if (OSDetection.isUnix()) {
if (OSDetection.is64Bit()) {
aaptBinary = Jar.getResourceAsFile("/prebuilt/aapt/linux/64/aapt");
} else {
aaptBinary = Jar.getResourceAsFile("/prebuilt/aapt/linux/32/aapt");
}
} else if (OSDetection.isWindows()) {
aaptBinary = Jar.getResourceAsFile("/prebuilt/aapt/windows/aapt.exe");
} else {
LOGGER.warning("Unknown Operating System: " + OSDetection.returnOS());
return null;
}
} catch (BrutException ex) {
throw new AndrolibException(ex);
}
if (aaptBinary.setExecutable(true)) {
return aaptBinary;
}
System.err.println("Can't set aapt binary as executable");
throw new AndrolibException("Can't set aapt binary as executable");
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method getFrameworkDir.
public File getFrameworkDir() throws AndrolibException {
if (mFrameworkDirectory != null) {
return mFrameworkDirectory;
}
String path;
// if a framework path was specified on the command line, use it
if (apkOptions.frameworkFolderLocation != null) {
path = apkOptions.frameworkFolderLocation;
} else {
File parentPath = new File(System.getProperty("user.home"));
if (!parentPath.canWrite()) {
LOGGER.severe(String.format("WARNING: Could not write to $HOME (%s), using %s instead...", parentPath.getAbsolutePath(), System.getProperty("java.io.tmpdir")));
LOGGER.severe("Please be aware this is a volatile directory and frameworks could go missing, " + "please utilize --frame-path if the default storage directory is unavailable");
parentPath = new File(System.getProperty("java.io.tmpdir"));
}
if (OSDetection.isMacOSX()) {
path = parentPath.getAbsolutePath() + String.format("%1$sLibrary%1$sapktool%1$sframework", File.separatorChar);
} else if (OSDetection.isWindows()) {
path = parentPath.getAbsolutePath() + String.format("%1$sAppData%1$sLocal%1$sapktool%1$sframework", File.separatorChar);
} else {
path = parentPath.getAbsolutePath() + String.format("%1$s.local%1$sshare%1$sapktool%1$sframework", File.separatorChar);
}
}
File dir = new File(path);
if (dir.getParentFile() != null && dir.getParentFile().isFile()) {
LOGGER.severe("Please remove file at " + dir.getParentFile());
System.exit(1);
}
if (!dir.exists()) {
if (!dir.mkdirs()) {
if (apkOptions.frameworkFolderLocation != null) {
LOGGER.severe("Can't create Framework directory: " + dir);
}
throw new AndrolibException("Can't create directory: " + dir);
}
}
mFrameworkDirectory = dir;
return dir;
}
use of brut.androlib.AndrolibException in project Apktool by iBotPeaches.
the class AndrolibResources method decodeManifest.
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...");
fileDecoder.decodeManifest(inApk, "AndroidManifest.xml", out, "AndroidManifest.xml");
} catch (DirectoryException ex) {
throw new AndrolibException(ex);
}
}
Aggregations