Properly parsing resource infos and implementing XexGetModuleSection.

This commit is contained in:
Ben Vanik
2014-01-19 00:46:46 -08:00
parent d22b59555e
commit 0bc49621d4
8 changed files with 100 additions and 36 deletions

View File

@@ -33,3 +33,9 @@ XModule::XModule(KernelState* kernel_state, const char* path) :
XModule::~XModule() {
}
X_STATUS XModule::GetSection(
const char* name,
uint32_t* out_section_data, uint32_t* out_section_size) {
return X_STATUS_UNSUCCESSFUL;
}

View File

@@ -28,6 +28,9 @@ public:
const char* name() const { return name_; }
virtual void* GetProcAddressByOrdinal(uint16_t ordinal) = 0;
virtual X_STATUS GetSection(
const char* name,
uint32_t* out_section_data, uint32_t* out_section_size);
protected:
char name_[256];

View File

@@ -124,23 +124,28 @@ XECLEANUP:
return X_STATUS_UNSUCCESSFUL;
}
X_STATUS XUserModule::GetSection(const char* name,
uint32_t* out_data, uint32_t* out_size) {
const PESection* section = xe_xex2_get_pe_section(xex_, name);
if (!section) {
return X_STATUS_UNSUCCESSFUL;
}
*out_data = section->address;
*out_size = section->size;
return X_STATUS_SUCCESS;
}
void* XUserModule::GetProcAddressByOrdinal(uint16_t ordinal) {
// TODO(benvanik): check export tables.
XELOGE("GetProcAddressByOrdinal not implemented");
return NULL;
}
X_STATUS XUserModule::GetSection(
const char* name,
uint32_t* out_section_data, uint32_t* out_section_size) {
auto header = xe_xex2_get_header(xex_);
for (size_t n = 0; n < header->resource_info_count; n++) {
auto& res = header->resource_infos[n];
if (xestrcmpa(name, res.name) == 0) {
// Found!
*out_section_data = res.address;
*out_section_size = res.size;
return X_STATUS_SUCCESS;
}
}
return X_STATUS_UNSUCCESSFUL;
}
X_STATUS XUserModule::Launch(uint32_t flags) {
const xe_xex2_header_t* header = xex_header();
@@ -226,9 +231,11 @@ void XUserModule::Dump() {
// Resources.
printf("Resources:\n");
printf(" %.8X, %db\n", header->resource_info.address,
header->resource_info.size);
printf(" TODO\n");
for (size_t n = 0; n < header->resource_info_count; n++) {
auto& res = header->resource_infos[n];
printf(" %-8s %.8X-%.8X, %db\n",
res.name, res.address, res.address + res.size, res.size);
}
printf("\n");
// Section info.

View File

@@ -32,8 +32,10 @@ public:
X_STATUS LoadFromFile(const char* path);
X_STATUS LoadFromMemory(const void* addr, const size_t length);
X_STATUS GetSection(const char* name, uint32_t* out_data, uint32_t* out_size);
virtual void* GetProcAddressByOrdinal(uint16_t ordinal);
virtual X_STATUS GetSection(
const char* name,
uint32_t* out_section_data, uint32_t* out_section_size);
X_STATUS Launch(uint32_t flags);