mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
Improve embedded PCK loading and exporting.
Windows export process: Limit size of executable with embedded PCK to 4 GB. Use "rcedit" before embedding PCK. Capture and process "rcedit" errors. Windows, Linux: Add support for PCK loading from executable "pck" section.
This commit is contained in:
parent
f4b0c7a1ea
commit
c0cc41d6c1
12 changed files with 310 additions and 75 deletions
|
@ -242,6 +242,91 @@ bool OS_LinuxBSD::_check_internal_feature_support(const String &p_feature) {
|
|||
return p_feature == "pc";
|
||||
}
|
||||
|
||||
uint64_t OS_LinuxBSD::get_embedded_pck_offset() const {
|
||||
Ref<FileAccess> f = FileAccess::open(get_executable_path(), FileAccess::READ);
|
||||
if (f.is_null()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Read and check ELF magic number.
|
||||
{
|
||||
uint32_t magic = f->get_32();
|
||||
if (magic != 0x464c457f) { // 0x7F + "ELF"
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Read program architecture bits from class field.
|
||||
int bits = f->get_8() * 32;
|
||||
|
||||
// Get info about the section header table.
|
||||
int64_t section_table_pos;
|
||||
int64_t section_header_size;
|
||||
if (bits == 32) {
|
||||
section_header_size = 40;
|
||||
f->seek(0x20);
|
||||
section_table_pos = f->get_32();
|
||||
f->seek(0x30);
|
||||
} else { // 64
|
||||
section_header_size = 64;
|
||||
f->seek(0x28);
|
||||
section_table_pos = f->get_64();
|
||||
f->seek(0x3c);
|
||||
}
|
||||
int num_sections = f->get_16();
|
||||
int string_section_idx = f->get_16();
|
||||
|
||||
// Load the strings table.
|
||||
uint8_t *strings;
|
||||
{
|
||||
// Jump to the strings section header.
|
||||
f->seek(section_table_pos + string_section_idx * section_header_size);
|
||||
|
||||
// Read strings data size and offset.
|
||||
int64_t string_data_pos;
|
||||
int64_t string_data_size;
|
||||
if (bits == 32) {
|
||||
f->seek(f->get_position() + 0x10);
|
||||
string_data_pos = f->get_32();
|
||||
string_data_size = f->get_32();
|
||||
} else { // 64
|
||||
f->seek(f->get_position() + 0x18);
|
||||
string_data_pos = f->get_64();
|
||||
string_data_size = f->get_64();
|
||||
}
|
||||
|
||||
// Read strings data.
|
||||
f->seek(string_data_pos);
|
||||
strings = (uint8_t *)memalloc(string_data_size);
|
||||
if (!strings) {
|
||||
return 0;
|
||||
}
|
||||
f->get_buffer(strings, string_data_size);
|
||||
}
|
||||
|
||||
// Search for the "pck" section.
|
||||
int64_t off = 0;
|
||||
for (int i = 0; i < num_sections; ++i) {
|
||||
int64_t section_header_pos = section_table_pos + i * section_header_size;
|
||||
f->seek(section_header_pos);
|
||||
|
||||
uint32_t name_offset = f->get_32();
|
||||
if (strcmp((char *)strings + name_offset, "pck") == 0) {
|
||||
if (bits == 32) {
|
||||
f->seek(section_header_pos + 0x10);
|
||||
off = f->get_32();
|
||||
} else { // 64
|
||||
f->seek(section_header_pos + 0x18);
|
||||
off = f->get_64();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
memfree(strings);
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
String OS_LinuxBSD::get_config_path() const {
|
||||
if (has_environment("XDG_CONFIG_HOME")) {
|
||||
if (get_environment("XDG_CONFIG_HOME").is_absolute_path()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue