use of soot.CompilationDeathException in project soot by Sable.
the class DexFileProvider method getDexFromSource.
/**
* Returns the first dex file with the given name found in the given dex source
*
* @param dexSource Path to a jar, apk, dex, odex or a directory containing multiple dex files
* @return Dex file with given name in dex source
* @throws CompilationDeathException If no dex file with the given name exists
*/
public DexContainer getDexFromSource(File dexSource, String dexName) throws IOException {
List<File> allSources = allSourcesFromFile(dexSource);
updateIndex(allSources);
// we take the first dex we find with the given name
for (File theSource : allSources) {
DexContainer dexFile = dexMap.get(theSource.getCanonicalPath()).get(dexName);
if (dexFile != null)
return dexFile;
}
throw new CompilationDeathException("Dex file with name '" + dexName + "' not found in " + dexSource);
}
use of soot.CompilationDeathException in project soot by Sable.
the class DexPrinter method print.
public void print() {
try {
if (Options.v().output_jar() || (originalApk != null && Options.v().output_format() != Options.output_format_force_dex)) {
printZip();
} else {
final String outputDir = SourceLocator.v().getOutputDir();
LOGGER.info("Writing dex files to \"{}\" folder.", outputDir);
dexBuilder.writeTo(outputDir);
}
} catch (IOException e) {
throw new CompilationDeathException("I/O exception while printing dex", e);
}
}
use of soot.CompilationDeathException in project soot by Sable.
the class DexPrinter method getZipOutputStream.
private ZipOutputStream getZipOutputStream() throws IOException {
if (Options.v().output_jar()) {
LOGGER.info("Writing JAR to \"{}\"", Options.v().output_dir());
return PackManager.v().getJarFile();
}
final String name = originalApk == null ? "out.apk" : originalApk.getName();
if (originalApk == null) {
LOGGER.warn("Setting output file name to \"{}\" as original APK has not been found.", name);
}
final Path outputFile = Paths.get(SourceLocator.v().getOutputDir(), name);
if (Files.exists(outputFile, LinkOption.NOFOLLOW_LINKS)) {
if (!Options.v().force_overwrite())
throw new CompilationDeathException("Output file \"" + outputFile + "\" exists. Not overwriting.");
try {
Files.delete(outputFile);
} catch (IOException exception) {
throw new IllegalStateException("Removing \"" + outputFile + "\" failed. Not writing out anything.", exception);
}
}
LOGGER.info("Writing APK to \"{}\".", outputFile);
return new ZipOutputStream(Files.newOutputStream(outputFile, StandardOpenOption.CREATE_NEW));
}
use of soot.CompilationDeathException in project soot by Sable.
the class DexPrinter method add.
public void add(SootClass c) {
if (c.isPhantom())
return;
addAsClassDefItem(c);
// save original APK for this class, needed to copy all the other files
// inside
Map<String, File> dexClassIndex = SourceLocator.v().dexClassIndex();
if (dexClassIndex == null) {
// no dex classes were loaded
return;
}
File sourceForClass = dexClassIndex.get(c.getName());
if (sourceForClass == null || sourceForClass.getName().endsWith(".dex")) {
// a class was written that was not a dex class or the class
return;
// originates from a .dex file, not an APK
}
if (originalApk != null && !originalApk.equals(sourceForClass)) {
throw new CompilationDeathException("multiple APKs as source of an application are not supported");
}
originalApk = sourceForClass;
}
use of soot.CompilationDeathException in project soot by Sable.
the class Dava method log.
public void log(String s) {
if (LOG_TO_SCREEN != null) {
LOG_TO_SCREEN.println(s);
LOG_TO_SCREEN.flush();
}
if (LOG_TO_FILE != null) {
if (iOut == null)
try {
iOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(LOG_TO_FILE), "US-ASCII"));
} catch (FileNotFoundException fnfe) {
logger.debug("" + "Unable to open " + LOG_TO_FILE);
logger.error(fnfe.getMessage(), fnfe);
throw new CompilationDeathException(CompilationDeathException.COMPILATION_ABORTED);
} catch (UnsupportedEncodingException uee) {
logger.debug("" + "This system doesn't support US-ASCII encoding!!");
logger.error(uee.getMessage(), uee);
throw new CompilationDeathException(CompilationDeathException.COMPILATION_ABORTED);
}
try {
iOut.write(s);
iOut.write("\n");
iOut.flush();
} catch (IOException ioe) {
logger.debug("" + "Unable to write to " + LOG_TO_FILE);
logger.error(ioe.getMessage(), ioe);
throw new CompilationDeathException(CompilationDeathException.COMPILATION_ABORTED);
}
}
}
Aggregations