diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2024-04-09 13:19:24 +0300 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2024-04-09 13:19:24 +0300 |
commit | bae27340c9f033740bd699aab110f555864352f6 (patch) | |
tree | 38cb1676b7175b9dd5e179617697db95fc0639a6 /platform/macos/export/macho.cpp | |
parent | dd926b9132c2f755b6f310fcd0aecaa441e123c5 (diff) | |
download | redot-engine-bae27340c9f033740bd699aab110f555864352f6.tar.gz |
[macOS export] Detect embedded helper executables using MachO header.
Diffstat (limited to 'platform/macos/export/macho.cpp')
-rw-r--r-- | platform/macos/export/macho.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/platform/macos/export/macho.cpp b/platform/macos/export/macho.cpp index c7556c1964..a829774a88 100644 --- a/platform/macos/export/macho.cpp +++ b/platform/macos/export/macho.cpp @@ -105,6 +105,26 @@ bool MachO::is_macho(const String &p_path) { return (magic == 0xcefaedfe || magic == 0xfeedface || magic == 0xcffaedfe || magic == 0xfeedfacf); } +uint32_t MachO::get_filetype(const String &p_path) { + Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::READ); + ERR_FAIL_COND_V_MSG(fa.is_null(), 0, vformat("MachO: Can't open file: \"%s\".", p_path)); + uint32_t magic = fa->get_32(); + MachHeader mach_header; + + // Read MachO header. + if (magic == 0xcefaedfe || magic == 0xfeedface) { + // Thin 32-bit binary. + fa->get_buffer((uint8_t *)&mach_header, sizeof(MachHeader)); + } else if (magic == 0xcffaedfe || magic == 0xfeedfacf) { + // Thin 64-bit binary. + fa->get_buffer((uint8_t *)&mach_header, sizeof(MachHeader)); + fa->get_32(); // Skip extra reserved field. + } else { + ERR_FAIL_V_MSG(0, vformat("MachO: File is not a valid MachO binary: \"%s\".", p_path)); + } + return mach_header.filetype; +} + bool MachO::open_file(const String &p_path) { fa = FileAccess::open(p_path, FileAccess::READ_WRITE); ERR_FAIL_COND_V_MSG(fa.is_null(), false, vformat("MachO: Can't open file: \"%s\".", p_path)); |