summaryrefslogtreecommitdiff
path: root/plugins/python/androperms/androperms.py
blob: c9af7c4c48cf7edd5f25245511497d61082df00f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/python
# -*- coding: utf-8 -*-

from manifest import AndroidManifest
from panel import PermsPanel
from pychrysalide import Plugin
from pychrysalide.gui.panels import PanelItem
from xml.dom import minidom

import gtk
import zipfile


class AndroPerms(Plugin):
    """List all permissions given to an APK files."""


    def get_action(self):
        """Register the plugin for given actions."""

        return Plugin.PGA_DISASS_PROCESS


    def execute_on_binary(self, binary, action):
        """Process once a binary is disassembled."""

        zf = zipfile.ZipFile(binary.get_filename())

        f = zf.open('AndroidManifest.xml', 'r')
        data = f.read()
        f.closed

        manifest = AndroidManifest(data)
        xml = minidom.parseString(manifest.getXML())

        print
        print "Permissions for ", binary.get_filename(), " :"
        print "-------------"
        print

        plist = []

        for p in xml.getElementsByTagName("uses-permission"):
            plist.append(p.getAttribute("android:name"))
            print p.getAttribute("android:name")

        print



        panel = PermsPanel()

        self._build_panel_item()



        panel.filter_permissions(plist)


        instrs = binary.get_instructions()
        buffer = binary.disassembled_buffer





        for i in instrs:

            if i.keyword.startswith("invoke"):

                line = buffer.find_line_by_addr(i.address)
                text = line.get_text()

                panel.check_call(i.address, text)





        panel.fill_tree(self._store)
        self._tree.expand_all()



    def _build_panel_item(self):

        self._scrolled_window = gtk.ScrolledWindow()
        self._scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self._scrolled_window.show()

        self._tree = gtk.TreeView()
        self._tree.set_headers_visible(False)
        self._tree.show()
        self._scrolled_window.add_with_viewport(self._tree)

        locations = gtk.TreeViewColumn()
        self._tree.append_column(locations)

        cell = gtk.CellRendererText()
        locations.pack_start(cell, False)
        locations.add_attribute(cell, "text", 0)

        functions = gtk.TreeViewColumn()
        self._tree.append_column(functions)

        cell = gtk.CellRendererText()
        functions.pack_start(cell, True)
        functions.add_attribute(cell, "text", 1)

        self._store = gtk.TreeStore(str, str)
        self._tree.set_model(self._store)

        pi = PanelItem(name="Permissions", lname="Permissions", widget=self._scrolled_window, path="SE")
        pi.dock()