mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-05 23:10:29 +03:00
use androguard if aapt isn't found
This commit is contained in:
parent
9607cdb621
commit
06598ae406
8 changed files with 490 additions and 111 deletions
|
|
@ -46,6 +46,8 @@ from pyasn1.codec.der import decoder, encoder
|
|||
from pyasn1_modules import rfc2315
|
||||
from pyasn1.error import PyAsn1Error
|
||||
|
||||
from distutils.util import strtobool
|
||||
|
||||
import fdroidserver.metadata
|
||||
from .asynchronousfilereader import AsynchronousFileReader
|
||||
|
||||
|
|
@ -1690,14 +1692,7 @@ def get_file_extension(filename):
|
|||
return os.path.splitext(filename)[1].lower()[1:]
|
||||
|
||||
|
||||
def isApkAndDebuggable(apkfile, config):
|
||||
"""Returns True if the given file is an APK and is debuggable
|
||||
|
||||
:param apkfile: full path to the apk to check"""
|
||||
|
||||
if get_file_extension(apkfile) != 'apk':
|
||||
return False
|
||||
|
||||
def get_apk_debuggable_aapt(apkfile):
|
||||
p = SdkToolsPopen(['aapt', 'dump', 'xmltree', apkfile, 'AndroidManifest.xml'],
|
||||
output=False)
|
||||
if p.returncode != 0:
|
||||
|
|
@ -1709,6 +1704,35 @@ def isApkAndDebuggable(apkfile, config):
|
|||
return False
|
||||
|
||||
|
||||
def get_apk_debuggable_androguard(apkfile):
|
||||
try:
|
||||
from androguard.core.bytecodes.apk import APK
|
||||
except ImportError:
|
||||
logging.critical("androguard library is not installed and aapt not present")
|
||||
sys.exit(1)
|
||||
|
||||
apkobject = APK(apkfile)
|
||||
if apkobject.is_valid_APK():
|
||||
debuggable = apkobject.get_element("application", "debuggable")
|
||||
if debuggable is not None:
|
||||
return bool(strtobool(debuggable))
|
||||
return False
|
||||
|
||||
|
||||
def isApkAndDebuggable(apkfile, config):
|
||||
"""Returns True if the given file is an APK and is debuggable
|
||||
|
||||
:param apkfile: full path to the apk to check"""
|
||||
|
||||
if get_file_extension(apkfile) != 'apk':
|
||||
return False
|
||||
|
||||
if set_command_in_config('aapt'):
|
||||
return get_apk_debuggable_aapt(apkfile)
|
||||
else:
|
||||
return get_apk_debuggable_androguard(apkfile)
|
||||
|
||||
|
||||
class PopenResult:
|
||||
def __init__(self):
|
||||
self.returncode = None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue