#!/usr/bin/python # -*- coding: utf-8 -*- import os import gtk class PermsPanel: """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.""" for p in self._perms: for c in self._perms[p]: if line.find(c) > -1: self._used[p].append([addr, c + "()"]) def fill_tree(self, store): """Fill a treeview with all found permissions.""" for p in self._used: if len(self._used[p]) > 0 or True: img = os.path.dirname(os.path.abspath(__file__)) + '/android.png' buf = gtk.gdk.pixbuf_new_from_file(img) it = store.append(None, [buf, p, None, None]) img = os.path.dirname(os.path.abspath(__file__)) + '/routine.png' buf = gtk.gdk.pixbuf_new_from_file(img) for f in self._used[p]: store.append(it, [None, "0x%08x" % f[0], buf, f[1]])