@@ -33,7 +33,7 @@ func loadProgram(from path: String) throws -> Program {
3333
3434func loadAllPrograms( in dirPath: String ) -> [ ( filename: String , program: Program ) ] {
3535 var isDir : ObjCBool = false
36- if !FileManager. default. fileExists ( atPath: dirPath, isDirectory: & isDir) || !isDir. boolValue {
36+ if !FileManager. default. fileExists ( atPath: dirPath, isDirectory: & isDir) || !isDir. boolValue {
3737 print ( " \( dirPath) is not a directory! " )
3838 exit ( - 1 )
3939 }
@@ -56,7 +56,7 @@ func loadAllPrograms(in dirPath: String) -> [(filename: String, program: Program
5656}
5757
5858// Takes a program and lifts it to JavaScript.
59- func liftToJS( _ jsLifter: JavaScriptLifter , _ prog: Program ) -> String {
59+ func liftToJS( _ jsLifter: JavaScriptLifter , _ prog: Program ) -> String {
6060 let res = jsLifter. lift ( prog)
6161 return res. trimmingCharacters ( in: . whitespacesAndNewlines)
6262}
@@ -72,10 +72,13 @@ func liftToFuzzIL(_ prog: Program) -> String {
7272func liftAllPrograms( in dirPath: String , with lifter: Lifter , fileExtension: String ) -> Int {
7373 var numLiftedPrograms = 0
7474 for (filename, program) in loadAllPrograms ( in: dirPath) {
75- let newFilePath = " \( dirPath) / \( filename. dropLast ( protoBufFileExtension. count) ) \( fileExtension) "
75+ let newFilePath =
76+ " \( dirPath) / \( filename. dropLast ( protoBufFileExtension. count) ) \( fileExtension) "
7677 let content = lifter. lift ( program)
7778 do {
78- try content. write ( to: URL ( fileURLWithPath: newFilePath) , atomically: false , encoding: String . Encoding. utf8)
79+ try content. write (
80+ to: URL ( fileURLWithPath: newFilePath) , atomically: false ,
81+ encoding: String . Encoding. utf8)
7982 numLiftedPrograms += 1
8083 } catch {
8184 print ( " Failed to write file \( newFilePath) : \( error) " )
@@ -96,29 +99,32 @@ func loadProgramOrExit(from path: String) -> Program {
9699let args = Arguments . parse ( from: CommandLine . arguments)
97100
98101if args [ " -h " ] != nil || args [ " --help " ] != nil || args. numPositionalArguments != 1 {
99- print ( """
100- Usage:
101- \( args. programName) options path
102-
103- Options:
104- --liftToFuzzIL : Lifts the given protobuf program to FuzzIL's text format and prints it
105- --liftToJS : Lifts the given protobuf program to JS and prints it
106- --liftCorpusToJS : Loads all .fzil files in a directory and lifts them to .js files in that same directory
107- --dumpProtobuf : Dumps the raw content of the given protobuf file
108- --dumpProgram : Dumps the internal representation of the program stored in the given protobuf file
109- --checkCorpus : Attempts to load all .fzil files in a directory and checks if they are statically valid
110- --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.
112- --generate : Generate a random program using Fuzzilli's code generators and save it to the specified path.
113- --forDifferentialFuzzing : Enable additional features for better support of external differential fuzzing.
114- """ )
102+ print (
103+ """
104+ Usage:
105+ \( args. programName) options path
106+
107+ Options:
108+ --liftToFuzzIL : Lifts the given protobuf program to FuzzIL's text format and prints it
109+ --liftToJS : Lifts the given protobuf program to JS and prints it
110+ --liftCorpusToJS : Loads all .fzil files in a directory and lifts them to .js files in that same directory
111+ --dumpProtobuf : Dumps the raw content of the given protobuf file
112+ --dumpProgram : Dumps the internal representation of the program stored in the given protobuf file
113+ --checkCorpus : Attempts to load all .fzil files in a directory and checks if they are statically valid
114+ --compile : Compile the given JavaScript program to a FuzzIL program. Requires node.js
115+ --outputPathJS : If given, --compile will write the lifted JS file to the given path after compilation.
116+ --generate : Generate a random program using Fuzzilli's code generators and save it to the specified path.
117+ --forDifferentialFuzzing : Enable additional features for better support of external differential fuzzing.
118+ """ )
115119 exit ( 0 )
116120}
117121
118122let path = args [ 0 ]
119123
120124let forDifferentialFuzzing = args. has ( " --forDifferentialFuzzing " )
121- let jsLifter = JavaScriptLifter ( prefix: jsPrefix, suffix: jsSuffix, ecmaVersion: ECMAScriptVersion . es6, environment: JavaScriptEnvironment ( ) , alwaysEmitVariables: forDifferentialFuzzing)
125+ let jsLifter = JavaScriptLifter (
126+ prefix: jsPrefix, suffix: jsSuffix, ecmaVersion: ECMAScriptVersion . es6,
127+ environment: JavaScriptEnvironment ( ) , alwaysEmitVariables: forDifferentialFuzzing)
122128
123129// Covert a single IL protobuf file to FuzzIL's text format and print to stdout
124130if args. has ( " --liftToFuzzIL " ) {
@@ -134,7 +140,8 @@ else if args.has("--liftToJS") {
134140
135141// Lift all protobuf programs to JavaScript
136142else if args. has ( " --liftCorpusToJS " ) {
137- let numLiftedPrograms = liftAllPrograms ( in: path, with: jsLifter, fileExtension: jsFileExtension)
143+ let numLiftedPrograms = liftAllPrograms (
144+ in: path, with: jsLifter, fileExtension: jsFileExtension)
138145 print ( " Lifted \( numLiftedPrograms) programs to JS " )
139146}
140147
@@ -166,7 +173,9 @@ else if args.has("--compile") {
166173 exit ( - 1 )
167174 }
168175 guard let parser = JavaScriptParser ( executor: nodejs) else {
169- print ( " The JavaScript parser does not appear to be working. See Sources/Fuzzilli/Compiler/Parser/README.md for instructions on how to set it up. " )
176+ print (
177+ " The JavaScript parser does not appear to be working. See Sources/Fuzzilli/Compiler/Parser/README.md for instructions on how to set it up. "
178+ )
170179 exit ( - 1 )
171180 }
172181
@@ -194,7 +203,9 @@ else if args.has("--compile") {
194203 if let js_path = args [ " --outputPathJS " ] {
195204 let content = ast. leadingComments + jsLifter. lift ( program)
196205 do {
197- try content. write ( to: URL ( fileURLWithPath: js_path) , atomically: false , encoding: String . Encoding. utf8)
206+ try content. write (
207+ to: URL ( fileURLWithPath: js_path) , atomically: false , encoding: String . Encoding. utf8
208+ )
198209 } catch {
199210 print ( " Failed to write file \( js_path) : \( error) " )
200211 exit ( - 1 )
@@ -205,7 +216,8 @@ else if args.has("--compile") {
205216 print ( jsLifter. lift ( program) )
206217
207218 do {
208- let outputPath = URL ( fileURLWithPath: path) . deletingPathExtension ( ) . appendingPathExtension ( " fzil " )
219+ let outputPath = URL ( fileURLWithPath: path) . deletingPathExtension ( )
220+ . appendingPathExtension ( " fzil " )
209221 try program. asProtobuf ( ) . serializedData ( ) . write ( to: outputPath)
210222 print ( " FuzzIL program written to \( outputPath. relativePath) " )
211223 } catch {
@@ -216,7 +228,9 @@ else if args.has("--compile") {
216228}
217229
218230else if args. has ( " --generate " ) {
219- let fuzzer = makeMockFuzzer ( config: Configuration ( logLevel: . warning, enableInspection: true ) , environment: JavaScriptEnvironment ( ) )
231+ let fuzzer = makeMockFuzzer (
232+ config: Configuration ( logLevel: . warning, enableInspection: true ) ,
233+ environment: JavaScriptEnvironment ( ) )
220234 let b = fuzzer. makeBuilder ( )
221235 b. buildPrefix ( )
222236 b. build ( n: 50 , by: . generating)
@@ -225,7 +239,8 @@ else if args.has("--generate") {
225239 print ( jsLifter. lift ( program, withOptions: . includeComments) )
226240
227241 do {
228- let outputPath = URL ( fileURLWithPath: path) . deletingPathExtension ( ) . appendingPathExtension ( " fzil " )
242+ let outputPath = URL ( fileURLWithPath: path) . deletingPathExtension ( ) . appendingPathExtension (
243+ " fzil " )
229244 try program. asProtobuf ( ) . serializedData ( ) . write ( to: outputPath)
230245 } catch {
231246 print ( " Failed to store output program to disk: \( error) " )
0 commit comments