Arion 1.0.2-alpha
A high-performance C++ framework for emulating executable binaries.
 
Loading...
Searching...
No Matches
arion_afl.hpp
Go to the documentation of this file.
1#ifndef ARION_ARION_AFL_HPP
2#define ARION_ARION_AFL_HPP
3
4#include <arion/arion.hpp>
5#include <arion/unicornafl/unicornafl.h>
6#include <memory>
7#include <sys/signal.h>
8
9namespace arion
10{
11
21using ARION_AFL_INPUT_CALLBACK = std::function<bool(std::shared_ptr<Arion> arion, char *input, size_t input_sz,
22 uint32_t persistent_round, void *user_data)>;
33using ARION_AFL_CRASH_CALLBACK = std::function<bool(std::shared_ptr<Arion> arion, uc_err res, char *input,
34 size_t input_sz, uint32_t persistent_round, void *user_data)>;
35
44
76
78inline std::map<uc_afl_ret, std::string> UC_AFL_ERR_STR = {
79 {UC_AFL_RET_CHILD, "Fork worked. We are a child (no error)."},
80 {UC_AFL_RET_NO_AFL, "No AFL, no need to fork (but no real error)."},
81 {UC_AFL_RET_FINISHED, "We forked before but now AFL is gone (time to quit)."},
82 {UC_AFL_RET_CALLED_TWICE, "Forkserver already running. This may be an error."},
83 {UC_AFL_RET_ERROR, "Something went horribly wrong in the parent."}};
84
87{
88 private:
90 std::weak_ptr<Arion> arion;
100 static bool uc_input_callback(uc_engine *uc, char *input, size_t input_sz, uint32_t persistent_round,
101 void *user_data);
112 static bool uc_crash_callback(uc_engine *uc, uc_err res, char *input, int input_len, int persistent_round,
113 void *user_data);
114
115 public:
120 ARION_EXPORT ArionAfl(std::weak_ptr<Arion> arion) : arion(arion) {};
134 std::vector<ADDR> exits, ARION_MEM_STRATEGY mem_strategy = ARION_MEM_STRATEGY::RECORD_EDITS,
135 std::vector<int> signals = {SIGSEGV, SIGABRT}, bool always_validate = false,
136 uint32_t persistent_iters = 1000, void *user_data = nullptr);
137};
138
139}; // namespace arion
140
141#endif // ARION_ARION_AFL_HPP
This class is used to managed a UnicornAFL fuzzing session from an Arion instance.
Definition arion_afl.hpp:87
ArionAfl(std::weak_ptr< Arion > arion)
Definition arion_afl.hpp:120
void fuzz(ARION_AFL_INPUT_CALLBACK input_callback, ARION_AFL_CRASH_CALLBACK crash_callback, std::vector< ADDR > exits, ARION_MEM_STRATEGY mem_strategy=ARION_MEM_STRATEGY::RECORD_EDITS, std::vector< int > signals={SIGSEGV, SIGABRT}, bool always_validate=false, uint32_t persistent_iters=1000, void *user_data=nullptr)
static bool uc_input_callback(uc_engine *uc, char *input, size_t input_sz, uint32_t persistent_round, void *user_data)
std::weak_ptr< Arion > arion
The Arion instance associated with this fuzzing session.
Definition arion_afl.hpp:90
static bool uc_crash_callback(uc_engine *uc, uc_err res, char *input, int input_len, int persistent_round, void *user_data)
#define ARION_EXPORT
Defines which symbols should be exported from the library.
Definition global_defs.hpp:13
Definition arch_x86-64.hpp:11
ARION_MEM_STRATEGY
Memory restoring strategies for the fuzzed Arion instance.
Definition arion_afl.hpp:38
@ MANUAL_MANAGEMENT
Nothing is restored.
Definition arion_afl.hpp:42
@ RECORD_EDITS
All memory changes are tracked, in order to restore only edited regions.
Definition arion_afl.hpp:39
@ RESTORE_MAPPINGS
Memory regions are restored, without caring about the data they contain.
Definition arion_afl.hpp:40
@ RAW_RESTORE
Everything is restored.
Definition arion_afl.hpp:41
std::function< bool(std::shared_ptr< Arion > arion, uc_err res, char *input, size_t input_sz, uint32_t persistent_round, void *user_data)> ARION_AFL_CRASH_CALLBACK
Definition arion_afl.hpp:34
std::map< uc_afl_ret, std::string > UC_AFL_ERR_STR
A map identifying a UnicornAFL error message given its error code.
Definition arion_afl.hpp:78
std::function< bool(std::shared_ptr< Arion > arion, char *input, size_t input_sz, uint32_t persistent_round, void *user_data)> ARION_AFL_INPUT_CALLBACK
Definition arion_afl.hpp:22
This structure is placed in the UnicornAFL user_data parameter.
Definition arion_afl.hpp:47
std::weak_ptr< Arion > arion
The Arion instance being fuzzed.
Definition arion_afl.hpp:49
ARION_AFL_CRASH_CALLBACK crash_callback
This callback gets triggered at each target crash detected by AFL.
Definition arion_afl.hpp:58
ARION_AFL_PARAM(std::weak_ptr< Arion > arion, std::shared_ptr< ARION_CONTEXT > ctxt, ARION_MEM_STRATEGY mem_strategy, ARION_AFL_INPUT_CALLBACK input_callback, ARION_AFL_CRASH_CALLBACK crash_callback, void *user_data)
Definition arion_afl.hpp:71
ARION_AFL_INPUT_CALLBACK input_callback
Definition arion_afl.hpp:56
ARION_MEM_STRATEGY mem_strategy
The memory restoring strategy.
Definition arion_afl.hpp:53
void * user_data
Optional user-defined data passed to the hook.
Definition arion_afl.hpp:60
std::shared_ptr< ARION_CONTEXT > ctxt
The original context of the Arion instance, before fuzzing started.
Definition arion_afl.hpp:51