Search in sources :

Example 11 with ExtFile

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

the class ProviderAttributeTest method isProviderStringReplacementWorking.

@Test
public void isProviderStringReplacementWorking() throws BrutException, IOException {
    String apk = "issue636.apk";
    // decode issue636.apk
    ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
    apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
    apkDecoder.decode();
    // build issue636
    ExtFile testApk = new ExtFile(sTmpDir, apk + ".out");
    new Androlib().build(testApk, null);
    String newApk = apk + ".out" + File.separator + "dist" + File.separator + apk;
    assertTrue(fileExists(newApk));
    // decode issues636 again
    apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + newApk));
    apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out.two"));
    apkDecoder.decode();
    String expected = TestUtils.replaceNewlines("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n" + "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"com.ibotpeaches.issue636\" platformBuildVersionCode=\"23\" platformBuildVersionName=\"6.0-2438415\">\n" + "    <application android:allowBackup=\"true\" android:debuggable=\"true\" android:icon=\"@mipmap/ic_launcher\" android:label=\"@string/app_name\" android:theme=\"@style/AppTheme\">\n" + "        <provider android:authorities=\"com.ibotpeaches.issue636.Provider\" android:exported=\"false\" android:grantUriPermissions=\"true\" android:label=\"@string/app_name\" android:multiprocess=\"false\" android:name=\"com.ibotpeaches.issue636.Provider\"/>\n" + "        <provider android:authorities=\"com.ibotpeaches.issue636.ProviderTwo\" android:exported=\"false\" android:grantUriPermissions=\"true\" android:label=\"@string/app_name\" android:multiprocess=\"false\" android:name=\"com.ibotpeaches.issue636.ProviderTwo\"/>\n" + "    </application>\n" + "</manifest>");
    byte[] encoded = Files.readAllBytes(Paths.get(sTmpDir + File.separator + apk + ".out.two" + File.separator + "AndroidManifest.xml"));
    String obtained = TestUtils.replaceNewlines(new String(encoded));
    assertEquals(expected, obtained);
}
Also used : ExtFile(brut.directory.ExtFile) ExtFile(brut.directory.ExtFile) File(java.io.File) Test(org.junit.Test)

Example 12 with ExtFile

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

the class Androlib method writeOriginalFiles.

public void writeOriginalFiles(ExtFile apkFile, File outDir) throws AndrolibException {
    LOGGER.info("Copying original files...");
    File originalDir = new File(outDir, "original");
    if (!originalDir.exists()) {
        originalDir.mkdirs();
    }
    try {
        Directory in = apkFile.getDirectory();
        if (in.containsFile("AndroidManifest.xml")) {
            in.copyToDir(originalDir, "AndroidManifest.xml");
        }
        if (in.containsDir("META-INF")) {
            in.copyToDir(originalDir, "META-INF");
        }
    } catch (DirectoryException ex) {
        throw new AndrolibException(ex);
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ExtFile(brut.directory.ExtFile)

Example 13 with ExtFile

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

the class Androlib method buildResourcesRaw.

public boolean buildResourcesRaw(ExtFile appDir) throws AndrolibException {
    try {
        if (!new File(appDir, "resources.arsc").exists()) {
            return false;
        }
        File apkDir = new File(appDir, APK_DIRNAME);
        if (!apkOptions.forceBuildAll) {
            LOGGER.info("Checking whether resources has changed...");
        }
        if (apkOptions.forceBuildAll || isModified(newFiles(APK_RESOURCES_FILENAMES, appDir), newFiles(APK_RESOURCES_FILENAMES, apkDir))) {
            LOGGER.info("Copying raw resources...");
            appDir.getDirectory().copyToDir(apkDir, APK_RESOURCES_FILENAMES);
        }
        return true;
    } catch (DirectoryException ex) {
        throw new AndrolibException(ex);
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ExtFile(brut.directory.ExtFile)

Example 14 with ExtFile

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

the class Androlib method buildSourcesSmali.

public boolean buildSourcesSmali(File appDir, String folder, String filename) throws AndrolibException {
    ExtFile smaliDir = new ExtFile(appDir, folder);
    if (!smaliDir.exists()) {
        return false;
    }
    File dex = new File(appDir, APK_DIRNAME + "/" + filename);
    if (!apkOptions.forceBuildAll) {
        LOGGER.info("Checking whether sources has changed...");
    }
    if (apkOptions.forceBuildAll || isModified(smaliDir, dex)) {
        LOGGER.info("Smaling " + folder + " folder into " + filename + "...");
        dex.delete();
        SmaliBuilder.build(smaliDir, dex, mMinSdkVersion);
    }
    return true;
}
Also used : ExtFile(brut.directory.ExtFile) ZipFile(java.util.zip.ZipFile) ExtFile(brut.directory.ExtFile)

Example 15 with ExtFile

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

the class Androlib method buildResourcesFull.

public boolean buildResourcesFull(File appDir, UsesFramework usesFramework) throws AndrolibException {
    try {
        if (!new File(appDir, "res").exists()) {
            return false;
        }
        if (!apkOptions.forceBuildAll) {
            LOGGER.info("Checking whether resources has changed...");
        }
        File apkDir = new File(appDir, APK_DIRNAME);
        if (apkOptions.forceBuildAll || isModified(newFiles(APP_RESOURCES_FILENAMES, appDir), newFiles(APK_RESOURCES_FILENAMES, apkDir))) {
            LOGGER.info("Building resources...");
            if (apkOptions.debugMode) {
                ResXmlPatcher.removeApplicationDebugTag(new File(appDir, "AndroidManifest.xml"));
            }
            File apkFile = File.createTempFile("APKTOOL", null);
            apkFile.delete();
            File ninePatch = new File(appDir, "9patch");
            if (!ninePatch.exists()) {
                ninePatch = null;
            }
            mAndRes.aaptPackage(apkFile, new File(appDir, "AndroidManifest.xml"), new File(appDir, "res"), ninePatch, null, parseUsesFramework(usesFramework));
            Directory tmpDir = new ExtFile(apkFile).getDirectory();
            tmpDir.copyToDir(apkDir, tmpDir.containsDir("res") ? APK_RESOURCES_FILENAMES : APK_RESOURCES_WITHOUT_RES_FILENAMES);
            // delete tmpDir
            apkFile.delete();
        }
        return true;
    } catch (IOException | BrutException ex) {
        throw new AndrolibException(ex);
    }
}
Also used : BrutException(brut.common.BrutException) ExtFile(brut.directory.ExtFile) 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