Search in sources :

Example 6 with BrutException

use of brut.common.BrutException in project Apktool by iBotPeaches.

the class Jar method extractToTmp.

public static File extractToTmp(String resourcePath, String tmpPrefix) throws BrutException {
    try {
        InputStream in = Class.class.getResourceAsStream(resourcePath);
        if (in == null) {
            throw new FileNotFoundException(resourcePath);
        }
        File fileOut = File.createTempFile(tmpPrefix, null);
        fileOut.deleteOnExit();
        OutputStream out = new FileOutputStream(fileOut);
        IOUtils.copy(in, out);
        in.close();
        out.close();
        return fileOut;
    } catch (IOException ex) {
        throw new BrutException("Could not extract resource: " + resourcePath, ex);
    }
}
Also used : BrutException(brut.common.BrutException)

Example 7 with BrutException

use of brut.common.BrutException in project Apktool by iBotPeaches.

the class ApkDecoder method decode.

public void decode() throws AndrolibException, IOException, DirectoryException {
    File outDir = getOutDir();
    AndrolibResources.sKeepBroken = mKeepBrokenResources;
    if (!mForceDelete && outDir.exists()) {
        throw new OutDirExistsException();
    }
    if (!mApkFile.isFile() || !mApkFile.canRead()) {
        throw new InFileNotFoundException();
    }
    try {
        OS.rmdir(outDir);
    } catch (BrutException ex) {
        throw new AndrolibException(ex);
    }
    outDir.mkdirs();
    LOGGER.info("Using Apktool " + Androlib.getVersion() + " on " + mApkFile.getName());
    if (hasResources()) {
        switch(mDecodeResources) {
            case DECODE_RESOURCES_NONE:
                mAndrolib.decodeResourcesRaw(mApkFile, outDir);
                break;
            case DECODE_RESOURCES_FULL:
                setTargetSdkVersion();
                setAnalysisMode(mAnalysisMode, true);
                if (hasManifest()) {
                    mAndrolib.decodeManifestWithResources(mApkFile, outDir, getResTable());
                }
                mAndrolib.decodeResourcesFull(mApkFile, outDir, getResTable());
                break;
        }
    } else {
        // up attribute references
        if (hasManifest()) {
            switch(mDecodeResources) {
                case DECODE_RESOURCES_NONE:
                    mAndrolib.decodeManifestRaw(mApkFile, outDir);
                    break;
                case DECODE_RESOURCES_FULL:
                    mAndrolib.decodeManifestFull(mApkFile, outDir, getResTable());
                    break;
            }
        }
    }
    if (hasSources()) {
        switch(mDecodeSources) {
            case DECODE_SOURCES_NONE:
                mAndrolib.decodeSourcesRaw(mApkFile, outDir, "classes.dex");
                break;
            case DECODE_SOURCES_SMALI:
                mAndrolib.decodeSourcesSmali(mApkFile, outDir, "classes.dex", mBakDeb, mApi);
                break;
        }
    }
    if (hasMultipleSources()) {
        // foreach unknown dex file in root, lets disassemble it
        Set<String> files = mApkFile.getDirectory().getFiles(true);
        for (String file : files) {
            if (file.endsWith(".dex")) {
                if (!file.equalsIgnoreCase("classes.dex")) {
                    switch(mDecodeSources) {
                        case DECODE_SOURCES_NONE:
                            mAndrolib.decodeSourcesRaw(mApkFile, outDir, file);
                            break;
                        case DECODE_SOURCES_SMALI:
                            mAndrolib.decodeSourcesSmali(mApkFile, outDir, file, mBakDeb, mApi);
                            break;
                    }
                }
            }
        }
    }
    mAndrolib.decodeRawFiles(mApkFile, outDir);
    mAndrolib.decodeUnknownFiles(mApkFile, outDir, mResTable);
    mUncompressedFiles = new ArrayList<String>();
    mAndrolib.recordUncompressedFiles(mApkFile, mUncompressedFiles);
    mAndrolib.writeOriginalFiles(mApkFile, outDir);
    writeMetaFile();
}
Also used : OutDirExistsException(brut.androlib.err.OutDirExistsException) BrutException(brut.common.BrutException) InFileNotFoundException(brut.androlib.err.InFileNotFoundException) File(java.io.File) ExtFile(brut.directory.ExtFile)

Example 8 with BrutException

use of brut.common.BrutException in project Apktool by iBotPeaches.

the class Androlib method decodeSourcesSmali.

public void decodeSourcesSmali(File apkFile, File outDir, String filename, boolean bakdeb, int api) throws AndrolibException {
    try {
        File smaliDir;
        if (filename.equalsIgnoreCase("classes.dex")) {
            smaliDir = new File(outDir, SMALI_DIRNAME);
        } else {
            smaliDir = new File(outDir, SMALI_DIRNAME + "_" + filename.substring(0, filename.indexOf(".")));
        }
        OS.rmdir(smaliDir);
        smaliDir.mkdirs();
        LOGGER.info("Baksmaling " + filename + "...");
        SmaliDecoder.decode(apkFile, smaliDir, filename, bakdeb, api);
    } catch (BrutException ex) {
        throw new AndrolibException(ex);
    }
}
Also used : BrutException(brut.common.BrutException) ZipFile(java.util.zip.ZipFile) ExtFile(brut.directory.ExtFile)

Example 9 with BrutException

use of brut.common.BrutException in project Apktool by iBotPeaches.

the class BuildAndDecodeTest method compareXmlFiles.

private void compareXmlFiles(String path, ElementQualifier qualifier) throws BrutException {
    DetailedDiff diff;
    try {
        Reader control = new FileReader(new File(sTestOrigDir, path));
        Reader test = new FileReader(new File(sTestNewDir, path));
        diff = new DetailedDiff(new Diff(control, test));
    } catch (SAXException | IOException ex) {
        throw new BrutException(ex);
    }
    if (qualifier != null) {
        diff.overrideElementQualifier(qualifier);
    }
    assertTrue(path + ": " + diff.getAllDifferences().toString(), diff.similar());
}
Also used : BrutException(brut.common.BrutException) ExtFile(brut.directory.ExtFile) SAXException(org.xml.sax.SAXException)

Example 10 with BrutException

use of brut.common.BrutException in project Apktool by iBotPeaches.

the class LargeIntsInManifestTest method compareXmlFiles.

private void compareXmlFiles(String path, ElementQualifier qualifier) throws BrutException {
    DetailedDiff diff;
    try {
        Reader control = new FileReader(new File(sTestOrigDir, path));
        Reader test = new FileReader(new File(sTestNewDir, path));
        diff = new DetailedDiff(new Diff(control, test));
    } catch (SAXException | IOException ex) {
        throw new BrutException(ex);
    }
    if (qualifier != null) {
        diff.overrideElementQualifier(qualifier);
    }
    assertTrue(path + ": " + diff.getAllDifferences().toString(), diff.similar());
}
Also used : BrutException(brut.common.BrutException) IOException(java.io.IOException) ExtFile(brut.directory.ExtFile) File(java.io.File) SAXException(org.xml.sax.SAXException)

Aggregations

BrutException (brut.common.BrutException)13 ExtFile (brut.directory.ExtFile)8 ZipFile (java.util.zip.ZipFile)5 AndrolibException (brut.androlib.AndrolibException)2 File (java.io.File)2 SAXException (org.xml.sax.SAXException)2 InFileNotFoundException (brut.androlib.err.InFileNotFoundException)1 OutDirExistsException (brut.androlib.err.OutDirExistsException)1 IOException (java.io.IOException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1