-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcodes.py
57 lines (42 loc) · 1.25 KB
/
pcodes.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
#TODO write a description for this script
#@author Yash
#@category _NEW_
#@keybinding
#@menupath
#@toolbar
from ghidra.util.task import ConsoleTaskMonitor
from ghidra.app.decompiler import DecompileOptions, DecompInterface
import os, json
def get_high_function(func):
options = DecompileOptions()
monitor = ConsoleTaskMonitor()
ifc = DecompInterface()
ifc.setOptions(options)
ifc.openProgram(getCurrentProgram())
res = ifc.decompileFunction(func, 60, monitor)
high = res.getHighFunction()
return high
def dump_refined_pcode(func, high_func):
stri = []
opiter = high_func.getPcodeOps()
while opiter.hasNext():
op = opiter.next()
stri.append(str(op))
return stri
def allfunctions():
func_data = []
f_nameArr = []
state = getState()
currentProgram = state.getCurrentProgram()
name = currentProgram.getName()
location = currentProgram.getExecutablePath()
f = getFirstFunction()
while f is not None:
print "[+]Function: ", f.getName()
f_nameArr.append(f.getName())
hf = get_high_function(f) #This returns "None"
print("the high function returns: " + str(hf))
f_pcode = dump_refined_pcode(f,hf)
func_data.append(f_pcode) #Appending the pcodes into the list
f = getFunctionAfter(f)
allfunctions()