Class GuidedFuzzing
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for creating guidance instances -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GuidanceReturns the currently registered Guidance instance.static Resultrun(Class<?> testClass, String testMethod, Guidance guidance, PrintStream out) Runs the guided fuzzing loop for a resolved class.static Resultrun(String testClassName, String testMethod, Guidance guidance, PrintStream out) Runs the guided fuzzing loop, using the system class loader to load test-application classes.static Resultrun(String testClassName, String testMethod, ClassLoader loader, Guidance guidance, PrintStream out) Runs the guided fuzzing loop, using a provided classloader to load test-application classes.static ResultrunAll(Class<?> testClass, GuidedFuzzing.GuidanceSupplier guidanceSupplier, PrintStream out) Runs the guided fuzzing loop for all @Fuzz methods in a test class.static voidSets the current global fuzzing guidance.static voidUnsets the current global fuzzing guidance.
-
Field Details
-
DEFAULT_MAX_TRIALS
public static long DEFAULT_MAX_TRIALS
-
-
Constructor Details
-
GuidedFuzzing
public GuidedFuzzing()
-
-
Method Details
-
setGuidance
Sets the current global fuzzing guidance. Note: There can only be one guidance in any given JVM, because the instrumented test classes make static method calls to generate callback events. The fuzzing entry point (i.e., the target method being fuzzed) should be invoked in the same thread as the thread that sets the global guidance. This property is ensured by all variants ofrun(Class, String, Guidance, PrintStream).- Parameters:
g- the guidance instance- Throws:
IllegalStateException- if a guidance has already been set
-
getCurrentGuidance
Returns the currently registered Guidance instance.- Returns:
- the currently registered Guidance instance
-
unsetGuidance
public static void unsetGuidance()Unsets the current global fuzzing guidance. This allows running multiple fuzzing sessions in the same JVM instance sequentially. This method should be invoked from the same thread that last invokedsetGuidance(Guidance). This method removes any tracers associated with the current thread, so that the entry point can be detected again. This property is ensured byrun(Class, String, Guidance, PrintStream). -
run
public static Result run(String testClassName, String testMethod, Guidance guidance, PrintStream out) throws ClassNotFoundException, IllegalStateException Runs the guided fuzzing loop, using the system class loader to load test-application classes.The test class must be annotated with
@RunWith(JQF.class)and the test method must be annotated with@Fuzz.Once this method is invoked, the guided fuzzing loop runs continuously until the guidance instance decides to stop by returning
falseforGuidance.hasInput(). Until the fuzzing stops, this method cannot be invoked again (i.e. at most one guided fuzzing can be running at any time in a single JVM instance).- Parameters:
testClassName- the test class containing the test methodtestMethod- the test method to execute in the fuzzing loopguidance- the fuzzing guidanceout- an output stream to log Junit messages- Returns:
- the Junit-style test result
- Throws:
ClassNotFoundException- if testClassName cannot be loadedIllegalStateException- if a guided fuzzing run is currently executing
-
run
public static Result run(String testClassName, String testMethod, ClassLoader loader, Guidance guidance, PrintStream out) throws ClassNotFoundException, IllegalStateException Runs the guided fuzzing loop, using a provided classloader to load test-application classes.The test class must be annotated with
@RunWith(JQF.class)and the test method must be annotated with@Fuzz.Once this method is invoked, the guided fuzzing loop runs continuously until the guidance instance decides to stop by returning
falseforGuidance.hasInput(). Until the fuzzing stops, this method cannot be invoked again (i.e. at most one guided fuzzing can be running at any time in a single JVM instance).- Parameters:
testClassName- the test class containing the test methodtestMethod- the test method to execute in the fuzzing looploader- the classloader to load the test class withguidance- the fuzzing guidanceout- an output stream to log Junit messages- Returns:
- the Junit-style test result
- Throws:
ClassNotFoundException- if testClassName cannot be loadedIllegalStateException- if a guided fuzzing run is currently executing
-
run
public static Result run(Class<?> testClass, String testMethod, Guidance guidance, PrintStream out) throws IllegalStateException Runs the guided fuzzing loop for a resolved class.The test class must be annotated with
@RunWith(JQF.class)and the test method must be annotated with@Fuzz.Once this method is invoked, the guided fuzzing loop runs continuously until the guidance instance decides to stop by returning
falseforGuidance.hasInput(). Until the fuzzing stops, this method cannot be invoked again (i.e. at most one guided fuzzing can be running at any time in a single JVM instance).- Parameters:
testClass- the test class containing the test methodtestMethod- the test method to execute in the fuzzing loopguidance- the fuzzing guidanceout- an output stream to log Junit messages- Returns:
- the Junit-style test result
- Throws:
IllegalStateException- if a guided fuzzing run is currently executing
-
runAll
public static Result runAll(Class<?> testClass, GuidedFuzzing.GuidanceSupplier guidanceSupplier, PrintStream out) throws IllegalStateException, IOException Runs the guided fuzzing loop for all @Fuzz methods in a test class.The test class must be annotated with
@RunWith(JQF.class).This method executes each @Fuzz method in the test class sequentially, creating a new guidance instance for each method.
- Parameters:
testClass- the test class containing the test methodsguidanceSupplier- a function that creates a new guidance instance for each methodout- an output stream to log JUnit messages- Returns:
- the JUnit-style test result
- Throws:
IllegalStateException- if a guided fuzzing run is currently executingIOException- if an I/O error occurs when setting up the guidance
-