Fix module mapping

This commit is contained in:
momo5502
2024-09-09 19:09:38 +02:00
parent fad1721cba
commit c23da4484b
3 changed files with 13 additions and 6 deletions

View File

@@ -285,18 +285,25 @@ bool memory_manager::release_memory(const uint64_t address, size_t size)
return true;
}
uint64_t memory_manager::find_free_allocation_base(const size_t size) const
uint64_t memory_manager::find_free_allocation_base(const size_t size, const uint64_t start) const
{
uint64_t start_address = std::max(MIN_ALLOCATION_ADDRESS, 0x1000000000ULL);
uint64_t start_address =
std::max(MIN_ALLOCATION_ADDRESS, start ? start : 0x100000000ULL);
for (const auto& region : this->reserved_regions_)
{
const auto region_end = region.first + region.second.length;
if(region_end < start_address)
{
continue;
}
if (!regions_with_length_intersect(start_address, size, region.first, region.second.length))
{
return start_address;
}
start_address = page_align_up(region.first + region.second.length);
start_address = page_align_up(region_end);
}
if (start_address + size <= MAX_ALLOCATION_ADDRESS)

View File

@@ -59,7 +59,7 @@ public:
bool release_memory(uint64_t address, size_t size);
uint64_t find_free_allocation_base(size_t size) const;
uint64_t find_free_allocation_base(size_t size, uint64_t start = 0) const;
region_info get_region_info(uint64_t address);

View File

@@ -200,8 +200,8 @@ namespace
if (!emu.allocate_memory(binary.image_base, binary.size_of_image, memory_permission::read))
{
binary.image_base = emu.find_free_allocation_base(binary.size_of_image);
if ((optional_header.DllCharacteristics &
IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) == 0 || //
if (/*(optional_header.DllCharacteristics &
IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) == 0 ||*/ //
!emu.allocate_memory(
binary.image_base, binary.size_of_image, memory_permission::read))
{