-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractFunMatrix.py
More file actions
executable file
·149 lines (131 loc) · 4.55 KB
/
Copy pathextractFunMatrix.py
File metadata and controls
executable file
·149 lines (131 loc) · 4.55 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import sys
import idaapi
import idautils
import idc
import ida_kernwin
import ida_nalt
import pymongo
from pymongo import MongoClient
import subprocess
_IDAREADFUNMATRIX_GUID = 'd3babbb6-669b-4e2e-9a57-4df6ae89cf79'
_IDAREADFUNMATRIX_HOTKEY = 'shift-ctrl-f'
class MyError(Exception):
def __init__(self, value):
print(value)
class ConfirmTraceForm(ida_kernwin.Form):
def __init__(self, msg):
ida_kernwin.Form.__init__(self, r"""STARTITEM 0
BUTTON YES* OK
BUTTON CANCEL Cancel
Confirm Trace
====={note}=====
""", {
'note' : ida_kernwin.Form.StringLabel(msg)
})
default_moduleName = ida_nalt.get_root_filename().replace('.','_')
default_dbpath = "D:\eclips\workspace\interestingFUN\win32\db"
moduleName = ida_kernwin.ask_str(default_moduleName, 0, 'The database name (default is the module name)')
dbpath = ''
dbpath = ida_kernwin.ask_str(default_dbpath, 0, 'The database path (default is FunctionMatrix path + projectname+db)')
if not os.path.exists(dbpath.replace('\\','/')):
checkpath = ConfirmTraceForm('Database path does not exist, Please check')
checkpath.Compile()
checkpath.Execute()
raise MyError('Database path does not exist, Please check')
dbexe = [r'C:\mongodb\bin\mongod.exe', '-port','24444', '-dbpath' ,dbpath]
dbprocess = subprocess.Popen(dbexe)
client = MongoClient('localhost',24444)
#what if connect failed?
db = client[moduleName]#projName
dbctrl = db[moduleName]
if 0 == dbctrl.count():
check = ConfirmTraceForm('Target Database is empty, Please check')
check.Compile()
check.Execute()
raise MyError('Target Database is empty, Please check')
func_name_ea = {name:ea for ea, name in idautils.Names()}
ftarget = 'alloc'
funlist = []
funfeaturelist = []
FIRST_RUN = 1
title = "Functions Searched"
cols = []
sample = dbctrl.find_one()
for col in sample:
if col != '_id':
if col == 'ea':
col_item = [col,10]
elif col == 'name':
col_item = [col,19]
else:
col_item = [col,5]
cols.append(col_item)
def DEBUG_PRINT(str):
# print('[debug info]')
# print(str)
return
class IdxChoose2(ida_kernwin.Choose):
'''
Index Chooser Dialog
'''
def __init__(self, title, cols, items, deflt = 1):
ida_kernwin.Choose.__init__(self, title, cols)
self.items = items
self.deflt = deflt
def OnClose(self):
return
def OnGetLine(self, n):
return self.items[n]
def OnGetSize(self):
return len(self.items)
def OnDeleteLine(self, n):
del self.items[n]
return n
def show(self):
return self.Show(True)
def Get_FunctionFeatures():
global ftarget, func_name_ea, dbctrl, FIRST_RUN, funlist, funfeaturelist, title, cols
origin_ftarget = ftarget #pAllocateAndInitializeMDSURF
ftarget = ida_kernwin.ask_str(origin_ftarget, 0, 'Type the Target String (CASE INSenstive)')
if ftarget == '':
print('NO input')
return
if ftarget == origin_ftarget and not FIRST_RUN:
# if target string doesn't change, then keep previous funlist, but first time run must be excluded
DEBUG_PRINT("ftarget == origin_ftarget ")
pass
else:
funlist = []
for f in func_name_ea.keys():
if ftarget.lower() in f.lower():
funlist.append(f)
DEBUG_PRINT(funlist)
funfeaturelist = []
for fun in funlist:
funfeature = dbctrl.find_one({"name":fun})
if funfeature:
featurelist = []
for feature in funfeature:
if feature != '_id':
featurelist.append(funfeature[feature].strip('(,)').split(',')[0])
DEBUG_PRINT(featurelist)
funfeaturelist.append(featurelist)
DEBUG_PRINT(funfeaturelist)
if FIRST_RUN:
FIRST_RUN = 0
#funfeaturelist prepared
DEBUG_PRINT("To show the window")
chooser = IdxChoose2(title, cols, funfeaturelist) #, deflt = deflt_id
id = chooser.show()
if -1 == id:
print('\n Index no change\n')
else:
ea = funfeaturelist[id][cols.index(['ea', 10])]
print('ea',ea)
type(ea)
idaapi.jumpto(int(ea,16), -1,1)
features = dbctrl.find_one({"ea":ea})
for f in features:
print('%-20s %s'%(f, features[f]))
DEBUG_PRINT("show finished")
ida_kernwin.add_hotkey(_IDAREADFUNMATRIX_HOTKEY, Get_FunctionFeatures)