mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
utils.android.ApkInfo: Retrieve APK class methods
Add a pseudo-attribute to ApkInfo giving all the methods available in the APK as a list of (class, method) tuples. To keep backward compatibility, this list is retrieved the first time the attribute is being accessed.
This commit is contained in:
parent
2b6cb264cf
commit
f2a87ce61c
@ -28,6 +28,9 @@ import tempfile
|
|||||||
import subprocess
|
import subprocess
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import pexpect
|
import pexpect
|
||||||
|
import xml.etree.ElementTree
|
||||||
|
import zipfile
|
||||||
|
|
||||||
from pipes import quote
|
from pipes import quote
|
||||||
|
|
||||||
from devlib.exception import TargetTransientError, TargetStableError, HostError
|
from devlib.exception import TargetTransientError, TargetStableError, HostError
|
||||||
@ -183,6 +186,7 @@ class ApkInfo(object):
|
|||||||
|
|
||||||
self._apk_path = apk_path
|
self._apk_path = apk_path
|
||||||
self._activities = None
|
self._activities = None
|
||||||
|
self._methods = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def activities(self):
|
def activities(self):
|
||||||
@ -193,6 +197,26 @@ class ApkInfo(object):
|
|||||||
self._activities = [m.group('name') for m in matched_activities]
|
self._activities = [m.group('name') for m in matched_activities]
|
||||||
return self._activities
|
return self._activities
|
||||||
|
|
||||||
|
@property
|
||||||
|
def methods(self):
|
||||||
|
if self._methods is None:
|
||||||
|
with zipfile.ZipFile(self._apk_path, 'r') as z:
|
||||||
|
extracted = z.extract('classes.dex', tempfile.gettempdir())
|
||||||
|
|
||||||
|
dexdump = os.path.join(os.path.dirname(aapt), 'dexdump')
|
||||||
|
command = [dexdump, '-l', 'xml', extracted]
|
||||||
|
dump = self._run(command)
|
||||||
|
|
||||||
|
xml_tree = xml.etree.ElementTree.fromstring(dump)
|
||||||
|
|
||||||
|
package = next(i for i in xml_tree.iter('package')
|
||||||
|
if i.attrib['name'] == self.package)
|
||||||
|
|
||||||
|
self._methods = [(meth.attrib['name'], klass.attrib['name'])
|
||||||
|
for klass in package.iter('class')
|
||||||
|
for meth in klass.iter('method')]
|
||||||
|
return self._methods
|
||||||
|
|
||||||
def _run(self, command):
|
def _run(self, command):
|
||||||
logger.debug(' '.join(command))
|
logger.debug(' '.join(command))
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user