-
Notifications
You must be signed in to change notification settings - Fork 38
/
HRAST.py
105 lines (88 loc) · 2.28 KB
/
HRAST.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
# -*- coding: utf-8 -*-
import ctypes
import sys
import re
import importlib
import idaapi
idaapi.require("Patterns")
idaapi.require("Matcher")
idaapi.require("ast_helper")
idaapi.require("traverse")
import ready_patterns
EVENTS_HEXR = {
0: 'hxe_flowchart',
1: 'hxe_prolog',
2: 'hxe_preoptimized',
3: 'hxe_locopt',
4: 'hxe_prealloc',
5: 'hxe_glbopt',
6: 'hxe_structural',
7: 'hxe_maturity',
8: 'hxe_interr',
9: 'hxe_combine',
10: 'hxe_print_func',
11: 'hxe_func_printed',
12: 'hxe_resolve_stkaddrs',
100: 'hxe_open_pseudocode',
101: 'hxe_switch_pseudocode',
102: 'hxe_refresh_pseudocode',
103: 'hxe_close_pseudocode',
104: 'hxe_keyboard',
105: 'hxe_right_click',
106: 'hxe_double_click',
107: 'hxe_curpos',
108: 'hxe_create_hint',
109: 'hxe_text_ready',
110: 'hxe_populating_popup'
}
CMAT_LEVEL = {
0: 'CMAT_ZERO',
1: 'CMAT_BUILT',
2: 'CMAT_TRANS1',
3: 'CMAT_NICE',
4: 'CMAT_TRANS2',
5: 'CMAT_CPA',
6: 'CMAT_TRANS3',
7: 'CMAT_CASTED',
8: 'CMAT_FINAL'
}
LEV = 0
NAME = 'log'
used_pats = []
DEBUG = False
def reLOAD():
global used_pats
# For tesing now I just rewrite "ready_patterns.py" and call reLOAD
reload(ready_patterns)
used_pats = []
for i in ready_patterns.PATTERNS:
print i[0]
used_pats.append((eval(i[0], globals(), locals()), i[1], i[2]))
def unLOAD():
global used_pats
used_pats = []
def deBUG():
global DEBUG
DEBUG = not DEBUG
def hexrays_events_callback_m(*args):
global LEV
global NAME
ev = args[0]
if ev == idaapi.hxe_maturity:
fcn = args[1]
level = args[2]
if level == idaapi.CMAT_FINAL:
for i in used_pats:
func_proc = traverse.FuncProcessor(fcn)
matcher = Matcher.Matcher(func_proc.fcn, None)
matcher.set_pattern(i[0])
matcher.chain = i[2]
matcher.replacer = i[1]
func_proc.pattern = matcher
func_proc.DEBUG = DEBUG
func_proc.traverse_function()
return 0
def hr_remove():
idaapi.remove_hexrays_callback(hexrays_events_callback_m)
if __name__ == "__main__":
print idaapi.install_hexrays_callback(hexrays_events_callback_m)