mirror of
https://github.com/momo5502/emulator.git
synced 2026-02-01 00:41:02 +00:00
Explicitly pass desired backend to emulator
This commit is contained in:
@@ -3,6 +3,7 @@ add_subdirectory(emulator)
|
|||||||
add_subdirectory(gdb-stub)
|
add_subdirectory(gdb-stub)
|
||||||
add_subdirectory(windows-emulator)
|
add_subdirectory(windows-emulator)
|
||||||
add_subdirectory(windows-gdb-stub)
|
add_subdirectory(windows-gdb-stub)
|
||||||
|
add_subdirectory(backend-selection)
|
||||||
|
|
||||||
momo_add_subdirectory_and_get_targets("backends" BACKEND_TARGETS)
|
momo_add_subdirectory_and_get_targets("backends" BACKEND_TARGETS)
|
||||||
momo_targets_set_folder("backends" ${BACKEND_TARGETS})
|
momo_targets_set_folder("backends" ${BACKEND_TARGETS})
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ target_link_libraries(analyzer PRIVATE
|
|||||||
debugger
|
debugger
|
||||||
windows-emulator
|
windows-emulator
|
||||||
windows-gdb-stub
|
windows-gdb-stub
|
||||||
|
backend-selection
|
||||||
)
|
)
|
||||||
|
|
||||||
set_property(GLOBAL PROPERTY VS_STARTUP_PROJECT analyzer)
|
set_property(GLOBAL PROPERTY VS_STARTUP_PROJECT analyzer)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "std_include.hpp"
|
#include "std_include.hpp"
|
||||||
|
|
||||||
#include <windows_emulator.hpp>
|
#include <windows_emulator.hpp>
|
||||||
|
#include <backend_selection.hpp>
|
||||||
#include <win_x64_gdb_stub_handler.hpp>
|
#include <win_x64_gdb_stub_handler.hpp>
|
||||||
|
|
||||||
#include "object_watching.hpp"
|
#include "object_watching.hpp"
|
||||||
@@ -217,7 +218,7 @@ namespace
|
|||||||
std::unique_ptr<windows_emulator> create_empty_emulator(const analysis_options& options)
|
std::unique_ptr<windows_emulator> create_empty_emulator(const analysis_options& options)
|
||||||
{
|
{
|
||||||
const auto settings = create_emulator_settings(options);
|
const auto settings = create_emulator_settings(options);
|
||||||
return std::make_unique<windows_emulator>(settings);
|
return std::make_unique<windows_emulator>(create_x86_64_emulator(), settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<windows_emulator> create_application_emulator(const analysis_options& options,
|
std::unique_ptr<windows_emulator> create_application_emulator(const analysis_options& options,
|
||||||
@@ -234,7 +235,7 @@ namespace
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto settings = create_emulator_settings(options);
|
const auto settings = create_emulator_settings(options);
|
||||||
return std::make_unique<windows_emulator>(std::move(app_settings), settings);
|
return std::make_unique<windows_emulator>(create_x86_64_emulator(), std::move(app_settings), settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<windows_emulator> setup_emulator(const analysis_options& options,
|
std::unique_ptr<windows_emulator> setup_emulator(const analysis_options& options,
|
||||||
|
|||||||
23
src/backend-selection/CMakeLists.txt
Normal file
23
src/backend-selection/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS
|
||||||
|
*.cpp
|
||||||
|
*.hpp
|
||||||
|
*.rc
|
||||||
|
)
|
||||||
|
|
||||||
|
list(SORT SRC_FILES)
|
||||||
|
|
||||||
|
add_library(backend-selection ${SRC_FILES})
|
||||||
|
|
||||||
|
momo_assign_source_group(${SRC_FILES})
|
||||||
|
|
||||||
|
target_include_directories(backend-selection INTERFACE "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
|
||||||
|
target_link_libraries(backend-selection PRIVATE
|
||||||
|
unicorn-emulator
|
||||||
|
)
|
||||||
|
|
||||||
|
if (MOMO_ENABLE_RUST_CODE)
|
||||||
|
target_link_libraries(backend-selection PRIVATE
|
||||||
|
icicle-emulator
|
||||||
|
)
|
||||||
|
endif()
|
||||||
23
src/backend-selection/backend_selection.cpp
Normal file
23
src/backend-selection/backend_selection.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include "backend_selection.hpp"
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
#include <unicorn_x86_64_emulator.hpp>
|
||||||
|
|
||||||
|
#if MOMO_ENABLE_RUST_CODE
|
||||||
|
#include <icicle_x86_64_emulator.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
|
std::unique_ptr<x86_64_emulator> create_x86_64_emulator()
|
||||||
|
{
|
||||||
|
#if MOMO_ENABLE_RUST_CODE
|
||||||
|
const auto* env = getenv("EMULATOR_ICICLE");
|
||||||
|
if (env && (env == "1"sv || env == "true"sv))
|
||||||
|
{
|
||||||
|
return icicle::create_x86_64_emulator();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return unicorn::create_x86_64_emulator();
|
||||||
|
}
|
||||||
6
src/backend-selection/backend_selection.hpp
Normal file
6
src/backend-selection/backend_selection.hpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <arch_emulator.hpp>
|
||||||
|
|
||||||
|
std::unique_ptr<x86_64_emulator> create_x86_64_emulator();
|
||||||
@@ -19,4 +19,10 @@ target_link_libraries(fuzzer PRIVATE
|
|||||||
windows-emulator
|
windows-emulator
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (MOMO_ENABLE_RUST_CODE)
|
||||||
|
target_link_libraries(fuzzer PRIVATE
|
||||||
|
icicle-emulator
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
momo_strip_target(fuzzer)
|
momo_strip_target(fuzzer)
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
#include <windows_emulator.hpp>
|
#include <windows_emulator.hpp>
|
||||||
#include <fuzzer.hpp>
|
#include <fuzzer.hpp>
|
||||||
|
|
||||||
#include "utils/finally.hpp"
|
#include <utils/finally.hpp>
|
||||||
|
|
||||||
|
#if MOMO_ENABLE_RUST_CODE
|
||||||
|
#include <icicle_x86_64_emulator.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(disable : 4702)
|
#pragma warning(disable : 4702)
|
||||||
@@ -13,6 +17,15 @@ bool use_gdb = false;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
std::unique_ptr<x86_64_emulator> create_emulator_backend()
|
||||||
|
{
|
||||||
|
#if MOMO_ENABLE_RUST_CODE
|
||||||
|
return icicle::create_x86_64_emulator();
|
||||||
|
#else
|
||||||
|
throw std::runtime_error("Fuzzer requires rust code to be enabled");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void run_emulation(windows_emulator& win_emu)
|
void run_emulation(windows_emulator& win_emu)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -47,7 +60,7 @@ namespace
|
|||||||
|
|
||||||
struct fuzzer_executer : fuzzer::executer
|
struct fuzzer_executer : fuzzer::executer
|
||||||
{
|
{
|
||||||
windows_emulator emu{}; // TODO: Fix root directory
|
windows_emulator emu{create_emulator_backend()};
|
||||||
std::span<const std::byte> emulator_data{};
|
std::span<const std::byte> emulator_data{};
|
||||||
std::unordered_set<uint64_t> visited_blocks{};
|
std::unordered_set<uint64_t> visited_blocks{};
|
||||||
const std::function<fuzzer::coverage_functor>* handler{nullptr};
|
const std::function<fuzzer::coverage_functor>* handler{nullptr};
|
||||||
@@ -148,7 +161,7 @@ namespace
|
|||||||
.application = application,
|
.application = application,
|
||||||
};
|
};
|
||||||
|
|
||||||
windows_emulator win_emu{std::move(settings)};
|
windows_emulator win_emu{create_emulator_backend(), std::move(settings)};
|
||||||
|
|
||||||
forward_emulator(win_emu);
|
forward_emulator(win_emu);
|
||||||
run_fuzzer(win_emu);
|
run_fuzzer(win_emu);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ target_link_libraries(windows-emulator-test PRIVATE
|
|||||||
gtest
|
gtest
|
||||||
gtest_main
|
gtest_main
|
||||||
windows-emulator
|
windows-emulator
|
||||||
|
backend-selection
|
||||||
)
|
)
|
||||||
|
|
||||||
if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <windows_emulator.hpp>
|
#include <windows_emulator.hpp>
|
||||||
|
#include <backend_selection.hpp>
|
||||||
|
|
||||||
#include <network/static_socket_factory.hpp>
|
#include <network/static_socket_factory.hpp>
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ namespace test
|
|||||||
std::filesystem::temp_directory_path() / ("emulator-test-file-" + std::to_string(getpid()) + ".txt");
|
std::filesystem::temp_directory_path() / ("emulator-test-file-" + std::to_string(getpid()) + ".txt");
|
||||||
|
|
||||||
return windows_emulator{
|
return windows_emulator{
|
||||||
|
create_x86_64_emulator(),
|
||||||
settings,
|
settings,
|
||||||
std::move(callbacks),
|
std::move(callbacks),
|
||||||
emulator_interfaces{
|
emulator_interfaces{
|
||||||
@@ -97,6 +99,7 @@ namespace test
|
|||||||
std::filesystem::temp_directory_path() / ("emulator-test-file-" + std::to_string(getpid()) + ".txt");
|
std::filesystem::temp_directory_path() / ("emulator-test-file-" + std::to_string(getpid()) + ".txt");
|
||||||
|
|
||||||
return windows_emulator{
|
return windows_emulator{
|
||||||
|
create_x86_64_emulator(),
|
||||||
get_sample_app_settings(config),
|
get_sample_app_settings(config),
|
||||||
settings,
|
settings,
|
||||||
std::move(callbacks),
|
std::move(callbacks),
|
||||||
|
|||||||
@@ -14,16 +14,6 @@ if(NOT MOMO_ENABLE_CLANG_TIDY)
|
|||||||
target_precompile_headers(windows-emulator PRIVATE std_include.hpp)
|
target_precompile_headers(windows-emulator PRIVATE std_include.hpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(windows-emulator PRIVATE
|
|
||||||
unicorn-emulator
|
|
||||||
)
|
|
||||||
|
|
||||||
if (MOMO_ENABLE_RUST_CODE)
|
|
||||||
target_link_libraries(windows-emulator PRIVATE
|
|
||||||
icicle-emulator
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_link_libraries(windows-emulator PUBLIC emulator)
|
target_link_libraries(windows-emulator PUBLIC emulator)
|
||||||
|
|
||||||
target_include_directories(windows-emulator INTERFACE "${CMAKE_CURRENT_LIST_DIR}")
|
target_include_directories(windows-emulator INTERFACE "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
|||||||
@@ -3,12 +3,6 @@
|
|||||||
|
|
||||||
#include "cpu_context.hpp"
|
#include "cpu_context.hpp"
|
||||||
|
|
||||||
#include <unicorn_x86_64_emulator.hpp>
|
|
||||||
|
|
||||||
#if MOMO_ENABLE_RUST_CODE
|
|
||||||
#include <icicle_x86_64_emulator.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <utils/io.hpp>
|
#include <utils/io.hpp>
|
||||||
#include <utils/finally.hpp>
|
#include <utils/finally.hpp>
|
||||||
#include <utils/lazy_object.hpp>
|
#include <utils/lazy_object.hpp>
|
||||||
@@ -268,30 +262,17 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<x86_64_emulator> create_default_x86_64_emulator()
|
windows_emulator::windows_emulator(std::unique_ptr<x86_64_emulator> emu, application_settings app_settings,
|
||||||
{
|
const emulator_settings& settings, emulator_callbacks callbacks,
|
||||||
#if MOMO_ENABLE_RUST_CODE
|
emulator_interfaces interfaces)
|
||||||
const auto* env = getenv("EMULATOR_ICICLE");
|
: windows_emulator(std::move(emu), settings, std::move(callbacks), std::move(interfaces))
|
||||||
if (env && (env == "1"sv || env == "true"sv))
|
|
||||||
{
|
|
||||||
return icicle::create_x86_64_emulator();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return unicorn::create_x86_64_emulator();
|
|
||||||
}
|
|
||||||
|
|
||||||
windows_emulator::windows_emulator(application_settings app_settings, const emulator_settings& settings,
|
|
||||||
emulator_callbacks callbacks, emulator_interfaces interfaces,
|
|
||||||
std::unique_ptr<x86_64_emulator> emu)
|
|
||||||
: windows_emulator(settings, std::move(callbacks), std::move(interfaces), std::move(emu))
|
|
||||||
{
|
{
|
||||||
fixup_application_settings(app_settings);
|
fixup_application_settings(app_settings);
|
||||||
this->setup_process(app_settings);
|
this->setup_process(app_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
windows_emulator::windows_emulator(const emulator_settings& settings, emulator_callbacks callbacks,
|
windows_emulator::windows_emulator(std::unique_ptr<x86_64_emulator> emu, const emulator_settings& settings,
|
||||||
emulator_interfaces interfaces, std::unique_ptr<x86_64_emulator> emu)
|
emulator_callbacks callbacks, emulator_interfaces interfaces)
|
||||||
: emu_(std::move(emu)),
|
: emu_(std::move(emu)),
|
||||||
clock_(get_clock(interfaces, this->executed_instructions_, settings.use_relative_time)),
|
clock_(get_clock(interfaces, this->executed_instructions_, settings.use_relative_time)),
|
||||||
socket_factory_(get_socket_factory(interfaces)),
|
socket_factory_(get_socket_factory(interfaces)),
|
||||||
|
|||||||
@@ -13,8 +13,6 @@
|
|||||||
#include "module/module_manager.hpp"
|
#include "module/module_manager.hpp"
|
||||||
#include "network/socket_factory.hpp"
|
#include "network/socket_factory.hpp"
|
||||||
|
|
||||||
std::unique_ptr<x86_64_emulator> create_default_x86_64_emulator();
|
|
||||||
|
|
||||||
struct emulator_callbacks : module_manager::callbacks, process_context::callbacks
|
struct emulator_callbacks : module_manager::callbacks, process_context::callbacks
|
||||||
{
|
{
|
||||||
utils::optional_function<instruction_hook_continuation(uint32_t syscall_id, x86_64_emulator::pointer_type address,
|
utils::optional_function<instruction_hook_continuation(uint32_t syscall_id, x86_64_emulator::pointer_type address,
|
||||||
@@ -72,12 +70,11 @@ class windows_emulator
|
|||||||
process_context process;
|
process_context process;
|
||||||
syscall_dispatcher dispatcher;
|
syscall_dispatcher dispatcher;
|
||||||
|
|
||||||
windows_emulator(const emulator_settings& settings = {}, emulator_callbacks callbacks = {},
|
windows_emulator(std::unique_ptr<x86_64_emulator> emu, const emulator_settings& settings = {},
|
||||||
emulator_interfaces interfaces = {},
|
emulator_callbacks callbacks = {}, emulator_interfaces interfaces = {});
|
||||||
std::unique_ptr<x86_64_emulator> emu = create_default_x86_64_emulator());
|
windows_emulator(std::unique_ptr<x86_64_emulator> emu, application_settings app_settings,
|
||||||
windows_emulator(application_settings app_settings, const emulator_settings& settings = {},
|
const emulator_settings& settings = {}, emulator_callbacks callbacks = {},
|
||||||
emulator_callbacks callbacks = {}, emulator_interfaces interfaces = {},
|
emulator_interfaces interfaces = {});
|
||||||
std::unique_ptr<x86_64_emulator> emu = create_default_x86_64_emulator());
|
|
||||||
|
|
||||||
windows_emulator(windows_emulator&&) = delete;
|
windows_emulator(windows_emulator&&) = delete;
|
||||||
windows_emulator(const windows_emulator&) = delete;
|
windows_emulator(const windows_emulator&) = delete;
|
||||||
|
|||||||
Reference in New Issue
Block a user