minor changes

This commit is contained in:
Elias Bachaalany
2025-02-11 10:25:02 -08:00
parent ab93de51d2
commit c0719651d3
6 changed files with 20 additions and 22 deletions

View File

@@ -136,7 +136,7 @@ namespace
if (options.silent)
{
win_emu.buffer_stdout = false;
win_emu.callbacks().stdout_callback = [](const std::string_view data) {
win_emu.callbacks.stdout_callback = [](const std::string_view data) {
(void)fwrite(data.data(), 1, data.size(), stdout);
};
}

View File

@@ -21,13 +21,15 @@ namespace utils
{
}
template <typename F, typename = std::enable_if_t<std::is_invocable_r_v<Ret, F, Args...>>>
template <typename F>
requires(std::is_invocable_r_v<Ret, F, Args...>)
optional_function(F&& f)
: func(std::forward<F>(f))
{
}
template <typename F, typename = std::enable_if_t<std::is_invocable_r_v<Ret, F, Args...>>>
template <typename F>
requires(std::is_invocable_r_v<Ret, F, Args...>)
optional_function& operator=(F&& f)
{
func = std::forward<F>(f);

View File

@@ -91,8 +91,8 @@ void syscall_dispatcher::dispatch(windows_emulator& win_emu)
const auto* mod = win_emu.mod_manager.find_by_address(address);
if (mod != win_emu.mod_manager.ntdll && mod != win_emu.mod_manager.win32u)
{
win_emu.callbacks().inline_syscall(syscall_id, address, mod ? mod->name.c_str() : "<N/A>",
entry->second.name);
win_emu.callbacks.inline_syscall(syscall_id, address, mod ? mod->name.c_str() : "<N/A>",
entry->second.name);
win_emu.log.print(color::blue, "Executing inline syscall: %s (0x%X) at 0x%" PRIx64 " (%s)\n",
entry->second.name.c_str(), syscall_id, address, mod ? mod->name.c_str() : "<N/A>");
@@ -116,9 +116,9 @@ void syscall_dispatcher::dispatch(windows_emulator& win_emu)
{
const auto* previous_mod = win_emu.mod_manager.find_by_address(context.previous_ip);
win_emu.callbacks().outofline_syscall(syscall_id, address, mod ? mod->name.c_str() : "<N/A>",
entry->second.name, context.previous_ip,
previous_mod ? previous_mod->name.c_str() : "<N/A>");
win_emu.callbacks.outofline_syscall(syscall_id, address, mod ? mod->name.c_str() : "<N/A>",
entry->second.name, context.previous_ip,
previous_mod ? previous_mod->name.c_str() : "<N/A>");
win_emu.log.print(color::blue,
"Crafted out-of-line syscall: %s (0x%X) at 0x%" PRIx64 " (%s) via 0x%" PRIx64

View File

@@ -2878,7 +2878,7 @@ namespace
io_status_block.write(block);
}
c.win_emu.callbacks().stdout_callback(temp_buffer);
c.win_emu.callbacks.stdout_callback(temp_buffer);
if (!temp_buffer.ends_with("\n"))
{
@@ -3124,7 +3124,9 @@ namespace
const auto local_filename = c.win_emu.file_sys.translate(filename).string();
struct _stat64 file_stat{};
struct _stat64 file_stat
{
};
if (_stat64(local_filename.c_str(), &file_stat) != 0)
{
return STATUS_OBJECT_NAME_NOT_FOUND;
@@ -3613,7 +3615,7 @@ namespace
}
thread->exit_status = exit_status;
c.win_emu.callbacks().thread_terminated(thread_handle, *thread);
c.win_emu.callbacks.thread_terminated(thread_handle, *thread);
if (thread == c.proc.active_thread)
{
c.win_emu.yield_thread();

View File

@@ -172,7 +172,7 @@ windows_emulator::windows_emulator(application_settings app_settings, const emul
emulator_callbacks callbacks, std::unique_ptr<x64_emulator> emu)
: windows_emulator(settings, std::move(emu))
{
this->callbacks_ = std::move(callbacks);
this->callbacks = std::move(callbacks);
fixup_application_settings(app_settings);
this->setup_process(app_settings, settings);
@@ -220,9 +220,9 @@ void windows_emulator::setup_process(const application_settings& app_settings, c
const auto& emu = this->emu();
auto& context = this->process;
mod_manager.on_module_load = [this](mapped_module& mod) { this->callbacks().module_loaded(mod); };
mod_manager.on_module_unload = [this](mapped_module& mod) { this->callbacks().module_unloaded(mod); };
context.on_create_thread = [this](handle h, emulator_thread& thr) { this->callbacks().thread_created(h, thr); };
mod_manager.on_module_load = std::move(callbacks.module_loaded);
mod_manager.on_module_unload = std::move(callbacks.module_unloaded);
context.on_create_thread = std::move(callbacks.thread_created);
this->mod_manager.map_main_modules(app_settings.application, R"(C:\Windows\System32\ntdll.dll)",
R"(C:\Windows\System32\win32u.dll)", this->log);

View File

@@ -64,6 +64,7 @@ class windows_emulator
module_manager mod_manager;
process_context process;
syscall_dispatcher dispatcher;
emulator_callbacks callbacks{};
windows_emulator(const emulator_settings& settings = {},
std::unique_ptr<x64_emulator> emu = create_default_x64_emulator());
@@ -164,18 +165,11 @@ class windows_emulator
return this->use_relative_time_;
}
emulator_callbacks& callbacks()
{
return this->callbacks_;
}
private:
bool switch_thread_{false};
bool use_relative_time_{false};
bool silent_until_main_{false};
emulator_callbacks callbacks_{};
std::vector<instruction_hook_callback> syscall_hooks_{};
std::unordered_map<uint16_t, uint16_t> port_mappings_{};