Search in sources :

Example 16 with ExtFile

use of brut.directory.ExtFile in project Apktool by iBotPeaches.

the class Androlib method buildManifestRaw.

public boolean buildManifestRaw(ExtFile appDir) throws AndrolibException {
    try {
        File apkDir = new File(appDir, APK_DIRNAME);
        LOGGER.info("Copying raw AndroidManifest.xml...");
        appDir.getDirectory().copyToDir(apkDir, APK_MANIFEST_FILENAMES);
        return true;
    } catch (DirectoryException ex) {
        throw new AndrolibException(ex);
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ExtFile(brut.directory.ExtFile)

Example 17 with ExtFile

use of brut.directory.ExtFile in project Apktool by iBotPeaches.

the class ApkDecoder method setApkFile.

public void setApkFile(File apkFile) {
    mApkFile = new ExtFile(apkFile);
    mResTable = null;
}
Also used : ExtFile(brut.directory.ExtFile)

Example 18 with ExtFile

use of brut.directory.ExtFile in project Apktool by iBotPeaches.

the class AndrolibResources method loadFrameworkPkg.

public ResPackage loadFrameworkPkg(ResTable resTable, int id, String frameTag) throws AndrolibException {
    File apk = getFrameworkApk(id, frameTag);
    LOGGER.info("Loading resource table from file: " + apk);
    ResPackage[] pkgs = getResPackagesFromApk(new ExtFile(apk), resTable, true);
    ResPackage pkg;
    if (pkgs.length > 1) {
        pkg = selectPkgWithMostResSpecs(pkgs);
    } else if (pkgs.length == 0) {
        throw new AndrolibException("Arsc files with zero or multiple packages");
    } else {
        pkg = pkgs[0];
    }
    if (pkg.getId() != id) {
        throw new AndrolibException("Expected pkg of id: " + String.valueOf(id) + ", got: " + pkg.getId());
    }
    resTable.addPackage(pkg, false);
    return pkg;
}
Also used : AndrolibException(brut.androlib.AndrolibException) ExtFile(brut.directory.ExtFile) ZipFile(java.util.zip.ZipFile) ExtFile(brut.directory.ExtFile)

Example 19 with ExtFile

use of brut.directory.ExtFile in project Apktool by iBotPeaches.

the class AndrolibResources method decodeManifestWithResources.

public void decodeManifestWithResources(ResTable resTable, ExtFile apkFile, File outDir) throws AndrolibException {
    Duo<ResFileDecoder, AXmlResourceParser> duo = getResFileDecoder();
    ResFileDecoder fileDecoder = duo.m1;
    ResAttrDecoder attrDecoder = duo.m2.getAttrDecoder();
    attrDecoder.setCurrentPackage(resTable.listMainPackages().iterator().next());
    Directory inApk, in = null, out;
    try {
        inApk = apkFile.getDirectory();
        out = new FileDirectory(outDir);
        LOGGER.info("Decoding AndroidManifest.xml with resources...");
        fileDecoder.decodeManifest(inApk, "AndroidManifest.xml", out, "AndroidManifest.xml");
        // Remove versionName / versionCode (aapt API 16)
        if (!resTable.getAnalysisMode()) {
            // check for a mismatch between resources.arsc package and the package listed in AndroidManifest
            // also remove the android::versionCode / versionName from manifest for rebuild
            // this is a required change to prevent aapt warning about conflicting versions
            // it will be passed as a parameter to aapt like "--min-sdk-version" via apktool.yml
            adjustPackageManifest(resTable, outDir.getAbsolutePath() + File.separator + "AndroidManifest.xml");
            ResXmlPatcher.removeManifestVersions(new File(outDir.getAbsolutePath() + File.separator + "AndroidManifest.xml"));
            mPackageId = String.valueOf(resTable.getPackageId());
        }
    } catch (DirectoryException ex) {
        throw new AndrolibException(ex);
    }
}
Also used : FileDirectory(brut.directory.FileDirectory) AndrolibException(brut.androlib.AndrolibException) ZipFile(java.util.zip.ZipFile) ExtFile(brut.directory.ExtFile) DirectoryException(brut.directory.DirectoryException) FileDirectory(brut.directory.FileDirectory) Directory(brut.directory.Directory)

Example 20 with ExtFile

use of brut.directory.ExtFile in project Apktool by iBotPeaches.

the class Androlib method decodeUnknownFiles.

public void decodeUnknownFiles(ExtFile apkFile, File outDir, ResTable resTable) throws AndrolibException {
    LOGGER.info("Copying unknown files...");
    File unknownOut = new File(outDir, UNK_DIRNAME);
    try {
        Directory unk = apkFile.getDirectory();
        // loop all items in container recursively, ignoring any that are pre-defined by aapt
        Set<String> files = unk.getFiles(true);
        for (String file : files) {
            if (!isAPKFileNames(file) && !file.endsWith(".dex")) {
                // copy file out of archive into special "unknown" folder
                unk.copyToDir(unknownOut, file);
                // lets record the name of the file, and its compression type
                // so that we may re-include it the same way
                mResUnknownFiles.addUnknownFileInfo(file, String.valueOf(unk.getCompressionLevel(file)));
            }
        }
    } catch (DirectoryException ex) {
        throw new AndrolibException(ex);
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ExtFile(brut.directory.ExtFile)

Aggregations

ExtFile (brut.directory.ExtFile)31 ZipFile (java.util.zip.ZipFile)12 File (java.io.File)10 BeforeClass (org.junit.BeforeClass)8 Test (org.junit.Test)5 MetaInfo (brut.androlib.meta.MetaInfo)4 AndrolibException (brut.androlib.AndrolibException)2 BrutException (brut.common.BrutException)1 Directory (brut.directory.Directory)1 DirectoryException (brut.directory.DirectoryException)1 FileDirectory (brut.directory.FileDirectory)1