I have been trying to extract the function prototypes from a binary file using Ghidra. Up till now what I have done was to use Ghidra's included "Decompile" script and filtered out the function prototypes through the produced text file using python. However, this approach seems to be cumbersome and sometimes it fails to produce the intended results when the compiler options are changed. I feel that there may be a quicker way to get these. Given a binary, my requirement is to get all the function prototypes such as float strtof_l(char *__nptr,char **__endptr,__locale_t __loc)
without the function bodies. Is there any existing script to do this? Or is there a method in the API that I could loop upon. Thank you very much.
1 Answer
You can use FunctionManager
to get all the functions in the current program and then, from it iterate and get signatures of each.
fm = currentProgram.getFunctionManager()
functions = fm.getFunctions(True)
for f in functions:
print(f.getSignature().getPrototypeString())
The output:
Signatures.py> Running...
char * strcpy(char * __dest, char * __src)
int mkdir(char * __path, __mode_t __mode)
int fclose(FILE * __stream)
int printf(char * __format, ...)
void * memset(void * __s, int __c, size_t __n)
void * memcpy(void * __dest, void * __src, size_t __n)
FILE * fopen(char * __filename, char * __modes)
char * strcat(char * __dest, char * __src)
...