0

I have been trying to extract the function prototypes from a binary file using Ghidra. Up for now what I have done was to use the 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 also some times fail to produce the intended results when the compiler options are changed. I feel that there may be a quick 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.

3

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)
...
| improve this answer | |
  • Thank You Very Much. – hEShaN Apr 4 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.