Skip to content

Commit 290051a

Browse files
frontends: python: update to new cg extraction data (#292)
1 parent f19aa7e commit 290051a

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

frontends/python/main.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16+
import json
1617
import argparse
1718

1819
from pycg.pycg import CallGraphGenerator
@@ -59,15 +60,28 @@ def convert_to_fuzzing_cfg(cg_extended):
5960
# Extract fuzzer entrypoint and print calltree.
6061
ep_key = cg_extended['ep']['mod'] + "." + cg_extended['ep']['name']
6162
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
6268
print_calltree(cg_extended['cg'], ep_key, set())
6369

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=""):
6571
"""Prints a calltree where k is the key in the cg of the root"""
6672

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'])
7185

7286
if __name__ == "__main__":
7387
main()

0 commit comments

Comments
 (0)