repo_file['hash'] = shasum
repo_file['hashType'] = 'sha256'
repo_file['versionCode'] = 0
- repo_file['versionName'] = shasum
+ repo_file['versionName'] = shasum[0:7]
# the static ID is the SHA256 unless it is set in the metadata
repo_file['packageName'] = shasum
apk['icons_src'] = _get_apk_icons_src(apkfile, icon_name)
+def _ensure_final_value(packageName, arsc, value):
+ """Ensure incoming value is always the value, not the resid
+
+ androguard will sometimes return the Android "resId" aka
+ Resource ID instead of the actual value. This checks whether
+ the value is actually a resId, then performs the Android
+ Resource lookup as needed.
+
+ """
+ if value:
+ returnValue = value
+ if value[0] == '@':
+ try: # can be a literal value or a resId
+ res_id = int(value.replace("@", "0x"), 16)
+ res_id = arsc.get_id(packageName, res_id)[1]
+ returnValue = arsc.get_string(packageName, res_id)[1]
+ except ValueError:
+ pass
+ return returnValue
+
+
+def _sanitize_sdk_version(value):
+ """Sanitize the raw values from androguard to handle bad values
+
+ minSdkVersion/targetSdkVersion/maxSdkVersion must be integers,
+ but that doesn't stop devs from doing strange things like
+ setting them using Android XML strings.
+
+ https://gitlab.com/souch/SMSbypass/blob/v0.9/app/src/main/AndroidManifest.xml#L29
+ https://gitlab.com/souch/SMSbypass/blob/v0.9/app/src/main/res/values/strings.xml#L27
+ """
+ try:
+ sdk_version = int(value)
+ if sdk_version > 0:
+ return str(sdk_version) # heinous, but this is still str in the codebase
+ except (TypeError, ValueError):
+ pass
+ return None
+
+
def scan_apk_androguard(apk, apkfile):
try:
from androguard.core.bytecodes.apk import APK
apk['packageName'] = apkobject.get_package()
apk['versionCode'] = int(apkobject.get_androidversion_code())
- apk['versionName'] = apkobject.get_androidversion_name()
- if apk['versionName'][0] == "@":
- version_id = int(apk['versionName'].replace("@", "0x"), 16)
- version_id = arsc.get_id(apk['packageName'], version_id)[1]
- apk['versionName'] = arsc.get_string(apk['packageName'], version_id)[1]
apk['name'] = apkobject.get_app_name()
- if apkobject.get_max_sdk_version() is not None:
- apk['maxSdkVersion'] = apkobject.get_max_sdk_version()
- if apkobject.get_min_sdk_version() is not None:
- apk['minSdkVersion'] = apkobject.get_min_sdk_version()
- if apkobject.get_target_sdk_version() is not None:
- apk['targetSdkVersion'] = apkobject.get_target_sdk_version()
+ apk['versionName'] = _ensure_final_value(apk['packageName'], arsc,
+ apkobject.get_androidversion_name())
+
+ minSdkVersion = _sanitize_sdk_version(apkobject.get_min_sdk_version())
+ if minSdkVersion is not None:
+ apk['minSdkVersion'] = minSdkVersion
+
+ targetSdkVersion = _sanitize_sdk_version(apkobject.get_target_sdk_version())
+ if targetSdkVersion is not None:
+ apk['targetSdkVersion'] = targetSdkVersion
+
+ maxSdkVersion = _sanitize_sdk_version(apkobject.get_max_sdk_version())
+ if maxSdkVersion is not None:
+ apk['maxSdkVersion'] = maxSdkVersion
icon_id_str = apkobject.get_element("application", "icon")
if icon_id_str: