#!/usr/bin/python # -*- coding: utf-8 -*- from pychrysalide.gui.panels import PanelItem import gtk import os def _build_permissions_panel_content(): """Build content for permissions panels.""" 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) functions = gtk.TreeViewColumn() tree.append_column(functions) cell = gtk.CellRendererPixbuf() functions.pack_start(cell, False) functions.add_attribute(cell, 'pixbuf', 2) cell = gtk.CellRendererText() functions.pack_start(cell, True) functions.add_attribute(cell, 'text', 3) store = gtk.TreeStore(gtk.gdk.Pixbuf, str, gtk.gdk.Pixbuf, str) tree.set_model(store) return scrolled_window, tree, store class PermsPanel(PanelItem): """Display all permissions found in the Manifest.""" def __new__(cls): """Create the GLib instance relative this class as soon as possible, for the pygobject registering process.""" scrolled_window, tree, store = _build_permissions_panel_content() self = super(PermsPanel, cls).__new__(cls, 'Permissions', 'Android Permissions', \ scrolled_window, 'SE') self._scrolled_window = scrolled_window self._tree = tree self._store = store self._perms = {} return self def __init__(self): """Initialize the Python instance of the panel.""" self._tree.connect('row-activated', self._on_row_selection) self.dock() self.register() def memorize_permissions(self, binary, perms): """Attach found permissions to a new loaded binary.""" self._perms[binary] = perms def update_for_binary(self, binary): """Fill the treeview with all found permissions for the given binary.""" self._store.clear() used = self._perms[binary] for p in used: 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 = 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 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))