Search in sources :

Example 1 with MetaInfo

use of brut.androlib.meta.MetaInfo in project Apktool by iBotPeaches.

the class ApkDecoder method writeMetaFile.

private void writeMetaFile() throws AndrolibException {
    MetaInfo meta = new MetaInfo();
    meta.version = Androlib.getVersion();
    meta.apkFileName = mApkFile.getName();
    if (mDecodeResources != DECODE_RESOURCES_NONE && (hasManifest() || hasResources())) {
        meta.isFrameworkApk = mAndrolib.isFrameworkApk(getResTable());
        putUsesFramework(meta);
        putSdkInfo(meta);
        putPackageInfo(meta);
        putVersionInfo(meta);
        putSharedLibraryInfo(meta);
    }
    putUnknownInfo(meta);
    putFileCompressionInfo(meta);
    mAndrolib.writeMetaFile(mOutDir, meta);
}
Also used : MetaInfo(brut.androlib.meta.MetaInfo)

Example 2 with MetaInfo

use of brut.androlib.meta.MetaInfo in project Apktool by iBotPeaches.

the class ReferenceVersionCodeTest method referenceBecomesLiteralTest.

@Test
public void referenceBecomesLiteralTest() throws BrutException, IOException {
    String apk = "issue1234.apk";
    // decode issue1234.apk
    ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
    ExtFile decodedApk = new ExtFile(sTmpDir + File.separator + apk + ".out");
    apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
    apkDecoder.decode();
    MetaInfo metaInfo = new Androlib().readMetaFile(decodedApk);
    assertEquals("v1.0.0", metaInfo.versionInfo.versionName);
}
Also used : MetaInfo(brut.androlib.meta.MetaInfo) ExtFile(brut.directory.ExtFile) ExtFile(brut.directory.ExtFile) File(java.io.File) Test(org.junit.Test)

Example 3 with MetaInfo

use of brut.androlib.meta.MetaInfo in project Apktool by iBotPeaches.

the class Androlib method build.

public void build(ExtFile appDir, File outFile) throws BrutException {
    LOGGER.info("Using Apktool " + Androlib.getVersion());
    MetaInfo meta = readMetaFile(appDir);
    apkOptions.isFramework = meta.isFrameworkApk;
    apkOptions.resourcesAreCompressed = meta.compressionType;
    apkOptions.doNotCompress = meta.doNotCompress;
    mAndRes.setSdkInfo(meta.sdkInfo);
    mAndRes.setPackageId(meta.packageInfo);
    mAndRes.setPackageRenamed(meta.packageInfo);
    mAndRes.setVersionInfo(meta.versionInfo);
    mAndRes.setSharedLibrary(meta.sharedLibrary);
    if (meta.sdkInfo != null && meta.sdkInfo.get("minSdkVersion") != null) {
        mMinSdkVersion = Integer.parseInt(meta.sdkInfo.get("minSdkVersion"));
    }
    if (outFile == null) {
        String outFileName = meta.apkFileName;
        outFile = new File(appDir, "dist" + File.separator + (outFileName == null ? "out.apk" : outFileName));
    }
    new File(appDir, APK_DIRNAME).mkdirs();
    buildSources(appDir);
    buildNonDefaultSources(appDir);
    File manifest = new File(appDir, "AndroidManifest.xml");
    File manifestOriginal = new File(appDir, "AndroidManifest.xml.orig");
    if (manifest.isFile() && manifest.exists()) {
        try {
            if (manifestOriginal.exists()) {
                manifestOriginal.delete();
            }
            FileUtils.copyFile(manifest, manifestOriginal);
            ResXmlPatcher.fixingPublicAttrsInProviderAttributes(manifest);
        } catch (IOException ex) {
            throw new AndrolibException(ex.getMessage());
        }
    }
    buildResources(appDir, meta.usesFramework);
    buildLib(appDir);
    buildLibs(appDir);
    buildCopyOriginalFiles(appDir);
    buildApk(appDir, outFile);
    // we must go after the Apk is built, and copy the files in via Zip
    // this is because Aapt won't add files it doesn't know (ex unknown files)
    buildUnknownFiles(appDir, outFile, meta);
    // lets restore the unedited one, to not change the original
    if (manifest.isFile() && manifest.exists()) {
        try {
            if (new File(appDir, "AndroidManifest.xml").delete()) {
                FileUtils.moveFile(manifestOriginal, manifest);
            }
        } catch (IOException ex) {
            throw new AndrolibException(ex.getMessage());
        }
    }
}
Also used : MetaInfo(brut.androlib.meta.MetaInfo) ZipFile(java.util.zip.ZipFile) ExtFile(brut.directory.ExtFile)

Example 4 with MetaInfo

use of brut.androlib.meta.MetaInfo in project Apktool by iBotPeaches.

the class BuildAndDecodeTest method compareUnknownFiles.

@SuppressWarnings("unchecked")
private void compareUnknownFiles() throws BrutException, IOException {
    MetaInfo control = new Androlib().readMetaFile(sTestOrigDir);
    MetaInfo test = new Androlib().readMetaFile(sTestNewDir);
    assertNotNull(control.unknownFiles);
    assertNotNull(test.unknownFiles);
    Map<String, String> control_files = control.unknownFiles;
    Map<String, String> test_files = test.unknownFiles;
    assertTrue(control_files.size() == test_files.size());
    // Make sure that the compression methods are still the same
    for (Map.Entry<String, String> controlEntry : control_files.entrySet()) {
        assertTrue(controlEntry.getValue().equals(test_files.get(controlEntry.getKey())));
    }
}
Also used : MetaInfo(brut.androlib.meta.MetaInfo) Map(java.util.Map)

Example 5 with MetaInfo

use of brut.androlib.meta.MetaInfo in project Apktool by iBotPeaches.

the class DoubleExtensionUnknownFileTest method multipleExtensionUnknownFileTest.

@Test
public void multipleExtensionUnknownFileTest() throws BrutException, IOException {
    String apk = "issue1244.apk";
    // decode issue1244.apk
    ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
    ExtFile decodedApk = new ExtFile(sTmpDir + File.separator + apk + ".out");
    apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
    apkDecoder.decode();
    MetaInfo metaInfo = new Androlib().readMetaFile(decodedApk);
    for (String string : metaInfo.doNotCompress) {
        if (StringUtils.countMatches(string, ".") > 1) {
            assertTrue(string.equalsIgnoreCase("assets/bin/Data/sharedassets1.assets.split0"));
        }
    }
}
Also used : MetaInfo(brut.androlib.meta.MetaInfo) ExtFile(brut.directory.ExtFile) ExtFile(brut.directory.ExtFile) File(java.io.File) Test(org.junit.Test)

Aggregations

MetaInfo (brut.androlib.meta.MetaInfo)6 ExtFile (brut.directory.ExtFile)4 File (java.io.File)3 Test (org.junit.Test)3 Map (java.util.Map)1 ZipFile (java.util.zip.ZipFile)1