mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-18 11:13:57 +00:00
Fix fuzzer
This commit is contained in:
@@ -47,7 +47,7 @@ namespace
|
||||
|
||||
struct fuzzer_executer : fuzzer::executer
|
||||
{
|
||||
windows_emulator emu{{.emulation_root = "./"}}; // TODO: Fix root directory
|
||||
windows_emulator emu{}; // TODO: Fix root directory
|
||||
std::span<const std::byte> emulator_data{};
|
||||
std::unordered_set<uint64_t> visited_blocks{};
|
||||
const std::function<fuzzer::coverage_functor>* handler{nullptr};
|
||||
@@ -66,6 +66,11 @@ namespace
|
||||
utils::buffer_deserializer deserializer{emulator_data};
|
||||
emu.deserialize(deserializer);
|
||||
emu.save_snapshot();
|
||||
|
||||
const auto return_address = emu.emu().read_stack(0);
|
||||
emu.emu().hook_memory_execution(return_address, [&](const uint64_t) {
|
||||
emu.emu().stop(); //
|
||||
});
|
||||
}
|
||||
|
||||
void restore_emulator()
|
||||
|
||||
@@ -50,7 +50,9 @@ namespace fuzzer
|
||||
++context.executions;
|
||||
context.generator.access_input([&](const std::span<const uint8_t> input) {
|
||||
uint64_t score{0};
|
||||
const auto result = executer.execute(input, [&](uint64_t) { ++score; });
|
||||
const auto result = executer.execute(input, [&](uint64_t) {
|
||||
++score; //
|
||||
});
|
||||
|
||||
if (result == execution_result::error)
|
||||
{
|
||||
@@ -84,7 +86,9 @@ namespace fuzzer
|
||||
|
||||
for (size_t i = 0; i < concurrency; ++i)
|
||||
{
|
||||
this->workers_.emplace_back([&context] { worker(context); });
|
||||
this->workers_.emplace_back([&context] {
|
||||
worker(context); //
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,11 @@ namespace fuzzer
|
||||
{
|
||||
std::unique_lock lock{this->mutex_};
|
||||
|
||||
if (this->top_scorer_.empty())
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double score{0.0};
|
||||
for (const auto& e : this->top_scorer_)
|
||||
{
|
||||
|
||||
@@ -638,19 +638,7 @@ void windows_emulator::start(size_t count)
|
||||
}
|
||||
}
|
||||
|
||||
void windows_emulator::serialize(utils::buffer_serializer& buffer) const
|
||||
{
|
||||
buffer.write(this->executed_instructions_);
|
||||
buffer.write(this->switch_thread_);
|
||||
buffer.write(this->use_relative_time_);
|
||||
this->emu().serialize_state(buffer, false);
|
||||
this->memory.serialize_memory_state(buffer, false);
|
||||
this->mod_manager.serialize(buffer);
|
||||
this->process.serialize(buffer);
|
||||
this->dispatcher.serialize(buffer);
|
||||
}
|
||||
|
||||
void windows_emulator::deserialize(utils::buffer_deserializer& buffer)
|
||||
void windows_emulator::register_factories(utils::buffer_deserializer& buffer)
|
||||
{
|
||||
buffer.register_factory<memory_manager_wrapper>([this] {
|
||||
return memory_manager_wrapper{this->memory}; //
|
||||
@@ -675,6 +663,23 @@ void windows_emulator::deserialize(utils::buffer_deserializer& buffer)
|
||||
buffer.register_factory<socket_factory_wrapper>([this] {
|
||||
return socket_factory_wrapper{this->socket_factory()}; //
|
||||
});
|
||||
}
|
||||
|
||||
void windows_emulator::serialize(utils::buffer_serializer& buffer) const
|
||||
{
|
||||
buffer.write(this->executed_instructions_);
|
||||
buffer.write(this->switch_thread_);
|
||||
buffer.write(this->use_relative_time_);
|
||||
this->emu().serialize_state(buffer, false);
|
||||
this->memory.serialize_memory_state(buffer, false);
|
||||
this->mod_manager.serialize(buffer);
|
||||
this->process.serialize(buffer);
|
||||
this->dispatcher.serialize(buffer);
|
||||
}
|
||||
|
||||
void windows_emulator::deserialize(utils::buffer_deserializer& buffer)
|
||||
{
|
||||
this->register_factories(buffer);
|
||||
|
||||
buffer.read(this->executed_instructions_);
|
||||
buffer.read(this->switch_thread_);
|
||||
@@ -719,6 +724,9 @@ void windows_emulator::restore_snapshot()
|
||||
}
|
||||
|
||||
utils::buffer_deserializer deserializer{this->process_snapshot_};
|
||||
|
||||
this->register_factories(deserializer);
|
||||
|
||||
this->emu().deserialize_state(deserializer, true);
|
||||
this->memory.deserialize_memory_state(deserializer, true);
|
||||
this->mod_manager.deserialize(deserializer);
|
||||
|
||||
@@ -202,4 +202,6 @@ class windows_emulator
|
||||
void setup_hooks();
|
||||
void setup_process(const application_settings& app_settings);
|
||||
void on_instruction_execution(uint64_t address);
|
||||
|
||||
void register_factories(utils::buffer_deserializer& buffer);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user