|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 | 15 | import os
|
| 16 | +import json |
16 | 17 | import argparse
|
17 | 18 |
|
18 | 19 | from pycg.pycg import CallGraphGenerator
|
@@ -59,15 +60,28 @@ def convert_to_fuzzing_cfg(cg_extended):
|
59 | 60 | # Extract fuzzer entrypoint and print calltree.
|
60 | 61 | ep_key = cg_extended['ep']['mod'] + "." + cg_extended['ep']['name']
|
61 | 62 | ep_node = cg_extended['cg'][ep_key]
|
| 63 | + |
| 64 | + # Dump the full cg to json. This includes information about each function. |
| 65 | + print(json.dumps(cg_extended, indent=4)) |
| 66 | + |
| 67 | + # Print the calltree for the given fuzzer |
62 | 68 | print_calltree(cg_extended['cg'], ep_key, set())
|
63 | 69 |
|
64 |
| -def print_calltree(cg_extended, k, s1, depth=0): |
| 70 | +def print_calltree(cg_extended, k, s1, depth=0, lineno=-1, themod="", ext_mod=""): |
65 | 71 | """Prints a calltree where k is the key in the cg of the root"""
|
66 | 72 |
|
67 |
| - print("%s%s"%(" "*(depth*2), k)) |
68 |
| - sorted_keys = sorted(cg_extended[k], key=lambda x: x['lineno']) |
69 |
| - for dst in cg_extended[k]: |
70 |
| - print_calltree(cg_extended, dst['dst'], s1, depth+1) |
| 73 | + if depth > 20: |
| 74 | + return |
| 75 | + print("%s%s src_mod=%s src_linenumber=%d dst_mod=%s"%(" "*(depth*2), k, themod, lineno, ext_mod)) |
| 76 | + sorted_keys = sorted(cg_extended[k]['dsts'], key=lambda x: x['lineno']) |
| 77 | + |
| 78 | + # Avoid deep recursions |
| 79 | + if k in s1: |
| 80 | + return |
| 81 | + |
| 82 | + s1.add(k) |
| 83 | + for dst in cg_extended[k]['dsts']: |
| 84 | + print_calltree(cg_extended, dst['dst'], s1, depth+1, dst['lineno'], dst['mod'], dst['ext_mod']) |
71 | 85 |
|
72 | 86 | if __name__ == "__main__":
|
73 | 87 | main()
|
0 commit comments