Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

Commit

Permalink
use axmlparserpy instead of androguard, close #121
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Apr 15, 2017
1 parent 4586fa5 commit 8130693
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
10 changes: 7 additions & 3 deletions atx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ def _inner(parser_args):

def _apk_parse(args):
import atx.androaxml as apkparse
(pkg_name, activity) = apkparse.parse_apk(args.filename)
manifest = apkparse.parse_apk(args.filename)
print(json.dumps({
'package_name': pkg_name,
'main_activity': activity,
'package_name': manifest.package_name,
'main_activity': manifest.main_activity,
'version': {
'code': manifest.version_code,
'name': manifest.version_name,
}
}, indent=4))


Expand Down
65 changes: 60 additions & 5 deletions atx/androaxml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,69 @@
#!/usr/bin/env python
# coding: utf-8

from androguard.core.bytecodes import apk
import zipfile
from xml.dom import minidom
from axmlparserpy.axmlprinter import AXMLPrinter


class Manifest(object):
def __init__(self, content):
self._dom = minidom.parseString(content)
self._permissions = None

@property
def package_name(self):
return self._dom.documentElement.getAttribute('package')

@property
def version_code(self):
return self._dom.documentElement.getAttribute("android:versionCode")

@property
def version_name(self):
return self._dom.documentElement.getAttribute("android:versionName")

@property
def permissions(self):
if self._permissions is not None:
return self._permissions

self._permissions = []
for item in self._dom.getElementsByTagName("uses-permission"):
self._permissions.append(str(item.getAttribute("android:name")))
return self._permissions

@property
def main_activity(self):
"""
Returns:
the name of the main activity
"""
x = set()
y = set()

for item in self._dom.getElementsByTagName("activity"):
for sitem in item.getElementsByTagName("action"):
val = sitem.getAttribute("android:name")
if val == "android.intent.action.MAIN":
x.add(item.getAttribute("android:name"))

for sitem in item.getElementsByTagName("category"):
val = sitem.getAttribute("android:name")
if val == "android.intent.category.LAUNCHER":
y.add(item.getAttribute("android:name"))

z = x.intersection(y)
if len(z) > 0:
return z.pop()
return None


def parse_apk(filename):
'''
Returns:
(package, activity)
Manifest(Class)
'''
a = apk.APK(filename)

return (a.get_package(), a.get_main_activity())
with zipfile.ZipFile(filename, 'r') as file:
manifest = file.read('AndroidManifest.xml')
return Manifest(AXMLPrinter(manifest).getBuff())
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ numpy>=1.11.0
Pillow>=2.7.0
requests>=2.9.1
facebook-wda==0.1.1.dev1
atx-androguard==3.0
atx-uiautomator==0.2.12.dev6
imageio==1.5
colorama==0.3.7
AxmlParserPY==0.0.2

0 comments on commit 8130693

Please sign in to comment.