diff --git a/diffuse/build.gradle b/diffuse/build.gradle index bba835d8..5aee9532 100644 --- a/diffuse/build.gradle +++ b/diffuse/build.gradle @@ -102,7 +102,7 @@ def binaryJar = tasks.register("binaryDiffuseJar") { task -> } } -[11, 17].forEach { majorVersion -> +[17, 21, 25].forEach { majorVersion -> def jdkTest = tasks.register("testJdk$majorVersion", Test) { javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(majorVersion) diff --git a/diffuse/src/test/kotlin/com/jakewharton/diffuse/ApkManifestTest.kt b/diffuse/src/test/kotlin/com/jakewharton/diffuse/ApkManifestTest.kt new file mode 100644 index 00000000..71cfc870 --- /dev/null +++ b/diffuse/src/test/kotlin/com/jakewharton/diffuse/ApkManifestTest.kt @@ -0,0 +1,40 @@ +package com.jakewharton.diffuse + +import com.jakewharton.diffuse.format.Apk.Companion.toApk +import com.jakewharton.diffuse.io.Input.Companion.asInput +import java.io.File +import kotlin.io.path.Path +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ApkManifestTest { + + @Test + fun `binary manifest of stripe master`() = assertManifest("stripe/paymentsheet-example-release-master.apk", "stripe/manifest-master.txt") + + @Test + fun `binary manifest of stripe pr`() = assertManifest("stripe/paymentsheet-example-release-pr.apk", "stripe/manifest-pr.txt") + + @Test + fun `binary manifest of signed artifact`() = assertManifest("otwarty-wykop-mobilny/app-release.apk", "otwarty-wykop-mobilny/manifest.txt") + + @Test + fun `binary manifest of obfuscated artifact A`() = assertManifest("github-browser/apkA.apk", "github-browser/manifest-a.txt") + + @Test + fun `binary manifest of obfuscated artifact B`() = assertManifest("github-browser/apkB.apk", "github-browser/manifest-b.txt") + + private fun assertManifest(apk: String, expected: String) { + val manifest = Path(loadResource(apk)).asInput().toApk().manifest + + val actual = buildString { + appendLine("package: ${manifest.packageName}") + appendLine("versionName: ${manifest.versionName}") + appendLine("versionCode: ${manifest.versionCode}") + appendLine() + append(manifest.xml) + } + + assertThat(actual).isEqualTo(File(loadResource(expected)).readText()) + } +} diff --git a/diffuse/src/test/resources/github-browser/manifest-a.txt b/diffuse/src/test/resources/github-browser/manifest-a.txt new file mode 100644 index 00000000..aaabb89a --- /dev/null +++ b/diffuse/src/test/resources/github-browser/manifest-a.txt @@ -0,0 +1,68 @@ +package: pl.mateuszkwiecinski.browser +versionName: 0.2.0 +versionCode: 2000 + + + + + + + + + + + + + + + + + + + diff --git a/diffuse/src/test/resources/github-browser/manifest-b.txt b/diffuse/src/test/resources/github-browser/manifest-b.txt new file mode 100644 index 00000000..aaabb89a --- /dev/null +++ b/diffuse/src/test/resources/github-browser/manifest-b.txt @@ -0,0 +1,68 @@ +package: pl.mateuszkwiecinski.browser +versionName: 0.2.0 +versionCode: 2000 + + + + + + + + + + + + + + + + + + + diff --git a/diffuse/src/test/resources/otwarty-wykop-mobilny/manifest.txt b/diffuse/src/test/resources/otwarty-wykop-mobilny/manifest.txt new file mode 100644 index 00000000..ea36b8e4 --- /dev/null +++ b/diffuse/src/test/resources/otwarty-wykop-mobilny/manifest.txt @@ -0,0 +1,732 @@ +package: io.github.wykopmobilny +versionName: 1.3.0 +versionCode: 1003000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/diffuse/src/test/resources/stripe/manifest-master.txt b/diffuse/src/test/resources/stripe/manifest-master.txt new file mode 100644 index 00000000..737406bf --- /dev/null +++ b/diffuse/src/test/resources/stripe/manifest-master.txt @@ -0,0 +1,238 @@ +package: com.stripe.android.paymentsheet.example +versionName: 1.0 +versionCode: 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/diffuse/src/test/resources/stripe/manifest-pr.txt b/diffuse/src/test/resources/stripe/manifest-pr.txt new file mode 100644 index 00000000..737406bf --- /dev/null +++ b/diffuse/src/test/resources/stripe/manifest-pr.txt @@ -0,0 +1,238 @@ +package: com.stripe.android.paymentsheet.example +versionName: 1.0 +versionCode: 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/formats/src/main/kotlin/com/jakewharton/diffuse/format/AndroidManifest.kt b/formats/src/main/kotlin/com/jakewharton/diffuse/format/AndroidManifest.kt index 733f134e..e481b6ae 100644 --- a/formats/src/main/kotlin/com/jakewharton/diffuse/format/AndroidManifest.kt +++ b/formats/src/main/kotlin/com/jakewharton/diffuse/format/AndroidManifest.kt @@ -3,17 +3,17 @@ package com.jakewharton.diffuse.format import com.android.aapt.Resources.XmlNode import com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode import com.android.tools.build.bundletool.xml.XmlProtoToXmlConverter -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceFile -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue.Type.INT_BOOLEAN -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue.Type.INT_COLOR_ARGB4 -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue.Type.INT_COLOR_ARGB8 -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue.Type.INT_COLOR_RGB4 -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue.Type.INT_COLOR_RGB8 -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue.Type.INT_DEC -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue.Type.INT_HEX -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue.Type.NULL -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue.Type.REFERENCE -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue.Type.STRING +import com.google.devrel.gmscore.tools.apk.arsc.ResourceFile +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue.Type.INT_BOOLEAN +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue.Type.INT_COLOR_ARGB4 +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue.Type.INT_COLOR_ARGB8 +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue.Type.INT_COLOR_RGB4 +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue.Type.INT_COLOR_RGB8 +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue.Type.INT_DEC +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue.Type.INT_HEX +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue.Type.NULL +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue.Type.REFERENCE +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue.Type.STRING import com.google.devrel.gmscore.tools.apk.arsc.XmlChunk import com.google.devrel.gmscore.tools.apk.arsc.XmlEndElementChunk import com.google.devrel.gmscore.tools.apk.arsc.XmlNamespaceStartChunk @@ -45,7 +45,7 @@ class AndroidManifest private constructor( isNamespaceAware = true } - internal fun BinaryResourceFile.toManifest(arsc: Arsc? = null): AndroidManifest = toDocument(arsc).toManifest() + internal fun ResourceFile.toManifest(arsc: Arsc? = null): AndroidManifest = toDocument(arsc).toManifest() @JvmStatic @JvmName("parse") @@ -59,7 +59,7 @@ class AndroidManifest private constructor( .apply { normalizeWhitespace() } .toManifest() - private fun BinaryResourceFile.toDocument(arsc: Arsc?): Document { + private fun ResourceFile.toDocument(arsc: Arsc?): Document { val rootChunk = requireNotNull(chunks.singleOrNull() as XmlChunk?) { "Unable to parse manifest from binary XML" } diff --git a/formats/src/main/kotlin/com/jakewharton/diffuse/format/Apk.kt b/formats/src/main/kotlin/com/jakewharton/diffuse/format/Apk.kt index 8eb08501..d85b9683 100644 --- a/formats/src/main/kotlin/com/jakewharton/diffuse/format/Apk.kt +++ b/formats/src/main/kotlin/com/jakewharton/diffuse/format/Apk.kt @@ -26,7 +26,7 @@ class Apk private constructor( toZip().use { zip -> val files = zip.toArchiveFiles { it.toApkFileType() } val arsc = zip[Arsc.NAME].asInput().toArsc() - val manifest = zip[AndroidManifest.NAME].asInput().toBinaryResourceFile().toManifest(arsc) + val manifest = zip[AndroidManifest.NAME].asInput().toResourceFile().toManifest(arsc) val dexes = zip.entries .filter { it.path.matches(classesDexRegex) } .map { it.asInput().toDex() } diff --git a/formats/src/main/kotlin/com/jakewharton/diffuse/format/Arsc.kt b/formats/src/main/kotlin/com/jakewharton/diffuse/format/Arsc.kt index f82b78ab..4fea835c 100644 --- a/formats/src/main/kotlin/com/jakewharton/diffuse/format/Arsc.kt +++ b/formats/src/main/kotlin/com/jakewharton/diffuse/format/Arsc.kt @@ -26,7 +26,7 @@ class Arsc private constructor( @JvmStatic @JvmName("create") fun Input.toArsc(): Arsc { - val chunk = toBinaryResourceFile().chunks.single() + val chunk = toResourceFile().chunks.single() check(chunk is ResourceTableChunk) { "Root arsc chunk is not a resource table " } val configs = mutableListOf() @@ -43,7 +43,7 @@ class Arsc private constructor( val typeId = typeChunk.id for ((entryId, entry) in typeChunk.entries) { - // See BinaryResourceIdentifier for the source of this algorithm. + // See ResourceIdentifier for the source of this algorithm. val id = ((packageId and 0xFF) shl 24) or ((typeId and 0xFF) shl 16) or ((entryId and 0xFFFF)) diff --git a/formats/src/main/kotlin/com/jakewharton/diffuse/format/util.kt b/formats/src/main/kotlin/com/jakewharton/diffuse/format/util.kt index 17dc33c3..ca622f77 100644 --- a/formats/src/main/kotlin/com/jakewharton/diffuse/format/util.kt +++ b/formats/src/main/kotlin/com/jakewharton/diffuse/format/util.kt @@ -1,6 +1,6 @@ package com.jakewharton.diffuse.format -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceFile +import com.google.devrel.gmscore.tools.apk.arsc.ResourceFile import com.jakewharton.diffuse.io.Input -internal fun Input.toBinaryResourceFile() = BinaryResourceFile(toByteArray()) +internal fun Input.toResourceFile() = ResourceFile(toByteArray()) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a521298a..358972e3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] java-compilation = "27" -java-target = "11" +java-target = "17" bundletool = "1.18.3" # Keep this values in sync with bundletool"s dependencies. aapt2Proto = "7.3.0-alpha07-8248216" @@ -8,7 +8,7 @@ protobufJava = "3.19.2" guava = "31.0.1-jre" dalvikdx = "16.0.1" -apkparser = "31.13.2" +apkparser = "32.5.2" apksign = "9.5.2" clikt = "5.2.1" junit = "5.14.4"