Spaces:
Running
Running
File size: 1,343 Bytes
dee983b 1bc7f4c dee983b 8464e89 dee983b 8464e89 dee983b 1bc7f4c dee983b 1bc7f4c ec41d0e dee983b |
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 |
import json
import sys
sys.path.append("/DIRTY/dirty")
import utils.infer
from utils.dataset import Example
def dump_functions_to_json():
functionManager = currentProgram().getFunctionManager()
functions = functionManager.getFunctions(True)
# Create a dictionary to store function names and their corresponding addresses
functions_dict = {}
for func in functions:
if func.isExternal() or func.isThunk():
continue
func_name = func.getName()
func_address = func.getEntryPoint().getOffset()
cf = utils.infer.ghidra_obtain_cf(func)
example = Example.from_cf(
cf, binary_file="binary_file", max_stack_length=1024, max_type_size=1024
)
# Add function name and address to the dictionary
if example.is_valid_example:
functions_dict[func_address] = (func_name, cf.to_json(), len(example.source))
# Convert the dictionary to a JSON object
json_data = json.dumps(functions_dict, indent=4)
args = getScriptArgs()
if len(args) == 0:
# Print JSON output to the console
print(json_data)
else:
# Write JSON output to a file
with open(args[0], 'w') as f:
f.write(json_data)
# Run the function
dump_functions_to_json()
|