Created
June 6, 2021 12:33
-
-
Save MohitDabas/d74f8fa7c260a31fb6ded75ea30baf19 to your computer and use it in GitHub Desktop.
A python ghidra script that will parse the functions and the referenced strings by those function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ghidra.program.util import DefinedDataIterator | |
from ghidra.app.util import XReferenceUtil | |
def getAddress(offset): | |
return currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(offset) | |
string_and_funcdata=[] | |
functionManager = currentProgram.getFunctionManager() | |
for string in DefinedDataIterator.definedStrings(currentProgram): | |
for ref in XReferenceUtil.getXRefList(string): | |
#print(string, ref) | |
#string_and_funcdata.extend([string,ref]) | |
addr=getAddress(hex(int('0x'+str(ref),16))) | |
#print(addr) | |
#print(functionManager.getFunctionContaining(addr)) | |
name_of_function=functionManager.getFunctionContaining(addr) | |
temp_list=[] | |
temp_list.extend([str(string),str(ref),str(name_of_function)]) | |
#print(temp_list) | |
string_and_funcdata.append(temp_list) | |
#print (string_and_funcdata[0:100]) | |
func_data={} | |
for li in string_and_funcdata: | |
if li[2] in func_data.keys(): | |
temp_list=[] | |
temp_list.extend([li[0],li[1]]) | |
func_data[li[2]].append(temp_list) | |
if li[2]!='None' and not(li[2] in func_data.keys()) : | |
func_data[li[2]]=[] | |
temp_list=[] | |
temp_list.append([li[0],li[1]]) | |
func_data[li[2]].extend(temp_list) | |
print(func_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one! thinking of adding some functionality to this