Created
May 20, 2024 21:20
-
-
Save obfusk/7484e4f5cea2c84fc841f472fffcc59c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.android.apksig.ApkSigner | |
import com.android.apksig.apk.ApkUtils | |
import com.android.apksig.internal.apk.v1.V1SchemeVerifier | |
import com.android.apksig.util.DataSource | |
import com.android.apksig.util.DataSources | |
def f = new RandomAccessFile(args[0], "r") | |
def apk = DataSources.asDataSource(f, 0, f.length()) | |
def zipSections = ApkUtils.findZipSections(apk) | |
def cdRecords = V1SchemeVerifier.parseZipCentralDirectory(apk, zipSections) | |
def androidManifest = ApkSigner.getAndroidManifestFromApk( | |
cdRecords, apk.slice(0, zipSections.getZipCentralDirectoryOffset())) | |
def minSdkVersion = ApkUtils.getMinSdkVersionFromBinaryAndroidManifest( | |
androidManifest.slice()) | |
def targetSdkVersion = ApkUtils.getTargetSdkVersionFromBinaryAndroidManifest( | |
androidManifest.slice()) | |
println "minSdkVersion=$minSdkVersion" | |
println "targetSdkVersion=$targetSdkVersion" | |
// def foo = ApkUtils.getAttributeValueFromBinaryAndroidManifest( | |
// androidManifest.slice(), "uses-sdk", 0x0101020c) | |
// | |
// println foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment