about summary refs log tree commit diff stats
path: root/example/ida/menu.py
blob: a0eecf67f59da113cf2cdc34bd7ed5d19390e82d (plain) (blame)
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
"""Implements a menu for IDA with:
- Miasm
- Miasm > Symbolic execution (icon 81, F3)
- Miasm > Dependency graph (icon 79, F4)
- Miasm > Graph IR (icon 188, F7)
- Miasm > Graph IR (simplified) (icon 191, F8)
- Miasm > RPYC server (icon 182, F10)
- Miasm > Type propagation (icon 38, F11)
"""

from symbol_exec import symbolic_exec
from graph_ir import build_graph
try:
    from rpyc_ida import serve_threaded
except ImportError:
    serve_threaded = None
from depgraph import launch_depgraph
try:
    from ctype_propagation import analyse_function
except ImportError:
    analyse_function = None

class Handler(idaapi.action_handler_t):

    def __init__(self, callback):
        """Create a Handler calling @callback when activated"""
        super(Handler, self).__init__()
        self.callback = callback

    def activate(self, ctx):
        return self.callback()

    # This action is always available.
    def update(self, ctx):
        return idaapi.AST_ENABLE_ALWAYS

    def register(self, name, label, shortcut=None, tooltip=None, icon=-1):
        action = idaapi.action_desc_t(
            name,    # The action name. This acts like an ID and must be unique
            label,   # The action text.
            self,    # The action handler.
            shortcut,# Optional: the action shortcut
            tooltip, # Optional: the action tooltip (available in menus/toolbar)
            icon,    # Optional: the action icon (shows when in menus/toolbars)
        )
        idaapi.register_action(action)
        self.name = name
        return action

    def attach_to_menu(self, menu):
        assert hasattr(self, "name")
        idaapi.attach_action_to_menu(menu, self.name, idaapi.SETMENU_APP)

idaapi.create_menu("Miasm", "Miasm")

handler_symb = Handler(symbolic_exec)
handler_symb.register("miasm:symbexec", "Symbolic exec", shortcut="F3", icon=81)
handler_symb.attach_to_menu("Miasm/Symbolic exec")
handler_depgraph = Handler(launch_depgraph)
handler_depgraph.register("miasm:depgraph", "Dependency graph", shortcut="F4", icon=79)
handler_depgraph.attach_to_menu("Miasm/Dependency graph")
handler_graph = Handler(build_graph)
handler_graph.register("miasm:graphir", "Graph IR", shortcut="F7", icon=188)
handler_graph.attach_to_menu("Miasm/Graph IR")
handler_graph_simp = Handler(lambda: build_graph(simplify=True))
handler_graph_simp.register("miasm:graphirsimp",
                            "Graph IR (simplified)", shortcut="F8", icon=191)
handler_graph_simp.attach_to_menu("Miasm/Graph IR (simplified)")
handler_graph_simp = Handler(lambda: build_graph(simplify=True, ssa=True))
handler_graph_simp.register("miasm:graphirssa",
                            "Graph IR (SSA)", shortcut="F8", icon=191)
handler_graph_simp.attach_to_menu("Miasm/Graph IR (SSA)")

handler_graph_simp = Handler(lambda: build_graph(simplify=True, ssa_simplify=True))
handler_graph_simp.register("miasm:graphirssasimple",
                            "Graph IR (SSA Simplified)", shortcut="F8", icon=191)
handler_graph_simp.attach_to_menu("Miasm/Graph IR (SSA Simplified)")

if serve_threaded is not None:
    handler_rpyc = Handler(serve_threaded)
    handler_rpyc.register("miasm:rpyc", "RPYC server", shortcut="F10", icon=182)
    handler_rpyc.attach_to_menu("Miasm/RPYC server")
if analyse_function is not None:
    handler_ctype = Handler(analyse_function)
    handler_ctype.register("miasm:ctype", "Type propagation", shortcut="F11",
                           icon=38)
    handler_ctype.attach_to_menu("Miasm/Type propagation")