Search in sources :

Example 1 with CompilationDeathException

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);
}
Also used : MultiDexContainer(org.jf.dexlib2.iface.MultiDexContainer) CompilationDeathException(soot.CompilationDeathException) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) File(java.io.File)

Example 2 with CompilationDeathException

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);
    }
}
Also used : CompilationDeathException(soot.CompilationDeathException) IOException(java.io.IOException)

Example 3 with CompilationDeathException

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));
}
Also used : Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) CompilationDeathException(soot.CompilationDeathException) IOException(java.io.IOException)

Example 4 with CompilationDeathException

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;
}
Also used : CompilationDeathException(soot.CompilationDeathException) File(java.io.File) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile)

Example 5 with CompilationDeathException

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);
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) CompilationDeathException(soot.CompilationDeathException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

CompilationDeathException (soot.CompilationDeathException)10 IOException (java.io.IOException)7 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)2 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)2 MultiDexContainer (org.jf.dexlib2.iface.MultiDexContainer)2 BufferedWriter (java.io.BufferedWriter)1 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 JarFile (java.util.jar.JarFile)1 ZipFile (java.util.zip.ZipFile)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 Transform (soot.Transform)1 ReflectiveCallsInliner (soot.jimple.toolkits.reflection.ReflectiveCallsInliner)1 DefaultHandler (soot.rtlib.tamiflex.DefaultHandler)1