This repository has been archived by the owner on Mar 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use axmlparserpy instead of androguard, close #121
- Loading branch information
1 parent
4586fa5
commit 8130693
Showing
3 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters