use of org.jf.dexlib2.dexbacked.DexBackedOdexFile 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 org.jf.dexlib2.dexbacked.DexBackedOdexFile in project smali by JesusFreke.
the class DeodexCommand method getOptions.
@Override
protected BaksmaliOptions getOptions() {
BaksmaliOptions options = super.getOptions();
options.deodex = true;
if (dexFile instanceof DexBackedOdexFile) {
if (inlineTable == null) {
options.inlineResolver = InlineMethodResolver.createInlineMethodResolver(((DexBackedOdexFile) dexFile).getOdexVersion());
} else {
File inlineTableFile = new File(inlineTable);
if (!inlineTableFile.exists()) {
System.err.println(String.format("Could not find file: %s", inlineTable));
System.exit(-1);
}
try {
options.inlineResolver = new CustomInlineMethodResolver(options.classPath, inlineTableFile);
} catch (IOException ex) {
System.err.println(String.format("Error while reading file: %s", inlineTableFile));
ex.printStackTrace(System.err);
System.exit(-1);
}
}
}
return options;
}
use of org.jf.dexlib2.dexbacked.DexBackedOdexFile in project smali by JesusFreke.
the class ListDependenciesCommand method run.
@Override
public void run() {
if (help || inputList == null || inputList.isEmpty()) {
usage();
return;
}
if (inputList.size() > 1) {
System.err.println("Too many files specified");
usage();
return;
}
String input = inputList.get(0);
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(input));
} catch (FileNotFoundException ex) {
System.err.println("Could not find file: " + input);
System.exit(-1);
}
try {
OatFile oatFile = OatFile.fromInputStream(inputStream);
for (String entry : oatFile.getBootClassPath()) {
System.out.println(entry);
}
return;
} catch (OatFile.NotAnOatFileException ex) {
// ignore
} catch (IOException ex) {
throw new RuntimeException(ex);
}
try {
DexBackedOdexFile odexFile = DexBackedOdexFile.fromInputStream(Opcodes.getDefault(), inputStream);
for (String entry : odexFile.getDependencies()) {
System.out.println(entry);
}
return;
} catch (IOException ex) {
throw new RuntimeException(ex);
} catch (DexBackedOdexFile.NotAnOdexFile ex) {
// handled below
} catch (DexBackedDexFile.NotADexFile ex) {
// handled below
}
System.err.println(input + " is not an odex or oat file.");
System.exit(-1);
}
use of org.jf.dexlib2.dexbacked.DexBackedOdexFile in project smali by JesusFreke.
the class DexFileFactory method loadDexContainer.
/**
* Loads a file containing 1 or more dex files
*
* If the given file is a dex or odex file, it will return a MultiDexContainer containing that single entry.
* Otherwise, for an oat or zip file, it will return an OatFile or ZipDexContainer respectively.
*
* @param file The file to open
* @param opcodes The set of opcodes to use
* @return A MultiDexContainer
* @throws DexFileNotFoundException If the given file does not exist
* @throws UnsupportedFileTypeException If the given file is not a valid dex/zip/odex/oat file
*/
public static MultiDexContainer<? extends DexBackedDexFile> loadDexContainer(@Nonnull File file, @Nonnull final Opcodes opcodes) throws IOException {
if (!file.exists()) {
throw new DexFileNotFoundException("%s does not exist", file.getName());
}
ZipDexContainer zipDexContainer = new ZipDexContainer(file, opcodes);
if (zipDexContainer.isZipFile()) {
return zipDexContainer;
}
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
try {
try {
DexBackedDexFile dexFile = DexBackedDexFile.fromInputStream(opcodes, inputStream);
return new SingletonMultiDexContainer(file.getPath(), dexFile);
} catch (DexBackedDexFile.NotADexFile ex) {
// just eat it
}
try {
DexBackedOdexFile odexFile = DexBackedOdexFile.fromInputStream(opcodes, inputStream);
return new SingletonMultiDexContainer(file.getPath(), odexFile);
} catch (DexBackedOdexFile.NotAnOdexFile ex) {
// just eat it
}
// Note: DexBackedDexFile.fromInputStream and DexBackedOdexFile.fromInputStream will reset inputStream
// back to the same position, if they fails
OatFile oatFile = null;
try {
oatFile = OatFile.fromInputStream(inputStream);
} catch (NotAnOatFileException ex) {
// just eat it
}
if (oatFile != null) {
// TODO: we should support loading earlier oat files, just not deodexing them
if (oatFile.isSupportedVersion() == OatFile.UNSUPPORTED) {
throw new UnsupportedOatVersionException(oatFile);
}
return oatFile;
}
} finally {
inputStream.close();
}
throw new UnsupportedFileTypeException("%s is not an apk, dex, odex or oat file.", file.getPath());
}
Aggregations