-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
587 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
add_subdirectory(common) | ||
add_subdirectory(emulator) | ||
add_subdirectory(unicorn_emulator) | ||
add_subdirectory(windows_emulator) | ||
add_subdirectory(unicorn-emulator) | ||
add_subdirectory(windows-emulator) | ||
add_subdirectory(sample) | ||
add_subdirectory(fuzzing-engine) | ||
add_subdirectory(fuzzer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS | ||
*.cpp | ||
*.hpp | ||
*.rc | ||
) | ||
|
||
list(SORT SRC_FILES) | ||
|
||
add_library(fuzzing-engine ${SRC_FILES}) | ||
|
||
momo_assign_source_group(${SRC_FILES}) | ||
|
||
target_link_libraries(fuzzing-engine PRIVATE | ||
common | ||
) | ||
|
||
target_include_directories(fuzzing-engine INTERFACE | ||
"${CMAKE_CURRENT_LIST_DIR}" | ||
) | ||
|
||
momo_strip_target(fuzzing-engine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include "fuzzer.hpp" | ||
#include "input_generator.hpp" | ||
|
||
namespace fuzzer | ||
{ | ||
namespace | ||
{ | ||
class fuzzing_context | ||
{ | ||
public: | ||
fuzzing_context(input_generator& generator, fuzzing_handler& handler) | ||
: generator(generator) | ||
, handler(handler) | ||
{ | ||
} | ||
|
||
void stop() | ||
{ | ||
this->stop_ = true; | ||
} | ||
|
||
bool should_stop() | ||
{ | ||
if (this->stop_) | ||
{ | ||
return true; | ||
} | ||
|
||
if (!handler.stop()) | ||
{ | ||
return false; | ||
} | ||
|
||
this->stop_ = true; | ||
return true; | ||
} | ||
|
||
input_generator& generator; | ||
fuzzing_handler& handler; | ||
|
||
private: | ||
std::atomic_bool stop_{false}; | ||
}; | ||
|
||
void perform_fuzzing_iteration(const fuzzing_context& context) | ||
{ | ||
context.generator.access_input([&](const std::span<const uint8_t> input) | ||
{ | ||
uint64_t score{0}; | ||
context.handler.execute(input, [&](uint64_t) | ||
{ | ||
++score; | ||
}); | ||
|
||
return score; | ||
}); | ||
} | ||
|
||
void worker(fuzzing_context& context) | ||
{ | ||
while (!context.should_stop()) | ||
{ | ||
perform_fuzzing_iteration(context); | ||
} | ||
} | ||
|
||
struct worker_pool | ||
{ | ||
fuzzing_context* context_{nullptr}; | ||
std::vector<std::thread> workers_{}; | ||
|
||
worker_pool(fuzzing_context& context, const size_t concurrency) | ||
: context_(&context) | ||
{ | ||
this->workers_.reserve(concurrency); | ||
|
||
for (size_t i = 0; i < concurrency; ++i) | ||
{ | ||
this->workers_.emplace_back([&context] | ||
{ | ||
worker(context); | ||
}); | ||
} | ||
} | ||
|
||
~worker_pool() | ||
{ | ||
if (this->workers_.empty()) | ||
{ | ||
return; | ||
} | ||
|
||
this->context_->stop(); | ||
|
||
for (auto& w : this->workers_) | ||
{ | ||
w.join(); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
void run(fuzzing_handler& handler, const size_t concurrency) | ||
{ | ||
input_generator generator{}; | ||
fuzzing_context context{generator, handler}; | ||
worker_pool pool{context, concurrency}; | ||
|
||
while (!context.should_stop()) | ||
{ | ||
std::this_thread::sleep_for(std::chrono::seconds{1}); | ||
} | ||
} | ||
} |
Oops, something went wrong.