imetting/backend/app/utils/apk_parser.py

44 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""
APK解析工具
用于从APK文件中提取版本信息使用 pyaxmlparser
"""
def parse_apk_with_androguard(apk_path):
"""
解析APK文件提取版本信息
使用 pyaxmlparser 库(轻量级,~1MB
"""
try:
from pyaxmlparser import APK
apk = APK(apk_path)
# 提取所有需要的信息
package_name = apk.package
version_code = apk.version_code
version_name = apk.version_name
app_name = apk.application
min_sdk_version = apk.get_min_sdk_version()
target_sdk_version = apk.get_target_sdk_version()
print(f"APK解析成功: package={package_name}, version_code={version_code}, version_name={version_name}, app_name={app_name}")
return {
'package_name': package_name,
'version_code': int(version_code) if version_code else None,
'version_name': version_name,
'app_name': app_name,
'min_sdk_version': min_sdk_version,
'target_sdk_version': target_sdk_version
}
except ImportError:
print("错误: pyaxmlparser 未安装")
print("请运行: pip install pyaxmlparser")
return None
except Exception as e:
print(f"APK解析失败: {str(e)}")
import traceback
traceback.print_exc()
return None