1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-11-22 23:15:24 +01:00
NekoX/apkfrombundle.py

72 lines
2.3 KiB
Python
Raw Normal View History

2023-01-24 19:08:20 +01:00
import sys
from zipfile import ZipFile
def compareFiles(first, second):
2023-01-26 14:06:12 +01:00
while True:
firstBytes = first.read(4096)
secondBytes = second.read(4096)
if firstBytes != secondBytes:
return False
if firstBytes == b"" and secondBytes == b"":
break
2023-01-24 19:08:20 +01:00
2023-01-26 14:06:12 +01:00
return True
2023-01-24 19:08:20 +01:00
def remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text
2023-01-26 14:06:12 +01:00
2023-01-24 19:08:20 +01:00
def compareApkFromBundle(bundle, apk):
2023-01-26 14:06:12 +01:00
FILES_TO_IGNORE = ["resources.arsc", "stamp-cert-sha256"]
2023-01-24 19:08:20 +01:00
apkZip = ZipFile(apk, 'r')
bundleZip = ZipFile(bundle, 'r')
firstList = list(filter(lambda info: info.filename not in FILES_TO_IGNORE, apkZip.infolist()))
secondList = list(filter(lambda secondInfo: secondInfo.filename not in FILES_TO_IGNORE, bundleZip.infolist()))
2023-01-26 14:06:12 +01:00
2023-01-24 19:08:20 +01:00
for apkInfo in firstList:
if (apkInfo.filename.startswith("META-INF/")):
continue
if (apkInfo.filename.startswith("res/")):
continue
if (apkInfo.filename.startswith("AndroidManifest.xml")):
continue
found = False
for bundleInfo in secondList:
fileName = bundleInfo.filename
fileName = remove_prefix(fileName, "base/root/")
fileName = remove_prefix(fileName, "base/dex/")
fileName = remove_prefix(fileName, "base/manifest/")
fileName = remove_prefix(fileName, "base/")
if (fileName.startswith("BUNDLE-METADATA")):
fileName = "META-INF" + remove_prefix(fileName, "BUNDLE-METADATA/")
if fileName == apkInfo.filename:
found = True
firstFile = apkZip.open(apkInfo, 'r')
secondFile = bundleZip.open(bundleInfo, 'r')
if compareFiles(firstFile, secondFile) != True:
print("APK file %s does not match" % apkInfo.filename)
return False
break
if found == False:
print("file %s not found in APK" % apkInfo.filename)
return False
2023-01-26 14:06:12 +01:00
2023-01-24 19:08:20 +01:00
return True
if __name__ == '__main__':
2023-01-26 14:06:12 +01:00
if len(sys.argv) != 3:
print("Usage: apkfrombundle <pathToBundle> <pathToApk>")
sys.exit(1)
2023-01-24 19:08:20 +01:00
2023-01-26 14:06:12 +01:00
if sys.argv[1] == sys.argv[2] or compareApkFromBundle(sys.argv[1], sys.argv[2]) == True:
print("APK from bundle!")
else:
print("APK has difference!")