[CPU/Kernel] Correct parsing of XEX_HEADER_IMPORT_LIBRARIES.
This commit is contained in:
parent
b3d509eb01
commit
207589e5a1
|
@ -1119,23 +1119,23 @@ bool XexModule::LoadContinue() {
|
||||||
processor_->backend()->CommitExecutableRange(low_address_, high_address_);
|
processor_->backend()->CommitExecutableRange(low_address_, high_address_);
|
||||||
|
|
||||||
// Add all imports (variables/functions).
|
// Add all imports (variables/functions).
|
||||||
xex2_opt_import_libraries* opt_import_header = nullptr;
|
xex2_opt_import_libraries* opt_import_libraries = nullptr;
|
||||||
GetOptHeader(XEX_HEADER_IMPORT_LIBRARIES, &opt_import_header);
|
GetOptHeader(XEX_HEADER_IMPORT_LIBRARIES, &opt_import_libraries);
|
||||||
|
|
||||||
if (opt_import_header) {
|
if (opt_import_libraries) {
|
||||||
// FIXME: Don't know if 32 is the actual limit, but haven't seen more than
|
// FIXME: Don't know if 32 is the actual limit, but haven't seen more than
|
||||||
// 2.
|
// 2.
|
||||||
const char* string_table[32];
|
const char* string_table[32];
|
||||||
std::memset(string_table, 0, sizeof(string_table));
|
std::memset(string_table, 0, sizeof(string_table));
|
||||||
size_t max_string_table_index = 0;
|
|
||||||
|
|
||||||
// Parse the string table
|
// Parse the string table
|
||||||
for (size_t i = 0; i < opt_import_header->string_table_size;
|
for (size_t i = 0, o = 0; i < opt_import_libraries->string_table.size &&
|
||||||
++max_string_table_index) {
|
o < opt_import_libraries->string_table.count;
|
||||||
assert_true(max_string_table_index < xe::countof(string_table));
|
++o) {
|
||||||
const char* str = opt_import_header->string_table + i;
|
assert_true(o < xe::countof(string_table));
|
||||||
|
const char* str = &opt_import_libraries->string_table.data[i];
|
||||||
|
|
||||||
string_table[max_string_table_index] = str;
|
string_table[o] = str;
|
||||||
i += std::strlen(str) + 1;
|
i += std::strlen(str) + 1;
|
||||||
|
|
||||||
// Padding
|
// Padding
|
||||||
|
@ -1144,15 +1144,19 @@ bool XexModule::LoadContinue() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto libraries_ptr = reinterpret_cast<uint8_t*>(opt_import_header) +
|
auto library_data = reinterpret_cast<uint8_t*>(opt_import_libraries) +
|
||||||
opt_import_header->string_table_size + 12;
|
opt_import_libraries->string_table.size + 12;
|
||||||
uint32_t library_offset = 0;
|
uint32_t library_offset = 0;
|
||||||
uint32_t library_count = opt_import_header->library_count;
|
while (library_offset < opt_import_libraries->size) {
|
||||||
for (uint32_t i = 0; i < library_count; i++) {
|
auto library =
|
||||||
auto library = reinterpret_cast<xex2_import_library*>(libraries_ptr +
|
reinterpret_cast<xex2_import_library*>(library_data + library_offset);
|
||||||
library_offset);
|
if (!library->size) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
size_t library_name_index = library->name_index & 0xFF;
|
size_t library_name_index = library->name_index & 0xFF;
|
||||||
assert_true(library_name_index < max_string_table_index);
|
assert_true(library_name_index <
|
||||||
|
opt_import_libraries->string_table.count);
|
||||||
|
assert_not_null(string_table[library_name_index]);
|
||||||
SetupLibraryImports(string_table[library_name_index], library);
|
SetupLibraryImports(string_table[library_name_index], library);
|
||||||
library_offset += library->size;
|
library_offset += library->size;
|
||||||
}
|
}
|
||||||
|
@ -1312,10 +1316,12 @@ bool XexModule::SetupLibraryImports(const char* name,
|
||||||
var_info->set_status(Symbol::Status::kDefined);
|
var_info->set_status(Symbol::Status::kDefined);
|
||||||
} else if (record_type == 1) {
|
} else if (record_type == 1) {
|
||||||
// Thunk.
|
// Thunk.
|
||||||
assert_true(library_info.imports.size() > 0);
|
if (library_info.imports.size() > 0) {
|
||||||
auto& prev_import = library_info.imports[library_info.imports.size() - 1];
|
auto& prev_import =
|
||||||
assert_true(prev_import.ordinal == ordinal);
|
library_info.imports[library_info.imports.size() - 1];
|
||||||
prev_import.thunk_address = record_addr;
|
assert_true(prev_import.ordinal == ordinal);
|
||||||
|
prev_import.thunk_address = record_addr;
|
||||||
|
}
|
||||||
|
|
||||||
if (kernel_export) {
|
if (kernel_export) {
|
||||||
import_name.AppendFormat("%s", kernel_export->name);
|
import_name.AppendFormat("%s", kernel_export->name);
|
||||||
|
|
|
@ -486,29 +486,33 @@ void UserModule::Dump() {
|
||||||
std::memset(string_table, 0, sizeof(string_table));
|
std::memset(string_table, 0, sizeof(string_table));
|
||||||
|
|
||||||
// Parse the string table
|
// Parse the string table
|
||||||
for (size_t l = 0, j = 0; l < opt_import_libraries->string_table_size;
|
for (size_t j = 0, o = 0; j < opt_import_libraries->string_table.size &&
|
||||||
j++) {
|
o < opt_import_libraries->string_table.count;
|
||||||
assert_true(j < xe::countof(string_table));
|
o++) {
|
||||||
const char* str = opt_import_libraries->string_table + l;
|
assert_true(o < xe::countof(string_table));
|
||||||
|
const char* str = &opt_import_libraries->string_table.data[o];
|
||||||
|
|
||||||
string_table[j] = str;
|
string_table[o] = str;
|
||||||
l += std::strlen(str) + 1;
|
j += std::strlen(str) + 1;
|
||||||
|
|
||||||
// Padding
|
// Padding
|
||||||
if ((l % 4) != 0) {
|
if ((j % 4) != 0) {
|
||||||
l += 4 - (l % 4);
|
j += 4 - (j % 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto libraries =
|
auto library_data =
|
||||||
reinterpret_cast<const uint8_t*>(opt_import_libraries) +
|
reinterpret_cast<const uint8_t*>(opt_import_libraries) +
|
||||||
opt_import_libraries->string_table_size + 12;
|
opt_import_libraries->string_table.size + 12;
|
||||||
uint32_t library_offset = 0;
|
uint32_t library_offset = 0;
|
||||||
uint32_t library_count = opt_import_libraries->library_count;
|
while (library_offset < opt_import_libraries->size) {
|
||||||
for (uint32_t l = 0; l < library_count; l++) {
|
|
||||||
auto library = reinterpret_cast<const xex2_import_library*>(
|
auto library = reinterpret_cast<const xex2_import_library*>(
|
||||||
libraries + library_offset);
|
library_data + library_offset);
|
||||||
|
if (!library->size) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
auto name = string_table[library->name_index & 0xFF];
|
auto name = string_table[library->name_index & 0xFF];
|
||||||
|
assert_not_null(name);
|
||||||
sb.AppendFormat(" %s - %d imports\n", name,
|
sb.AppendFormat(" %s - %d imports\n", name,
|
||||||
(uint16_t)library->count);
|
(uint16_t)library->count);
|
||||||
|
|
||||||
|
@ -786,11 +790,11 @@ void UserModule::Dump() {
|
||||||
}
|
}
|
||||||
if (kernel_export &&
|
if (kernel_export &&
|
||||||
kernel_export->type == cpu::Export::Type::kVariable) {
|
kernel_export->type == cpu::Export::Type::kVariable) {
|
||||||
sb.AppendFormat(" V %.8X %.3X (%3d) %s %s\n",
|
sb.AppendFormat(" V %.8X %.3X (%4d) %s %s\n",
|
||||||
info->value_address, info->ordinal, info->ordinal,
|
info->value_address, info->ordinal, info->ordinal,
|
||||||
implemented ? " " : "!!", name);
|
implemented ? " " : "!!", name);
|
||||||
} else if (info->thunk_address) {
|
} else if (info->thunk_address) {
|
||||||
sb.AppendFormat(" F %.8X %.8X %.3X (%3d) %s %s\n",
|
sb.AppendFormat(" F %.8X %.8X %.3X (%4d) %s %s\n",
|
||||||
info->value_address, info->thunk_address,
|
info->value_address, info->thunk_address,
|
||||||
info->ordinal, info->ordinal,
|
info->ordinal, info->ordinal,
|
||||||
implemented ? " " : "!!", name);
|
implemented ? " " : "!!", name);
|
||||||
|
|
|
@ -474,10 +474,12 @@ struct xex2_opt_execution_info {
|
||||||
static_assert_size(xex2_opt_execution_info, 0x18);
|
static_assert_size(xex2_opt_execution_info, 0x18);
|
||||||
|
|
||||||
struct xex2_opt_import_libraries {
|
struct xex2_opt_import_libraries {
|
||||||
xe::be<uint32_t> section_size; // 0x0
|
xe::be<uint32_t> size; // 0x0
|
||||||
xe::be<uint32_t> string_table_size; // 0x4
|
struct {
|
||||||
xe::be<uint32_t> library_count; // 0x8
|
xe::be<uint32_t> size; // 0x4
|
||||||
char string_table[1]; // 0xC string_table_size bytes
|
xe::be<uint32_t> count; // 0x8
|
||||||
|
char data[1]; // 0xC string_table_size bytes
|
||||||
|
} string_table;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct xex2_import_library {
|
struct xex2_import_library {
|
||||||
|
|
Loading…
Reference in New Issue