Moving get_opt_header out of xex2.

This commit is contained in:
Ben Vanik 2015-06-28 14:01:53 -07:00
parent 010b701e05
commit 84e884a07f
5 changed files with 41 additions and 36 deletions

View File

@ -146,20 +146,47 @@ X_STATUS XUserModule::GetSection(const char* name, uint32_t* out_section_data,
X_STATUS XUserModule::GetOptHeader(xe_xex2_header_keys key,
uint32_t* out_header_guest_ptr) {
assert_not_null(out_header_guest_ptr);
auto header = memory()->TranslateVirtual<xex2_header*>(xex_header_);
if (!header) {
return X_STATUS_UNSUCCESSFUL;
}
uint32_t field_value =
xex2_get_opt_header(memory()->virtual_membase(), header, key);
if (!field_value) {
return X_STATUS_NOT_FOUND;
return GetOptHeader(memory()->virtual_membase(), header, key,
out_header_guest_ptr);
}
X_STATUS XUserModule::GetOptHeader(uint8_t* membase, const xex2_header* header,
xe_xex2_header_keys key,
uint32_t* out_header_guest_ptr) {
assert_not_null(out_header_guest_ptr);
uint32_t field_value = 0;
bool field_found = false;
for (uint32_t i = 0; i < header->header_count; i++) {
auto& opt_header = header->headers[i];
if (opt_header.key != key) {
continue;
}
field_found = true;
switch (opt_header.key & 0xFF) {
case 0x00:
// Return data stored in header value.
field_value = opt_header.value;
break;
case 0x01:
// Return pointer to data stored in header value.
field_value = uint32_t((uint8_t*)&opt_header.value - membase);
break;
default:
// Data stored at offset to header.
field_value = uint32_t((uint8_t*)&header->headers[0] - membase) +
opt_header.offset;
break;
}
break;
}
*out_header_guest_ptr = field_value;
if (!field_found) {
return X_STATUS_NOT_FOUND;
}
return X_STATUS_SUCCESS;
}

View File

@ -35,8 +35,12 @@ class XUserModule : public XModule {
uint32_t GetProcAddressByName(const char* name) override;
X_STATUS GetSection(const char* name, uint32_t* out_section_data,
uint32_t* out_section_size) override;
X_STATUS GetOptHeader(xe_xex2_header_keys key,
uint32_t* out_header_guest_ptr);
static X_STATUS GetOptHeader(uint8_t* membase, const xex2_header* header,
xe_xex2_header_keys key,
uint32_t* out_header_guest_ptr);
X_STATUS Launch(uint32_t flags);

View File

@ -29,31 +29,6 @@
namespace xe {
namespace kernel {
uint32_t xex2_get_opt_header(uint8_t *membase, const xex2_header *header,
uint32_t key) {
for (uint32_t i = 0; i < header->header_count; i++) {
const xex2_opt_header &opt_header = header->headers[i];
if (opt_header.key != key) {
continue;
}
switch (opt_header.key & 0xFF) {
case 0x00:
// Return data stored in header value.
return opt_header.value;
case 0x01:
// Return pointer to data stored in header value.
return uint32_t((uint8_t *)&opt_header.value - membase);
default:
// Data stored at offset to header.
return uint32_t((uint8_t *)&header->headers[0] - membase) +
opt_header.offset;
}
}
return 0;
}
uint32_t xex2_get_header_size(const xex2_header *header) {
return header->exe_offset;
}

View File

@ -15,8 +15,6 @@
namespace xe {
namespace kernel {
uint32_t xex2_get_opt_header(uint8_t* membase, const xex2_header* header,
uint32_t key);
uint32_t xex2_get_header_size(const xex2_header* header);
} // namespace kernel
} // namespace xe

View File

@ -394,8 +394,9 @@ SHIM_CALL RtlImageXexHeaderField_shim(PPCContext* ppc_context,
return;
}
uint32_t field_value =
xex2_get_opt_header(SHIM_MEM_BASE, header, image_field);
uint32_t field_value = 0;
XUserModule::GetOptHeader(SHIM_MEM_BASE, header,
xe_xex2_header_keys(image_field), &field_value);
SHIM_SET_RETURN_32(field_value);
}