summaryrefslogtreecommitdiff
path: root/plugins/python/androperms/panel.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/python/androperms/panel.py')
-rw-r--r--plugins/python/androperms/panel.py121
1 files changed, 78 insertions, 43 deletions
diff --git a/plugins/python/androperms/panel.py b/plugins/python/androperms/panel.py
index ea26f74..bebeed5 100644
--- a/plugins/python/androperms/panel.py
+++ b/plugins/python/androperms/panel.py
@@ -1,85 +1,120 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-import os
+from pychrysalide.gui.panels import PanelItem
import gtk
+import os
-class PermsPanel:
- """Display all permissions found in the Manifest."""
+def _build_permissions_panel_content():
+ """Build content for permissions panels."""
- def __init__(self):
+ scrolled_window = gtk.ScrolledWindow()
+ scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ scrolled_window.show()
+
+ tree = gtk.TreeView()
+ tree.set_headers_visible(False)
+ tree.show()
+ scrolled_window.add_with_viewport(tree)
+
+ locations = gtk.TreeViewColumn()
+ tree.append_column(locations)
+
+ cell = gtk.CellRendererPixbuf()
+ locations.pack_start(cell, False)
+ locations.add_attribute(cell, 'pixbuf', 0)
+
+ cell = gtk.CellRendererText()
+ locations.pack_start(cell, False)
+ locations.add_attribute(cell, 'text', 1)
- self._perms = { }
- self._used = { }
-
- self._load_all_definitions()
+ functions = gtk.TreeViewColumn()
+ tree.append_column(functions)
+ cell = gtk.CellRendererPixbuf()
+ functions.pack_start(cell, False)
+ functions.add_attribute(cell, 'pixbuf', 2)
- def _load_all_definitions(self):
- """Load the database in memory."""
+ cell = gtk.CellRendererText()
+ functions.pack_start(cell, True)
+ functions.add_attribute(cell, 'text', 3)
- with open(os.path.dirname(__file__) + '/androperms.db', 'r') as f:
+ store = gtk.TreeStore(gtk.gdk.Pixbuf, str, gtk.gdk.Pixbuf, str)
+ tree.set_model(store)
- for line in f.readlines():
+ return scrolled_window, tree, store
- perm = line.strip("\n").split("\t")
- for p in perm[1].split(" "):
+class PermsPanel(PanelItem):
+ """Display all permissions found in the Manifest."""
- if not p.startswith("android.permission."):
- continue
+ def __new__(cls):
+ """Create the GLib instance relative this class as soon as possible,
+ for the pygobject registering process."""
- if p not in self._perms:
- self._perms[p] = []
+ scrolled_window, tree, store = _build_permissions_panel_content()
- call = perm[0].split("(")[0]
+ self = super(PermsPanel, cls).__new__(cls, 'Permissions', 'Android Permissions', \
+ scrolled_window, 'SE')
- if call not in self._perms[p]:
- self._perms[p].append(call)
+ self._scrolled_window = scrolled_window
+ self._tree = tree
+ self._store = store
+ self._perms = {}
- def filter_permissions(self, used):
- """Forget all permissions which are not used."""
+ return self
- keep = {}
- for p in self._perms:
- if p in used:
- keep[p] = self._perms[p]
+ def __init__(self):
+ """Initialize the Python instance of the panel."""
- self._perms = keep
+ self._tree.connect('row-activated', self._on_row_selection)
- for p in keep:
- self._used[p] = []
+ self.dock()
+ self.register()
- def check_call(self, addr, line):
- """Check if a call requires some rights."""
+ def memorize_permissions(self, binary, perms):
+ """Attach found permissions to a new loaded binary."""
- for p in self._perms:
+ self._perms[binary] = perms
- for c in self._perms[p]:
- if line.find(c) > -1:
- self._used[p].append([addr, c + "()"])
+ def update_for_binary(self, binary):
+ """Fill the treeview with all found permissions for the given binary."""
+ self._store.clear()
- def fill_tree(self, store):
- """Fill a treeview with all found permissions."""
+ used = self._perms[binary]
- for p in self._used:
+ for p in used:
- if len(self._used[p]) > 0 or True:
+ if len(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])
+ it = self._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]])
+ for f in used[p]:
+ self._store.append(it, [None, "0x%08x" % f[0], buf, f[1]])
+
+ self._tree.expand_all()
+
+
+ def _on_row_selection(self, treeview, path, column):
+ """Scroll the current view to the selected address."""
+
+ selection = treeview.get_selection()
+ model, it = selection.get_selected()
+
+ # On ne traite que les lignes de code
+ if model.get_value(it, 0) == None:
+
+ self.get_current_view().scroll_to_address(int(model.get_value(it, 1), 16))