diff options
Diffstat (limited to 'plugins/python/androperms/db.py')
-rw-r--r-- | plugins/python/androperms/db.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/plugins/python/androperms/db.py b/plugins/python/androperms/db.py new file mode 100644 index 0000000..625d400 --- /dev/null +++ b/plugins/python/androperms/db.py @@ -0,0 +1,94 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import os + + +class PermsDataBase: + """Display all permissions found in the Manifest.""" + + def __init__(self): + + self._perms = { } + self._used = { } + + self._load_all_definitions() + + + def _load_all_definitions(self): + """Load the database in memory.""" + + with open(os.path.dirname(__file__) + '/androperms.db', 'r') as f: + + for line in f.readlines(): + + perm = line.strip("\n").split("\t") + + for p in perm[1].split(" "): + + if not p.startswith("android.permission."): + continue + + if p not in self._perms: + self._perms[p] = [] + + call = perm[0].split("(")[0] + + if call not in self._perms[p]: + self._perms[p].append(call) + + + def filter_permissions(self, used): + """Forget all permissions which are not used.""" + + keep = {} + + for p in self._perms: + if p in used: + keep[p] = self._perms[p] + + self._perms = keep + + for p in keep: + self._used[p] = [] + + + def check_call(self, addr, line): + """Check if a call requires some rights.""" + + found = False + + for p in self._perms: + + if line.find("Wall") > -1: + print "[+]", line, ' ==> ', p + + for c in self._perms[p]: + + #print " - ", c + + #if line.find(c) > -1: + if c.find(line) > -1: + self._used[p].append([addr, c + "()"]) + #found = True + + if not found: + + func = line.split('.')[-1] + + for p in self._perms: + + for c in self._perms[p]: + + if line.find("Wall") > -1: + print " <> ", c, " vs ", func + + if c.find(func) > -1: + self._used[p].append([addr, line + "()"]) + break + + + def get_used_permissions(self): + """Provide the list of used permissions.""" + + return self._used |