From 67d34b39888c35c50ed4103886071ea5a3bb13ee Mon Sep 17 00:00:00 2001 From: Maurice Heumann Date: Mon, 7 Apr 2025 22:01:33 +0200 Subject: [PATCH] Small fix --- src/common/platform/status.hpp | 1 + src/windows-emulator/exception_dispatch.cpp | 5 +++ src/windows-emulator/exception_dispatch.hpp | 1 + src/windows-emulator/process_context.cpp | 1 + src/windows-emulator/syscalls.cpp | 36 +++++++++++++++++++++ src/windows-emulator/windows_emulator.cpp | 4 +++ 6 files changed, 48 insertions(+) diff --git a/src/common/platform/status.hpp b/src/common/platform/status.hpp index ba1a0cc3..79d97a3b 100644 --- a/src/common/platform/status.hpp +++ b/src/common/platform/status.hpp @@ -9,6 +9,7 @@ using NTSTATUS = std::uint32_t; #define STATUS_TIMEOUT ((NTSTATUS)0x00000102L) #define STATUS_PENDING ((NTSTATUS)0x00000103L) +#define STATUS_BREAKPOINT ((NTSTATUS)0x80000003L) #define STATUS_SINGLE_STEP ((NTSTATUS)0x80000004L) #define STATUS_ACCESS_VIOLATION ((NTSTATUS)0xC0000005L) diff --git a/src/windows-emulator/exception_dispatch.cpp b/src/windows-emulator/exception_dispatch.cpp index 12a40452..96c5b9e8 100644 --- a/src/windows-emulator/exception_dispatch.cpp +++ b/src/windows-emulator/exception_dispatch.cpp @@ -196,3 +196,8 @@ void dispatch_single_step(x64_emulator& emu, const process_context& proc) { dispatch_exception(emu, proc, STATUS_SINGLE_STEP, {}); } + +void dispatch_breakpoint(x64_emulator& emu, const process_context& proc) +{ + dispatch_exception(emu, proc, STATUS_BREAKPOINT, {}); +} diff --git a/src/windows-emulator/exception_dispatch.hpp b/src/windows-emulator/exception_dispatch.hpp index 7befde5c..c324399e 100644 --- a/src/windows-emulator/exception_dispatch.hpp +++ b/src/windows-emulator/exception_dispatch.hpp @@ -22,3 +22,4 @@ void dispatch_access_violation(x64_emulator& emu, const process_context& proc, u void dispatch_illegal_instruction_violation(x64_emulator& emu, const process_context& proc); void dispatch_integer_division_by_zero(x64_emulator& emu, const process_context& proc); void dispatch_single_step(x64_emulator& emu, const process_context& proc); +void dispatch_breakpoint(x64_emulator& emu, const process_context& proc); diff --git a/src/windows-emulator/process_context.cpp b/src/windows-emulator/process_context.cpp index f8a1d766..06bb6e7a 100644 --- a/src/windows-emulator/process_context.cpp +++ b/src/windows-emulator/process_context.cpp @@ -93,6 +93,7 @@ void process_context::setup(x64_emulator& emu, memory_manager& memory, const app }); this->peb.access([&](PEB64& p) { + p.BeingDebugged = 0; p.ImageBaseAddress = executable.image_base; p.ProcessParameters = this->process_params.ptr(); p.ApiSetMap = apiset::clone(emu, allocator, apiset_container).ptr(); diff --git a/src/windows-emulator/syscalls.cpp b/src/windows-emulator/syscalls.cpp index adcb7df8..0665b967 100644 --- a/src/windows-emulator/syscalls.cpp +++ b/src/windows-emulator/syscalls.cpp @@ -1718,6 +1718,42 @@ namespace return STATUS_SUCCESS; } + if (info_class == ThreadPerformanceCount) + { + if (return_length) + { + return_length.write(sizeof(LARGE_INTEGER)); + } + + if (thread_information_length < sizeof(LARGE_INTEGER)) + { + return STATUS_BUFFER_OVERFLOW; + } + + const emulator_object info{c.emu, thread_information}; + info.write({}); + + return STATUS_SUCCESS; + } + + if (info_class == ThreadHideFromDebugger) + { + if (return_length) + { + return_length.write(sizeof(BOOLEAN)); + } + + if (thread_information_length < sizeof(BOOLEAN)) + { + return STATUS_BUFFER_OVERFLOW; + } + + const emulator_object info{c.emu, thread_information}; + info.write(0); + + return STATUS_SUCCESS; + } + if (info_class == ThreadTimes) { if (return_length) diff --git a/src/windows-emulator/windows_emulator.cpp b/src/windows-emulator/windows_emulator.cpp index de8f6874..e87f7044 100644 --- a/src/windows-emulator/windows_emulator.cpp +++ b/src/windows-emulator/windows_emulator.cpp @@ -475,6 +475,10 @@ void windows_emulator::setup_hooks() this->log.print(color::pink, "Singlestep: 0x%" PRIx64 "\n", rip); dispatch_single_step(this->emu(), this->process); return; + case 3: + this->log.print(color::pink, "Breakpoint: 0x%" PRIx64 "\n", rip); + dispatch_breakpoint(this->emu(), this->process); + return; case 6: dispatch_illegal_instruction_violation(this->emu(), this->process); return;