From 35b7839ec850a7ca2d2ee40b344430acb667dcaf Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 23 Dec 2025 10:50:07 +0100 Subject: [PATCH] Support section offsets --- src/windows-emulator/syscalls/section.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/windows-emulator/syscalls/section.cpp b/src/windows-emulator/syscalls/section.cpp index 6d012794..178bba59 100644 --- a/src/windows-emulator/syscalls/section.cpp +++ b/src/windows-emulator/syscalls/section.cpp @@ -248,7 +248,7 @@ namespace syscalls const emulator_object base_address, const EMULATOR_CAST(EmulatorTraits::ULONG_PTR, ULONG_PTR) /*zero_bits*/, const EMULATOR_CAST(EmulatorTraits::SIZE_T, SIZE_T) /*commit_size*/, - const emulator_object /*section_offset*/, + const emulator_object section_offset, const emulator_object::SIZE_T, SIZE_T)> view_size, const SECTION_INHERIT /*inherit_disposition*/, const ULONG /*allocation_type*/, const ULONG /*win32_protect*/) @@ -353,6 +353,13 @@ namespace syscalls uint64_t size = section_entry->maximum_size; std::vector file_data{}; + int64_t offset = 0; + if (section_offset) + { + offset = section_offset.read().QuadPart; + offset = std::max(offset, 0); + } + if (!section_entry->file_name.empty()) { if (!utils::io::read_file(c.win_emu.file_sys.translate(section_entry->file_name), &file_data)) @@ -360,21 +367,22 @@ namespace syscalls return STATUS_INVALID_PARAMETER; } - size = page_align_up(file_data.size()); + size = file_data.size() - offset; } + const auto aligned_size = page_align_up(size); const auto reserve_only = section_entry->allocation_attributes == SEC_RESERVE; const auto protection = map_nt_to_emulator_protection(section_entry->section_page_protection); - const auto address = c.win_emu.memory.allocate_memory(static_cast(size), protection, reserve_only); + const auto address = c.win_emu.memory.allocate_memory(static_cast(aligned_size), protection, reserve_only); if (!reserve_only && !file_data.empty()) { - c.emu.write_memory(address, file_data.data(), file_data.size()); + c.emu.write_memory(address, file_data.data() + offset, size); } if (view_size) { - view_size.write(size); + view_size.write(aligned_size); } base_address.write(address);