namespace fuzzer {
-// Simple C-like interface with a single user-supplied callback.
-/* Usage: ---------------------------------------------------------------------
+typedef void (*UserCallback)(const uint8_t *Data, size_t Size);
+/** Simple C-like interface with a single user-supplied callback.
+
+Usage:
+
+#\code
#include "FuzzerInterface.h"
void LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
InitializeMeIfNeeded();
return fuzzer::FuzzerDriver(argc, argv, LLVMFuzzerTestOneInput);
}
------------------------------------------------------------------------------ */
-typedef void (*UserCallback)(const uint8_t *Data, size_t Size);
+#\endcode
+*/
int FuzzerDriver(int argc, char **argv, UserCallback Callback);
-// An abstract class that allows to use user-supplied mutators with libFuzzer.
-/* Usage: ---------------------------------------------------------------------
+/** An abstract class that allows to use user-supplied mutators with libFuzzer.
+
+Usage:
+
+#\code
#include "FuzzerInterface.h"
class MyFuzzer : public fuzzer::UserSuppliedFuzzer {
public:
MyFuzzer F;
fuzzer::FuzzerDriver(argc, argv, F);
}
------------------------------------------------------------------------------ */
+#\endcode
+*/
class UserSuppliedFuzzer {
public:
- // Executes the target function on 'Size' bytes of 'Data'.
+ /// Executes the target function on 'Size' bytes of 'Data'.
virtual void TargetFunction(const uint8_t *Data, size_t Size) = 0;
- // Mutates 'Size' bytes of data in 'Data' inplace into up to 'MaxSize' bytes,
- // returns the new size of the data.
+ /// Mutates 'Size' bytes of data in 'Data' inplace into up to 'MaxSize' bytes,
+ /// returns the new size of the data.
virtual size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize) {
return BasicMutate(Data, Size, MaxSize);
}
- // Crosses 'Data1' and 'Data2', writes up to 'MaxOutSize' bytes into Out,
- // returns the number of bytes written.
+ /// Crosses 'Data1' and 'Data2', writes up to 'MaxOutSize' bytes into Out,
+ /// returns the number of bytes written.
virtual size_t CrossOver(const uint8_t *Data1, size_t Size1,
const uint8_t *Data2, size_t Size2,
uint8_t *Out, size_t MaxOutSize) {
virtual ~UserSuppliedFuzzer() {}
protected:
- // These can be called internally by Mutate and CrossOver.
+ /// These can be called internally by Mutate and CrossOver.
size_t BasicMutate(uint8_t *Data, size_t Size, size_t MaxSize);
size_t BasicCrossOver(const uint8_t *Data1, size_t Size1,
const uint8_t *Data2, size_t Size2,
uint8_t *Out, size_t MaxOutSize);
};
+/// Runs the fuzzing with the UserSuppliedFuzzer.
int FuzzerDriver(int argc, char **argv, UserSuppliedFuzzer &USF);
} // namespace fuzzer