I would like to know a reliable and convinient way (preexisting libraries, C-compilers) to extract the specific information from a C Source Code or C binary code - the format does not really matter, but rather the result is what matters ;-).
Basically the idea is to extract the read and write accesses to variables on a function level as well as called subfunctions recursively, top to bottom. That means, I want to find out what variables does a certain parent function A access directly (Read, Write or both Read Write access), and then also recursively extract the same information from subfunctions function B, C called by the function A. Similarly, the directly accessed variables by subfunctions function B, C shall be identified, and then the same procedure shall continue recursively for all subfunctions of function B and function C.
I think of it as a call graph, where
- Nodes represent a function
- Arrows represent a function call
- Each node contains additional information about:
- name of the accessed variable
- access type to a variable (Read, Write or Read/Write)
I attached a picture showing the call graph below to illustrate the idea better. Please be aware that the variable access information shall be collected for each function, and not only for the parent function A.
I am aware that there are there are preexisting compilers and libraries that can parse the C Source code or work directly on the binary such as clang compiler, LLVM, libclang Py-Library and pycparser. I am however not sure if those tools are capable of achieving my task. For example, from my understanding the combination of Clang and LLVM can extract the variable accesses from the binary application file, but not recusively so to speak. That means, all of the variable accesses done by child functions B, C, E, F, etc would be directly assigned to the parent function A.
I definitely want avoid writing a (e.g. python) script on my own that would extract this information from the C source code manually, but I rather prefer the well tested, and well documented tool/API/compiler to do this task.
Thank you a lot in advance!