Search in sources :

Example 1 with InFileNotFoundException

use of brut.androlib.err.InFileNotFoundException in project Apktool by iBotPeaches.

the class Main method cmdDecode.

private static void cmdDecode(CommandLine cli) throws AndrolibException {
    ApkDecoder decoder = new ApkDecoder();
    int paraCount = cli.getArgList().size();
    String apkName = (String) cli.getArgList().get(paraCount - 1);
    File outDir;
    // check for options
    if (cli.hasOption("s") || cli.hasOption("no-src")) {
        decoder.setDecodeSources(ApkDecoder.DECODE_SOURCES_NONE);
    }
    if (cli.hasOption("d") || cli.hasOption("debug")) {
        System.err.println("SmaliDebugging has been removed in 2.1.0 onward. Please see: https://github.com/iBotPeaches/Apktool/issues/1061");
        System.exit(1);
    }
    if (cli.hasOption("b") || cli.hasOption("no-debug-info")) {
        decoder.setBaksmaliDebugMode(false);
    }
    if (cli.hasOption("t") || cli.hasOption("frame-tag")) {
        decoder.setFrameworkTag(cli.getOptionValue("t"));
    }
    if (cli.hasOption("f") || cli.hasOption("force")) {
        decoder.setForceDelete(true);
    }
    if (cli.hasOption("r") || cli.hasOption("no-res")) {
        decoder.setDecodeResources(ApkDecoder.DECODE_RESOURCES_NONE);
    }
    if (cli.hasOption("k") || cli.hasOption("keep-broken-res")) {
        decoder.setKeepBrokenResources(true);
    }
    if (cli.hasOption("p") || cli.hasOption("frame-path")) {
        decoder.setFrameworkDir(cli.getOptionValue("p"));
    }
    if (cli.hasOption("m") || cli.hasOption("match-original")) {
        decoder.setAnalysisMode(true, false);
    }
    if (cli.hasOption("api")) {
        decoder.setApi(Integer.parseInt(cli.getOptionValue("api")));
    }
    if (cli.hasOption("o") || cli.hasOption("output")) {
        outDir = new File(cli.getOptionValue("o"));
        decoder.setOutDir(outDir);
    } else {
        // make out folder manually using name of apk
        String outName = apkName;
        outName = outName.endsWith(".apk") ? outName.substring(0, outName.length() - 4).trim() : outName + ".out";
        // make file from path
        outName = new File(outName).getName();
        outDir = new File(outName);
        decoder.setOutDir(outDir);
    }
    decoder.setApkFile(new File(apkName));
    try {
        decoder.decode();
    } catch (OutDirExistsException ex) {
        System.err.println("Destination directory (" + outDir.getAbsolutePath() + ") " + "already exists. Use -f switch if you want to overwrite it.");
        System.exit(1);
    } catch (InFileNotFoundException ex) {
        System.err.println("Input file (" + apkName + ") " + "was not found or was not readable.");
        System.exit(1);
    } catch (CantFindFrameworkResException ex) {
        System.err.println("Can't find framework resources for package of id: " + String.valueOf(ex.getPkgId()) + ". You must install proper " + "framework files, see project website for more info.");
        System.exit(1);
    } catch (IOException ex) {
        System.err.println("Could not modify file. Please ensure you have permission.");
        System.exit(1);
    } catch (DirectoryException ex) {
        System.err.println("Could not modify internal dex files. Please ensure you have permission.");
        System.exit(1);
    }
}
Also used : CantFindFrameworkResException(brut.androlib.err.CantFindFrameworkResException) OutDirExistsException(brut.androlib.err.OutDirExistsException) InFileNotFoundException(brut.androlib.err.InFileNotFoundException) IOException(java.io.IOException) File(java.io.File) DirectoryException(brut.directory.DirectoryException)

Example 2 with InFileNotFoundException

use of brut.androlib.err.InFileNotFoundException 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)

Aggregations

InFileNotFoundException (brut.androlib.err.InFileNotFoundException)2 OutDirExistsException (brut.androlib.err.OutDirExistsException)2 File (java.io.File)2 CantFindFrameworkResException (brut.androlib.err.CantFindFrameworkResException)1 BrutException (brut.common.BrutException)1 DirectoryException (brut.directory.DirectoryException)1 ExtFile (brut.directory.ExtFile)1 IOException (java.io.IOException)1