-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilefunctioncorrGHIDRA.py
More file actions
35 lines (22 loc) · 1.16 KB
/
filefunctioncorrGHIDRA.py
File metadata and controls
35 lines (22 loc) · 1.16 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
import delegator
import json
from tqdm import tqdm
GHIDRANAMEPATH = './GHIDRAfuncnames' # path to text file with names of all GHIDRA functions
GHIDRAfuncs = {}
folderpath = './decomp_funcs_GHIDRA' #folder path to GHIDRA decompiled function folder
functionfilepath = './function-file GHIDRA.json' #output path
'''
The purpose of this script is to create a JSON file for GHIDRA that links a function name to a applicable file path
'''
def getmethod(FunctionName):
c = delegator.run(f"joern --script joerngetname.sc --params FolderPath={folderpath},FunctionName={FunctionName}") #equivalent to cpg.method(methodName).toJsonPretty in joern
j = json.loads(c.out)
GHIDRAfuncs[j['name']] = j['filename'].split('/')[-1] #create a dictionary functionname : functionname + binaryname
with open(GHIDRANAMEPATH, 'r') as GHIDRA:
funcnames = GHIDRA.read().splitlines()
funcnames = list(set(funcnames)) #filter out duplicates
funcnames = list(filter(("<global>").__ne__, funcnames)) # filter out global functions
for i in tqdm(funcnames):
getmethod(i)
with open(functionfilepath, 'w') as outfile:
json.dump(GHIDRAfuncs, outfile)