@@ -95,7 +95,7 @@ func loadProgramOrExit(from path: String) -> Program {
9595
9696let args = Arguments . parse ( from: CommandLine . arguments)
9797
98- if args [ " -h " ] != nil || args [ " --help " ] != nil || args. numPositionalArguments != 1 || args . numOptionalArguments > 2 {
98+ if args [ " -h " ] != nil || args [ " --help " ] != nil || args. numPositionalArguments != 1 {
9999 print ( """
100100 Usage:
101101 \( args. programName) options path
@@ -108,6 +108,7 @@ if args["-h"] != nil || args["--help"] != nil || args.numPositionalArguments !=
108108 --dumpProgram : Dumps the internal representation of the program stored in the given protobuf file
109109 --checkCorpus : Attempts to load all .fzil files in a directory and checks if they are statically valid
110110 --compile : Compile the given JavaScript program to a FuzzIL program. Requires node.js
111+ --outputPathJS : If given, --compile will write the lifted JS file to the given path after compilation.
111112 --generate : Generate a random program using Fuzzilli's code generators and save it to the specified path.
112113 --forDifferentialFuzzing : Enable additional features for better support of external differential fuzzing.
113114 """ )
@@ -186,17 +187,27 @@ else if args.has("--compile") {
186187 exit ( - 1 )
187188 }
188189
189- print ( fuzzILLifter. lift ( program) )
190- print ( )
191- print ( jsLifter. lift ( program) )
190+ if let js_path = args [ " --outputPathJS " ] {
191+ let content = jsLifter. lift ( program)
192+ do {
193+ try content. write ( to: URL ( fileURLWithPath: js_path) , atomically: false , encoding: String . Encoding. utf8)
194+ } catch {
195+ print ( " Failed to write file \( js_path) : \( error) " )
196+ exit ( - 1 )
197+ }
198+ } else {
199+ print ( fuzzILLifter. lift ( program) )
200+ print ( )
201+ print ( jsLifter. lift ( program) )
192202
193- do {
194- let outputPath = URL ( fileURLWithPath: path) . deletingPathExtension ( ) . appendingPathExtension ( " fzil " )
195- try program. asProtobuf ( ) . serializedData ( ) . write ( to: outputPath)
196- print ( " FuzzIL program written to \( outputPath. relativePath) " )
197- } catch {
198- print ( " Failed to store output program to disk: \( error) " )
199- exit ( - 1 )
203+ do {
204+ let outputPath = URL ( fileURLWithPath: path) . deletingPathExtension ( ) . appendingPathExtension ( " fzil " )
205+ try program. asProtobuf ( ) . serializedData ( ) . write ( to: outputPath)
206+ print ( " FuzzIL program written to \( outputPath. relativePath) " )
207+ } catch {
208+ print ( " Failed to store output program to disk: \( error) " )
209+ exit ( - 1 )
210+ }
200211 }
201212}
202213
0 commit comments