Support section offsets

This commit is contained in:
momo5502
2025-12-23 10:50:07 +01:00
parent db3a89a0da
commit 35b7839ec8

View File

@@ -248,7 +248,7 @@ namespace syscalls
const emulator_object<uint64_t> base_address,
const EMULATOR_CAST(EmulatorTraits<Emu64>::ULONG_PTR, ULONG_PTR) /*zero_bits*/,
const EMULATOR_CAST(EmulatorTraits<Emu64>::SIZE_T, SIZE_T) /*commit_size*/,
const emulator_object<LARGE_INTEGER> /*section_offset*/,
const emulator_object<LARGE_INTEGER> section_offset,
const emulator_object<EMULATOR_CAST(EmulatorTraits<Emu64>::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<std::byte> file_data{};
int64_t offset = 0;
if (section_offset)
{
offset = section_offset.read().QuadPart;
offset = std::max<int64_t>(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_t>(size), protection, reserve_only);
const auto address = c.win_emu.memory.allocate_memory(static_cast<size_t>(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);