From 1f5e5c1fad5f5507eb99472e7b80dfa3c3002996 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 22 Sep 2024 11:21:49 +0200 Subject: [PATCH] More syscalls --- src/emulator/memory_manager.cpp | 4 +++- src/emulator/memory_manager.hpp | 1 + src/windows_emulator/syscalls.cpp | 34 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/emulator/memory_manager.cpp b/src/emulator/memory_manager.cpp index 539f4c93..610d3863 100644 --- a/src/emulator/memory_manager.cpp +++ b/src/emulator/memory_manager.cpp @@ -394,6 +394,7 @@ region_info memory_manager::get_region_info(const uint64_t address) result.length = MAX_ALLOCATION_ADDRESS - result.start; result.pemissions = memory_permission::none; result.allocation_base = {}; + result.allocation_length = result.length; result.is_committed = false; result.is_reserved = false; @@ -424,8 +425,9 @@ region_info memory_manager::get_region_info(const uint64_t address) result.is_reserved = true; result.allocation_base = entry->first; + result.allocation_length = reserved_region.length; result.start = result.allocation_base; - result.length = reserved_region.length; + result.length = result.allocation_length; if (committed_regions.empty()) { diff --git a/src/emulator/memory_manager.hpp b/src/emulator/memory_manager.hpp index f24253b4..54e33dda 100644 --- a/src/emulator/memory_manager.hpp +++ b/src/emulator/memory_manager.hpp @@ -8,6 +8,7 @@ struct region_info : basic_memory_region { uint64_t allocation_base{}; + size_t allocation_length{}; bool is_reserved{}; bool is_committed{}; }; diff --git a/src/windows_emulator/syscalls.cpp b/src/windows_emulator/syscalls.cpp index bdaf28d3..09131ba4 100644 --- a/src/windows_emulator/syscalls.cpp +++ b/src/windows_emulator/syscalls.cpp @@ -644,6 +644,40 @@ namespace return STATUS_SUCCESS; } + if (info_class == MemoryRegionInformation) + { + if (return_length) + { + return_length.write(sizeof(MEMORY_REGION_INFORMATION)); + } + + if (memory_information_length != sizeof(MEMORY_REGION_INFORMATION)) + { + return STATUS_BUFFER_OVERFLOW; + } + + const auto region_info = c.emu.get_region_info(base_address); + if(!region_info.is_reserved) + { + return STATUS_INVALID_ADDRESS; + } + + const emulator_object info{c.emu, memory_information}; + + info.access([&](MEMORY_REGION_INFORMATION& image_info) + { + memset(&image_info, 0, sizeof(image_info)); + + image_info.AllocationBase = reinterpret_cast(region_info.allocation_base); + image_info.AllocationProtect = 0; + image_info.PartitionId = 0; + image_info.RegionSize = region_info.allocation_length; + image_info.Reserved = 0x10; + }); + + return STATUS_SUCCESS; + } + printf("Unsupported memory info class: %X\n", info_class); c.emu.stop(); return STATUS_NOT_SUPPORTED;