13
13
# limitations under the License.
14
14
15
15
import os
16
+ import sys
16
17
import json
17
18
import argparse
18
19
23
24
def main ():
24
25
parser = argparse .ArgumentParser ()
25
26
parser .add_argument (
26
- "entry_point" ,
27
- nargs = "*" ,
28
- help = "Entry points to be processed"
27
+ "--fuzzer" ,
28
+ help = "Fuzzer to be processed"
29
29
)
30
30
parser .add_argument (
31
31
"--package" ,
32
32
help = "Package containing the code to be analyzed" ,
33
33
default = None
34
34
)
35
35
args = parser .parse_args ()
36
- run_fuzz_pass (args .package , args .entry_point )
36
+ run_fuzz_pass (args .fuzzer , args .package )
37
37
38
- def run_fuzz_pass (package , entry_point ):
38
+ def resolve_package (fuzzer_path ):
39
+ """Resolves the package of a fuzzer"""
40
+ print ("Fuzzer path: %s" % (fuzzer_path ))
41
+ dirpath = os .path .dirname (fuzzer_path )
42
+
43
+ # sanity check one
44
+ all_dirs = []
45
+ for d in os .listdir (dirpath ):
46
+ if os .path .isdir (os .path .join (dirpath , d )):
47
+ all_dirs .append (d )
48
+
49
+ # Read all potential imports in the fuzzer
50
+ fuzz_content = ""
51
+ with open (fuzzer_path , "r" ) as fp :
52
+ fuzz_content = fp .read ()
53
+
54
+ # Now go through each of the directories and check if any dir is in the fuzzer
55
+ imported_dirs = []
56
+ for d in all_dirs :
57
+ if d in fuzz_content :
58
+ print ("Directory: %s" % (d ))
59
+ imported_dirs .append (d )
60
+
61
+ if len (imported_dirs ) > 0 :
62
+ print ("Package path: %s" % (dirpath ))
63
+ return dirpath + "/"
64
+
65
+ print ("Could not identify the package" )
66
+ return None
67
+
68
+ def run_fuzz_pass (fuzzer , package ):
69
+ if package is None :
70
+ package = resolve_package (fuzzer )
71
+ if package is None :
72
+ print ("No package. Exiting early now as the results will not be good" )
73
+ sys .exit (1 )
74
+
75
+ print ("Fuzzer: %s" % (fuzzer ))
76
+ print ("Package: %s" % (package ))
39
77
cg = CallGraphGenerator (
40
- entry_point ,
78
+ [ fuzzer ] ,
41
79
package ,
42
80
- 1 ,
43
81
CALL_GRAPH_OP
@@ -60,11 +98,7 @@ def convert_to_fuzzing_cfg(cg_extended):
60
98
# Extract fuzzer entrypoint and print calltree.
61
99
ep_key = cg_extended ['ep' ]['mod' ] + "." + cg_extended ['ep' ]['name' ]
62
100
ep_node = cg_extended ['cg' ][ep_key ]
63
-
64
- # Dump the full cg to json. This includes information about each function.
65
101
print (json .dumps (cg_extended , indent = 4 ))
66
-
67
- # Print the calltree for the given fuzzer
68
102
print_calltree (cg_extended ['cg' ], ep_key , set ())
69
103
70
104
def print_calltree (cg_extended , k , s1 , depth = 0 , lineno = - 1 , themod = "" , ext_mod = "" ):
0 commit comments