From f2c5df51396d3823746b2261d182e74305c85f33 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 4 Feb 2025 18:31:29 +0100 Subject: [PATCH 1/2] Support hardware breakpoints --- deps/unicorn | 2 +- src/common/platform/status.hpp | 5 +++-- src/windows-emulator/windows_emulator.cpp | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/deps/unicorn b/deps/unicorn index 9a6618ba..73be28b6 160000 --- a/deps/unicorn +++ b/deps/unicorn @@ -1 +1 @@ -Subproject commit 9a6618baf899d515b8eccd22c1eec532bfbc7cd6 +Subproject commit 73be28b6509d0cbf3333071aec4efbb9be1f1e59 diff --git a/src/common/platform/status.hpp b/src/common/platform/status.hpp index 8c60d27d..0d0d9b62 100644 --- a/src/common/platform/status.hpp +++ b/src/common/platform/status.hpp @@ -7,14 +7,15 @@ using NTSTATUS = std::uint32_t; #ifndef OS_WINDOWS #define STATUS_WAIT_0 ((NTSTATUS)0x00000000L) #define STATUS_TIMEOUT ((NTSTATUS)0x00000102L) +#define STATUS_PENDING ((NTSTATUS)0x00000103L) + +#define STATUS_SINGLE_STEP ((NTSTATUS)0x80000004L) #define STATUS_ACCESS_VIOLATION ((NTSTATUS)0xC0000005L) #define STATUS_INVALID_HANDLE ((NTSTATUS)0xC0000008L) #define STATUS_INVALID_PARAMETER ((NTSTATUS)0xC000000DL) #define STATUS_ILLEGAL_INSTRUCTION ((NTSTATUS)0xC000001DL) #define STATUS_INTEGER_DIVIDE_BY_ZERO ((NTSTATUS)0xC0000094L) - -#define STATUS_PENDING ((NTSTATUS)0x00000103L) #endif #define STATUS_SUCCESS ((NTSTATUS)0x00000000L) diff --git a/src/windows-emulator/windows_emulator.cpp b/src/windows-emulator/windows_emulator.cpp index 2e83cd40..4446c827 100644 --- a/src/windows-emulator/windows_emulator.cpp +++ b/src/windows-emulator/windows_emulator.cpp @@ -505,6 +505,11 @@ namespace dispatch_exception(emu, proc, STATUS_INTEGER_DIVIDE_BY_ZERO, {}); } + void dispatch_single_step(x64_emulator& emu, const process_context& proc) + { + dispatch_exception(emu, proc, STATUS_SINGLE_STEP, {}); + } + void perform_context_switch_work(windows_emulator& win_emu) { auto& devices = win_emu.process().devices; @@ -1033,16 +1038,19 @@ void windows_emulator::setup_hooks() }); this->emu().hook_interrupt([&](const int interrupt) { - if (interrupt == 0) + switch (interrupt) { + case 0: dispatch_integer_division_by_zero(this->emu(), this->process()); return; - } - - if (interrupt == 6) - { + case 1: + dispatch_single_step(this->emu(), this->process()); + return; + case 6: dispatch_illegal_instruction_violation(this->emu(), this->process()); return; + default: + break; } const auto rip = this->emu().read_instruction_pointer(); From 94e65bbecf0d809221e9e511c9559546ce167d0d Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 4 Feb 2025 18:43:36 +0100 Subject: [PATCH 2/2] Add new syscalls --- src/windows-emulator/syscalls.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/windows-emulator/syscalls.cpp b/src/windows-emulator/syscalls.cpp index 5a9e1cd8..7dafe4ef 100644 --- a/src/windows-emulator/syscalls.cpp +++ b/src/windows-emulator/syscalls.cpp @@ -1042,7 +1042,7 @@ namespace return STATUS_SUCCESS; } - if (info_class == SystemProcessInformation) + if (info_class == SystemProcessInformation || info_class == SystemModuleInformation) { return STATUS_NOT_SUPPORTED; } @@ -3497,6 +3497,11 @@ namespace return STATUS_NOT_SUPPORTED; } + NTSTATUS handle_NtUserFindWindowEx() + { + return 0; + } + NTSTATUS handle_NtGetNextThread(const syscall_context& c, const handle process_handle, const handle thread_handle, const ACCESS_MASK /*desired_access*/, const ULONG /*handle_attributes*/, const ULONG flags, const emulator_object new_thread_handle) @@ -3728,6 +3733,7 @@ void syscall_dispatcher::add_handlers(std::map& ha add_handler(NtUserReleaseDC); add_handler(NtUserFindExistingCursorIcon); add_handler(NtSetContextThread); + add_handler(NtUserFindWindowEx); #undef add_handler }