imetting_backend/app/utils/apk_parser.py

34 lines
920 B
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)
version_code = apk.version_code
version_name = apk.version_name
print(f"APK解析成功: version_code={version_code}, version_name={version_name}")
return {
'version_code': int(version_code) if version_code else None,
'version_name': version_name
}
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