-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathherast.py
109 lines (83 loc) · 2.97 KB
/
herast.py
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
import time
import idaapi
def reload_modules():
# order of requires (from imported to importers) is most likely important
idaapi.require('herast.settings.base_settings')
idaapi.require('herast.settings.idb_settings')
idaapi.require('herast.settings.global_settings')
idaapi.require('herast.settings.settings_manager')
idaapi.require('herast.tree.consts')
idaapi.require('herast.tree.utils')
idaapi.require('herast.tree.pattern_context')
idaapi.require('herast.tree.processing')
idaapi.require('herast.tree.patterns.base_pattern')
idaapi.require('herast.tree.patterns.abstracts')
idaapi.require('herast.tree.patterns.instructions')
idaapi.require('herast.tree.patterns.expressions')
idaapi.require('herast.tree.patterns.helpers')
idaapi.require('herast.tree.matcher')
idaapi.require('herast.tree.callbacks')
idaapi.require('herast.tree.actions')
idaapi.require('herast.tree.selection_factory')
idaapi.require('herast.tree.scheme')
idaapi.require('herast.schemes_storage')
idaapi.require('herast.passive_manager')
idaapi.require('herast.views.storage_manager_view')
idaapi.require('herapi')
import herast.views.storage_manager_view as smanager_view
import herast.passive_manager as passive_manager
import herast.settings.settings_manager as settings_manager
from herast.tree.actions import action_manager, hx_callback_manager
class HerastPlugin(idaapi.plugin_t):
flags = 0
wanted_name = "herast"
comment = ""
help = ""
wanted_hotkey = ""
def herast_callback(self, *args):
event = args[0]
if event != idaapi.hxe_maturity:
return 0
cfunc, level = args[1], args[2]
if level != idaapi.CMAT_FINAL:
return 0
assert isinstance(cfunc.body, idaapi.cinsn_t), "Function body is not cinsn_t"
assert isinstance(cfunc.body.cblock, idaapi.cblock_t), "Function body must be a cblock_t"
try:
matcher = passive_manager.get_passive_matcher()
if settings_manager.get_time_matching():
traversal_start = time.time()
matcher.match_cfunc(cfunc)
traversal_end = time.time()
print("[TIME] Tree traversal done within %f seconds" % (traversal_end - traversal_start))
else:
matcher.match_cfunc(cfunc)
except Exception as e:
print(e)
raise e
return 0
def init(self):
if not idaapi.init_hexrays_plugin():
return idaapi.PLUGIN_SKIP
def __register_action(action):
idaapi.register_action(
idaapi.action_desc_t(action.name, action.description, action, action.hotkey)
)
# first import before IDB got loaded does not correctly loads settings
settings_manager.reload_settings()
__register_action(smanager_view.ShowScriptManager())
idaapi.remove_hexrays_callback(self.herast_callback)
idaapi.install_hexrays_callback(self.herast_callback)
passive_manager.initialize()
action_manager.initialize()
hx_callback_manager.initialize()
return idaapi.PLUGIN_KEEP
def run(self, arg):
return
def term(self):
return
def PLUGIN_ENTRY():
return HerastPlugin()
# if __name__ == '__plugins__herast':
if __name__ == "__main__":
reload_modules()