2from zipfile import ZipFile
4def compareFiles(first, second):
6 firstBytes = first.read(4096)
7 secondBytes = second.read(4096)
8 if firstBytes != secondBytes:
11 if firstBytes == b"" and secondBytes == b"":
16def remove_prefix(text, prefix):
17 if text.startswith(prefix):
18 return text[len(prefix):]
21def compareApkFromBundle(bundle, apk):
22 FILES_TO_IGNORE = ["resources.arsc", "stamp-cert-sha256"]
24 apkZip = ZipFile(apk, 'r')
25 bundleZip = ZipFile(bundle, 'r')
27 firstList = list(filter(lambda info: info.filename not in FILES_TO_IGNORE, apkZip.infolist()))
28 secondList = list(filter(lambda secondInfo: secondInfo.filename not in FILES_TO_IGNORE, bundleZip.infolist()))
30 for apkInfo in firstList:
31 if (apkInfo.filename.startswith("META-INF/")):
33 if (apkInfo.filename.startswith("res/")):
35 if (apkInfo.filename.startswith("AndroidManifest.xml")):
39 for bundleInfo in secondList:
40 fileName = bundleInfo.filename
41 fileName = remove_prefix(fileName, "base/root/")
42 fileName = remove_prefix(fileName, "base/dex/")
43 fileName = remove_prefix(fileName, "base/manifest/")
44 fileName = remove_prefix(fileName, "base/")
45 if (fileName.startswith("BUNDLE-METADATA")):
46 fileName = "META-INF" + remove_prefix(fileName, "BUNDLE-METADATA/")
47 if fileName == apkInfo.filename:
49 firstFile = apkZip.open(apkInfo, 'r')
50 secondFile = bundleZip.open(bundleInfo, 'r')
51 if compareFiles(firstFile, secondFile) != True:
52 print("APK file %s does not match" % apkInfo.filename)
57 print("file %s not found in APK" % apkInfo.filename)
62if __name__ == '__main__':
63 if len(sys.argv) != 3:
64 print("Usage: apkfrombundle <pathToBundle> <pathToApk>")
68 if sys.argv[1] == sys.argv[2] or compareApkFromBundle(sys.argv[1], sys.argv[2]) == True:
69 print("APK from bundle!")
71 print("APK has difference!")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list