From e6b4c6056f56cc998bcd35aa70e4d6717a135835 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Thu, 14 May 2015 21:53:29 -0500 Subject: [PATCH] Calculate xex size based on the total size of all of the sections --- src/xenia/kernel/util/xex2.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/xenia/kernel/util/xex2.cc b/src/xenia/kernel/util/xex2.cc index bfdd40a7f..c46687aba 100644 --- a/src/xenia/kernel/util/xex2.cc +++ b/src/xenia/kernel/util/xex2.cc @@ -585,9 +585,17 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header, uncompressed_size += data_size + zero_size; } + // Calculate the total size of the XEX image from its headers. + uint32_t total_size = 0; + for (uint32_t i = 0; i < header->section_count; i++) { + xe_xex2_section_t& section = header->sections[i]; + + total_size += section.info.page_count * section.page_size; + } + // Allocate in-place the XEX memory. uint32_t alloc_result = memory->HeapAlloc( - header->exe_address, uncompressed_size, xe::MEMORY_FLAG_ZERO); + header->exe_address, total_size, xe::MEMORY_FLAG_ZERO); if (!alloc_result) { XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address, uncompressed_size);