Title Update fixup

Co-Authored-By: aerosoul94 <aerosoul94@hotmail.com>
This commit is contained in:
illusion98 2019-11-21 22:36:23 -05:00 committed by illusion
parent 144e2eb51c
commit 79d6893eec
3 changed files with 32 additions and 31 deletions

View File

@ -122,9 +122,9 @@ const PESection* XexModule::GetPESection(const char* name) {
uint32_t XexModule::GetProcAddress(uint16_t ordinal) const { uint32_t XexModule::GetProcAddress(uint16_t ordinal) const {
// First: Check the xex2 export table. // First: Check the xex2 export table.
if (xex_security_info()->export_table) { if (*xex_security_info()->export_table) {
auto export_table = memory()->TranslateVirtual<const xex2_export_table*>( auto export_table = memory()->TranslateVirtual<const xex2_export_table*>(
xex_security_info()->export_table); *xex_security_info()->export_table);
ordinal -= export_table->base; ordinal -= export_table->base;
if (ordinal >= export_table->count) { if (ordinal >= export_table->count) {
@ -587,7 +587,7 @@ int XexModule::ReadImageBasicCompressed(const void* xex_addr,
// Calculate the total size of the XEX image from its headers. // Calculate the total size of the XEX image from its headers.
uint32_t total_size = 0; uint32_t total_size = 0;
for (uint32_t i = 0; i < xex_security_info()->page_descriptor_count; i++) { for (uint32_t i = 0; i < *xex_security_info()->page_descriptor_count; i++) {
// Byteswap the bitfield manually. // Byteswap the bitfield manually.
xex2_page_descriptor desc; xex2_page_descriptor desc;
desc.value = xe::byte_swap(xex_security_info()->page_descriptors[i].value); desc.value = xe::byte_swap(xex_security_info()->page_descriptors[i].value);
@ -891,11 +891,12 @@ bool XexModule::Load(const std::string_view name, const std::string_view path,
security_info_.rsa_signature = xex1_sec_info->rsa_signature; security_info_.rsa_signature = xex1_sec_info->rsa_signature;
security_info_.aes_key = xex1_sec_info->aes_key; security_info_.aes_key = xex1_sec_info->aes_key;
security_info_.image_size = xex1_sec_info->image_size; security_info_.image_size = &xex1_sec_info->image_size;
security_info_.image_flags = xex1_sec_info->image_flags; security_info_.image_flags = &xex1_sec_info->image_flags;
security_info_.export_table = xex1_sec_info->export_table; security_info_.export_table = &xex1_sec_info->export_table;
security_info_.load_address = xex1_sec_info->load_address; security_info_.load_address = &xex1_sec_info->load_address;
security_info_.page_descriptor_count = xex1_sec_info->page_descriptor_count; security_info_.page_descriptor_count =
&xex1_sec_info->page_descriptor_count;
security_info_.page_descriptors = xex1_sec_info->page_descriptors; security_info_.page_descriptors = xex1_sec_info->page_descriptors;
} else if (xex_format_ == kFormatXex2) { } else if (xex_format_ == kFormatXex2) {
const xex2_security_info* xex2_sec_info = const xex2_security_info* xex2_sec_info =
@ -904,19 +905,18 @@ bool XexModule::Load(const std::string_view name, const std::string_view path,
security_info_.rsa_signature = xex2_sec_info->rsa_signature; security_info_.rsa_signature = xex2_sec_info->rsa_signature;
security_info_.aes_key = xex2_sec_info->aes_key; security_info_.aes_key = xex2_sec_info->aes_key;
security_info_.image_size = xex2_sec_info->image_size; security_info_.image_size = &xex2_sec_info->image_size;
security_info_.image_flags = xex2_sec_info->image_flags; security_info_.image_flags = &xex2_sec_info->image_flags;
security_info_.export_table = xex2_sec_info->export_table; security_info_.export_table = &xex2_sec_info->export_table;
security_info_.load_address = xex2_sec_info->load_address; security_info_.load_address = &xex2_sec_info->load_address;
security_info_.page_descriptor_count = xex2_sec_info->page_descriptor_count; security_info_.page_descriptor_count =
&xex2_sec_info->page_descriptor_count;
security_info_.page_descriptors = xex2_sec_info->page_descriptors; security_info_.page_descriptors = xex2_sec_info->page_descriptors;
} }
auto sec_header = xex_security_info();
// Try setting our base_address based on XEX_HEADER_IMAGE_BASE_ADDRESS, fall // Try setting our base_address based on XEX_HEADER_IMAGE_BASE_ADDRESS, fall
// back to xex_security_info otherwise // back to xex_security_info otherwise
base_address_ = xex_security_info()->load_address; base_address_ = *xex_security_info()->load_address;
xe::be<uint32_t>* base_addr_opt = nullptr; xe::be<uint32_t>* base_addr_opt = nullptr;
if (GetOptHeader(XEX_HEADER_IMAGE_BASE_ADDRESS, &base_addr_opt)) if (GetOptHeader(XEX_HEADER_IMAGE_BASE_ADDRESS, &base_addr_opt))
base_address_ = *base_addr_opt; base_address_ = *base_addr_opt;
@ -971,7 +971,7 @@ bool XexModule::LoadContinue() {
high_address_ = 0; high_address_ = 0;
auto sec_header = xex_security_info(); auto sec_header = xex_security_info();
for (uint32_t i = 0, page = 0; i < sec_header->page_descriptor_count; i++) { for (uint32_t i = 0, page = 0; i < *sec_header->page_descriptor_count; i++) {
// Byteswap the bitfield manually. // Byteswap the bitfield manually.
xex2_page_descriptor desc; xex2_page_descriptor desc;
desc.value = xe::byte_swap(sec_header->page_descriptors[i].value); desc.value = xe::byte_swap(sec_header->page_descriptors[i].value);
@ -1047,7 +1047,7 @@ bool XexModule::LoadContinue() {
} }
// Setup memory protection. // Setup memory protection.
for (uint32_t i = 0, page = 0; i < sec_header->page_descriptor_count; i++) { for (uint32_t i = 0, page = 0; i < *sec_header->page_descriptor_count; i++) {
// Byteswap the bitfield manually. // Byteswap the bitfield manually.
xex2_page_descriptor desc; xex2_page_descriptor desc;
desc.value = xe::byte_swap(sec_header->page_descriptors[i].value); desc.value = xe::byte_swap(sec_header->page_descriptors[i].value);
@ -1448,7 +1448,7 @@ bool XexModule::FindSaveRest() {
auto page_size = base_address_ <= 0x90000000 ? 64 * 1024 : 4 * 1024; auto page_size = base_address_ <= 0x90000000 ? 64 * 1024 : 4 * 1024;
auto sec_header = xex_security_info(); auto sec_header = xex_security_info();
for (uint32_t i = 0, page = 0; i < sec_header->page_descriptor_count; i++) { for (uint32_t i = 0, page = 0; i < *sec_header->page_descriptor_count; i++) {
// Byteswap the bitfield manually. // Byteswap the bitfield manually.
xex2_page_descriptor desc; xex2_page_descriptor desc;
desc.value = xe::byte_swap(sec_header->page_descriptors[i].value); desc.value = xe::byte_swap(sec_header->page_descriptors[i].value);

View File

@ -46,11 +46,11 @@ class XexModule : public xe::cpu::Module {
struct SecurityInfoContext { struct SecurityInfoContext {
const char* rsa_signature; const char* rsa_signature;
const char* aes_key; const char* aes_key;
uint32_t image_size; const xe::be<uint32_t>* image_size;
uint32_t image_flags; const xe::be<uint32_t>* image_flags;
uint32_t export_table; const xe::be<uint32_t>* export_table;
uint32_t load_address; const xe::be<uint32_t>* load_address;
uint32_t page_descriptor_count; const xe::be<uint32_t>* page_descriptor_count;
const xex2_page_descriptor* page_descriptors; const xex2_page_descriptor* page_descriptors;
}; };
enum XexFormat { enum XexFormat {
@ -76,7 +76,7 @@ class XexModule : public xe::cpu::Module {
// Calculate the new total size of the XEX image from its headers. // Calculate the new total size of the XEX image from its headers.
auto heap = memory()->LookupHeap(base_address_); auto heap = memory()->LookupHeap(base_address_);
uint32_t total_size = 0; uint32_t total_size = 0;
for (uint32_t i = 0; i < xex_security_info()->page_descriptor_count; i++) { for (uint32_t i = 0; i < *xex_security_info()->page_descriptor_count; i++) {
// Byteswap the bitfield manually. // Byteswap the bitfield manually.
xex2_page_descriptor desc; xex2_page_descriptor desc;
desc.value = desc.value =

View File

@ -277,7 +277,7 @@ X_STATUS UserModule::LoadXexContinue() {
ldr_data->dll_base = 0; // GetProcAddress will read this. ldr_data->dll_base = 0; // GetProcAddress will read this.
ldr_data->xex_header_base = guest_xex_header_; ldr_data->xex_header_base = guest_xex_header_;
ldr_data->full_image_size = security_header->image_size; ldr_data->full_image_size = *security_header->image_size;
ldr_data->image_base = this->xex_module()->base_address(); ldr_data->image_base = this->xex_module()->base_address();
ldr_data->entry_point = entry_point_; ldr_data->entry_point = entry_point_;
@ -455,15 +455,16 @@ void UserModule::Dump() {
// Security header // Security header
auto security_info = xex_module()->xex_security_info(); auto security_info = xex_module()->xex_security_info();
sb.Append("Security Header:\n"); sb.Append("Security Header:\n");
sb.AppendFormat(" Image Flags: {:08X}\n", sb.AppendFormat(" Image Flags: {:08X}\n",
(uint32_t)security_info->image_flags); (uint32_t)*security_info->image_flags);
sb.AppendFormat(" Load Address: {:08X}\n", sb.AppendFormat(" Load Address: {:08X}\n",
(uint32_t)security_info->load_address); (uint32_t)*security_info->load_address);
sb.AppendFormat(" Image Size: {:08X}\n", sb.AppendFormat(" Image Size: {:08X}\n",
(uint32_t)security_info->image_size); (uint32_t)*security_info->image_size);
sb.AppendFormat(" Export Table: {:08X}\n", sb.AppendFormat(" Export Table: {:08X}\n",
(uint32_t)security_info->export_table); (uint32_t)*security_info->export_table);
// Optional headers // Optional headers
sb.AppendFormat("Optional Header Count: {}\n", sb.AppendFormat("Optional Header Count: {}\n",
@ -708,7 +709,7 @@ void UserModule::Dump() {
} }
sb.Append("Sections:\n"); sb.Append("Sections:\n");
for (uint32_t i = 0, page = 0; i < security_info->page_descriptor_count; for (uint32_t i = 0, page = 0; i < *security_info->page_descriptor_count;
i++) { i++) {
// Manually byteswap the bitfield data. // Manually byteswap the bitfield data.
xex2_page_descriptor page_descriptor; xex2_page_descriptor page_descriptor;