Search code examples
javaandroidkotlinjava-iozip

Read manifest from third app


I try to read the manifest of a third app in my emulator, so I have used the PackageManager to list all apps and then picked a random app to read its manifest. The problem is that it returns be bad characters like that:

����>����r��������������������������������������l�����

There is my listing function:

val apps = context.packageManager.getInstalledApplications(PackageManager.GET_META_DATA or PackageManager.GET_SHARED_LIBRARY_FILES)

for (i in 0 until apps.size)
{
    Log.i("List", "Application $i = ${apps[i]}")

    if (i == 80)
    {
        val content = readManifest(apps[i].publicSourceDir)
    }
}

And there is my function where I try to read the manifest :

private fun readManifest(path: String): String
{
    Log.i("readManifest", "path = $path")

    val apk = ZipFile(path)
    val manifest = apk.getEntry("AndroidManifest.xml")
    val stream = apk.getInputStream(manifest)
    val content = StringBuilder()

    if (manifest != null)
    {
        val bufferedReader = BufferedReader(InputStreamReader(apk.getInputStream(manifest), "utf-8"))
        var line = bufferedReader.readLine()
        while (line != null)
        {
            Log.i("readManifest", "line = $line")
            content.append(line)
            line = bufferedReader.readLine()
        }
    }

    apk.close()
    stream.close()

    return content.toString()
}

I also tried to use another function that I found here but with the same result.

Why do I get this weird characters ? I also put the android.permission.READ_EXTERNAL_STORAGE in my manifest


Solution

  • After some research about the apk format, it seems that the Manifest is compiled in the apk file. So it's why I couldn't read it.

    To read it, we must decompile the apk before, either with a library (that I couldn't find) either in coding it.