diff --git a/SConstruct b/SConstruct index 6aa0a35..b1a651b 100644 --- a/SConstruct +++ b/SConstruct @@ -38,8 +38,6 @@ for x in sorted(glob.glob("platform/*")): sys.path.insert(0, tmppath) import detect - if os.path.exists(x + "/export/export.cpp"): - platform_exporters.append(x[9:]) if os.path.exists(x + "/api/api.cpp"): platform_apis.append(x[9:]) if detect.is_active(): diff --git a/platform/osx/export/codesign.cpp b/platform/osx/export/codesign.cpp deleted file mode 100644 index d479043..0000000 --- a/platform/osx/export/codesign.cpp +++ /dev/null @@ -1,1621 +0,0 @@ -/*************************************************************************/ -/* codesign.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "codesign.h" - -#include "lipo.h" -#include "macho.h" -#include "plist.h" - -#include "core/os/os.h" -#include "editor/editor_settings.h" -#include "modules/modules_enabled.gen.h" // For regex. - -#include - -#ifdef MODULE_REGEX_ENABLED - -/*************************************************************************/ -/* CodeSignCodeResources */ -/*************************************************************************/ - -String CodeSignCodeResources::hash_sha1_base64(const String &p_path) { - FileAccessRef fa = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!fa, String(), vformat("CodeSign/CodeResources: Can't open file: \"%s\".", p_path)); - - CryptoCore::SHA1Context ctx; - ctx.start(); - - unsigned char step[4096]; - while (true) { - uint64_t br = fa->get_buffer(step, 4096); - if (br > 0) { - ctx.update(step, br); - } - if (br < 4096) { - break; - } - } - - unsigned char hash[0x14]; - ctx.finish(hash); - fa->close(); - - return CryptoCore::b64_encode_str(hash, 0x14); -} - -String CodeSignCodeResources::hash_sha256_base64(const String &p_path) { - FileAccessRef fa = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!fa, String(), vformat("CodeSign/CodeResources: Can't open file: \"%s\".", p_path)); - - CryptoCore::SHA256Context ctx; - ctx.start(); - - unsigned char step[4096]; - while (true) { - uint64_t br = fa->get_buffer(step, 4096); - if (br > 0) { - ctx.update(step, br); - } - if (br < 4096) { - break; - } - } - - unsigned char hash[0x20]; - ctx.finish(hash); - fa->close(); - - return CryptoCore::b64_encode_str(hash, 0x20); -} - -void CodeSignCodeResources::add_rule1(const String &p_rule, const String &p_key, int p_weight, bool p_store) { - rules1.push_back(CRRule(p_rule, p_key, p_weight, p_store)); -} - -void CodeSignCodeResources::add_rule2(const String &p_rule, const String &p_key, int p_weight, bool p_store) { - rules2.push_back(CRRule(p_rule, p_key, p_weight, p_store)); -} - -CodeSignCodeResources::CRMatch CodeSignCodeResources::match_rules1(const String &p_path) const { - CRMatch found = CRMatch::CR_MATCH_NO; - int weight = 0; - for (int i = 0; i < rules1.size(); i++) { - RegEx regex(rules1[i].file_pattern); - if (regex.search(p_path).is_valid()) { - if (rules1[i].key == "omit") { - return CRMatch::CR_MATCH_NO; - } else if (rules1[i].key == "nested") { - if (weight <= rules1[i].weight) { - found = CRMatch::CR_MATCH_NESTED; - weight = rules1[i].weight; - } - } else if (rules1[i].key == "optional") { - if (weight <= rules1[i].weight) { - found = CRMatch::CR_MATCH_OPTIONAL; - weight = rules1[i].weight; - } - } else { - if (weight <= rules1[i].weight) { - found = CRMatch::CR_MATCH_YES; - weight = rules1[i].weight; - } - } - } - } - return found; -} - -CodeSignCodeResources::CRMatch CodeSignCodeResources::match_rules2(const String &p_path) const { - CRMatch found = CRMatch::CR_MATCH_NO; - int weight = 0; - for (int i = 0; i < rules2.size(); i++) { - RegEx regex(rules2[i].file_pattern); - if (regex.search(p_path).is_valid()) { - if (rules2[i].key == "omit") { - return CRMatch::CR_MATCH_NO; - } else if (rules2[i].key == "nested") { - if (weight <= rules2[i].weight) { - found = CRMatch::CR_MATCH_NESTED; - weight = rules2[i].weight; - } - } else if (rules2[i].key == "optional") { - if (weight <= rules2[i].weight) { - found = CRMatch::CR_MATCH_OPTIONAL; - weight = rules2[i].weight; - } - } else { - if (weight <= rules2[i].weight) { - found = CRMatch::CR_MATCH_YES; - weight = rules2[i].weight; - } - } - } - } - return found; -} - -bool CodeSignCodeResources::add_file1(const String &p_root, const String &p_path) { - CRMatch found = match_rules1(p_path); - if (found != CRMatch::CR_MATCH_YES && found != CRMatch::CR_MATCH_OPTIONAL) { - return true; // No match. - } - - CRFile f; - f.name = p_path; - f.optional = (found == CRMatch::CR_MATCH_OPTIONAL); - f.nested = false; - f.hash = hash_sha1_base64(p_root.plus_file(p_path)); - print_verbose(vformat("CodeSign/CodeResources: File(V1) %s hash1:%s", f.name, f.hash)); - - files1.push_back(f); - return true; -} - -bool CodeSignCodeResources::add_file2(const String &p_root, const String &p_path) { - CRMatch found = match_rules2(p_path); - if (found == CRMatch::CR_MATCH_NESTED) { - return add_nested_file(p_root, p_path, p_root.plus_file(p_path)); - } - if (found != CRMatch::CR_MATCH_YES && found != CRMatch::CR_MATCH_OPTIONAL) { - return true; // No match. - } - - CRFile f; - f.name = p_path; - f.optional = (found == CRMatch::CR_MATCH_OPTIONAL); - f.nested = false; - f.hash = hash_sha1_base64(p_root.plus_file(p_path)); - f.hash2 = hash_sha256_base64(p_root.plus_file(p_path)); - - print_verbose(vformat("CodeSign/CodeResources: File(V2) %s hash1:%s hash2:%s", f.name, f.hash, f.hash2)); - - files2.push_back(f); - return true; -} - -bool CodeSignCodeResources::add_nested_file(const String &p_root, const String &p_path, const String &p_exepath) { -#define CLEANUP() \ - if (files_to_add.size() > 1) { \ - for (int j = 0; j < files_to_add.size(); j++) { \ - da->remove(files_to_add[j]); \ - } \ - } - - DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - ERR_FAIL_COND_V(!da, false); - - Vector files_to_add; - if (LipO::is_lipo(p_exepath)) { - String tmp_path_name = EditorSettings::get_singleton()->get_cache_dir().plus_file("_lipo"); - Error err = da->make_dir_recursive(tmp_path_name); - if (err != OK) { - ERR_FAIL_V_MSG(false, vformat("CodeSign/CodeResources: Failed to create \"%s\" subfolder.", tmp_path_name)); - } - LipO lip; - if (lip.open_file(p_exepath)) { - for (int i = 0; i < lip.get_arch_count(); i++) { - if (!lip.extract_arch(i, tmp_path_name.plus_file("_rqexe_" + itos(i)))) { - CLEANUP(); - ERR_FAIL_V_MSG(false, "CodeSign/CodeResources: Failed to extract thin binary."); - } - files_to_add.push_back(tmp_path_name.plus_file("_rqexe_" + itos(i))); - } - } - } else if (MachO::is_macho(p_exepath)) { - files_to_add.push_back(p_exepath); - } - - CRFile f; - f.name = p_path; - f.optional = false; - f.nested = true; - for (int i = 0; i < files_to_add.size(); i++) { - MachO mh; - if (!mh.open_file(files_to_add[i])) { - CLEANUP(); - ERR_FAIL_V_MSG(false, "CodeSign/CodeResources: Invalid executable file."); - } - PoolByteArray hash = mh.get_cdhash_sha256(); // Use SHA-256 variant, if available. - if (hash.size() != 0x20) { - hash = mh.get_cdhash_sha1(); // Use SHA-1 instead. - if (hash.size() != 0x14) { - CLEANUP(); - ERR_FAIL_V_MSG(false, "CodeSign/CodeResources: Unsigned nested executable file."); - } - } - hash.resize(0x14); // Always clamp to 0x14 size. - f.hash = CryptoCore::b64_encode_str(hash.read().ptr(), hash.size()); - - PoolByteArray rq_blob = mh.get_requirements(); - String req_string; - if (rq_blob.size() > 8) { - CodeSignRequirements rq(rq_blob); - Vector rqs = rq.parse_requirements(); - for (int j = 0; j < rqs.size(); j++) { - if (rqs[j].begins_with("designated => ")) { - req_string = rqs[j].replace("designated => ", ""); - } - } - } - if (req_string.empty()) { - req_string = "cdhash H\"" + String::hex_encode_buffer(hash.read().ptr(), hash.size()) + "\""; - } - print_verbose(vformat("CodeSign/CodeResources: Nested object %s (cputype: %d) cdhash:%s designated rq:%s", f.name, mh.get_cputype(), f.hash, req_string)); - if (f.requirements != req_string) { - if (i != 0) { - f.requirements += " or "; - } - f.requirements += req_string; - } - } - files2.push_back(f); - - CLEANUP(); - return true; - -#undef CLEANUP -} - -bool CodeSignCodeResources::add_folder_recursive(const String &p_root, const String &p_path, const String &p_main_exe_path) { - DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - ERR_FAIL_COND_V(!da, false); - Error err = da->change_dir(p_root.plus_file(p_path)); - ERR_FAIL_COND_V(err != OK, false); - - bool ret = true; - da->list_dir_begin(); - String n = da->get_next(); - while (n != String()) { - if (n != "." && n != "..") { - String path = p_root.plus_file(p_path).plus_file(n); - if (path == p_main_exe_path) { - n = da->get_next(); - continue; // Skip main executable. - } - if (da->current_is_dir()) { - CRMatch found = match_rules2(p_path.plus_file(n)); - String fmw_ver = "Current"; // Framework version (default). - String info_path; - String main_exe; - String bundle_path; - bool bundle = false; - if (da->file_exists(path.plus_file("Contents/Info.plist"))) { - info_path = path.plus_file("Contents/Info.plist"); - main_exe = path.plus_file("Contents/MacOS"); - bundle = true; - } else if (da->file_exists(path.plus_file(vformat("Versions/%s/Resources/Info.plist", fmw_ver)))) { - info_path = path.plus_file(vformat("Versions/%s/Resources/Info.plist", fmw_ver)); - main_exe = path.plus_file(vformat("Versions/%s", fmw_ver)); - bundle = true; - } else if (da->file_exists(path.plus_file("Info.plist"))) { - info_path = path.plus_file("Info.plist"); - main_exe = path; - bundle = true; - } - if (bundle && found == CRMatch::CR_MATCH_NESTED && !info_path.empty()) { - // Read Info.plist. - PList info_plist; - if (info_plist.load_file(info_path)) { - if (info_plist.get_root()->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && info_plist.get_root()->data_dict.has("CFBundleExecutable")) { - main_exe = main_exe.plus_file(String::utf8(info_plist.get_root()->data_dict["CFBundleExecutable"]->data_string.get_data())); - } else { - ERR_FAIL_V_MSG(false, "CodeSign/CodeResources: Invalid Info.plist, no exe name."); - } - } else { - ERR_FAIL_V_MSG(false, "CodeSign/CodeResources: Invalid Info.plist, can't load."); - } - ret = ret && add_nested_file(p_root, p_path.plus_file(n), main_exe); - } else { - ret = ret && add_folder_recursive(p_root, p_path.plus_file(n), p_main_exe_path); - } - } else { - ret = ret && add_file1(p_root, p_path.plus_file(n)); - ret = ret && add_file2(p_root, p_path.plus_file(n)); - } - } - - n = da->get_next(); - } - - da->list_dir_end(); - return ret; -} - -bool CodeSignCodeResources::save_to_file(const String &p_path) { - PList pl; - - print_verbose(vformat("CodeSign/CodeResources: Writing to file: %s", p_path)); - - // Write version 1 hashes. - Ref files1_dict = PListNode::new_dict(); - pl.get_root()->push_subnode(files1_dict, "files"); - for (int i = 0; i < files1.size(); i++) { - if (files1[i].optional) { - Ref file_dict = PListNode::new_dict(); - files1_dict->push_subnode(file_dict, files1[i].name); - - file_dict->push_subnode(PListNode::new_data(files1[i].hash), "hash"); - file_dict->push_subnode(PListNode::new_bool(true), "optional"); - } else { - files1_dict->push_subnode(PListNode::new_data(files1[i].hash), files1[i].name); - } - } - - // Write version 2 hashes. - Ref files2_dict = PListNode::new_dict(); - pl.get_root()->push_subnode(files2_dict, "files2"); - for (int i = 0; i < files2.size(); i++) { - Ref file_dict = PListNode::new_dict(); - files2_dict->push_subnode(file_dict, files2[i].name); - - if (files2[i].nested) { - file_dict->push_subnode(PListNode::new_data(files2[i].hash), "cdhash"); - file_dict->push_subnode(PListNode::new_string(files2[i].requirements), "requirement"); - } else { - file_dict->push_subnode(PListNode::new_data(files2[i].hash), "hash"); - file_dict->push_subnode(PListNode::new_data(files2[i].hash2), "hash2"); - if (files2[i].optional) { - file_dict->push_subnode(PListNode::new_bool(true), "optional"); - } - } - } - - // Write version 1 rules. - Ref rules1_dict = PListNode::new_dict(); - pl.get_root()->push_subnode(rules1_dict, "rules"); - for (int i = 0; i < rules1.size(); i++) { - if (rules1[i].store) { - if (rules1[i].key.empty() && rules1[i].weight <= 0) { - rules1_dict->push_subnode(PListNode::new_bool(true), rules1[i].file_pattern); - } else { - Ref rule_dict = PListNode::new_dict(); - rules1_dict->push_subnode(rule_dict, rules1[i].file_pattern); - if (!rules1[i].key.empty()) { - rule_dict->push_subnode(PListNode::new_bool(true), rules1[i].key); - } - if (rules1[i].weight != 1) { - rule_dict->push_subnode(PListNode::new_real(rules1[i].weight), "weight"); - } - } - } - } - - // Write version 2 rules. - Ref rules2_dict = PListNode::new_dict(); - pl.get_root()->push_subnode(rules2_dict, "rules2"); - for (int i = 0; i < rules2.size(); i++) { - if (rules2[i].store) { - if (rules2[i].key.empty() && rules2[i].weight <= 0) { - rules2_dict->push_subnode(PListNode::new_bool(true), rules2[i].file_pattern); - } else { - Ref rule_dict = PListNode::new_dict(); - rules2_dict->push_subnode(rule_dict, rules2[i].file_pattern); - if (!rules2[i].key.empty()) { - rule_dict->push_subnode(PListNode::new_bool(true), rules2[i].key); - } - if (rules2[i].weight != 1) { - rule_dict->push_subnode(PListNode::new_real(rules2[i].weight), "weight"); - } - } - } - } - String text = pl.save_text(); - ERR_FAIL_COND_V_MSG(text.empty(), false, "CodeSign/CodeResources: Generating resources PList failed."); - - FileAccessRef fa = FileAccess::open(p_path, FileAccess::WRITE); - ERR_FAIL_COND_V_MSG(!fa, false, vformat("CodeSign/CodeResources: Can't open file: \"%s\".", p_path)); - - CharString cs = text.utf8(); - fa->store_buffer((const uint8_t *)cs.ptr(), cs.length()); - fa->close(); - return true; -} - -/*************************************************************************/ -/* CodeSignRequirements */ -/*************************************************************************/ - -CodeSignRequirements::CodeSignRequirements() { -#define _W(a, b, c, d) \ - blob.push_back(a); \ - blob.push_back(b); \ - blob.push_back(c); \ - blob.push_back(d); - _W(0xFA, 0xDE, 0x0C, 0x01); // Requirement set magic. - _W(0x00, 0x00, 0x00, 0x0C); // Length of requirements set (12 bytes). - _W(0x00, 0x00, 0x00, 0x00); // Empty. -#undef _W -} - -CodeSignRequirements::CodeSignRequirements(const PoolByteArray &p_data) { - blob = p_data; -} - -_FORCE_INLINE_ void CodeSignRequirements::_parse_certificate_slot(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const { -#define _R(x) BSWAP32(*(uint32_t *)(r.ptr() + x)) - PoolByteArray::Read r = blob.read(); - ERR_FAIL_COND_MSG(r_pos >= p_rq_size, "CodeSign/Requirements: Out of bounds."); - r_out += "certificate "; - uint32_t tag_slot = _R(r_pos); - if (tag_slot == 0x00000000) { - r_out += "leaf"; - } else if (tag_slot == 0xffffffff) { - r_out += "root"; - } else { - r_out += itos((int32_t)tag_slot); - } - r_pos += 4; -#undef _R -} - -_FORCE_INLINE_ void CodeSignRequirements::_parse_key(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const { -#define _R(x) BSWAP32(*(uint32_t *)(r.ptr() + x)) - PoolByteArray::Read r = blob.read(); - ERR_FAIL_COND_MSG(r_pos >= p_rq_size, "CodeSign/Requirements: Out of bounds."); - uint32_t key_size = _R(r_pos); - ERR_FAIL_COND_MSG(r_pos + key_size > p_rq_size, "CodeSign/Requirements: Out of bounds."); - CharString key; - key.resize(key_size); - memcpy((void *)key.ptrw(), blob.read().ptr() + r_pos + 4, key_size); - r_pos += 4 + key_size + PAD(key_size, 4); - r_out += "[" + String::utf8(key, key_size) + "]"; -#undef _R -} - -_FORCE_INLINE_ void CodeSignRequirements::_parse_oid_key(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const { -#define _R(x) BSWAP32(*(uint32_t *)(r.ptr() + x)) - PoolByteArray::Read r = blob.read(); - ERR_FAIL_COND_MSG(r_pos >= p_rq_size, "CodeSign/Requirements: Out of bounds."); - uint32_t key_size = _R(r_pos); - ERR_FAIL_COND_MSG(r_pos + key_size > p_rq_size, "CodeSign/Requirements: Out of bounds."); - r_out += "[field."; - r_out += itos(blob[r_pos + 4] / 40) + "."; - r_out += itos(blob[r_pos + 4] % 40); - uint32_t spos = r_pos + 5; - while (spos < r_pos + 4 + key_size) { - r_out += "."; - if (blob[spos] <= 127) { - r_out += itos(blob[spos]); - spos += 1; - } else { - uint32_t x = (0x7F & blob[spos]) << 7; - spos += 1; - while (blob[spos] > 127) { - x = (x + (0x7F & blob[spos])) << 7; - spos += 1; - } - x = (x + (0x7F & blob[spos])); - r_out += itos(x); - spos += 1; - } - } - r_out += "]"; - r_pos += 4 + key_size + PAD(key_size, 4); -#undef _R -} - -_FORCE_INLINE_ void CodeSignRequirements::_parse_hash_string(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const { -#define _R(x) BSWAP32(*(uint32_t *)(r.ptr() + x)) - PoolByteArray::Read r = blob.read(); - ERR_FAIL_COND_MSG(r_pos >= p_rq_size, "CodeSign/Requirements: Out of bounds."); - uint32_t tag_size = _R(r_pos); - ERR_FAIL_COND_MSG(r_pos + tag_size > p_rq_size, "CodeSign/Requirements: Out of bounds."); - PoolByteArray data; - data.resize(tag_size); - memcpy(data.write().ptr(), blob.read().ptr() + r_pos + 4, tag_size); - r_out += "H\"" + String::hex_encode_buffer(data.read().ptr(), data.size()) + "\""; - r_pos += 4 + tag_size + PAD(tag_size, 4); -#undef _R -} - -_FORCE_INLINE_ void CodeSignRequirements::_parse_value(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const { -#define _R(x) BSWAP32(*(uint32_t *)(r.ptr() + x)) - PoolByteArray::Read r = blob.read(); - ERR_FAIL_COND_MSG(r_pos >= p_rq_size, "CodeSign/Requirements: Out of bounds."); - uint32_t key_size = _R(r_pos); - ERR_FAIL_COND_MSG(r_pos + key_size > p_rq_size, "CodeSign/Requirements: Out of bounds."); - CharString key; - key.resize(key_size); - memcpy((void *)key.ptrw(), blob.read().ptr() + r_pos + 4, key_size); - r_pos += 4 + key_size + PAD(key_size, 4); - r_out += "\"" + String::utf8(key, key_size) + "\""; -#undef _R -} - -_FORCE_INLINE_ void CodeSignRequirements::_parse_date(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const { -#define _R(x) BSWAP32(*(uint32_t *)(r.ptr() + x)) - PoolByteArray::Read r = blob.read(); - ERR_FAIL_COND_MSG(r_pos >= p_rq_size, "CodeSign/Requirements: Out of bounds."); - uint32_t date = _R(r_pos); - time_t t = 978307200 + date; - struct tm lt; -#ifdef WINDOWS_ENABLED - gmtime_s(<, &t); -#else - gmtime_r(&t, <); -#endif - r_out += vformat("<%04d-%02d-%02d ", (int)(1900 + lt.tm_year), (int)(lt.tm_mon + 1), (int)(lt.tm_mday)) + vformat("%02d:%02d:%02d +0000>", (int)(lt.tm_hour), (int)(lt.tm_min), (int)(lt.tm_sec)); -#undef _R -} - -_FORCE_INLINE_ bool CodeSignRequirements::_parse_match(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const { -#define _R(x) BSWAP32(*(uint32_t *)(r.ptr() + x)) - PoolByteArray::Read r = blob.read(); - ERR_FAIL_COND_V_MSG(r_pos >= p_rq_size, false, "CodeSign/Requirements: Out of bounds."); - uint32_t match = _R(r_pos); - r_pos += 4; - switch (match) { - case 0x00000000: { - r_out += "exists"; - } break; - case 0x00000001: { - r_out += "= "; - _parse_value(r_pos, r_out, p_rq_size); - } break; - case 0x00000002: { - r_out += "~ "; - _parse_value(r_pos, r_out, p_rq_size); - } break; - case 0x00000003: { - r_out += "= *"; - _parse_value(r_pos, r_out, p_rq_size); - } break; - case 0x00000004: { - r_out += "= "; - _parse_value(r_pos, r_out, p_rq_size); - r_out += "*"; - } break; - case 0x00000005: { - r_out += "< "; - _parse_value(r_pos, r_out, p_rq_size); - } break; - case 0x00000006: { - r_out += "> "; - _parse_value(r_pos, r_out, p_rq_size); - } break; - case 0x00000007: { - r_out += "<= "; - _parse_value(r_pos, r_out, p_rq_size); - } break; - case 0x00000008: { - r_out += ">= "; - _parse_value(r_pos, r_out, p_rq_size); - } break; - case 0x00000009: { - r_out += "= "; - _parse_date(r_pos, r_out, p_rq_size); - } break; - case 0x0000000A: { - r_out += "< "; - _parse_date(r_pos, r_out, p_rq_size); - } break; - case 0x0000000B: { - r_out += "> "; - _parse_date(r_pos, r_out, p_rq_size); - } break; - case 0x0000000C: { - r_out += "<= "; - _parse_date(r_pos, r_out, p_rq_size); - } break; - case 0x0000000D: { - r_out += ">= "; - _parse_date(r_pos, r_out, p_rq_size); - } break; - case 0x0000000E: { - r_out += "absent"; - } break; - default: { - return false; - } - } - return true; -#undef _R -} - -Vector CodeSignRequirements::parse_requirements() const { -#define _R(x) BSWAP32(*(uint32_t *)(r.ptr() + x)) - PoolByteArray::Read r = blob.read(); - Vector list; - - // Read requirements set header. - ERR_FAIL_COND_V_MSG(blob.size() < 12, list, "CodeSign/Requirements: Blob is too small."); - uint32_t magic = _R(0); - ERR_FAIL_COND_V_MSG(magic != 0xfade0c01, list, "CodeSign/Requirements: Invalid set magic."); - uint32_t size = _R(4); - ERR_FAIL_COND_V_MSG(size != (uint32_t)blob.size(), list, "CodeSign/Requirements: Invalid set size."); - uint32_t count = _R(8); - - for (uint32_t i = 0; i < count; i++) { - String out; - - // Read requirement header. - uint32_t rq_type = _R(12 + i * 8); - uint32_t rq_offset = _R(12 + i * 8 + 4); - ERR_FAIL_COND_V_MSG(rq_offset + 12 >= (uint32_t)blob.size(), list, "CodeSign/Requirements: Invalid requirement offset."); - switch (rq_type) { - case 0x00000001: { - out += "host => "; - } break; - case 0x00000002: { - out += "guest => "; - } break; - case 0x00000003: { - out += "designated => "; - } break; - case 0x00000004: { - out += "library => "; - } break; - case 0x00000005: { - out += "plugin => "; - } break; - default: { - ERR_FAIL_V_MSG(list, "CodeSign/Requirements: Invalid requirement type."); - } - } - uint32_t rq_magic = _R(rq_offset); - uint32_t rq_size = _R(rq_offset + 4); - uint32_t rq_ver = _R(rq_offset + 8); - uint32_t pos = rq_offset + 12; - ERR_FAIL_COND_V_MSG(rq_magic != 0xfade0c00, list, "CodeSign/Requirements: Invalid requirement magic."); - ERR_FAIL_COND_V_MSG(rq_ver != 0x00000001, list, "CodeSign/Requirements: Invalid requirement version."); - - // Read requirement tokens. - List tokens; - while (pos < rq_offset + rq_size) { - uint32_t rq_tag = _R(pos); - pos += 4; - String token; - switch (rq_tag) { - case 0x00000000: { - token = "false"; - } break; - case 0x00000001: { - token = "true"; - } break; - case 0x00000002: { - token = "identifier "; - _parse_value(pos, token, rq_offset + rq_size); - } break; - case 0x00000003: { - token = "anchor apple"; - } break; - case 0x00000004: { - _parse_certificate_slot(pos, token, rq_offset + rq_size); - token += " "; - _parse_hash_string(pos, token, rq_offset + rq_size); - } break; - case 0x00000005: { - token = "info"; - _parse_key(pos, token, rq_offset + rq_size); - token += " = "; - _parse_value(pos, token, rq_offset + rq_size); - } break; - case 0x00000006: { - token = "and"; - } break; - case 0x00000007: { - token = "or"; - } break; - case 0x00000008: { - token = "cdhash "; - _parse_hash_string(pos, token, rq_offset + rq_size); - } break; - case 0x00000009: { - token = "!"; - } break; - case 0x0000000A: { - token = "info"; - _parse_key(pos, token, rq_offset + rq_size); - token += " "; - ERR_FAIL_COND_V_MSG(!_parse_match(pos, token, rq_offset + rq_size), list, "CodeSign/Requirements: Unsupported match suffix."); - } break; - case 0x0000000B: { - _parse_certificate_slot(pos, token, rq_offset + rq_size); - _parse_key(pos, token, rq_offset + rq_size); - token += " "; - ERR_FAIL_COND_V_MSG(!_parse_match(pos, token, rq_offset + rq_size), list, "CodeSign/Requirements: Unsupported match suffix."); - } break; - case 0x0000000C: { - _parse_certificate_slot(pos, token, rq_offset + rq_size); - token += " trusted"; - } break; - case 0x0000000D: { - token = "anchor trusted"; - } break; - case 0x0000000E: { - _parse_certificate_slot(pos, token, rq_offset + rq_size); - _parse_oid_key(pos, token, rq_offset + rq_size); - token += " "; - ERR_FAIL_COND_V_MSG(!_parse_match(pos, token, rq_offset + rq_size), list, "CodeSign/Requirements: Unsupported match suffix."); - } break; - case 0x0000000F: { - token = "anchor apple generic"; - } break; - default: { - ERR_FAIL_V_MSG(list, "CodeSign/Requirements: Invalid requirement token."); - } break; - } - tokens.push_back(token); - } - - // Polish to infix notation (w/o bracket optimization). - for (List::Element *E = tokens.back(); E; E = E->prev()) { - if (E->get() == "and") { - ERR_FAIL_COND_V_MSG(!E->next() || !E->next()->next(), list, "CodeSign/Requirements: Invalid token sequence."); - String token = "(" + E->next()->get() + " and " + E->next()->next()->get() + ")"; - tokens.erase(E->next()->next()); - tokens.erase(E->next()); - E->get() = token; - } else if (E->get() == "or") { - ERR_FAIL_COND_V_MSG(!E->next() || !E->next()->next(), list, "CodeSign/Requirements: Invalid token sequence."); - String token = "(" + E->next()->get() + " or " + E->next()->next()->get() + ")"; - tokens.erase(E->next()->next()); - tokens.erase(E->next()); - E->get() = token; - } - } - - if (tokens.size() == 1) { - list.push_back(out + tokens.front()->get()); - } else { - ERR_FAIL_V_MSG(list, "CodeSign/Requirements: Invalid token sequence."); - } - } - - return list; -#undef _R -} - -PoolByteArray CodeSignRequirements::get_hash_sha1() const { - PoolByteArray hash; - hash.resize(0x14); - - CryptoCore::SHA1Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; -} - -PoolByteArray CodeSignRequirements::get_hash_sha256() const { - PoolByteArray hash; - hash.resize(0x20); - - CryptoCore::SHA256Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; -} - -int CodeSignRequirements::get_size() const { - return blob.size(); -} - -void CodeSignRequirements::write_to_file(FileAccess *p_file) const { - ERR_FAIL_COND_MSG(!p_file, "CodeSign/Requirements: Invalid file handle."); - p_file->store_buffer(blob.read().ptr(), blob.size()); -} - -/*************************************************************************/ -/* CodeSignEntitlementsText */ -/*************************************************************************/ - -CodeSignEntitlementsText::CodeSignEntitlementsText() { -#define _W(a, b, c, d) \ - blob.push_back(a); \ - blob.push_back(b); \ - blob.push_back(c); \ - blob.push_back(d); - _W(0xFA, 0xDE, 0x71, 0x71); // Text Entitlements set magic. - _W(0x00, 0x00, 0x00, 0x08); // Length (8 bytes). -#undef _W -} - -CodeSignEntitlementsText::CodeSignEntitlementsText(const String &p_string) { - CharString utf8 = p_string.utf8(); -#define _W(a, b, c, d) \ - blob.push_back(a); \ - blob.push_back(b); \ - blob.push_back(c); \ - blob.push_back(d); - _W(0xFA, 0xDE, 0x71, 0x71); // Text Entitlements set magic. - for (int i = 3; i >= 0; i--) { - uint8_t x = ((utf8.length() + 8) >> i * 8) & 0xFF; // Size. - blob.push_back(x); - } - for (int i = 0; i < utf8.length(); i++) { // Write data. - blob.push_back(utf8[i]); - } -#undef _W -} - -PoolByteArray CodeSignEntitlementsText::get_hash_sha1() const { - PoolByteArray hash; - hash.resize(0x14); - - CryptoCore::SHA1Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; -} - -PoolByteArray CodeSignEntitlementsText::get_hash_sha256() const { - PoolByteArray hash; - hash.resize(0x20); - - CryptoCore::SHA256Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; -} - -int CodeSignEntitlementsText::get_size() const { - return blob.size(); -} - -void CodeSignEntitlementsText::write_to_file(FileAccess *p_file) const { - ERR_FAIL_COND_MSG(!p_file, "CodeSign/EntitlementsText: Invalid file handle."); - p_file->store_buffer(blob.read().ptr(), blob.size()); -} - -/*************************************************************************/ -/* CodeSignEntitlementsBinary */ -/*************************************************************************/ - -CodeSignEntitlementsBinary::CodeSignEntitlementsBinary() { -#define _W(a, b, c, d) \ - blob.push_back(a); \ - blob.push_back(b); \ - blob.push_back(c); \ - blob.push_back(d); - _W(0xFA, 0xDE, 0x71, 0x72); // Binary Entitlements magic. - _W(0x00, 0x00, 0x00, 0x08); // Length (8 bytes). -#undef _W -} - -CodeSignEntitlementsBinary::CodeSignEntitlementsBinary(const String &p_string) { - PList pl(p_string); - - PoolByteArray asn1 = pl.save_asn1(); -#define _W(a, b, c, d) \ - blob.push_back(a); \ - blob.push_back(b); \ - blob.push_back(c); \ - blob.push_back(d); - _W(0xFA, 0xDE, 0x71, 0x72); // Binary Entitlements magic. - uint32_t size = asn1.size() + 8; - for (int i = 3; i >= 0; i--) { - uint8_t x = (size >> i * 8) & 0xFF; // Size. - blob.push_back(x); - } - blob.append_array(asn1); // Write data. -#undef _W -} - -PoolByteArray CodeSignEntitlementsBinary::get_hash_sha1() const { - PoolByteArray hash; - hash.resize(0x14); - - CryptoCore::SHA1Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; -} - -PoolByteArray CodeSignEntitlementsBinary::get_hash_sha256() const { - PoolByteArray hash; - hash.resize(0x20); - - CryptoCore::SHA256Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; -} - -int CodeSignEntitlementsBinary::get_size() const { - return blob.size(); -} - -void CodeSignEntitlementsBinary::write_to_file(FileAccess *p_file) const { - ERR_FAIL_COND_MSG(!p_file, "CodeSign/EntitlementsBinary: Invalid file handle."); - p_file->store_buffer(blob.read().ptr(), blob.size()); -} - -/*************************************************************************/ -/* CodeSignCodeDirectory */ -/*************************************************************************/ - -CodeSignCodeDirectory::CodeSignCodeDirectory() { -#define _W(a, b, c, d) \ - blob.push_back(a); \ - blob.push_back(b); \ - blob.push_back(c); \ - blob.push_back(d); - _W(0xFA, 0xDE, 0x0C, 0x02); // Code Directory magic. - _W(0x00, 0x00, 0x00, 0x00); // Size (8 bytes). -#undef _W -} - -CodeSignCodeDirectory::CodeSignCodeDirectory(uint8_t p_hash_size, uint8_t p_hash_type, bool p_main, const CharString &p_id, const CharString &p_team_id, uint32_t p_page_size, uint64_t p_exe_limit, uint64_t p_code_limit) { - pages = p_code_limit / (uint64_t(1) << p_page_size); - remain = p_code_limit % (uint64_t(1) << p_page_size); - code_slots = pages + (remain > 0 ? 1 : 0); - special_slots = 7; - - int cd_size = 8 + sizeof(CodeDirectoryHeader) + (code_slots + special_slots) * p_hash_size + p_id.size() + p_team_id.size(); - int cd_off = 8 + sizeof(CodeDirectoryHeader); -#define _W(a, b, c, d) \ - blob.push_back(a); \ - blob.push_back(b); \ - blob.push_back(c); \ - blob.push_back(d); - _W(0xFA, 0xDE, 0x0C, 0x02); // Code Directory magic. - for (int i = 3; i >= 0; i--) { - uint8_t x = (cd_size >> i * 8) & 0xFF; // Size. - blob.push_back(x); - } -#undef _W - blob.resize(cd_size); - memset(blob.write().ptr() + 8, 0x00, cd_size - 8); - CodeDirectoryHeader *cd = (CodeDirectoryHeader *)(blob.write().ptr() + 8); - - bool is_64_cl = (p_code_limit >= std::numeric_limits::max()); - - // Version and options. - cd->version = BSWAP32(0x20500); - cd->flags = BSWAP32(SIGNATURE_ADHOC | SIGNATURE_RUNTIME); - cd->special_slots = BSWAP32(special_slots); - cd->code_slots = BSWAP32(code_slots); - if (is_64_cl) { - cd->code_limit_64 = BSWAP64(p_code_limit); - } else { - cd->code_limit = BSWAP32(p_code_limit); - } - cd->hash_size = p_hash_size; - cd->hash_type = p_hash_type; - cd->page_size = p_page_size; - cd->exec_seg_base = 0x00; - cd->exec_seg_limit = BSWAP64(p_exe_limit); - cd->exec_seg_flags = 0; - if (p_main) { - cd->exec_seg_flags |= EXECSEG_MAIN_BINARY; - } - cd->exec_seg_flags = BSWAP64(cd->exec_seg_flags); - uint32_t version = (11 << 16) + (3 << 8) + 0; // Version 11.3.0 - cd->runtime = BSWAP32(version); - - // Copy ID. - cd->ident_offset = BSWAP32(cd_off); - memcpy(blob.write().ptr() + cd_off, p_id.get_data(), p_id.size()); - cd_off += p_id.size(); - - // Copy Team ID. - if (p_team_id.length() > 0) { - cd->team_offset = BSWAP32(cd_off); - memcpy(blob.write().ptr() + cd_off, p_team_id.get_data(), p_team_id.size()); - cd_off += p_team_id.size(); - } else { - cd->team_offset = 0; - } - - // Scatter vector. - cd->scatter_vector_offset = 0; // Not used. - - // Executable hashes offset. - cd->hash_offset = BSWAP32(cd_off + special_slots * cd->hash_size); -} - -bool CodeSignCodeDirectory::set_hash_in_slot(const PoolByteArray &p_hash, int p_slot) { - ERR_FAIL_COND_V_MSG((p_slot < -special_slots) || (p_slot >= code_slots), false, vformat("CodeSign/CodeDirectory: Invalid hash slot index: %d.", p_slot)); - CodeDirectoryHeader *cd = reinterpret_cast(blob.write().ptr() + 8); - for (int i = 0; i < cd->hash_size; i++) { - blob.write()[BSWAP32(cd->hash_offset) + p_slot * cd->hash_size + i] = p_hash[i]; - } - return true; -} - -int32_t CodeSignCodeDirectory::get_page_count() { - return pages; -} - -int32_t CodeSignCodeDirectory::get_page_remainder() { - return remain; -} - -PoolByteArray CodeSignCodeDirectory::get_hash_sha1() const { - PoolByteArray hash; - hash.resize(0x14); - - CryptoCore::SHA1Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; -} - -PoolByteArray CodeSignCodeDirectory::get_hash_sha256() const { - PoolByteArray hash; - hash.resize(0x20); - - CryptoCore::SHA256Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; -} - -int CodeSignCodeDirectory::get_size() const { - return blob.size(); -} - -void CodeSignCodeDirectory::write_to_file(FileAccess *p_file) const { - ERR_FAIL_COND_MSG(!p_file, "CodeSign/CodeDirectory: Invalid file handle."); - p_file->store_buffer(blob.read().ptr(), blob.size()); -} - -/*************************************************************************/ -/* CodeSignSignature */ -/*************************************************************************/ - -CodeSignSignature::CodeSignSignature() { -#define _W(a, b, c, d) \ - blob.push_back(a); \ - blob.push_back(b); \ - blob.push_back(c); \ - blob.push_back(d); - _W(0xFA, 0xDE, 0x0B, 0x01); // Signature magic. - uint32_t sign_size = 8; // Ad-hoc signature is empty. - for (int i = 3; i >= 0; i--) { - uint8_t x = (sign_size >> i * 8) & 0xFF; // Size. - blob.push_back(x); - } -#undef _W -} - -PoolByteArray CodeSignSignature::get_hash_sha1() const { - PoolByteArray hash; - hash.resize(0x14); - - CryptoCore::SHA1Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; -} - -PoolByteArray CodeSignSignature::get_hash_sha256() const { - PoolByteArray hash; - hash.resize(0x20); - - CryptoCore::SHA256Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; -} - -int CodeSignSignature::get_size() const { - return blob.size(); -} - -void CodeSignSignature::write_to_file(FileAccess *p_file) const { - ERR_FAIL_COND_MSG(!p_file, "CodeSign/Signature: Invalid file handle."); - p_file->store_buffer(blob.read().ptr(), blob.size()); -} - -/*************************************************************************/ -/* CodeSignSuperBlob */ -/*************************************************************************/ - -bool CodeSignSuperBlob::add_blob(const Ref &p_blob) { - if (p_blob.is_valid()) { - blobs.push_back(p_blob); - return true; - } else { - return false; - } -} - -int CodeSignSuperBlob::get_size() const { - int size = 12 + blobs.size() * 8; - for (int i = 0; i < blobs.size(); i++) { - if (blobs[i].is_null()) { - return 0; - } - size += blobs[i]->get_size(); - } - return size; -} - -void CodeSignSuperBlob::write_to_file(FileAccess *p_file) const { - ERR_FAIL_COND_MSG(!p_file, "CodeSign/SuperBlob: Invalid file handle."); - uint32_t size = get_size(); - uint32_t data_offset = 12 + blobs.size() * 8; - - // Write header. - p_file->store_32(BSWAP32(0xfade0cc0)); - p_file->store_32(BSWAP32(size)); - p_file->store_32(BSWAP32(blobs.size())); - - // Write index. - for (int i = 0; i < blobs.size(); i++) { - if (blobs[i].is_null()) { - return; - } - p_file->store_32(BSWAP32(blobs[i]->get_index_type())); - p_file->store_32(BSWAP32(data_offset)); - data_offset += blobs[i]->get_size(); - } - - // Write blobs. - for (int i = 0; i < blobs.size(); i++) { - blobs[i]->write_to_file(p_file); - } -} - -/*************************************************************************/ -/* CodeSign */ -/*************************************************************************/ - -PoolByteArray CodeSign::file_hash_sha1(const String &p_path) { - PoolByteArray file_hash; - FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!f, PoolByteArray(), vformat("CodeSign: Can't open file: \"%s\".", p_path)); - - CryptoCore::SHA1Context ctx; - ctx.start(); - - unsigned char step[4096]; - while (true) { - uint64_t br = f->get_buffer(step, 4096); - if (br > 0) { - ctx.update(step, br); - } - if (br < 4096) { - break; - } - } - - file_hash.resize(0x14); - ctx.finish(file_hash.write().ptr()); - return file_hash; -} - -PoolByteArray CodeSign::file_hash_sha256(const String &p_path) { - PoolByteArray file_hash; - FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!f, PoolByteArray(), vformat("CodeSign: Can't open file: \"%s\".", p_path)); - - CryptoCore::SHA256Context ctx; - ctx.start(); - - unsigned char step[4096]; - while (true) { - uint64_t br = f->get_buffer(step, 4096); - if (br > 0) { - ctx.update(step, br); - } - if (br < 4096) { - break; - } - } - - file_hash.resize(0x20); - ctx.finish(file_hash.write().ptr()); - return file_hash; -} - -Error CodeSign::_codesign_file(bool p_use_hardened_runtime, bool p_force, const String &p_info, const String &p_exe_path, const String &p_bundle_path, const String &p_ent_path, bool p_ios_bundle, String &r_error_msg) { -#define CLEANUP() \ - if (files_to_sign.size() > 1) { \ - for (int j = 0; j < files_to_sign.size(); j++) { \ - da->remove(files_to_sign[j]); \ - } \ - } - - print_verbose(vformat("CodeSign: Signing executable: %s, bundle: %s with entitlements %s", p_exe_path, p_bundle_path, p_ent_path)); - - PoolByteArray info_hash1, info_hash2; - PoolByteArray res_hash1, res_hash2; - String id; - String main_exe = p_exe_path; - - DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - if (!da) { - r_error_msg = TTR("Can't get filesystem access."); - ERR_FAIL_V_MSG(ERR_CANT_CREATE, "CodeSign: Can't get filesystem access."); - } - - // Read Info.plist. - if (!p_info.empty()) { - print_verbose(vformat("CodeSign: Reading bundle info...")); - PList info_plist; - if (info_plist.load_file(p_info)) { - info_hash1 = file_hash_sha1(p_info); - info_hash2 = file_hash_sha256(p_info); - if (info_hash1.empty() || info_hash2.empty()) { - r_error_msg = TTR("Failed to get Info.plist hash."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Failed to get Info.plist hash."); - } - - if (info_plist.get_root()->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && info_plist.get_root()->data_dict.has("CFBundleExecutable")) { - main_exe = p_exe_path.plus_file(String::utf8(info_plist.get_root()->data_dict["CFBundleExecutable"]->data_string.get_data())); - } else { - r_error_msg = TTR("Invalid Info.plist, no exe name."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Invalid Info.plist, no exe name."); - } - - if (info_plist.get_root()->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && info_plist.get_root()->data_dict.has("CFBundleIdentifier")) { - id = info_plist.get_root()->data_dict["CFBundleIdentifier"]->data_string.get_data(); - } else { - r_error_msg = TTR("Invalid Info.plist, no bundle id."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Invalid Info.plist, no bundle id."); - } - } else { - r_error_msg = TTR("Invalid Info.plist, can't load."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Invalid Info.plist, can't load."); - } - } - - // Extract fat binary. - PoolStringArray files_to_sign; - if (LipO::is_lipo(main_exe)) { - print_verbose(vformat("CodeSign: Executable is fat, extracting...")); - String tmp_path_name = EditorSettings::get_singleton()->get_cache_dir().plus_file("_lipo"); - Error err = da->make_dir_recursive(tmp_path_name); - if (err != OK) { - r_error_msg = vformat(TTR("Failed to create \"%s\" subfolder."), tmp_path_name); - ERR_FAIL_V_MSG(FAILED, vformat("CodeSign: Failed to create \"%s\" subfolder.", tmp_path_name)); - } - LipO lip; - if (lip.open_file(main_exe)) { - for (int i = 0; i < lip.get_arch_count(); i++) { - if (!lip.extract_arch(i, tmp_path_name.plus_file("_exe_" + itos(i)))) { - CLEANUP(); - r_error_msg = TTR("Failed to extract thin binary."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Failed to extract thin binary."); - } - files_to_sign.push_back(tmp_path_name.plus_file("_exe_" + itos(i))); - } - } - } else if (MachO::is_macho(main_exe)) { - print_verbose(vformat("CodeSign: Executable is thin...")); - files_to_sign.push_back(main_exe); - } else { - r_error_msg = TTR("Invalid binary format."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Invalid binary format."); - } - - // Check if it's already signed. - if (!p_force) { - for (int i = 0; i < files_to_sign.size(); i++) { - MachO mh; - mh.open_file(files_to_sign[i]); - if (mh.is_signed()) { - CLEANUP(); - r_error_msg = TTR("Already signed!"); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Already signed!"); - } - } - } - - // Generate core resources. - if (!p_bundle_path.empty()) { - print_verbose(vformat("CodeSign: Generating bundle CodeResources...")); - CodeSignCodeResources cr; - - if (p_ios_bundle) { - cr.add_rule1("^.*"); - cr.add_rule1("^.*\\.lproj/", "optional", 100); - cr.add_rule1("^.*\\.lproj/locversion.plist$", "omit", 1100); - cr.add_rule1("^Base\\.lproj/", "", 1010); - cr.add_rule1("^version.plist$"); - - cr.add_rule2(".*\\.dSYM($|/)", "", 11); - cr.add_rule2("^(.*/)?\\.DS_Store$", "omit", 2000); - cr.add_rule2("^.*"); - cr.add_rule2("^.*\\.lproj/", "optional", 1000); - cr.add_rule2("^.*\\.lproj/locversion.plist$", "omit", 1100); - cr.add_rule2("^Base\\.lproj/", "", 1010); - cr.add_rule2("^Info\\.plist$", "omit", 20); - cr.add_rule2("^PkgInfo$", "omit", 20); - cr.add_rule2("^embedded\\.provisionprofile$", "", 10); - cr.add_rule2("^version\\.plist$", "", 20); - - cr.add_rule2("^_MASReceipt", "omit", 2000, false); - cr.add_rule2("^_CodeSignature", "omit", 2000, false); - cr.add_rule2("^CodeResources", "omit", 2000, false); - } else { - cr.add_rule1("^Resources/"); - cr.add_rule1("^Resources/.*\\.lproj/", "optional", 1000); - cr.add_rule1("^Resources/.*\\.lproj/locversion.plist$", "omit", 1100); - cr.add_rule1("^Resources/Base\\.lproj/", "", 1010); - cr.add_rule1("^version.plist$"); - - cr.add_rule2(".*\\.dSYM($|/)", "", 11); - cr.add_rule2("^(.*/)?\\.DS_Store$", "omit", 2000); - cr.add_rule2("^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/", "nested", 10); - cr.add_rule2("^.*"); - cr.add_rule2("^Info\\.plist$", "omit", 20); - cr.add_rule2("^PkgInfo$", "omit", 20); - cr.add_rule2("^Resources/", "", 20); - cr.add_rule2("^Resources/.*\\.lproj/", "optional", 1000); - cr.add_rule2("^Resources/.*\\.lproj/locversion.plist$", "omit", 1100); - cr.add_rule2("^Resources/Base\\.lproj/", "", 1010); - cr.add_rule2("^[^/]+$", "nested", 10); - cr.add_rule2("^embedded\\.provisionprofile$", "", 10); - cr.add_rule2("^version\\.plist$", "", 20); - cr.add_rule2("^_MASReceipt", "omit", 2000, false); - cr.add_rule2("^_CodeSignature", "omit", 2000, false); - cr.add_rule2("^CodeResources", "omit", 2000, false); - } - - if (!cr.add_folder_recursive(p_bundle_path, "", main_exe)) { - CLEANUP(); - r_error_msg = TTR("Failed to process nested resources."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Failed to process nested resources."); - } - Error err = da->make_dir_recursive(p_bundle_path.plus_file("_CodeSignature")); - if (err != OK) { - CLEANUP(); - r_error_msg = TTR("Failed to create _CodeSignature subfolder."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Failed to create _CodeSignature subfolder."); - } - cr.save_to_file(p_bundle_path.plus_file("_CodeSignature").plus_file("CodeResources")); - res_hash1 = file_hash_sha1(p_bundle_path.plus_file("_CodeSignature").plus_file("CodeResources")); - res_hash2 = file_hash_sha256(p_bundle_path.plus_file("_CodeSignature").plus_file("CodeResources")); - if (res_hash1.empty() || res_hash2.empty()) { - CLEANUP(); - r_error_msg = TTR("Failed to get CodeResources hash."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Failed to get CodeResources hash."); - } - } - - // Generate common signature structures. - if (id.empty()) { - Ref crypto = Ref(Crypto::create()); - PoolByteArray uuid = crypto->generate_random_bytes(16); - id = (String("a-55554944") /*a-UUID*/ + String::hex_encode_buffer(uuid.read().ptr(), 16)); - } - CharString uuid_str = id.utf8(); - print_verbose(vformat("CodeSign: Used bundle ID: %s", id)); - - print_verbose(vformat("CodeSign: Processing entitlements...")); - - Ref cet; - Ref ceb; - if (!p_ent_path.empty()) { - String entitlements = FileAccess::get_file_as_string(p_ent_path); - if (entitlements.empty()) { - CLEANUP(); - r_error_msg = TTR("Invalid entitlements file."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Invalid entitlements file."); - } - cet = Ref(memnew(CodeSignEntitlementsText(entitlements))); - ceb = Ref(memnew(CodeSignEntitlementsBinary(entitlements))); - } - - print_verbose(vformat("CodeSign: Generating requirements...")); - Ref rq; - String team_id = ""; - rq = Ref(memnew(CodeSignRequirements())); - - // Sign executables. - for (int i = 0; i < files_to_sign.size(); i++) { - MachO mh; - if (!mh.open_file(files_to_sign[i])) { - CLEANUP(); - r_error_msg = TTR("Invalid executable file."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Invalid executable file."); - } - print_verbose(vformat("CodeSign: Signing executable for cputype: %d ...", mh.get_cputype())); - - print_verbose(vformat("CodeSign: Generating CodeDirectory...")); - Ref cd1 = memnew(CodeSignCodeDirectory(0x14, 0x01, true, uuid_str, team_id.utf8(), 12, mh.get_exe_limit(), mh.get_code_limit())); - Ref cd2 = memnew(CodeSignCodeDirectory(0x20, 0x02, true, uuid_str, team_id.utf8(), 12, mh.get_exe_limit(), mh.get_code_limit())); - print_verbose(vformat("CodeSign: Calculating special slot hashes...")); - if (info_hash2.size() == 0x20) { - cd2->set_hash_in_slot(info_hash2, CodeSignCodeDirectory::SLOT_INFO_PLIST); - } - if (info_hash1.size() == 0x14) { - cd1->set_hash_in_slot(info_hash1, CodeSignCodeDirectory::SLOT_INFO_PLIST); - } - cd1->set_hash_in_slot(rq->get_hash_sha1(), CodeSignCodeDirectory::Slot::SLOT_REQUIREMENTS); - cd2->set_hash_in_slot(rq->get_hash_sha256(), CodeSignCodeDirectory::Slot::SLOT_REQUIREMENTS); - if (res_hash2.size() == 0x20) { - cd2->set_hash_in_slot(res_hash2, CodeSignCodeDirectory::SLOT_RESOURCES); - } - if (res_hash1.size() == 0x14) { - cd1->set_hash_in_slot(res_hash1, CodeSignCodeDirectory::SLOT_RESOURCES); - } - if (cet.is_valid()) { - cd1->set_hash_in_slot(cet->get_hash_sha1(), CodeSignCodeDirectory::Slot::SLOT_ENTITLEMENTS); //Text variant. - cd2->set_hash_in_slot(cet->get_hash_sha256(), CodeSignCodeDirectory::Slot::SLOT_ENTITLEMENTS); - } - if (ceb.is_valid()) { - cd1->set_hash_in_slot(ceb->get_hash_sha1(), CodeSignCodeDirectory::Slot::SLOT_DER_ENTITLEMENTS); //ASN.1 variant. - cd2->set_hash_in_slot(ceb->get_hash_sha256(), CodeSignCodeDirectory::Slot::SLOT_DER_ENTITLEMENTS); - } - - // Calculate signature size. - int sign_size = 12; // SuperBlob header. - sign_size += cd1->get_size() + 8; - sign_size += cd2->get_size() + 8; - sign_size += rq->get_size() + 8; - if (cet.is_valid()) { - sign_size += cet->get_size() + 8; - } - if (ceb.is_valid()) { - sign_size += ceb->get_size() + 8; - } - sign_size += 16; // Empty signature size. - - // Alloc/resize signature load command. - print_verbose(vformat("CodeSign: Reallocating space for the signature superblob (%d)...", sign_size)); - if (!mh.set_signature_size(sign_size)) { - CLEANUP(); - r_error_msg = TTR("Can't resize signature load command."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Can't resize signature load command."); - } - - print_verbose(vformat("CodeSign: Calculating executable code hashes...")); - // Calculate executable code hashes. - PoolByteArray buffer; - PoolByteArray hash1, hash2; - hash1.resize(0x14); - hash2.resize(0x20); - buffer.resize(1 << 12); - mh.get_file()->seek(0); - for (int32_t j = 0; j < cd2->get_page_count(); j++) { - mh.get_file()->get_buffer(buffer.write().ptr(), (1 << 12)); - CryptoCore::SHA256Context ctx2; - ctx2.start(); - ctx2.update(buffer.read().ptr(), (1 << 12)); - ctx2.finish(hash2.write().ptr()); - cd2->set_hash_in_slot(hash2, j); - - CryptoCore::SHA1Context ctx1; - ctx1.start(); - ctx1.update(buffer.read().ptr(), (1 << 12)); - ctx1.finish(hash1.write().ptr()); - cd1->set_hash_in_slot(hash1, j); - } - if (cd2->get_page_remainder() > 0) { - mh.get_file()->get_buffer(buffer.write().ptr(), cd2->get_page_remainder()); - CryptoCore::SHA256Context ctx2; - ctx2.start(); - ctx2.update(buffer.read().ptr(), cd2->get_page_remainder()); - ctx2.finish(hash2.write().ptr()); - cd2->set_hash_in_slot(hash2, cd2->get_page_count()); - - CryptoCore::SHA1Context ctx1; - ctx1.start(); - ctx1.update(buffer.read().ptr(), cd1->get_page_remainder()); - ctx1.finish(hash1.write().ptr()); - cd1->set_hash_in_slot(hash1, cd1->get_page_count()); - } - - print_verbose(vformat("CodeSign: Generating signature...")); - Ref cs; - cs = Ref(memnew(CodeSignSignature())); - - print_verbose(vformat("CodeSign: Writing signature superblob...")); - // Write signature data to the executable. - CodeSignSuperBlob sb = CodeSignSuperBlob(); - sb.add_blob(cd2); - sb.add_blob(cd1); - sb.add_blob(rq); - if (cet.is_valid()) { - sb.add_blob(cet); - } - if (ceb.is_valid()) { - sb.add_blob(ceb); - } - sb.add_blob(cs); - mh.get_file()->seek(mh.get_signature_offset()); - sb.write_to_file(mh.get_file()); - } - if (files_to_sign.size() > 1) { - print_verbose(vformat("CodeSign: Rebuilding fat executable...")); - LipO lip; - if (!lip.create_file(main_exe, files_to_sign)) { - CLEANUP(); - r_error_msg = TTR("Failed to create fat binary."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Failed to create fat binary."); - } - CLEANUP(); - } - FileAccess::set_unix_permissions(main_exe, 0755); // Restore unix permissions. - return OK; -#undef CLEANUP -} - -Error CodeSign::codesign(bool p_use_hardened_runtime, bool p_force, const String &p_path, const String &p_ent_path, String &r_error_msg) { - DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - if (!da) { - r_error_msg = TTR("Can't get filesystem access."); - ERR_FAIL_V_MSG(ERR_CANT_CREATE, "CodeSign: Can't get filesystem access."); - } - - if (da->dir_exists(p_path)) { - String fmw_ver = "Current"; // Framework version (default). - String info_path; - String main_exe; - String bundle_path; - bool bundle = false; - bool ios_bundle = false; - if (da->file_exists(p_path.plus_file("Contents/Info.plist"))) { - info_path = p_path.plus_file("Contents/Info.plist"); - main_exe = p_path.plus_file("Contents/MacOS"); - bundle_path = p_path.plus_file("Contents"); - bundle = true; - } else if (da->file_exists(p_path.plus_file(vformat("Versions/%s/Resources/Info.plist", fmw_ver)))) { - info_path = p_path.plus_file(vformat("Versions/%s/Resources/Info.plist", fmw_ver)); - main_exe = p_path.plus_file(vformat("Versions/%s", fmw_ver)); - bundle_path = p_path.plus_file(vformat("Versions/%s", fmw_ver)); - bundle = true; - } else if (da->file_exists(p_path.plus_file("Info.plist"))) { - info_path = p_path.plus_file("Info.plist"); - main_exe = p_path; - bundle_path = p_path; - bundle = true; - ios_bundle = true; - } - if (bundle) { - return _codesign_file(p_use_hardened_runtime, p_force, info_path, main_exe, bundle_path, p_ent_path, ios_bundle, r_error_msg); - } else { - r_error_msg = TTR("Unknown bundle type."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Unknown bundle type."); - } - } else if (da->file_exists(p_path)) { - return _codesign_file(p_use_hardened_runtime, p_force, "", p_path, "", p_ent_path, false, r_error_msg); - } else { - r_error_msg = TTR("Unknown object type."); - ERR_FAIL_V_MSG(FAILED, "CodeSign: Unknown object type."); - } -} - -#endif // MODULE_REGEX_ENABLED diff --git a/platform/osx/export/codesign.h b/platform/osx/export/codesign.h deleted file mode 100644 index d08d1b2..0000000 --- a/platform/osx/export/codesign.h +++ /dev/null @@ -1,368 +0,0 @@ -/*************************************************************************/ -/* codesign.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -// macOS code signature creation utility. -// -// Current implementation has the following limitation: -// - Only version 11.3.0 signatures are supported. -// - Only "framework" and "app" bundle types are supported. -// - Page hash array scattering is not supported. -// - Reading and writing binary property lists i snot supported (third-party frameworks with binary Info.plist will not work unless .plist is converted to text format). -// - Requirements code generator is not implemented (only hard-coded requirements for the ad-hoc signing is supported). -// - RFC5652/CMS blob generation is not implemented, supports ad-hoc signing only. - -#ifndef CODESIGN_H -#define CODESIGN_H - -#include "core/crypto/crypto.h" -#include "core/crypto/crypto_core.h" -#include "core/os/dir_access.h" -#include "core/os/file_access.h" -#include "core/object/reference.h" -#include "modules/modules_enabled.gen.h" // For regex. -#ifdef MODULE_REGEX_ENABLED -#include "modules/regex/regex.h" -#endif - -#include "plist.h" - -#ifdef MODULE_REGEX_ENABLED - -/*************************************************************************/ -/* CodeSignCodeResources */ -/*************************************************************************/ - -class CodeSignCodeResources { -public: - enum class CRMatch { - CR_MATCH_NO, - CR_MATCH_YES, - CR_MATCH_NESTED, - CR_MATCH_OPTIONAL, - }; - -private: - struct CRFile { - String name; - String hash; - String hash2; - bool optional; - bool nested; - String requirements; - }; - - struct CRRule { - String file_pattern; - String key; - int weight; - bool store; - CRRule() { - weight = 1; - store = true; - } - CRRule(const String &p_file_pattern, const String &p_key, int p_weight, bool p_store) { - file_pattern = p_file_pattern; - key = p_key; - weight = p_weight; - store = p_store; - } - }; - - Vector rules1; - Vector rules2; - - Vector files1; - Vector files2; - - String hash_sha1_base64(const String &p_path); - String hash_sha256_base64(const String &p_path); - -public: - void add_rule1(const String &p_rule, const String &p_key = "", int p_weight = 0, bool p_store = true); - void add_rule2(const String &p_rule, const String &p_key = "", int p_weight = 0, bool p_store = true); - - CRMatch match_rules1(const String &p_path) const; - CRMatch match_rules2(const String &p_path) const; - - bool add_file1(const String &p_root, const String &p_path); - bool add_file2(const String &p_root, const String &p_path); - bool add_nested_file(const String &p_root, const String &p_path, const String &p_exepath); - - bool add_folder_recursive(const String &p_root, const String &p_path = "", const String &p_main_exe_path = ""); - - bool save_to_file(const String &p_path); -}; - -/*************************************************************************/ -/* CodeSignBlob */ -/*************************************************************************/ - -class CodeSignBlob : public Reference { -public: - virtual PoolByteArray get_hash_sha1() const = 0; - virtual PoolByteArray get_hash_sha256() const = 0; - - virtual int get_size() const = 0; - virtual uint32_t get_index_type() const = 0; - - virtual void write_to_file(FileAccess *p_file) const = 0; -}; - -/*************************************************************************/ -/* CodeSignRequirements */ -/*************************************************************************/ - -// Note: Proper code generator is not implemented (any we probably won't ever need it), just a hardcoded bytecode for the limited set of cases. - -class CodeSignRequirements : public CodeSignBlob { - PoolByteArray blob; - - static inline size_t PAD(size_t s, size_t a) { - return (s % a == 0) ? 0 : (a - s % a); - } - - _FORCE_INLINE_ void _parse_certificate_slot(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const; - _FORCE_INLINE_ void _parse_key(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const; - _FORCE_INLINE_ void _parse_oid_key(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const; - _FORCE_INLINE_ void _parse_hash_string(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const; - _FORCE_INLINE_ void _parse_value(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const; - _FORCE_INLINE_ void _parse_date(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const; - _FORCE_INLINE_ bool _parse_match(uint32_t &r_pos, String &r_out, uint32_t p_rq_size) const; - -public: - CodeSignRequirements(); - CodeSignRequirements(const PoolByteArray &p_data); - - Vector parse_requirements() const; - - virtual PoolByteArray get_hash_sha1() const; - virtual PoolByteArray get_hash_sha256() const; - - virtual int get_size() const; - - virtual uint32_t get_index_type() const { return 0x00000002; }; - virtual void write_to_file(FileAccess *p_file) const; -}; - -/*************************************************************************/ -/* CodeSignEntitlementsText */ -/*************************************************************************/ - -// PList formatted entitlements. - -class CodeSignEntitlementsText : public CodeSignBlob { - PoolByteArray blob; - -public: - CodeSignEntitlementsText(); - CodeSignEntitlementsText(const String &p_string); - - virtual PoolByteArray get_hash_sha1() const; - virtual PoolByteArray get_hash_sha256() const; - - virtual int get_size() const; - - virtual uint32_t get_index_type() const { return 0x00000005; }; - virtual void write_to_file(FileAccess *p_file) const; -}; - -/*************************************************************************/ -/* CodeSignEntitlementsBinary */ -/*************************************************************************/ - -// ASN.1 serialized entitlements. - -class CodeSignEntitlementsBinary : public CodeSignBlob { - PoolByteArray blob; - -public: - CodeSignEntitlementsBinary(); - CodeSignEntitlementsBinary(const String &p_string); - - virtual PoolByteArray get_hash_sha1() const; - virtual PoolByteArray get_hash_sha256() const; - - virtual int get_size() const; - - virtual uint32_t get_index_type() const { return 0x00000007; }; - virtual void write_to_file(FileAccess *p_file) const; -}; - -/*************************************************************************/ -/* CodeSignCodeDirectory */ -/*************************************************************************/ - -// Code Directory, runtime options, code segment and special structure hashes. - -class CodeSignCodeDirectory : public CodeSignBlob { -public: - enum Slot { - SLOT_INFO_PLIST = -1, - SLOT_REQUIREMENTS = -2, - SLOT_RESOURCES = -3, - SLOT_APP_SPECIFIC = -4, // Unused. - SLOT_ENTITLEMENTS = -5, - SLOT_RESERVER1 = -6, // Unused. - SLOT_DER_ENTITLEMENTS = -7, - }; - - enum CodeSignExecSegFlags { - EXECSEG_MAIN_BINARY = 0x1, - EXECSEG_ALLOW_UNSIGNED = 0x10, - EXECSEG_DEBUGGER = 0x20, - EXECSEG_JIT = 0x40, - EXECSEG_SKIP_LV = 0x80, - EXECSEG_CAN_LOAD_CDHASH = 0x100, - EXECSEG_CAN_EXEC_CDHASH = 0x200, - }; - - enum CodeSignatureFlags { - SIGNATURE_HOST = 0x0001, - SIGNATURE_ADHOC = 0x0002, - SIGNATURE_TASK_ALLOW = 0x0004, - SIGNATURE_INSTALLER = 0x0008, - SIGNATURE_FORCED_LV = 0x0010, - SIGNATURE_INVALID_ALLOWED = 0x0020, - SIGNATURE_FORCE_HARD = 0x0100, - SIGNATURE_FORCE_KILL = 0x0200, - SIGNATURE_FORCE_EXPIRATION = 0x0400, - SIGNATURE_RESTRICT = 0x0800, - SIGNATURE_ENFORCEMENT = 0x1000, - SIGNATURE_LIBRARY_VALIDATION = 0x2000, - SIGNATURE_ENTITLEMENTS_VALIDATED = 0x4000, - SIGNATURE_NVRAM_UNRESTRICTED = 0x8000, - SIGNATURE_RUNTIME = 0x10000, - SIGNATURE_LINKER_SIGNED = 0x20000, - }; - -private: - PoolByteArray blob; - - struct CodeDirectoryHeader { - uint32_t version; // Using version 0x0020500. - uint32_t flags; // // Option flags. - uint32_t hash_offset; // Slot zero offset. - uint32_t ident_offset; // Identifier string offset. - uint32_t special_slots; // Nr. of slots with negative index. - uint32_t code_slots; // Nr. of slots with index >= 0, (code_limit / page_size). - uint32_t code_limit; // Everything before code signature load command offset. - uint8_t hash_size; // 20 (SHA-1) or 32 (SHA-256). - uint8_t hash_type; // 1 (SHA-1) or 2 (SHA-256). - uint8_t platform; // Not used. - uint8_t page_size; // Page size, power of two, 2^12 (4096). - uint32_t spare2; // Not used. - // Version 0x20100 - uint32_t scatter_vector_offset; // Set to 0 and ignore. - // Version 0x20200 - uint32_t team_offset; // Team id string offset. - // Version 0x20300 - uint32_t spare3; // Not used. - uint64_t code_limit_64; // Set to 0 and ignore. - // Version 0x20400 - uint64_t exec_seg_base; // Start of the signed code segmet. - uint64_t exec_seg_limit; // Code segment (__TEXT) vmsize. - uint64_t exec_seg_flags; // Executable segment flags. - // Version 0x20500 - uint32_t runtime; // Runtime version. - uint32_t pre_encrypt_offset; // Set to 0 and ignore. - }; - - int32_t pages = 0; - int32_t remain = 0; - int32_t code_slots = 0; - int32_t special_slots = 0; - -public: - CodeSignCodeDirectory(); - CodeSignCodeDirectory(uint8_t p_hash_size, uint8_t p_hash_type, bool p_main, const CharString &p_id, const CharString &p_team_id, uint32_t p_page_size, uint64_t p_exe_limit, uint64_t p_code_limit); - - int32_t get_page_count(); - int32_t get_page_remainder(); - - bool set_hash_in_slot(const PoolByteArray &p_hash, int p_slot); - - virtual PoolByteArray get_hash_sha1() const; - virtual PoolByteArray get_hash_sha256() const; - - virtual int get_size() const; - virtual uint32_t get_index_type() const { return 0x00000000; }; - - virtual void write_to_file(FileAccess *p_file) const; -}; - -/*************************************************************************/ -/* CodeSignSignature */ -/*************************************************************************/ - -class CodeSignSignature : public CodeSignBlob { - PoolByteArray blob; - -public: - CodeSignSignature(); - - virtual PoolByteArray get_hash_sha1() const; - virtual PoolByteArray get_hash_sha256() const; - - virtual int get_size() const; - virtual uint32_t get_index_type() const { return 0x00010000; }; - - virtual void write_to_file(FileAccess *p_file) const; -}; - -/*************************************************************************/ -/* CodeSignSuperBlob */ -/*************************************************************************/ - -class CodeSignSuperBlob { - Vector> blobs; - -public: - bool add_blob(const Ref &p_blob); - - int get_size() const; - void write_to_file(FileAccess *p_file) const; -}; - -/*************************************************************************/ -/* CodeSign */ -/*************************************************************************/ - -class CodeSign { - static PoolByteArray file_hash_sha1(const String &p_path); - static PoolByteArray file_hash_sha256(const String &p_path); - static Error _codesign_file(bool p_use_hardened_runtime, bool p_force, const String &p_info, const String &p_exe_path, const String &p_bundle_path, const String &p_ent_path, bool p_ios_bundle, String &r_error_msg); - -public: - static Error codesign(bool p_use_hardened_runtime, bool p_force, const String &p_path, const String &p_ent_path, String &r_error_msg); -}; - -#endif // MODULE_REGEX_ENABLED - -#endif // CODESIGN_H diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp deleted file mode 100644 index a7352b8..0000000 --- a/platform/osx/export/export.cpp +++ /dev/null @@ -1,2115 +0,0 @@ -/*************************************************************************/ -/* export.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "export.h" -#include "codesign.h" - -#include "core/config/project_settings.h" -#include "core/io/image_loader.h" -#include "core/io/marshalls.h" -#include "core/io/resource_saver.h" -#include "core/io/zip_io.h" -#include "core/os/dir_access.h" -#include "core/os/file_access.h" -#include "core/os/os.h" -#include "core/version.h" -#include "editor/editor_export.h" -#include "editor/editor_node.h" -#include "editor/editor_settings.h" -#include "modules/modules_enabled.gen.h" // For regex. -#include "platform/osx/logo.gen.h" - -#include - -class EditorExportPlatformOSX : public EditorExportPlatform { - GDCLASS(EditorExportPlatformOSX, EditorExportPlatform); - - int version_code; - - Ref logo; - - void _fix_plist(const Ref &p_preset, Vector &plist, const String &p_binary); - void _make_icon(const Ref &p_preset, const Ref &p_icon, Vector &p_data); - - Error _notarize(const Ref &p_preset, const String &p_path); - Error _code_sign(const Ref &p_preset, const String &p_path, const String &p_ent_path); - Error _code_sign_directory(const Ref &p_preset, const String &p_path, const String &p_ent_path, - bool p_should_error_on_non_code = true); - Error _copy_and_sign_files(DirAccessRef &dir_access, const String &p_src_path, const String &p_in_app_path, - bool p_sign_enabled, const Ref &p_preset, const String &p_ent_path, - bool p_should_error_on_non_code_sign); - Error _export_osx_plugins_for(Ref p_editor_export_plugin, const String &p_app_path_name, - DirAccessRef &dir_access, bool p_sign_enabled, const Ref &p_preset, - const String &p_ent_path); - Error _create_pkg(const Ref &p_preset, const String &p_pkg_path, const String &p_app_path_name); - Error _create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name); - void _zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name); - - bool use_codesign() const { return true; } -#ifdef OSX_ENABLED - bool use_dmg() const { - return true; - } -#else - bool use_dmg() const { - return false; - } -#endif - bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const { - String pname = p_package; - - if (pname.length() == 0) { - if (r_error) { - *r_error = TTR("Identifier is missing."); - } - return false; - } - - for (int i = 0; i < pname.length(); i++) { - char32_t c = pname[i]; - if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '.')) { - if (r_error) { - *r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c)); - } - return false; - } - } - - return true; - } - -protected: - virtual void get_preset_features(const Ref &p_preset, List *r_features); - virtual void get_export_options(List *r_options); - virtual bool get_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const RBMap &p_options) const; - -public: - virtual String get_name() const { - return "Mac OSX"; - } - virtual String get_os_name() const { - return "OSX"; - } - virtual Ref get_logo() const { - return logo; - } - - virtual List get_binary_extensions(const Ref &p_preset) const { - List list; - - if (p_preset.is_valid()) { - int dist_type = p_preset->get("export/distribution_type"); - if (dist_type == 0) { -#ifdef OSX_ENABLED - list.push_back("dmg"); -#endif - list.push_back("zip"); -#ifndef WINDOWS_ENABLED - list.push_back("app"); -#endif - } else if (dist_type == 1) { -#ifdef OSX_ENABLED - list.push_back("dmg"); -#endif - list.push_back("zip"); - } else if (dist_type == 2) { -#ifdef OSX_ENABLED - list.push_back("pkg"); -#endif - } - } - - return list; - } - virtual Error export_project(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags = 0); - - virtual bool has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; - virtual bool has_valid_project_configuration(const Ref &p_preset, String &r_error) const; - - virtual void get_platform_features(List *r_features) { - r_features->push_back("pc"); - r_features->push_back("s3tc"); - r_features->push_back("OSX"); - } - - virtual void resolve_platform_feature_priorities(const Ref &p_preset, RBSet &p_features) { - } - - EditorExportPlatformOSX(); - ~EditorExportPlatformOSX(); -}; - -void EditorExportPlatformOSX::get_preset_features(const Ref &p_preset, List *r_features) { - if (p_preset->get("texture_format/s3tc")) { - r_features->push_back("s3tc"); - } - if (p_preset->get("texture_format/etc")) { - r_features->push_back("etc"); - } - if (p_preset->get("texture_format/etc2")) { - r_features->push_back("etc2"); - } - - r_features->push_back("64"); -} - -bool EditorExportPlatformOSX::get_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const RBMap &p_options) const { - // Hide irrelevant code signing options. - if (p_preset) { - int codesign_tool = p_preset->get("codesign/codesign"); - switch (codesign_tool) { - case 1: { // built-in ad-hoc - if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options" || p_option == "codesign/team_id") { - return false; - } - } break; - case 2: { // "rcodesign" - if (p_option == "codesign/identity") { - return false; - } - } break; -#ifdef OSX_ENABLED - case 3: { // "codesign" - if (p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password") { - return false; - } - } break; -#endif - default: { // disabled - if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options" || p_option.begins_with("codesign/entitlements") || p_option == "codesign/team_id") { - return false; - } - } break; - } - - // Distribution type. - int dist_type = p_preset->get("export/distribution_type"); - if (dist_type != 2 && p_option == "codesign/installer_identity") { - return false; - } - - if (dist_type == 2 && p_option.begins_with("notarization/")) { - return false; - } - - if (dist_type != 2 && p_option == "codesign/provisioning_profile") { - return false; - } - - String custom_prof = p_preset->get("codesign/entitlements/custom_file"); - if (custom_prof != "" && p_option != "codesign/entitlements/custom_file" && p_option.begins_with("codesign/entitlements/")) { - return false; - } - - // Hide sandbox entitlements. - bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled"); - if (!sandbox && p_option != "codesign/entitlements/app_sandbox/enabled" && p_option.begins_with("codesign/entitlements/app_sandbox/")) { - return false; - } - - // Hide irrelevant notarization options. - int notary_tool = p_preset->get("notarization/notarization"); - switch (notary_tool) { - case 1: { // "rcodesign" - if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password") { - return false; - } - } break; - case 2: { // "notarytool" - // All options are visible. - } break; - case 3: { // "altool" - // All options are visible. - } break; - default: { // disabled - if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/api_uuid" || p_option == "notarization/api_key" || p_option == "notarization/api_key_id") { - return false; - } - } break; - } - } - - return true; -} - -void EditorExportPlatformOSX::get_export_options(List *r_options) { -#ifdef OSX_ENABLED - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution,App Store"), 1, true)); -#else - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution"), 1, true)); -#endif - - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), "")); - - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.icns,*.png,*.webp,*.svg"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4)); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_category", PROPERTY_HINT_ENUM, "Business,Developer-tools,Education,Entertainment,Finance,Games,Action-games,Adventure-games,Arcade-games,Board-games,Card-games,Casino-games,Dice-games,Educational-games,Family-games,Kids-games,Music-games,Puzzle-games,Racing-games,Role-playing-games,Simulation-games,Sports-games,Strategy-games,Trivia-games,Word-games,Graphics-design,Healthcare-fitness,Lifestyle,Medical,Music,News,Photography,Productivity,Reference,Social-networking,Sports,Travel,Utilities,Video,Weather"), "Games")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version"), "10.12")); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false)); - - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/platform_build"), "14C18")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_version"), "13.1")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_build"), "22C55")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_name"), "macosx13.1")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_version"), "1420")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_build"), "14C18")); - -#ifdef OSX_ENABLED - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign,Xcode codesign"), 3, true)); -#else - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign"), 1, true)); -#endif - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/installer_identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "3rd Party Mac Developer Installer: (ID)"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "ID"), "")); - // "codesign" only options: - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), "")); - // "rcodesign" only options: - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_password"), "")); - // "codesign" and "rcodesign" only options: - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/provisioning_profile", PROPERTY_HINT_GLOBAL_FILE, "*.provisionprofile"), "")); - - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false, true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0)); - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0)); - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0)); - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0)); - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_user_selected", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0)); - r_options->push_back(ExportOption(PropertyInfo(Variant::POOL_STRING_ARRAY, "codesign/custom_options"), PoolStringArray())); - -#ifdef OSX_ENABLED - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign,Xcode notarytool,Xcode altool (deprecated)"), 0, true)); -#else - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign"), 0, true)); -#endif - // "altool" and "notarytool" only options: - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_password", PROPERTY_HINT_PLACEHOLDER_TEXT, "Enable two-factor authentication and provide app-specific password"), "")); - // "altool" and "rcodesign" only options: - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_uuid", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect issuer ID"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_GLOBAL_FILE, "*.p8"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect API key ID"), "")); - - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the microphone"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/camera_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the camera"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/location_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the location information"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/address_book_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the address book"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/calendar_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the calendar"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photos_library_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the photo library"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/desktop_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Desktop folder"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/documents_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Documents folder"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/downloads_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Downloads folder"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/network_volumes_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use network volumes"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/removable_volumes_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use removable volumes"), "")); - - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false)); -} - -void _rgba8_to_packbits_encode(int p_ch, int p_size, PoolVector &p_source, Vector &p_dest) { - int src_len = p_size * p_size; - - Vector result; - result.resize(src_len * 1.25); //temp vector for rle encoded data, make it 25% larger for worst case scenario - int res_size = 0; - - uint8_t buf[128]; - int buf_size = 0; - - int i = 0; - while (i < src_len) { - uint8_t cur = p_source.read()[i * 4 + p_ch]; - - if (i < src_len - 2) { - if ((p_source.read()[(i + 1) * 4 + p_ch] == cur) && (p_source.read()[(i + 2) * 4 + p_ch] == cur)) { - if (buf_size > 0) { - result.write[res_size++] = (uint8_t)(buf_size - 1); - memcpy(&result.write[res_size], &buf, buf_size); - res_size += buf_size; - buf_size = 0; - } - - uint8_t lim = i + 130 >= src_len ? src_len - i - 1 : 130; - bool hit_lim = true; - - for (int j = 3; j <= lim; j++) { - if (p_source.read()[(i + j) * 4 + p_ch] != cur) { - hit_lim = false; - i = i + j - 1; - result.write[res_size++] = (uint8_t)(j - 3 + 0x80); - result.write[res_size++] = cur; - break; - } - } - if (hit_lim) { - result.write[res_size++] = (uint8_t)(lim - 3 + 0x80); - result.write[res_size++] = cur; - i = i + lim; - } - } else { - buf[buf_size++] = cur; - if (buf_size == 128) { - result.write[res_size++] = (uint8_t)(buf_size - 1); - memcpy(&result.write[res_size], &buf, buf_size); - res_size += buf_size; - buf_size = 0; - } - } - } else { - buf[buf_size++] = cur; - result.write[res_size++] = (uint8_t)(buf_size - 1); - memcpy(&result.write[res_size], &buf, buf_size); - res_size += buf_size; - buf_size = 0; - } - - i++; - } - - int ofs = p_dest.size(); - p_dest.resize(p_dest.size() + res_size); - memcpy(&p_dest.write[ofs], result.ptr(), res_size); -} - -void EditorExportPlatformOSX::_make_icon(const Ref &p_preset, const Ref &p_icon, Vector &p_data) { - Ref it = memnew(ImageTexture); - - Vector data; - - data.resize(8); - data.write[0] = 'i'; - data.write[1] = 'c'; - data.write[2] = 'n'; - data.write[3] = 's'; - - struct MacOSIconInfo { - const char *name; - const char *mask_name; - bool is_png; - int size; - }; - - static const MacOSIconInfo icon_infos[] = { - { "ic10", "", true, 1024 }, //1024x1024 32-bit PNG and 512x512@2x 32-bit "retina" PNG - { "ic09", "", true, 512 }, //512×512 32-bit PNG - { "ic14", "", true, 512 }, //256x256@2x 32-bit "retina" PNG - { "ic08", "", true, 256 }, //256×256 32-bit PNG - { "ic13", "", true, 256 }, //128x128@2x 32-bit "retina" PNG - { "ic07", "", true, 128 }, //128x128 32-bit PNG - { "ic12", "", true, 64 }, //32x32@2x 32-bit "retina" PNG - { "ic11", "", true, 32 }, //16x16@2x 32-bit "retina" PNG - { "il32", "l8mk", false, 32 }, //32x32 24-bit RLE + 8-bit uncompressed mask - { "is32", "s8mk", false, 16 } //16x16 24-bit RLE + 8-bit uncompressed mask - }; - - for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) { - Ref copy = p_icon; // does this make sense? doesn't this just increase the reference count instead of making a copy? Do we even need a copy? - copy->convert(Image::FORMAT_RGBA8); - copy->resize(icon_infos[i].size, icon_infos[i].size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int())); - - if (icon_infos[i].is_png) { - // Encode PNG icon. - it->create_from_image(copy); - String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png"); - ResourceSaver::save(path, it); - - FileAccess *f = FileAccess::open(path, FileAccess::READ); - if (!f) { - // Clean up generated file. - DirAccess::remove_file_or_error(path); - add_message(EXPORT_MESSAGE_ERROR, TTR("Icon Creation"), vformat(TTR("Could not open icon file \"%s\"."), path)); - return; - } - - int ofs = data.size(); - uint64_t len = f->get_len(); - data.resize(data.size() + len + 8); - f->get_buffer(&data.write[ofs + 8], len); - memdelete(f); - len += 8; - len = BSWAP32(len); - memcpy(&data.write[ofs], icon_infos[i].name, 4); - encode_uint32(len, &data.write[ofs + 4]); - - // Clean up generated file. - DirAccess::remove_file_or_error(path); - - } else { - PoolVector src_data = copy->get_data(); - - //encode 24bit RGB RLE icon - { - int ofs = data.size(); - data.resize(data.size() + 8); - - _rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // encode R - _rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // encode G - _rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // encode B - - int len = data.size() - ofs; - len = BSWAP32(len); - memcpy(&data.write[ofs], icon_infos[i].name, 4); - encode_uint32(len, &data.write[ofs + 4]); - } - - //encode 8bit mask uncompressed icon - { - int ofs = data.size(); - int len = copy->get_width() * copy->get_height(); - data.resize(data.size() + len + 8); - - for (int j = 0; j < len; j++) { - data.write[ofs + 8 + j] = src_data.read()[j * 4 + 3]; - } - len += 8; - len = BSWAP32(len); - memcpy(&data.write[ofs], icon_infos[i].mask_name, 4); - encode_uint32(len, &data.write[ofs + 4]); - } - } - } - - uint32_t total_len = data.size(); - total_len = BSWAP32(total_len); - encode_uint32(total_len, &data.write[4]); - - p_data = data; -} - -void EditorExportPlatformOSX::_fix_plist(const Ref &p_preset, Vector &plist, const String &p_binary) { - String str; - String strnew; - str.parse_utf8((const char *)plist.ptr(), plist.size()); - Vector lines = str.split("\n"); - for (int i = 0; i < lines.size(); i++) { - if (lines[i].find("$binary") != -1) { - strnew += lines[i].replace("$binary", p_binary) + "\n"; - } else if (lines[i].find("$name") != -1) { - strnew += lines[i].replace("$name", p_binary) + "\n"; - } else if (lines[i].find("$identifier") != -1) { - strnew += lines[i].replace("$identifier", p_preset->get("application/identifier")) + "\n"; - } else if (lines[i].find("$short_version") != -1) { - strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n"; - } else if (lines[i].find("$version") != -1) { - strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n"; - } else if (lines[i].find("$signature") != -1) { - strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n"; - } else if (lines[i].find("$app_category") != -1) { - String cat = p_preset->get("application/app_category"); - strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n"; - } else if (lines[i].find("$copyright") != -1) { - strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n"; - } else if (lines[i].find("$min_version") != -1) { - strnew += lines[i].replace("$min_version", p_preset->get("application/min_macos_version")) + "\n"; - } else if (lines[i].find("$highres") != -1) { - strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t" : "\t") + "\n"; - } else if (lines[i].find("$platfbuild") != -1) { - strnew += lines[i].replace("$platfbuild", p_preset->get("xcode/platform_build")) + "\n"; - } else if (lines[i].find("$sdkver") != -1) { - strnew += lines[i].replace("$sdkver", p_preset->get("xcode/sdk_version")) + "\n"; - } else if (lines[i].find("$sdkname") != -1) { - strnew += lines[i].replace("$sdkname", p_preset->get("xcode/sdk_name")) + "\n"; - } else if (lines[i].find("$sdkbuild") != -1) { - strnew += lines[i].replace("$sdkbuild", p_preset->get("xcode/sdk_build")) + "\n"; - } else if (lines[i].find("$xcodever") != -1) { - strnew += lines[i].replace("$xcodever", p_preset->get("xcode/xcode_version")) + "\n"; - } else if (lines[i].find("$xcodebuild") != -1) { - strnew += lines[i].replace("$xcodebuild", p_preset->get("xcode/xcode_build")) + "\n"; - } else if (lines[i].find("$usage_descriptions") != -1) { - String descriptions; - if (!((String)p_preset->get("privacy/microphone_usage_description")).empty()) { - descriptions += "\tNSMicrophoneUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/microphone_usage_description") + "\n"; - } - if (!((String)p_preset->get("privacy/camera_usage_description")).empty()) { - descriptions += "\tNSCameraUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/camera_usage_description") + "\n"; - } - if (!((String)p_preset->get("privacy/location_usage_description")).empty()) { - descriptions += "\tNSLocationUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/location_usage_description") + "\n"; - } - if (!((String)p_preset->get("privacy/address_book_usage_description")).empty()) { - descriptions += "\tNSContactsUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/address_book_usage_description") + "\n"; - } - if (!((String)p_preset->get("privacy/calendar_usage_description")).empty()) { - descriptions += "\tNSCalendarsUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/calendar_usage_description") + "\n"; - } - if (!((String)p_preset->get("privacy/photos_library_usage_description")).empty()) { - descriptions += "\tNSPhotoLibraryUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/photos_library_usage_description") + "\n"; - } - if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).empty()) { - descriptions += "\tNSDesktopFolderUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/desktop_folder_usage_description") + "\n"; - } - if (!((String)p_preset->get("privacy/documents_folder_usage_description")).empty()) { - descriptions += "\tNSDocumentsFolderUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/documents_folder_usage_description") + "\n"; - } - if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).empty()) { - descriptions += "\tNSDownloadsFolderUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/downloads_folder_usage_description") + "\n"; - } - if (!((String)p_preset->get("privacy/network_volumes_usage_description")).empty()) { - descriptions += "\tNSNetworkVolumesUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/network_volumes_usage_description") + "\n"; - } - if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).empty()) { - descriptions += "\tNSRemovableVolumesUsageDescription\n"; - descriptions += "\t" + (String)p_preset->get("privacy/removable_volumes_usage_description") + "\n"; - } - if (!descriptions.empty()) { - strnew += lines[i].replace("$usage_descriptions", descriptions); - } - } else { - strnew += lines[i] + "\n"; - } - } - - CharString cs = strnew.utf8(); - plist.resize(cs.size() - 1); - for (int i = 0; i < cs.size() - 1; i++) { - plist.write[i] = cs[i]; - } -} - -/** - If we're running the OSX version of the Pandemonium editor we'll: - - export our application bundle to a temporary folder - - attempt to code sign it - - and then wrap it up in a DMG -**/ - -Error EditorExportPlatformOSX::_notarize(const Ref &p_preset, const String &p_path) { - int notary_tool = p_preset->get("notarization/notarization"); - switch (notary_tool) { - case 1: { // "rcodesign" - print_verbose("using rcodesign notarization..."); - - String rcodesign = EditorSettings::get_singleton()->get("export/macos/rcodesign").operator String(); - if (rcodesign.empty()) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).")); - return Error::FAILED; - } - - List args; - - args.push_back("notary-submit"); - - if (p_preset->get("notarization/api_uuid") == "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect issuer ID name not specified.")); - return Error::FAILED; - } - if (p_preset->get("notarization/api_key") == "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified.")); - return Error::FAILED; - } - - args.push_back("--api-issuer"); - args.push_back(p_preset->get("notarization/api_uuid")); - - args.push_back("--api-key"); - args.push_back(p_preset->get("notarization/api_key_id")); - - if (p_preset->get("notarization/api_key") != "") { - args.push_back("--api-key-path"); - args.push_back(p_preset->get("notarization/api_key")); - } - - args.push_back(p_path); - - String str; - int exitcode = 0; - - Error err = OS::get_singleton()->execute(rcodesign, args, true, NULL, &str, &exitcode, true); - if (err != OK) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start rcodesign executable.")); - return err; - } - - int rq_offset = str.find("created submission ID:"); - if (exitcode != 0 || rq_offset == -1) { - print_line("rcodesign (" + p_path + "):\n" + str); - add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details.")); - return Error::FAILED; - } else { - print_verbose("rcodesign (" + p_path + "):\n" + str); - int next_nl = str.find("\n", rq_offset); - String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 14, -1) : str.substr(rq_offset + 14, next_nl - rq_offset - 14); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour.")); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:")); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign notary-log --api-issuer --api-key \""); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):")); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign staple \""); - } - } break; -#ifdef OSX_ENABLED - case 2: { // "notarytool" - print_verbose("using notarytool notarization..."); - - if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed.")); - return Error::FAILED; - } - - List args; - - args.push_back("notarytool"); - args.push_back("submit"); - - args.push_back(p_path); - - if (p_preset->get("notarization/apple_id_name") == "" && p_preset->get("notarization/api_uuid") == "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified.")); - return Error::FAILED; - } - if (p_preset->get("notarization/apple_id_name") != "" && p_preset->get("notarization/api_uuid") != "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.")); - return Error::FAILED; - } - - if (p_preset->get("notarization/apple_id_name") != "") { - if (p_preset->get("notarization/apple_id_password") == "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified.")); - return Error::FAILED; - } - args.push_back("--apple-id"); - args.push_back(p_preset->get("notarization/apple_id_name")); - - args.push_back("--password"); - args.push_back(p_preset->get("notarization/apple_id_password")); - } else { - if (p_preset->get("notarization/api_key_id") == "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified.")); - return Error::FAILED; - } - args.push_back("--issuer"); - args.push_back(p_preset->get("notarization/api_uuid")); - - if (p_preset->get("notarization/api_key") != "") { - args.push_back("--key"); - args.push_back(p_preset->get("notarization/api_key")); - } - - args.push_back("--key-id"); - args.push_back(p_preset->get("notarization/api_key_id")); - } - - args.push_back("--no-progress"); - - if (p_preset->get("codesign/apple_team_id")) { - args.push_back("--team-id"); - args.push_back(p_preset->get("codesign/apple_team_id")); - } - - String str; - int exitcode = 0; - Error err = OS::get_singleton()->execute("xcrun", args, true, NULL, &str, &exitcode, true); - if (err != OK) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable.")); - return err; - } - - int rq_offset = str.find("id:"); - if (exitcode != 0 || rq_offset == -1) { - print_line("notarytool (" + p_path + "):\n" + str); - add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details.")); - return Error::FAILED; - } else { - print_verbose("notarytool (" + p_path + "):\n" + str); - int next_nl = str.find("\n", rq_offset); - String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 4, -1) : str.substr(rq_offset + 4, next_nl - rq_offset - 4); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour.")); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:")); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log --issuer --key-id --key \" or"); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log --apple-id --password >\""); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):")); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple \""); - } - } break; - case 3: { // "altool" - print_verbose("using altool notarization..."); - - if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed.")); - return Error::FAILED; - } - - List args; - - args.push_back("altool"); - args.push_back("--notarize-app"); - - args.push_back("--primary-bundle-id"); - args.push_back(p_preset->get("application/bundle_identifier")); - - if (p_preset->get("notarization/apple_id_name") == "" && p_preset->get("notarization/api_uuid") == "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified.")); - return Error::FAILED; - } - if (p_preset->get("notarization/apple_id_name") != "" && p_preset->get("notarization/api_uuid") != "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.")); - return Error::FAILED; - } - - if (p_preset->get("notarization/apple_id_name") != "") { - if (p_preset->get("notarization/apple_id_password") == "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified.")); - return Error::FAILED; - } - args.push_back("--username"); - args.push_back(p_preset->get("notarization/apple_id_name")); - - args.push_back("--password"); - args.push_back(p_preset->get("notarization/apple_id_password")); - } else { - if (p_preset->get("notarization/api_key") == "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified.")); - return Error::FAILED; - } - args.push_back("--apiIssuer"); - args.push_back(p_preset->get("notarization/api_uuid")); - - args.push_back("--apiKey"); - args.push_back(p_preset->get("notarization/api_key_id")); - } - - args.push_back("--type"); - args.push_back("osx"); - - if (p_preset->get("codesign/apple_team_id")) { - args.push_back("--asc-provider"); - args.push_back(p_preset->get("codesign/apple_team_id")); - } - - args.push_back("--file"); - args.push_back(p_path); - - String str; - int exitcode = 0; - Error err = OS::get_singleton()->execute("xcrun", args, true, NULL, &str, &exitcode, true); - if (err != OK) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable.")); - return err; - } - - int rq_offset = str.find("RequestUUID"); - if (exitcode != 0 || rq_offset == -1) { - print_line("xcrun altool (" + p_path + "):\n" + str); - add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details.")); - return Error::FAILED; - } else { - print_verbose("xcrun altool (" + p_path + "):\n" + str); - int next_nl = str.find("\n", rq_offset); - String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 14, -1) : str.substr(rq_offset + 14, next_nl - rq_offset - 14); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour. When the process is completed, you'll receive an email.")); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:")); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun altool --notarization-history 0 -u -p \""); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):")); - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple \""); - } - } break; -#endif - default: { - }; - } - - return OK; -} - -Error EditorExportPlatformOSX::_code_sign(const Ref &p_preset, const String &p_path, const String &p_ent_path) { - int codesign_tool = p_preset->get("codesign/codesign"); - switch (codesign_tool) { - case 1: { // built-in ad-hoc - print_verbose("using built-in codesign..."); -#ifdef MODULE_REGEX_ENABLED - String error_msg; - Error err = CodeSign::codesign(false, true, p_path, p_ent_path, error_msg); - if (err != OK) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Built-in CodeSign failed with error \"%s\"."), error_msg)); - return Error::FAILED; - } -#else - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Built-in CodeSign require regex module.")); -#endif - } break; - case 2: { // "rcodesign" - print_verbose("using rcodesign codesign..."); - - String rcodesign = EditorSettings::get_singleton()->get("export/macos/rcodesign").operator String(); - if (rcodesign.empty()) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xrcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).")); - return Error::FAILED; - } - - List args; - args.push_back("sign"); - - if (p_path.get_extension() != "dmg") { - args.push_back("--entitlements-xml-path"); - args.push_back(p_ent_path); - } - - String certificate_file = p_preset->get("codesign/certificate_file"); - String certificate_pass = p_preset->get("codesign/certificate_password"); - if (!certificate_file.empty() && !certificate_file.empty()) { - args.push_back("--p12-file"); - args.push_back(certificate_file); - args.push_back("--p12-password"); - args.push_back(certificate_pass); - } - - args.push_back("-v"); /* provide some more feedback */ - - args.push_back(p_path); - - String str; - int exitcode = 0; - - Error err = OS::get_singleton()->execute(rcodesign, args, true, NULL, &str, &exitcode, true); - if (err != OK) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start rcodesign executable.")); - return err; - } - - if (exitcode != 0) { - print_line("rcodesign (" + p_path + "):\n" + str); - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details.")); - return Error::FAILED; - } else { - print_verbose("rcodesign (" + p_path + "):\n" + str); - } - } break; -#ifdef OSX_ENABLED - case 3: { // "codesign" - print_verbose("using xcode codesign..."); - - if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xcode command line tools are not installed.")); - return Error::FAILED; - } - - bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-"); - - List args; - if (!ad_hoc) { - args.push_back("--timestamp"); - args.push_back("--options"); - args.push_back("runtime"); - } - - if (p_path.get_extension() != "dmg") { - args.push_back("--entitlements"); - args.push_back(p_ent_path); - } - - PoolStringArray user_args = p_preset->get("codesign/custom_options"); - for (int i = 0; i < user_args.size(); i++) { - String user_arg = user_args[i].strip_edges(); - if (!user_arg.empty()) { - args.push_back(user_arg); - } - } - - args.push_back("-s"); - if (ad_hoc) { - args.push_back("-"); - } else { - args.push_back(p_preset->get("codesign/identity")); - } - - args.push_back("-v"); /* provide some more feedback */ - args.push_back("-f"); - - args.push_back(p_path); - - String str; - int exitcode = 0; - - Error err = OS::get_singleton()->execute("codesign", args, true, NULL, &str, &exitcode, true); - if (err != OK) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start codesign executable, make sure Xcode command line tools are installed.")); - return err; - } - - if (exitcode != 0) { - print_line("codesign (" + p_path + "):\n" + str); - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details.")); - return Error::FAILED; - } else { - print_verbose("codesign (" + p_path + "):\n" + str); - } - } break; -#endif - default: { - }; - } - - return OK; -} - -Error EditorExportPlatformOSX::_code_sign_directory(const Ref &p_preset, const String &p_path, - const String &p_ent_path, bool p_should_error_on_non_code) { -#ifdef OSX_ENABLED - static Vector extensions_to_sign; - - if (extensions_to_sign.empty()) { - extensions_to_sign.push_back("dylib"); - extensions_to_sign.push_back("framework"); - extensions_to_sign.push_back(""); - } - - Error dir_access_error; - DirAccessRef dir_access{ DirAccess::open(p_path, &dir_access_error) }; - - if (dir_access_error != OK) { - return dir_access_error; - } - - dir_access->list_dir_begin(); - String current_file{ dir_access->get_next() }; - while (!current_file.empty()) { - String current_file_path{ p_path.plus_file(current_file) }; - - if (current_file == ".." || current_file == ".") { - current_file = dir_access->get_next(); - continue; - } - - if (extensions_to_sign.find(current_file.get_extension()) > -1) { - Error code_sign_error{ _code_sign(p_preset, current_file_path, p_ent_path) }; - if (code_sign_error != OK) { - return code_sign_error; - } - } else if (dir_access->current_is_dir()) { - Error code_sign_error{ _code_sign_directory(p_preset, current_file_path, p_ent_path, p_should_error_on_non_code) }; - if (code_sign_error != OK) { - return code_sign_error; - } - } else if (p_should_error_on_non_code) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign file %s."), current_file)); - return Error::FAILED; - } - - current_file = dir_access->get_next(); - } -#endif - - return OK; -} - -Error EditorExportPlatformOSX::_copy_and_sign_files(DirAccessRef &dir_access, const String &p_src_path, - const String &p_in_app_path, bool p_sign_enabled, - const Ref &p_preset, const String &p_ent_path, - bool p_should_error_on_non_code_sign) { - static Vector extensions_to_sign; - - if (extensions_to_sign.size() == 0) { - extensions_to_sign.push_back("dylib"); - extensions_to_sign.push_back("framework"); - extensions_to_sign.push_back(""); - } - - Error err{ OK }; - if (dir_access->dir_exists(p_src_path)) { -#ifndef UNIX_ENABLED - add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Relative symlinks are not supported, exported \"%s\" might be broken!"), p_src_path.get_file())); -#endif - print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path); - err = dir_access->make_dir_recursive(p_in_app_path); - if (err == OK) { - err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true); - } - } else { - print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path); - err = dir_access->copy(p_src_path, p_in_app_path); - } - if (err == OK && p_sign_enabled) { - if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().empty()) { - // If it is a directory, find and sign all dynamic libraries. - err = _code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_should_error_on_non_code_sign); - } else { - if (extensions_to_sign.find(p_in_app_path.get_extension()) > -1) { - err = _code_sign(p_preset, p_in_app_path, p_ent_path); - } - } - } - return err; -} - -Error EditorExportPlatformOSX::_export_osx_plugins_for(Ref p_editor_export_plugin, - const String &p_app_path_name, DirAccessRef &dir_access, - bool p_sign_enabled, const Ref &p_preset, - const String &p_ent_path) { - Error error{ OK }; - const Vector &osx_plugins{ p_editor_export_plugin->get_osx_plugin_files() }; - for (int i = 0; i < osx_plugins.size(); ++i) { - String src_path{ ProjectSettings::get_singleton()->globalize_path(osx_plugins[i]) }; - String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() }; - error = _copy_and_sign_files(dir_access, src_path, path_in_app, p_sign_enabled, p_preset, p_ent_path, false); - if (error != OK) { - break; - } - } - return error; -} - -Error EditorExportPlatformOSX::_create_pkg(const Ref &p_preset, const String &p_pkg_path, const String &p_app_path_name) { - List args; - - if (FileAccess::exists(p_pkg_path)) { - OS::get_singleton()->move_to_trash(p_pkg_path); - } - - args.push_back("productbuild"); - args.push_back("--component"); - args.push_back(p_app_path_name); - args.push_back("/Applications"); - String ident = p_preset->get("codesign/installer_identity"); - if (ident != "") { - args.push_back("--timestamp"); - args.push_back("--sign"); - args.push_back(ident); - } - args.push_back("--quiet"); - args.push_back(p_pkg_path); - - String str; - Error err = OS::get_singleton()->execute("xcrun", args, true, nullptr, &str, nullptr, true); - if (err != OK) { - add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("Could not start productbuild executable.")); - return err; - } - - print_verbose("productbuild returned: " + str); - if (str.find("productbuild: error:") != -1) { - add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("`productbuild` failed.")); - return FAILED; - } - - return OK; -} - -Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) { - List args; - - if (FileAccess::exists(p_dmg_path)) { - OS::get_singleton()->move_to_trash(p_dmg_path); - } - - args.push_back("create"); - args.push_back(p_dmg_path); - args.push_back("-volname"); - args.push_back(p_pkg_name); - args.push_back("-fs"); - args.push_back("HFS+"); - args.push_back("-srcfolder"); - args.push_back(p_app_path_name); - - String str; - Error err = OS::get_singleton()->execute("hdiutil", args, true, nullptr, &str, nullptr, true); - if (err != OK) { - add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("Could not start hdiutil executable.")); - return err; - } - - print_line("hdiutil returned: " + str); - if (str.find("create failed") != -1) { - if (str.find("File exists") != -1) { - add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed - file exists.")); - } else { - add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed.")); - } - return FAILED; - } - - return OK; -} - -Error EditorExportPlatformOSX::export_project(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags) { - ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags); - - String src_pkg_name; - - EditorProgress ep("export", "Exporting for OSX", 3, true); - - if (p_debug) { - src_pkg_name = p_preset->get("custom_template/debug"); - } else { - src_pkg_name = p_preset->get("custom_template/release"); - } - - if (src_pkg_name == "") { - String err; - src_pkg_name = find_export_template("osx.zip", &err); - if (src_pkg_name == "") { - add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found.")); - return ERR_FILE_NOT_FOUND; - } - } - - if (!DirAccess::exists(p_path.get_base_dir())) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("The given export path doesn't exist.")); - return ERR_FILE_BAD_PATH; - } - - FileAccess *src_f = nullptr; - zlib_filefunc_def io = zipio_create_io_from_file(&src_f); - - if (ep.step(TTR("Creating app bundle"), 0)) { - return ERR_SKIP; - } - - unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io); - if (!src_pkg_zip) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not find template app to export: \"%s\"."), src_pkg_name)); - return ERR_FILE_NOT_FOUND; - } - - int ret = unzGoToFirstFile(src_pkg_zip); - - String binary_to_use = "pandemonium_osx_" + String(p_debug ? "debug" : "release") + ".64"; - - String pkg_name; - if (p_preset->get("application/name") != "") { - pkg_name = p_preset->get("application/name"); // app_name - } else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") { - pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name")); - } else { - pkg_name = "Unnamed"; - } - - pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name); - - String export_format; - if (p_path.ends_with("zip")) { - export_format = "zip"; - } else if (p_path.ends_with("app")) { - export_format = "app"; -#ifdef OSX_ENABLED - } else if (p_path.ends_with("dmg")) { - export_format = "dmg"; - } else if (p_path.ends_with("pkg")) { - export_format = "pkg"; -#endif - } else { - add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Invalid export format.")); - return ERR_CANT_CREATE; - } - - // Create our application bundle. - String tmp_app_dir_name = pkg_name + ".app"; - String tmp_app_path_name; - if (export_format == "app") { - tmp_app_path_name = p_path; - } else { - tmp_app_path_name = EditorSettings::get_singleton()->get_cache_dir().plus_file(tmp_app_dir_name); - } - print_verbose("Exporting to " + tmp_app_path_name); - - Error err = OK; - - DirAccessRef tmp_app_dir = DirAccess::create_for_path(tmp_app_path_name); - if (!tmp_app_dir) { - err = ERR_CANT_CREATE; - } - - if (DirAccess::exists(tmp_app_dir_name)) { - String old_dir = tmp_app_dir->get_current_dir(); - if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) { - tmp_app_dir->erase_contents_recursive(); - tmp_app_dir->change_dir(old_dir); - } - } - - // Create our folder structure. - if (err == OK) { - print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS"); - err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS"); - if (err != OK) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/MacOS")); - } - } - - if (err == OK) { - print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks"); - err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks"); - if (err != OK) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Frameworks")); - } - } - - if (err == OK) { - print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources"); - err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources"); - if (err != OK) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Resources")); - } - } - - Vector translations = ProjectSettings::get_singleton()->get("locale/translations"); - if (translations.size() > 0) { - { - String fname = tmp_app_path_name + "/Contents/Resources/en.lproj"; - tmp_app_dir->make_dir_recursive(fname); - FileAccessRef f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE); - f->store_line("CFBundleDisplayName = \"" + ProjectSettings::get_singleton()->get("application/config/name").operator String() + "\";"); - } - - RBSet languages; - for (int j = 0; j < translations.size(); j++) { - Ref tr = ResourceLoader::load(translations[j]); - if (tr.is_valid() && tr->get_locale() != "en") { - languages.insert(tr->get_locale()); - } - } - for (const RBSet::Element *E = languages.front(); E; E = E->next()) { - String fname = tmp_app_path_name + "/Contents/Resources/" + E->get() + ".lproj"; - tmp_app_dir->make_dir_recursive(fname); - FileAccessRef f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE); - String prop = "application/config/name_" + E->get(); - if (ProjectSettings::get_singleton()->has_setting(prop)) { - f->store_line("CFBundleDisplayName = \"" + ProjectSettings::get_singleton()->get(prop).operator String() + "\";"); - } - } - } - - // Now process our template. - bool found_binary = false; - Vector dylibs_found; - - while (ret == UNZ_OK && err == OK) { - bool is_execute = false; - - // Get filename. - unz_file_info info; - char fname[16384]; - ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0); - if (ret != UNZ_OK) { - break; - } - - String file = String::utf8(fname); - - Vector data; - data.resize(info.uncompressed_size); - - // Read. - unzOpenCurrentFile(src_pkg_zip); - unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size()); - unzCloseCurrentFile(src_pkg_zip); - - // Write. - file = file.replace_first("osx_template.app/", ""); - - if (((info.external_fa >> 16L) & 0120000) == 0120000) { -#ifndef UNIX_ENABLED - add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Relative symlinks are not supported on this OS, the exported project might be broken!")); -#endif - // Handle symlinks in the archive. - file = tmp_app_path_name.plus_file(file); - if (err == OK) { - err = tmp_app_dir->make_dir_recursive(file.get_base_dir()); - if (err != OK) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir())); - } - } - if (err == OK) { - String lnk_data = String::utf8((const char *)data.ptr(), data.size()); - err = tmp_app_dir->create_link(lnk_data, file); - if (err != OK) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not created symlink \"%s\" -> \"%s\"."), lnk_data, file)); - } - print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data)); - } - - ret = unzGoToNextFile(src_pkg_zip); - continue; // next - } - - if (file == "Contents/Info.plist") { - _fix_plist(p_preset, data, pkg_name); - } - - if (file.begins_with("Contents/MacOS/pandemonium_")) { - if (file != "Contents/MacOS/" + binary_to_use) { - ret = unzGoToNextFile(src_pkg_zip); - continue; // skip - } - found_binary = true; - is_execute = true; - file = "Contents/MacOS/" + pkg_name; - } - - if (file == "Contents/Resources/icon.icns") { - // See if there is an icon. - String iconpath; - if (p_preset->get("application/icon") != "") { - iconpath = p_preset->get("application/icon"); - } else { - iconpath = ProjectSettings::get_singleton()->get("application/config/icon"); - } - - if (iconpath != "") { - if (iconpath.get_extension() == "icns") { - FileAccess *icon = FileAccess::open(iconpath, FileAccess::READ); - if (icon) { - data.resize(icon->get_len()); - icon->get_buffer(&data.write[0], icon->get_len()); - icon->close(); - memdelete(icon); - } - } else { - Ref icon; - icon.instance(); - err = ImageLoader::load_image(iconpath, icon); - if (err == OK && !icon->empty()) { - _make_icon(p_preset, icon, data); - } - } - } - } - - if (data.size() > 0) { - if (file.ends_with(".dylib")) { - dylibs_found.push_back(file); - } - - print_verbose("ADDING: " + file + " size: " + itos(data.size())); - - // Write it into our application bundle. - file = tmp_app_path_name.plus_file(file); - if (err == OK) { - err = tmp_app_dir->make_dir_recursive(file.get_base_dir()); - if (err != OK) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir())); - } - } - if (err == OK) { - FileAccess *f = FileAccess::open(file, FileAccess::WRITE); - if (f) { - f->store_buffer(data.ptr(), data.size()); - f->close(); - if (is_execute) { - // chmod with 0755 if the file is executable. - FileAccess::set_unix_permissions(file, 0755); - } - memdelete(f); - } else { - add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not open \"%s\"."), file)); - err = ERR_CANT_CREATE; - } - } - } - - ret = unzGoToNextFile(src_pkg_zip); - } - - // We're done with our source zip. - unzClose(src_pkg_zip); - - if (!found_binary) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Requested template binary \"%s\" not found. It might be missing from your template archive."), binary_to_use)); - err = ERR_FILE_NOT_FOUND; - } - - if (err == OK) { - if (ep.step(TTR("Making PKG"), 1)) { - return ERR_SKIP; - } - - String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck"; - Vector shared_objects; - err = save_pack(p_preset, pack_path, &shared_objects); - - // See if we can code sign our new package. - bool sign_enabled = (p_preset->get("codesign/codesign").operator int() > 0); - bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation"); - - String ent_path = p_preset->get("codesign/entitlements/custom_file"); - if (sign_enabled && (ent_path == "")) { - ent_path = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".entitlements"); - - FileAccess *ent_f = FileAccess::open(ent_path, FileAccess::WRITE); - if (ent_f) { - ent_f->store_line(""); - ent_f->store_line(""); - ent_f->store_line(""); - ent_f->store_line(""); - - if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) { - ent_f->store_line("com.apple.security.cs.allow-jit"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) { - ent_f->store_line("com.apple.security.cs.allow-unsigned-executable-memory"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) { - ent_f->store_line("com.apple.security.cs.allow-dyld-environment-variables"); - ent_f->store_line(""); - } - - if (lib_validation) { - ent_f->store_line("com.apple.security.cs.disable-library-validation"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/audio_input")) { - ent_f->store_line("com.apple.security.device.audio-input"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/camera")) { - ent_f->store_line("com.apple.security.device.camera"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/location")) { - ent_f->store_line("com.apple.security.personal-information.location"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/address_book")) { - ent_f->store_line("com.apple.security.personal-information.addressbook"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/calendars")) { - ent_f->store_line("com.apple.security.personal-information.calendars"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/photos_library")) { - ent_f->store_line("com.apple.security.personal-information.photos-library"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/apple_events")) { - ent_f->store_line("com.apple.security.automation.apple-events"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/debugging")) { - ent_f->store_line("com.apple.security.get-task-allow"); - ent_f->store_line(""); - } - - int dist_type = p_preset->get("export/distribution_type"); - if (dist_type == 2) { - String pprof = p_preset->get("codesign/provisioning_profile"); - String teamid = p_preset->get("codesign/apple_team_id"); - String bid = p_preset->get("application/bundle_identifier"); - if (pprof != "" && teamid != "") { - ent_f->store_line("com.apple.developer.team-identifier"); - ent_f->store_line("" + teamid + ""); - ent_f->store_line("com.apple.application-identifier"); - ent_f->store_line("" + teamid + "." + bid + ""); - } - } - - if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) { - ent_f->store_line("com.apple.security.app-sandbox"); - ent_f->store_line(""); - - if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) { - ent_f->store_line("com.apple.security.network.server"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) { - ent_f->store_line("com.apple.security.network.client"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) { - ent_f->store_line("com.apple.security.device.usb"); - ent_f->store_line(""); - } - if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) { - ent_f->store_line("com.apple.security.device.bluetooth"); - ent_f->store_line(""); - } - if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) { - ent_f->store_line("com.apple.security.files.downloads.read-only"); - ent_f->store_line(""); - } - if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) { - ent_f->store_line("com.apple.security.files.downloads.read-write"); - ent_f->store_line(""); - } - if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) { - ent_f->store_line("com.apple.security.files.pictures.read-only"); - ent_f->store_line(""); - } - if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) { - ent_f->store_line("com.apple.security.files.pictures.read-write"); - ent_f->store_line(""); - } - if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) { - ent_f->store_line("com.apple.security.files.music.read-only"); - ent_f->store_line(""); - } - if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) { - ent_f->store_line("com.apple.security.files.music.read-write"); - ent_f->store_line(""); - } - if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) { - ent_f->store_line("com.apple.security.files.movies.read-only"); - ent_f->store_line(""); - } - if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) { - ent_f->store_line("com.apple.security.files.movies.read-write"); - ent_f->store_line(""); - } - if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 1) { - ent_f->store_line("com.apple.security.files.user-selected.read-only"); - ent_f->store_line(""); - } - if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 2) { - ent_f->store_line("com.apple.security.files.user-selected.read-write"); - ent_f->store_line(""); - } - } - - ent_f->store_line(""); - ent_f->store_line(""); - - ent_f->close(); - memdelete(ent_f); - } else { - err = ERR_CANT_CREATE; - } - } - - bool ad_hoc = false; - int codesign_tool = p_preset->get("codesign/codesign"); - switch (codesign_tool) { - case 1: { // built-in ad-hoc - ad_hoc = true; - } break; - case 2: { // "rcodesign" - ad_hoc = p_preset->get("codesign/certificate_file").operator String().empty() || p_preset->get("codesign/certificate_password").operator String().empty(); - } break; -#ifdef OSX_ENABLED - case 3: { // "codesign" - ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-"); - } break; -#endif - default: { - }; - } - - if (err == OK) { - if ((!dylibs_found.empty() || !shared_objects.empty()) && sign_enabled && ad_hoc && !lib_validation) { - add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Ad-hoc signed applications require the 'Disable Library Validation' entitlement to load dynamic libraries.")); - err = ERR_CANT_CREATE; - } - } - - if (err == OK) { - DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - for (int i = 0; i < shared_objects.size(); i++) { - String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path); - String path_in_app{ tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file() }; - err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, true); - if (err != OK) { - break; - } - } - - Vector> export_plugins{ EditorExport::get_singleton()->get_export_plugins() }; - for (int i = 0; i < export_plugins.size(); ++i) { - err = _export_osx_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path); - if (err != OK) { - break; - } - } - } - - if (sign_enabled) { - for (int i = 0; i < dylibs_found.size(); i++) { - if (err == OK) { - err = _code_sign(p_preset, tmp_app_path_name + "/" + dylibs_found[i], ent_path); - } - } - } - - if (err == OK && sign_enabled) { - int dist_type = p_preset->get("export/distribution_type"); - if (dist_type == 2) { - String pprof = p_preset->get("codesign/provisioning_profile").operator String(); - if (pprof != "") { - DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - err = da->copy(pprof, tmp_app_path_name + "/Contents/embedded.provisionprofile"); - } - } - - if (ep.step(TTR("Code signing bundle"), 2)) { - return ERR_SKIP; - } - err = _code_sign(p_preset, tmp_app_path_name, ent_path); - } - - if (export_format == "dmg") { - // Create a DMG. - if (err == OK) { - if (ep.step(TTR("Making DMG"), 3)) { - return ERR_SKIP; - } - err = _create_dmg(p_path, pkg_name, tmp_app_path_name); - } - // Sign DMG. - if (err == OK && sign_enabled && !ad_hoc) { - if (ep.step(TTR("Code signing DMG"), 3)) { - return ERR_SKIP; - } - err = _code_sign(p_preset, p_path, ent_path); - } - } else if (export_format == "pkg") { - // Create a Installer. - if (err == OK) { - if (ep.step(TTR("Making PKG installer"), 3)) { - return ERR_SKIP; - } - err = _create_pkg(p_preset, p_path, tmp_app_path_name); - } - } else if (export_format == "zip") { - // Create ZIP. - if (err == OK) { - if (ep.step(TTR("Making ZIP"), 3)) { - return ERR_SKIP; - } - if (FileAccess::exists(p_path)) { - OS::get_singleton()->move_to_trash(p_path); - } - - FileAccess *dst_f = nullptr; - zlib_filefunc_def io_dst = zipio_create_io_from_file(&dst_f); - zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst); - - _zip_folder_recursive(zip, EditorSettings::get_singleton()->get_cache_dir(), pkg_name + ".app", pkg_name); - - zipClose(zip, nullptr); - } - } - - bool noto_enabled = (p_preset->get("notarization/notarization").operator int() > 0); - if (err == OK && noto_enabled) { - if (export_format == "app" || export_format == "pkg") { - add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("Notarization requires the app to be archived first, select the DMG or ZIP export format instead.")); - } else { - if (ep.step(TTR("Sending archive for notarization"), 4)) { - return ERR_SKIP; - } - err = _notarize(p_preset, p_path); - } - } - - // Clean up temporary .app dir and generated entitlements. - if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") { - tmp_app_dir->remove(ent_path); - } - if (export_format != "app") { - if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) { - tmp_app_dir->erase_contents_recursive(); - tmp_app_dir->change_dir(".."); - tmp_app_dir->remove(tmp_app_dir_name); - } - } - } - - return err; -} - -void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name) { - String dir = p_root_path.plus_file(p_folder); - - DirAccess *da = DirAccess::open(dir); - da->list_dir_begin(); - String f = da->get_next(); - while (f.empty()) { - if (f == "." || f == "..") { - f = da->get_next(); - continue; - } - - if (da->is_link(f)) { - OS::Time time = OS::get_singleton()->get_time(); - OS::Date date = OS::get_singleton()->get_date(); - - zip_fileinfo zipfi; - zipfi.tmz_date.tm_hour = time.hour; - zipfi.tmz_date.tm_mday = date.day; - zipfi.tmz_date.tm_min = time.min; - zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Pandemonium month range - 1..12, http://www.cplusplus.com/reference/ctime/tm/ - zipfi.tmz_date.tm_sec = time.sec; - zipfi.tmz_date.tm_year = date.year; - zipfi.dosDate = 0; - // 0120000: symbolic link type - // 0000755: permissions rwxr-xr-x - // 0000644: permissions rw-r--r-- - uint32_t _mode = 0120644; - zipfi.external_fa = (_mode << 16L) | !(_mode & 0200); - zipfi.internal_fa = 0; - - zipOpenNewFileInZip4(p_zip, - p_folder.plus_file(f).utf8().get_data(), - &zipfi, - nullptr, - 0, - nullptr, - 0, - nullptr, - Z_DEFLATED, - Z_DEFAULT_COMPRESSION, - 0, - -MAX_WBITS, - DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, - nullptr, - 0, - 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions - 0); - - String target = da->read_link(f); - zipWriteInFileInZip(p_zip, target.utf8().get_data(), target.utf8().size()); - zipCloseFileInZip(p_zip); - } else if (da->current_is_dir()) { - _zip_folder_recursive(p_zip, p_root_path, p_folder.plus_file(f), p_pkg_name); - } else { - bool is_executable = (p_folder.ends_with("MacOS") && (f == p_pkg_name)); - - OS::Time time = OS::get_singleton()->get_time(); - OS::Date date = OS::get_singleton()->get_date(); - - zip_fileinfo zipfi; - zipfi.tmz_date.tm_hour = time.hour; - zipfi.tmz_date.tm_mday = date.day; - zipfi.tmz_date.tm_min = time.min; - zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Pandemonium month range - 1..12, http://www.cplusplus.com/reference/ctime/tm/ - zipfi.tmz_date.tm_sec = time.sec; - zipfi.tmz_date.tm_year = date.year; - zipfi.dosDate = 0; - // 0100000: regular file type - // 0000755: permissions rwxr-xr-x - // 0000644: permissions rw-r--r-- - uint32_t _mode = (is_executable ? 0100755 : 0100644); - zipfi.external_fa = (_mode << 16L) | !(_mode & 0200); - zipfi.internal_fa = 0; - - zipOpenNewFileInZip4(p_zip, - p_folder.plus_file(f).utf8().get_data(), - &zipfi, - nullptr, - 0, - nullptr, - 0, - nullptr, - Z_DEFLATED, - Z_DEFAULT_COMPRESSION, - 0, - -MAX_WBITS, - DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, - nullptr, - 0, - 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions - 0); - - FileAccessRef fa = FileAccess::open(dir.plus_file(f), FileAccess::READ); - if (!fa) { - add_message(EXPORT_MESSAGE_ERROR, TTR("ZIP Creation"), vformat(TTR("Could not open file to read from path \"%s\"."), dir.plus_file(f))); - return; - } - - const int bufsize = 16384; - uint8_t buf[bufsize]; - - while (true) { - uint64_t got = fa->get_buffer(buf, bufsize); - if (got == 0) { - break; - } - zipWriteInFileInZip(p_zip, buf, got); - } - - zipCloseFileInZip(p_zip); - } - - f = da->get_next(); - } - - da->list_dir_end(); - memdelete(da); -} - -bool EditorExportPlatformOSX::has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { - String err; - bool valid = false; - - // Look for export templates (custom templates). - bool dvalid = false; - bool rvalid = false; - - if (p_preset->get("custom_template/debug") != "") { - dvalid = FileAccess::exists(p_preset->get("custom_template/debug")); - if (!dvalid) { - err += TTR("Custom debug template not found.") + "\n"; - } - } - if (p_preset->get("custom_template/release") != "") { - rvalid = FileAccess::exists(p_preset->get("custom_template/release")); - if (!rvalid) { - err += TTR("Custom release template not found.") + "\n"; - } - } - - // Look for export templates (official templates, check only is custom templates are not set). - if (!dvalid || !rvalid) { - dvalid = exists_export_template("osx.zip", &err); - rvalid = dvalid; // Both in the same ZIP. - } - - valid = dvalid || rvalid; - r_missing_templates = !valid; - - if (!err.empty()) { - r_error = err; - } - - return valid; -} - -bool EditorExportPlatformOSX::has_valid_project_configuration(const Ref &p_preset, String &r_error) const { - String err; - bool valid = true; - - String identifier = p_preset->get("application/identifier"); - String pn_err; - if (!is_package_name_valid(identifier, &pn_err)) { - err += TTR("Invalid bundle identifier:") + " " + pn_err + "\n"; - valid = false; - } - - bool ad_hoc = false; - int codesign_tool = p_preset->get("codesign/codesign"); - switch (codesign_tool) { - case 1: { // built-in ad-hoc - ad_hoc = true; - } break; - case 2: { // "rcodesign" - ad_hoc = p_preset->get("codesign/certificate_file").operator String().empty() || p_preset->get("codesign/certificate_password").operator String().empty(); - } break; -#ifdef OSX_ENABLED - case 3: { // "codesign" - ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-"); - } break; -#endif - default: { - }; - } - int notary_tool = p_preset->get("notarization/notarization"); - int dist_type = p_preset->get("export/distribution_type"); - - if (dist_type == 2) { - String pprof = p_preset->get("codesign/provisioning_profile"); - if (pprof == "") { - err += TTR("Provisioning profile is required for App Store distribution.") + "\n"; - valid = false; - } - String ident = p_preset->get("codesign/installer_identity"); - if (ident == "") { - err += TTR("Installer signing identity is required for App Store distribution.") + "\n"; - valid = false; - } - bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled"); - if (!sandbox) { - err += TTR("App sandbox is required for App Store distribution.") + "\n"; - valid = false; - } - if (codesign_tool == 0) { - err += TTR("Code signing is required for App Store distribution.") + "\n"; - valid = false; - } - if (codesign_tool == 1) { - err += TTR("App Store distribution with ad-hoc code signing is not supported.") + "\n"; - valid = false; - } - } - - if (notary_tool > 0) { - if (ad_hoc) { - err += TTR("Notarization: Notarization with an ad-hoc signature is not supported.") + "\n"; - valid = false; - } - if (codesign_tool == 0) { - err += TTR("Notarization: Code signing is required for notarization.") + "\n"; - valid = false; - } - if (notary_tool == 2 || notary_tool == 3) { - if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { - err += TTR("Notarization: Xcode command line tools are not installed.") + "\n"; - valid = false; - } - if (p_preset->get("notarization/apple_id_name") == "" && p_preset->get("notarization/api_uuid") == "") { - err += TTR("Notarization: Neither Apple ID name nor App Store Connect issuer ID name not specified.") + "\n"; - valid = false; - } else if (p_preset->get("notarization/apple_id_name") != "" && p_preset->get("notarization/api_uuid") != "") { - err += TTR("Notarization: Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.") + "\n"; - valid = false; - } else { - if (p_preset->get("notarization/apple_id_name") != "") { - if (p_preset->get("notarization/apple_id_password") == "") { - err += TTR("Notarization: Apple ID password not specified.") + "\n"; - valid = false; - } - } - if (p_preset->get("notarization/api_uuid") != "") { - if (p_preset->get("notarization/api_key") == "") { - err += TTR("Notarization: App Store Connect API key ID not specified.") + "\n"; - valid = false; - } - } - } - } else if (notary_tool == 1) { - if (p_preset->get("notarization/api_uuid") == "") { - err += TTR("Notarization: App Store Connect issuer ID name not specified.") + "\n"; - valid = false; - } - if (p_preset->get("notarization/api_key") == "") { - err += TTR("Notarization: App Store Connect API key ID not specified.") + "\n"; - valid = false; - } - - String rcodesign = EditorSettings::get_singleton()->get("export/macos/rcodesign").operator String(); - if (rcodesign.empty()) { - err += TTR("Notarization: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n"; - valid = false; - } - } - } else if (dist_type != 2) { - err += TTR("Warning: Notarization is disabled. The exported project will be blocked by Gatekeeper if it's downloaded from an unknown source.") + "\n"; - if (codesign_tool == 0) { - err += TTR("Code signing is disabled. The exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n"; - } - } - - if (codesign_tool > 0) { - if (ad_hoc) { - err += TTR("Code signing: Using ad-hoc signature. The exported project will be blocked by Gatekeeper") + "\n"; - } - if (codesign_tool == 3) { - if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) { - err += TTR("Code signing: Xcode command line tools are not installed.") + "\n"; - valid = false; - } - } else if (codesign_tool == 2) { - String rcodesign = EditorSettings::get_singleton()->get("export/macos/rcodesign").operator String(); - if (rcodesign.empty()) { - err += TTR("Code signing: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n"; - valid = false; - } - } - if ((bool)p_preset->get("codesign/entitlements/audio_input") && ((String)p_preset->get("privacy/microphone_usage_description")).empty()) { - err += TTR("Privacy: Microphone access is enabled, but usage description is not specified.") + "\n"; - valid = false; - } - if ((bool)p_preset->get("codesign/entitlements/camera") && ((String)p_preset->get("privacy/camera_usage_description")).empty()) { - err += TTR("Privacy: Camera access is enabled, but usage description is not specified.") + "\n"; - valid = false; - } - if ((bool)p_preset->get("codesign/entitlements/location") && ((String)p_preset->get("privacy/location_usage_description")).empty()) { - err += TTR("Privacy: Location information access is enabled, but usage description is not specified.") + "\n"; - valid = false; - } - if ((bool)p_preset->get("codesign/entitlements/address_book") && ((String)p_preset->get("privacy/address_book_usage_description")).empty()) { - err += TTR("Privacy: Address book access is enabled, but usage description is not specified.") + "\n"; - valid = false; - } - if ((bool)p_preset->get("codesign/entitlements/calendars") && ((String)p_preset->get("privacy/calendar_usage_description")).empty()) { - err += TTR("Privacy: Calendar access is enabled, but usage description is not specified.") + "\n"; - valid = false; - } - if ((bool)p_preset->get("codesign/entitlements/photos_library") && ((String)p_preset->get("privacy/photos_library_usage_description")).empty()) { - err += TTR("Privacy: Photo library access is enabled, but usage description is not specified.") + "\n"; - valid = false; - } - } - - if (!err.empty()) { - r_error = err; - } - return valid; -} - -EditorExportPlatformOSX::EditorExportPlatformOSX() { - Ref img = memnew(Image(_osx_logo)); - logo.instance(); - logo->create_from_image(img); -} - -EditorExportPlatformOSX::~EditorExportPlatformOSX() { -} - -void register_osx_exporter() { - EDITOR_DEF("export/macos/rcodesign", ""); -#ifdef WINDOWS_ENABLED - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/macos/rcodesign", PROPERTY_HINT_GLOBAL_FILE, "*.exe")); -#else - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/macos/rcodesign", PROPERTY_HINT_GLOBAL_FILE)); -#endif - - Ref platform; - platform.instance(); - - EditorExport::get_singleton()->add_export_platform(platform); -} diff --git a/platform/osx/export/export.h b/platform/osx/export/export.h deleted file mode 100644 index b386337..0000000 --- a/platform/osx/export/export.h +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************/ -/* export.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef OSX_EXPORT_H -#define OSX_EXPORT_H - -void register_osx_exporter(); - -#endif // OSX_EXPORT_H diff --git a/platform/osx/export/lipo.cpp b/platform/osx/export/lipo.cpp deleted file mode 100644 index fc9c990..0000000 --- a/platform/osx/export/lipo.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/*************************************************************************/ -/* lipo.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "lipo.h" - -#include "modules/modules_enabled.gen.h" // For regex. - -#ifdef MODULE_REGEX_ENABLED - -bool LipO::is_lipo(const String &p_path) { - FileAccessRef fb = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!fb, false, vformat("LipO: Can't open file: \"%s\".", p_path)); - uint32_t magic = fb->get_32(); - return (magic == 0xbebafeca || magic == 0xcafebabe || magic == 0xbfbafeca || magic == 0xcafebabf); -} - -bool LipO::create_file(const String &p_output_path, const PoolStringArray &p_files) { - close(); - - fa = FileAccess::open(p_output_path, FileAccess::WRITE); - ERR_FAIL_COND_V_MSG(!fa, false, vformat("LipO: Can't open file: \"%s\".", p_output_path)); - - uint64_t max_size = 0; - for (int i = 0; i < p_files.size(); i++) { - MachO mh; - if (!mh.open_file(p_files[i])) { - ERR_FAIL_V_MSG(false, vformat("LipO: Can't open file: \"%s\".", p_files[i])); - } - - FatArch arch; - arch.cputype = mh.get_cputype(); - arch.cpusubtype = mh.get_cpusubtype(); - arch.offset = 0; - arch.size = mh.get_size(); - arch.align = mh.get_align(); - max_size += arch.size; - - archs.push_back(arch); - - FileAccessRef fb = FileAccess::open(p_files[i], FileAccess::READ); - if (!fb) { - close(); - ERR_FAIL_V_MSG(false, vformat("LipO: Can't open file: \"%s\".", p_files[i])); - } - } - - // Write header. - bool is_64 = (max_size >= std::numeric_limits::max()); - if (is_64) { - fa->store_32(0xbfbafeca); - } else { - fa->store_32(0xbebafeca); - } - fa->store_32(BSWAP32(archs.size())); - uint64_t offset = archs.size() * (is_64 ? 32 : 20) + 8; - for (int i = 0; i < archs.size(); i++) { - archs.write[i].offset = offset + PAD(offset, uint64_t(1) << archs[i].align); - if (is_64) { - fa->store_32(BSWAP32(archs[i].cputype)); - fa->store_32(BSWAP32(archs[i].cpusubtype)); - fa->store_64(BSWAP64(archs[i].offset)); - fa->store_64(BSWAP64(archs[i].size)); - fa->store_32(BSWAP32(archs[i].align)); - fa->store_32(0); - } else { - fa->store_32(BSWAP32(archs[i].cputype)); - fa->store_32(BSWAP32(archs[i].cpusubtype)); - fa->store_32(BSWAP32(archs[i].offset)); - fa->store_32(BSWAP32(archs[i].size)); - fa->store_32(BSWAP32(archs[i].align)); - } - offset = archs[i].offset + archs[i].size; - } - - // Write files and padding. - for (int i = 0; i < archs.size(); i++) { - FileAccessRef fb = FileAccess::open(p_files[i], FileAccess::READ); - if (!fb) { - close(); - ERR_FAIL_V_MSG(false, vformat("LipO: Can't open file: \"%s\".", p_files[i])); - } - uint64_t cur = fa->get_position(); - for (uint64_t j = cur; j < archs[i].offset; j++) { - fa->store_8(0); - } - int pages = archs[i].size / 4096; - int remain = archs[i].size % 4096; - unsigned char step[4096]; - for (int j = 0; j < pages; j++) { - uint64_t br = fb->get_buffer(step, 4096); - if (br > 0) { - fa->store_buffer(step, br); - } - } - uint64_t br = fb->get_buffer(step, remain); - if (br > 0) { - fa->store_buffer(step, br); - } - fb->close(); - } - return true; -} - -bool LipO::open_file(const String &p_path) { - close(); - - fa = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!fa, false, vformat("LipO: Can't open file: \"%s\".", p_path)); - - uint32_t magic = fa->get_32(); - if (magic == 0xbebafeca) { - // 32-bit fat binary, bswap. - uint32_t nfat_arch = BSWAP32(fa->get_32()); - for (uint32_t i = 0; i < nfat_arch; i++) { - FatArch arch; - arch.cputype = BSWAP32(fa->get_32()); - arch.cpusubtype = BSWAP32(fa->get_32()); - arch.offset = BSWAP32(fa->get_32()); - arch.size = BSWAP32(fa->get_32()); - arch.align = BSWAP32(fa->get_32()); - - archs.push_back(arch); - } - } else if (magic == 0xcafebabe) { - // 32-bit fat binary. - uint32_t nfat_arch = fa->get_32(); - for (uint32_t i = 0; i < nfat_arch; i++) { - FatArch arch; - arch.cputype = fa->get_32(); - arch.cpusubtype = fa->get_32(); - arch.offset = fa->get_32(); - arch.size = fa->get_32(); - arch.align = fa->get_32(); - - archs.push_back(arch); - } - } else if (magic == 0xbfbafeca) { - // 64-bit fat binary, bswap. - uint32_t nfat_arch = BSWAP32(fa->get_32()); - for (uint32_t i = 0; i < nfat_arch; i++) { - FatArch arch; - arch.cputype = BSWAP32(fa->get_32()); - arch.cpusubtype = BSWAP32(fa->get_32()); - arch.offset = BSWAP64(fa->get_64()); - arch.size = BSWAP64(fa->get_64()); - arch.align = BSWAP32(fa->get_32()); - fa->get_32(); // Skip, reserved. - - archs.push_back(arch); - } - } else if (magic == 0xcafebabf) { - // 64-bit fat binary. - uint32_t nfat_arch = fa->get_32(); - for (uint32_t i = 0; i < nfat_arch; i++) { - FatArch arch; - arch.cputype = fa->get_32(); - arch.cpusubtype = fa->get_32(); - arch.offset = fa->get_64(); - arch.size = fa->get_64(); - arch.align = fa->get_32(); - fa->get_32(); // Skip, reserved. - - archs.push_back(arch); - } - } else { - close(); - ERR_FAIL_V_MSG(false, vformat("LipO: Invalid fat binary: \"%s\".", p_path)); - } - return true; -} - -int LipO::get_arch_count() const { - ERR_FAIL_COND_V_MSG(!fa, 0, "LipO: File not opened."); - return archs.size(); -} - -bool LipO::extract_arch(int p_index, const String &p_path) { - ERR_FAIL_COND_V_MSG(!fa, false, "LipO: File not opened."); - ERR_FAIL_INDEX_V(p_index, archs.size(), false); - - FileAccessRef fb = FileAccess::open(p_path, FileAccess::WRITE); - ERR_FAIL_COND_V_MSG(!fb, false, vformat("LipO: Can't open file: \"%s\".", p_path)); - - fa->seek(archs[p_index].offset); - - int pages = archs[p_index].size / 4096; - int remain = archs[p_index].size % 4096; - unsigned char step[4096]; - for (int i = 0; i < pages; i++) { - uint64_t br = fa->get_buffer(step, 4096); - if (br > 0) { - fb->store_buffer(step, br); - } - } - uint64_t br = fa->get_buffer(step, remain); - if (br > 0) { - fb->store_buffer(step, br); - } - fb->close(); - return true; -} - -void LipO::close() { - if (fa) { - fa->close(); - memdelete(fa); - fa = nullptr; - } - archs.clear(); -} - -LipO::~LipO() { - close(); -} - -#endif // MODULE_REGEX_ENABLED diff --git a/platform/osx/export/lipo.h b/platform/osx/export/lipo.h deleted file mode 100644 index 276867c..0000000 --- a/platform/osx/export/lipo.h +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************/ -/* lipo.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -// Universal / Universal 2 fat binary file creator and extractor. - -#ifndef LIPO_H -#define LIPO_H - -#include "core/os/file_access.h" -#include "core/object/reference.h" -#include "modules/modules_enabled.gen.h" // For regex. - -#include "macho.h" - -#ifdef MODULE_REGEX_ENABLED - -class LipO : public Reference { - struct FatArch { - uint32_t cputype; - uint32_t cpusubtype; - uint64_t offset; - uint64_t size; - uint32_t align; - }; - - FileAccess *fa = nullptr; - Vector archs; - - static inline size_t PAD(size_t s, size_t a) { - return (a - s % a); - } - -public: - static bool is_lipo(const String &p_path); - - bool create_file(const String &p_output_path, const PoolStringArray &p_files); - - bool open_file(const String &p_path); - int get_arch_count() const; - bool extract_arch(int p_index, const String &p_path); - - void close(); - - ~LipO(); -}; - -#endif // MODULE_REGEX_ENABLED - -#endif // LIPO_H diff --git a/platform/osx/export/macho.cpp b/platform/osx/export/macho.cpp deleted file mode 100644 index 9b76076..0000000 --- a/platform/osx/export/macho.cpp +++ /dev/null @@ -1,556 +0,0 @@ -/*************************************************************************/ -/* macho.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "macho.h" - -#include "modules/modules_enabled.gen.h" // For regex. - -#ifdef MODULE_REGEX_ENABLED - -uint32_t MachO::seg_align(uint64_t p_vmaddr, uint32_t p_min, uint32_t p_max) { - uint32_t align = p_max; - if (p_vmaddr != 0) { - uint64_t seg_align = 1; - align = 0; - while ((seg_align & p_vmaddr) == 0) { - seg_align = seg_align << 1; - align++; - } - align = CLAMP(align, p_min, p_max); - } - return align; -} - -bool MachO::alloc_signature(uint64_t p_size) { - ERR_FAIL_COND_V_MSG(!fa, false, "MachO: File not opened."); - if (signature_offset != 0) { - // Nothing to do, already have signature load command. - return true; - } - if (lc_limit == 0 || lc_limit + 16 > exe_base) { - ERR_FAIL_V_MSG(false, "MachO: Can't allocate signature load command, please use \"codesign_allocate\" utility first."); - } else { - // Add signature load command. - signature_offset = lc_limit; - - fa->seek(lc_limit); - LoadCommandHeader lc; - lc.cmd = LC_CODE_SIGNATURE; - lc.cmdsize = 16; - if (swap) { - lc.cmdsize = BSWAP32(lc.cmdsize); - } - fa->store_buffer((const uint8_t *)&lc, sizeof(LoadCommandHeader)); - - uint32_t lc_offset = fa->get_len() + PAD(fa->get_len(), 16); - uint32_t lc_size = 0; - if (swap) { - lc_offset = BSWAP32(lc_offset); - lc_size = BSWAP32(lc_size); - } - fa->store_32(lc_offset); - fa->store_32(lc_size); - - // Write new command number. - fa->seek(0x10); - uint32_t ncmds = fa->get_32(); - uint32_t cmdssize = fa->get_32(); - if (swap) { - ncmds = BSWAP32(ncmds); - cmdssize = BSWAP32(cmdssize); - } - ncmds += 1; - cmdssize += 16; - if (swap) { - ncmds = BSWAP32(ncmds); - cmdssize = BSWAP32(cmdssize); - } - fa->seek(0x10); - fa->store_32(ncmds); - fa->store_32(cmdssize); - - lc_limit = lc_limit + sizeof(LoadCommandHeader) + 8; - - return true; - } -} - -bool MachO::is_macho(const String &p_path) { - FileAccessRef fb = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!fb, false, vformat("MachO: Can't open file: \"%s\".", p_path)); - uint32_t magic = fb->get_32(); - return (magic == 0xcefaedfe || magic == 0xfeedface || magic == 0xcffaedfe || magic == 0xfeedfacf); -} - -bool MachO::open_file(const String &p_path) { - fa = FileAccess::open(p_path, FileAccess::READ_WRITE); - ERR_FAIL_COND_V_MSG(!fa, false, vformat("MachO: Can't open file: \"%s\".", p_path)); - uint32_t magic = fa->get_32(); - MachHeader mach_header; - - // Read MachO header. - swap = (magic == 0xcffaedfe || magic == 0xcefaedfe); - 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(false, vformat("MachO: File is not a valid MachO binary: \"%s\".", p_path)); - } - - if (swap) { - mach_header.ncmds = BSWAP32(mach_header.ncmds); - mach_header.cpusubtype = BSWAP32(mach_header.cpusubtype); - mach_header.cputype = BSWAP32(mach_header.cputype); - } - cpusubtype = mach_header.cpusubtype; - cputype = mach_header.cputype; - align = 0; - exe_base = std::numeric_limits::max(); - exe_limit = 0; - lc_limit = 0; - link_edit_offset = 0; - signature_offset = 0; - - // Read load commands. - for (uint32_t i = 0; i < mach_header.ncmds; i++) { - LoadCommandHeader lc; - fa->get_buffer((uint8_t *)&lc, sizeof(LoadCommandHeader)); - if (swap) { - lc.cmd = BSWAP32(lc.cmd); - lc.cmdsize = BSWAP32(lc.cmdsize); - } - uint64_t ps = fa->get_position(); - switch (lc.cmd) { - case LC_SEGMENT: { - LoadCommandSegment lc_seg; - fa->get_buffer((uint8_t *)&lc_seg, sizeof(LoadCommandSegment)); - if (swap) { - lc_seg.nsects = BSWAP32(lc_seg.nsects); - lc_seg.vmaddr = BSWAP32(lc_seg.vmaddr); - lc_seg.vmsize = BSWAP32(lc_seg.vmsize); - } - align = MAX(align, seg_align(lc_seg.vmaddr, 2, 15)); - if (String(lc_seg.segname) == "__TEXT") { - exe_limit = MAX(exe_limit, lc_seg.vmsize); - for (uint32_t j = 0; j < lc_seg.nsects; j++) { - Section lc_sect; - fa->get_buffer((uint8_t *)&lc_sect, sizeof(Section)); - if (String(lc_sect.sectname) == "__text") { - if (swap) { - exe_base = MIN(exe_base, BSWAP32(lc_sect.offset)); - } else { - exe_base = MIN(exe_base, lc_sect.offset); - } - } - if (swap) { - align = MAX(align, BSWAP32(lc_sect.align)); - } else { - align = MAX(align, lc_sect.align); - } - } - } else if (String(lc_seg.segname) == "__LINKEDIT") { - link_edit_offset = ps - 8; - } - } break; - case LC_SEGMENT_64: { - LoadCommandSegment64 lc_seg; - fa->get_buffer((uint8_t *)&lc_seg, sizeof(LoadCommandSegment64)); - if (swap) { - lc_seg.nsects = BSWAP32(lc_seg.nsects); - lc_seg.vmaddr = BSWAP64(lc_seg.vmaddr); - lc_seg.vmsize = BSWAP64(lc_seg.vmsize); - } - align = MAX(align, seg_align(lc_seg.vmaddr, 3, 15)); - if (String(lc_seg.segname) == "__TEXT") { - exe_limit = MAX(exe_limit, lc_seg.vmsize); - for (uint32_t j = 0; j < lc_seg.nsects; j++) { - Section64 lc_sect; - fa->get_buffer((uint8_t *)&lc_sect, sizeof(Section64)); - if (String(lc_sect.sectname) == "__text") { - if (swap) { - exe_base = MIN(exe_base, BSWAP32(lc_sect.offset)); - } else { - exe_base = MIN(exe_base, lc_sect.offset); - } - if (swap) { - align = MAX(align, BSWAP32(lc_sect.align)); - } else { - align = MAX(align, lc_sect.align); - } - } - } - } else if (String(lc_seg.segname) == "__LINKEDIT") { - link_edit_offset = ps - 8; - } - } break; - case LC_CODE_SIGNATURE: { - signature_offset = ps - 8; - } break; - default: { - } break; - } - fa->seek(ps + lc.cmdsize - 8); - lc_limit = ps + lc.cmdsize - 8; - } - - if (exe_limit == 0 || lc_limit == 0) { - ERR_FAIL_V_MSG(false, vformat("MachO: No load commands or executable code found: \"%s\".", p_path)); - } - - return true; -} - -uint64_t MachO::get_exe_base() { - ERR_FAIL_COND_V_MSG(!fa, 0, "MachO: File not opened."); - return exe_base; -} - -uint64_t MachO::get_exe_limit() { - ERR_FAIL_COND_V_MSG(!fa, 0, "MachO: File not opened."); - return exe_limit; -} - -int32_t MachO::get_align() { - ERR_FAIL_COND_V_MSG(!fa, 0, "MachO: File not opened."); - return align; -} - -uint32_t MachO::get_cputype() { - ERR_FAIL_COND_V_MSG(!fa, 0, "MachO: File not opened."); - return cputype; -} - -uint32_t MachO::get_cpusubtype() { - ERR_FAIL_COND_V_MSG(!fa, 0, "MachO: File not opened."); - return cpusubtype; -} - -uint64_t MachO::get_size() { - ERR_FAIL_COND_V_MSG(!fa, 0, "MachO: File not opened."); - return fa->get_len(); -} - -uint64_t MachO::get_signature_offset() { - ERR_FAIL_COND_V_MSG(!fa, 0, "MachO: File not opened."); - ERR_FAIL_COND_V_MSG(signature_offset == 0, 0, "MachO: No signature load command."); - - fa->seek(signature_offset + 8); - if (swap) { - return BSWAP32(fa->get_32()); - } else { - return fa->get_32(); - } -} - -uint64_t MachO::get_code_limit() { - ERR_FAIL_COND_V_MSG(!fa, 0, "MachO: File not opened."); - - if (signature_offset == 0) { - return fa->get_len() + PAD(fa->get_len(), 16); - } else { - return get_signature_offset(); - } -} - -uint64_t MachO::get_signature_size() { - ERR_FAIL_COND_V_MSG(!fa, 0, "MachO: File not opened."); - ERR_FAIL_COND_V_MSG(signature_offset == 0, 0, "MachO: No signature load command."); - - fa->seek(signature_offset + 12); - if (swap) { - return BSWAP32(fa->get_32()); - } else { - return fa->get_32(); - } -} - -bool MachO::is_signed() { - ERR_FAIL_COND_V_MSG(!fa, false, "MachO: File not opened."); - if (signature_offset == 0) { - return false; - } - - fa->seek(get_signature_offset()); - uint32_t magic = BSWAP32(fa->get_32()); - if (magic != 0xfade0cc0) { - return false; // No SuperBlob found. - } - fa->get_32(); // Skip size field, unused. - uint32_t count = BSWAP32(fa->get_32()); - for (uint32_t i = 0; i < count; i++) { - uint32_t index_type = BSWAP32(fa->get_32()); - uint32_t offset = BSWAP32(fa->get_32()); - if (index_type == 0x00000000) { // CodeDirectory index type. - fa->seek(get_signature_offset() + offset + 12); - uint32_t flags = BSWAP32(fa->get_32()); - if (flags & 0x20000) { - return false; // Found CD, linker-signed. - } else { - return true; // Found CD, not linker-signed. - } - } - } - return false; // No CD found. -} - -PoolByteArray MachO::get_cdhash_sha1() { - ERR_FAIL_COND_V_MSG(!fa, PoolByteArray(), "MachO: File not opened."); - if (signature_offset == 0) { - return PoolByteArray(); - } - - fa->seek(get_signature_offset()); - uint32_t magic = BSWAP32(fa->get_32()); - if (magic != 0xfade0cc0) { - return PoolByteArray(); // No SuperBlob found. - } - fa->get_32(); // Skip size field, unused. - uint32_t count = BSWAP32(fa->get_32()); - for (uint32_t i = 0; i < count; i++) { - fa->get_32(); // Index type, skip. - uint32_t offset = BSWAP32(fa->get_32()); - uint64_t pos = fa->get_position(); - - fa->seek(get_signature_offset() + offset); - uint32_t cdmagic = BSWAP32(fa->get_32()); - uint32_t cdsize = BSWAP32(fa->get_32()); - if (cdmagic == 0xfade0c02) { // CodeDirectory. - fa->seek(get_signature_offset() + offset + 36); - uint8_t hash_size = fa->get_8(); - uint8_t hash_type = fa->get_8(); - if (hash_size == 0x14 && hash_type == 0x01) { /* SHA-1 */ - PoolByteArray hash; - hash.resize(0x14); - - fa->seek(get_signature_offset() + offset); - PoolByteArray blob; - blob.resize(cdsize); - fa->get_buffer(blob.write().ptr(), cdsize); - - CryptoCore::SHA1Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; - } - } - fa->seek(pos); - } - return PoolByteArray(); -} - -PoolByteArray MachO::get_cdhash_sha256() { - ERR_FAIL_COND_V_MSG(!fa, PoolByteArray(), "MachO: File not opened."); - if (signature_offset == 0) { - return PoolByteArray(); - } - - fa->seek(get_signature_offset()); - uint32_t magic = BSWAP32(fa->get_32()); - if (magic != 0xfade0cc0) { - return PoolByteArray(); // No SuperBlob found. - } - fa->get_32(); // Skip size field, unused. - uint32_t count = BSWAP32(fa->get_32()); - for (uint32_t i = 0; i < count; i++) { - fa->get_32(); // Index type, skip. - uint32_t offset = BSWAP32(fa->get_32()); - uint64_t pos = fa->get_position(); - - fa->seek(get_signature_offset() + offset); - uint32_t cdmagic = BSWAP32(fa->get_32()); - uint32_t cdsize = BSWAP32(fa->get_32()); - if (cdmagic == 0xfade0c02) { // CodeDirectory. - fa->seek(get_signature_offset() + offset + 36); - uint8_t hash_size = fa->get_8(); - uint8_t hash_type = fa->get_8(); - if (hash_size == 0x20 && hash_type == 0x02) { /* SHA-256 */ - PoolByteArray hash; - hash.resize(0x20); - - fa->seek(get_signature_offset() + offset); - PoolByteArray blob; - blob.resize(cdsize); - fa->get_buffer(blob.write().ptr(), cdsize); - - CryptoCore::SHA256Context ctx; - ctx.start(); - ctx.update(blob.read().ptr(), blob.size()); - ctx.finish(hash.write().ptr()); - - return hash; - } - } - fa->seek(pos); - } - return PoolByteArray(); -} - -PoolByteArray MachO::get_requirements() { - ERR_FAIL_COND_V_MSG(!fa, PoolByteArray(), "MachO: File not opened."); - if (signature_offset == 0) { - return PoolByteArray(); - } - - fa->seek(get_signature_offset()); - uint32_t magic = BSWAP32(fa->get_32()); - if (magic != 0xfade0cc0) { - return PoolByteArray(); // No SuperBlob found. - } - fa->get_32(); // Skip size field, unused. - uint32_t count = BSWAP32(fa->get_32()); - for (uint32_t i = 0; i < count; i++) { - fa->get_32(); // Index type, skip. - uint32_t offset = BSWAP32(fa->get_32()); - uint64_t pos = fa->get_position(); - - fa->seek(get_signature_offset() + offset); - uint32_t rqmagic = BSWAP32(fa->get_32()); - uint32_t rqsize = BSWAP32(fa->get_32()); - if (rqmagic == 0xfade0c01) { // Requirements. - PoolByteArray blob; - fa->seek(get_signature_offset() + offset); - blob.resize(rqsize); - fa->get_buffer(blob.write().ptr(), rqsize); - return blob; - } - fa->seek(pos); - } - return PoolByteArray(); -} - -const FileAccess *MachO::get_file() const { - return fa; -} - -FileAccess *MachO::get_file() { - return fa; -} - -bool MachO::set_signature_size(uint64_t p_size) { - ERR_FAIL_COND_V_MSG(!fa, false, "MachO: File not opened."); - - // Ensure signature load command exists. - ERR_FAIL_COND_V_MSG(link_edit_offset == 0, false, "MachO: No __LINKEDIT segment found."); - ERR_FAIL_COND_V_MSG(!alloc_signature(p_size), false, "MachO: Can't allocate signature load command."); - - // Update signature load command. - uint64_t old_size = get_signature_size(); - uint64_t new_size = p_size + PAD(p_size, 16384); - - if (new_size <= old_size) { - fa->seek(get_signature_offset()); - for (uint64_t i = 0; i < old_size; i++) { - fa->store_8(0x00); - } - return true; - } - - fa->seek(signature_offset + 12); - if (swap) { - fa->store_32(BSWAP32(new_size)); - } else { - fa->store_32(new_size); - } - - uint64_t end = get_signature_offset() + new_size; - - // Update "__LINKEDIT" segment. - LoadCommandHeader lc; - fa->seek(link_edit_offset); - fa->get_buffer((uint8_t *)&lc, sizeof(LoadCommandHeader)); - if (swap) { - lc.cmd = BSWAP32(lc.cmd); - lc.cmdsize = BSWAP32(lc.cmdsize); - } - switch (lc.cmd) { - case LC_SEGMENT: { - LoadCommandSegment lc_seg; - fa->get_buffer((uint8_t *)&lc_seg, sizeof(LoadCommandSegment)); - if (swap) { - lc_seg.vmsize = BSWAP32(lc_seg.vmsize); - lc_seg.filesize = BSWAP32(lc_seg.filesize); - lc_seg.fileoff = BSWAP32(lc_seg.fileoff); - } - - lc_seg.vmsize = end - lc_seg.fileoff; - lc_seg.vmsize += PAD(lc_seg.vmsize, 4096); - lc_seg.filesize = end - lc_seg.fileoff; - - if (swap) { - lc_seg.vmsize = BSWAP32(lc_seg.vmsize); - lc_seg.filesize = BSWAP32(lc_seg.filesize); - } - fa->seek(link_edit_offset + 8); - fa->store_buffer((const uint8_t *)&lc_seg, sizeof(LoadCommandSegment)); - } break; - case LC_SEGMENT_64: { - LoadCommandSegment64 lc_seg; - fa->get_buffer((uint8_t *)&lc_seg, sizeof(LoadCommandSegment64)); - if (swap) { - lc_seg.vmsize = BSWAP64(lc_seg.vmsize); - lc_seg.filesize = BSWAP64(lc_seg.filesize); - lc_seg.fileoff = BSWAP64(lc_seg.fileoff); - } - lc_seg.vmsize = end - lc_seg.fileoff; - lc_seg.vmsize += PAD(lc_seg.vmsize, 4096); - lc_seg.filesize = end - lc_seg.fileoff; - if (swap) { - lc_seg.vmsize = BSWAP64(lc_seg.vmsize); - lc_seg.filesize = BSWAP64(lc_seg.filesize); - } - fa->seek(link_edit_offset + 8); - fa->store_buffer((const uint8_t *)&lc_seg, sizeof(LoadCommandSegment64)); - } break; - default: { - ERR_FAIL_V_MSG(false, "MachO: Invalid __LINKEDIT segment type."); - } break; - } - fa->seek(get_signature_offset()); - for (uint64_t i = 0; i < new_size; i++) { - fa->store_8(0x00); - } - return true; -} - -MachO::~MachO() { - if (fa) { - fa->close(); - memdelete(fa); - fa = nullptr; - } -} - -#endif // MODULE_REGEX_ENABLED diff --git a/platform/osx/export/macho.h b/platform/osx/export/macho.h deleted file mode 100644 index 38a9f53..0000000 --- a/platform/osx/export/macho.h +++ /dev/null @@ -1,217 +0,0 @@ -/*************************************************************************/ -/* macho.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -// Mach-O binary object file format parser and editor. - -#ifndef MACHO_H -#define MACHO_H - -#include "core/crypto/crypto.h" -#include "core/crypto/crypto_core.h" -#include "core/os/file_access.h" -#include "core/object/reference.h" -#include "modules/modules_enabled.gen.h" // For regex. - -#ifdef MODULE_REGEX_ENABLED - -class MachO : public Reference { - struct MachHeader { - uint32_t cputype; - uint32_t cpusubtype; - uint32_t filetype; - uint32_t ncmds; - uint32_t sizeofcmds; - uint32_t flags; - }; - - enum LoadCommandID { - LC_SEGMENT = 0x00000001, - LC_SYMTAB = 0x00000002, - LC_SYMSEG = 0x00000003, - LC_THREAD = 0x00000004, - LC_UNIXTHREAD = 0x00000005, - LC_LOADFVMLIB = 0x00000006, - LC_IDFVMLIB = 0x00000007, - LC_IDENT = 0x00000008, - LC_FVMFILE = 0x00000009, - LC_PREPAGE = 0x0000000a, - LC_DYSYMTAB = 0x0000000b, - LC_LOAD_DYLIB = 0x0000000c, - LC_ID_DYLIB = 0x0000000d, - LC_LOAD_DYLINKER = 0x0000000e, - LC_ID_DYLINKER = 0x0000000f, - LC_PREBOUND_DYLIB = 0x00000010, - LC_ROUTINES = 0x00000011, - LC_SUB_FRAMEWORK = 0x00000012, - LC_SUB_UMBRELLA = 0x00000013, - LC_SUB_CLIENT = 0x00000014, - LC_SUB_LIBRARY = 0x00000015, - LC_TWOLEVEL_HINTS = 0x00000016, - LC_PREBIND_CKSUM = 0x00000017, - LC_LOAD_WEAK_DYLIB = 0x80000018, - LC_SEGMENT_64 = 0x00000019, - LC_ROUTINES_64 = 0x0000001a, - LC_UUID = 0x0000001b, - LC_RPATH = 0x8000001c, - LC_CODE_SIGNATURE = 0x0000001d, - LC_SEGMENT_SPLIT_INFO = 0x0000001e, - LC_REEXPORT_DYLIB = 0x8000001f, - LC_LAZY_LOAD_DYLIB = 0x00000020, - LC_ENCRYPTION_INFO = 0x00000021, - LC_DYLD_INFO = 0x00000022, - LC_DYLD_INFO_ONLY = 0x80000022, - LC_LOAD_UPWARD_DYLIB = 0x80000023, - LC_VERSION_MIN_MACOSX = 0x00000024, - LC_VERSION_MIN_IPHONEOS = 0x00000025, - LC_FUNCTION_STARTS = 0x00000026, - LC_DYLD_ENVIRONMENT = 0x00000027, - LC_MAIN = 0x80000028, - LC_DATA_IN_CODE = 0x00000029, - LC_SOURCE_VERSION = 0x0000002a, - LC_DYLIB_CODE_SIGN_DRS = 0x0000002b, - LC_ENCRYPTION_INFO_64 = 0x0000002c, - LC_LINKER_OPTION = 0x0000002d, - LC_LINKER_OPTIMIZATION_HINT = 0x0000002e, - LC_VERSION_MIN_TVOS = 0x0000002f, - LC_VERSION_MIN_WATCHOS = 0x00000030, - }; - - struct LoadCommandHeader { - uint32_t cmd; - uint32_t cmdsize; - }; - - struct LoadCommandSegment { - char segname[16]; - uint32_t vmaddr; - uint32_t vmsize; - uint32_t fileoff; - uint32_t filesize; - uint32_t maxprot; - uint32_t initprot; - uint32_t nsects; - uint32_t flags; - }; - - struct LoadCommandSegment64 { - char segname[16]; - uint64_t vmaddr; - uint64_t vmsize; - uint64_t fileoff; - uint64_t filesize; - uint32_t maxprot; - uint32_t initprot; - uint32_t nsects; - uint32_t flags; - }; - - struct Section { - char sectname[16]; - char segname[16]; - uint32_t addr; - uint32_t size; - uint32_t offset; - uint32_t align; - uint32_t reloff; - uint32_t nreloc; - uint32_t flags; - uint32_t reserved1; - uint32_t reserved2; - }; - - struct Section64 { - char sectname[16]; - char segname[16]; - uint64_t addr; - uint64_t size; - uint32_t offset; - uint32_t align; - uint32_t reloff; - uint32_t nreloc; - uint32_t flags; - uint32_t reserved1; - uint32_t reserved2; - uint32_t reserved3; - }; - - FileAccess *fa = nullptr; - bool swap = false; - - uint64_t lc_limit = 0; - - uint64_t exe_limit = 0; - uint64_t exe_base = std::numeric_limits::max(); // Start of first __text section. - uint32_t align = 0; - uint32_t cputype = 0; - uint32_t cpusubtype = 0; - - uint64_t link_edit_offset = 0; // __LINKEDIT segment offset. - uint64_t signature_offset = 0; // Load command offset. - - uint32_t seg_align(uint64_t p_vmaddr, uint32_t p_min, uint32_t p_max); - bool alloc_signature(uint64_t p_size); - - static inline size_t PAD(size_t s, size_t a) { - return (a - s % a); - } - -public: - static bool is_macho(const String &p_path); - - bool open_file(const String &p_path); - - uint64_t get_exe_base(); - uint64_t get_exe_limit(); - int32_t get_align(); - uint32_t get_cputype(); - uint32_t get_cpusubtype(); - uint64_t get_size(); - uint64_t get_code_limit(); - - uint64_t get_signature_offset(); - bool is_signed(); - - PoolByteArray get_cdhash_sha1(); - PoolByteArray get_cdhash_sha256(); - - PoolByteArray get_requirements(); - - const FileAccess *get_file() const; - FileAccess *get_file(); - - uint64_t get_signature_size(); - bool set_signature_size(uint64_t p_size); - - ~MachO(); -}; - -#endif // MODULE_REGEX_ENABLED - -#endif // MACHO_H diff --git a/platform/osx/export/plist.cpp b/platform/osx/export/plist.cpp deleted file mode 100644 index 64098d1..0000000 --- a/platform/osx/export/plist.cpp +++ /dev/null @@ -1,570 +0,0 @@ -/*************************************************************************/ -/* plist.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "plist.h" - -#include "modules/modules_enabled.gen.h" // For regex. - -#ifdef MODULE_REGEX_ENABLED - -Ref PListNode::new_array() { - Ref node = memnew(PListNode()); - ERR_FAIL_COND_V(node.is_null(), Ref()); - node->data_type = PList::PLNodeType::PL_NODE_TYPE_ARRAY; - return node; -} - -Ref PListNode::new_dict() { - Ref node = memnew(PListNode()); - ERR_FAIL_COND_V(node.is_null(), Ref()); - node->data_type = PList::PLNodeType::PL_NODE_TYPE_DICT; - return node; -} - -Ref PListNode::new_string(const String &p_string) { - Ref node = memnew(PListNode()); - ERR_FAIL_COND_V(node.is_null(), Ref()); - node->data_type = PList::PLNodeType::PL_NODE_TYPE_STRING; - node->data_string = p_string.utf8(); - return node; -} - -Ref PListNode::new_data(const String &p_string) { - Ref node = memnew(PListNode()); - ERR_FAIL_COND_V(node.is_null(), Ref()); - node->data_type = PList::PLNodeType::PL_NODE_TYPE_DATA; - node->data_string = p_string.utf8(); - return node; -} - -Ref PListNode::new_date(const String &p_string) { - Ref node = memnew(PListNode()); - ERR_FAIL_COND_V(node.is_null(), Ref()); - node->data_type = PList::PLNodeType::PL_NODE_TYPE_DATE; - node->data_string = p_string.utf8(); - return node; -} - -Ref PListNode::new_bool(bool p_bool) { - Ref node = memnew(PListNode()); - ERR_FAIL_COND_V(node.is_null(), Ref()); - node->data_type = PList::PLNodeType::PL_NODE_TYPE_BOOLEAN; - node->data_bool = p_bool; - return node; -} - -Ref PListNode::new_int(int32_t p_int) { - Ref node = memnew(PListNode()); - ERR_FAIL_COND_V(node.is_null(), Ref()); - node->data_type = PList::PLNodeType::PL_NODE_TYPE_INTEGER; - node->data_int = p_int; - return node; -} - -Ref PListNode::new_real(float p_real) { - Ref node = memnew(PListNode()); - ERR_FAIL_COND_V(node.is_null(), Ref()); - node->data_type = PList::PLNodeType::PL_NODE_TYPE_REAL; - node->data_real = p_real; - return node; -} - -bool PListNode::push_subnode(const Ref &p_node, const String &p_key) { - ERR_FAIL_COND_V(p_node.is_null(), false); - if (data_type == PList::PLNodeType::PL_NODE_TYPE_DICT) { - ERR_FAIL_COND_V(p_key.empty(), false); - ERR_FAIL_COND_V(data_dict.has(p_key), false); - data_dict[p_key] = p_node; - return true; - } else if (data_type == PList::PLNodeType::PL_NODE_TYPE_ARRAY) { - data_array.push_back(p_node); - return true; - } else { - ERR_FAIL_V_MSG(false, "PList: Invalid parent node type, should be DICT or ARRAY."); - } -} - -size_t PListNode::get_asn1_size(uint8_t p_len_octets) const { - // Get size of all data, excluding type and size information. - switch (data_type) { - case PList::PLNodeType::PL_NODE_TYPE_NIL: { - return 0; - } break; - case PList::PLNodeType::PL_NODE_TYPE_DATA: - case PList::PLNodeType::PL_NODE_TYPE_DATE: { - ERR_FAIL_V_MSG(0, "PList: DATE and DATA nodes are not supported by ASN.1 serialization."); - } break; - case PList::PLNodeType::PL_NODE_TYPE_STRING: { - return data_string.length(); - } break; - case PList::PLNodeType::PL_NODE_TYPE_BOOLEAN: { - return 1; - } break; - case PList::PLNodeType::PL_NODE_TYPE_INTEGER: - case PList::PLNodeType::PL_NODE_TYPE_REAL: { - return 4; - } break; - case PList::PLNodeType::PL_NODE_TYPE_ARRAY: { - size_t size = 0; - for (int i = 0; i < data_array.size(); i++) { - size += 1 + _asn1_size_len(p_len_octets) + data_array[i]->get_asn1_size(p_len_octets); - } - return size; - } break; - case PList::PLNodeType::PL_NODE_TYPE_DICT: { - size_t size = 0; - for (const RBMap>::Element *it = data_dict.front(); it; it = it->next()) { - size += 1 + _asn1_size_len(p_len_octets); // Sequence. - size += 1 + _asn1_size_len(p_len_octets) + it->key().utf8().length(); //Key. - size += 1 + _asn1_size_len(p_len_octets) + it->value()->get_asn1_size(p_len_octets); // Value. - } - return size; - } break; - default: { - return 0; - } break; - } -} - -int PListNode::_asn1_size_len(uint8_t p_len_octets) { - if (p_len_octets > 1) { - return p_len_octets + 1; - } else { - return 1; - } -} - -void PListNode::store_asn1_size(PoolByteArray &p_stream, uint8_t p_len_octets) const { - uint32_t size = get_asn1_size(p_len_octets); - if (p_len_octets > 1) { - p_stream.push_back(0x80 + p_len_octets); - } - for (int i = p_len_octets - 1; i >= 0; i--) { - uint8_t x = (size >> i * 8) & 0xFF; - p_stream.push_back(x); - } -} - -bool PListNode::store_asn1(PoolByteArray &p_stream, uint8_t p_len_octets) const { - // Convert to binary ASN1 stream. - bool valid = true; - switch (data_type) { - case PList::PLNodeType::PL_NODE_TYPE_NIL: { - // Nothing to store. - } break; - case PList::PLNodeType::PL_NODE_TYPE_DATE: - case PList::PLNodeType::PL_NODE_TYPE_DATA: { - ERR_FAIL_V_MSG(false, "PList: DATE and DATA nodes are not supported by ASN.1 serialization."); - } break; - case PList::PLNodeType::PL_NODE_TYPE_STRING: { - p_stream.push_back(0x0C); - store_asn1_size(p_stream, p_len_octets); - for (int i = 0; i < data_string.size(); i++) { - p_stream.push_back(data_string[i]); - } - } break; - case PList::PLNodeType::PL_NODE_TYPE_BOOLEAN: { - p_stream.push_back(0x01); - store_asn1_size(p_stream, p_len_octets); - if (data_bool) { - p_stream.push_back(0x01); - } else { - p_stream.push_back(0x00); - } - } break; - case PList::PLNodeType::PL_NODE_TYPE_INTEGER: { - p_stream.push_back(0x02); - store_asn1_size(p_stream, p_len_octets); - for (int i = 4; i >= 0; i--) { - uint8_t x = (data_int >> i * 8) & 0xFF; - p_stream.push_back(x); - } - } break; - case PList::PLNodeType::PL_NODE_TYPE_REAL: { - p_stream.push_back(0x03); - store_asn1_size(p_stream, p_len_octets); - for (int i = 4; i >= 0; i--) { - uint8_t x = (data_int >> i * 8) & 0xFF; - p_stream.push_back(x); - } - } break; - case PList::PLNodeType::PL_NODE_TYPE_ARRAY: { - p_stream.push_back(0x30); // Sequence. - store_asn1_size(p_stream, p_len_octets); - for (int i = 0; i < data_array.size(); i++) { - valid = valid && data_array[i]->store_asn1(p_stream, p_len_octets); - } - } break; - case PList::PLNodeType::PL_NODE_TYPE_DICT: { - p_stream.push_back(0x31); // Set. - store_asn1_size(p_stream, p_len_octets); - for (const RBMap>::Element *it = data_dict.front(); it; it = it->next()) { - CharString cs = it->key().utf8(); - uint32_t size = cs.length(); - - // Sequence. - p_stream.push_back(0x30); - uint32_t seq_size = 2 * (1 + _asn1_size_len(p_len_octets)) + size + it->value()->get_asn1_size(p_len_octets); - if (p_len_octets > 1) { - p_stream.push_back(0x80 + p_len_octets); - } - for (int i = p_len_octets - 1; i >= 0; i--) { - uint8_t x = (seq_size >> i * 8) & 0xFF; - p_stream.push_back(x); - } - // Key. - p_stream.push_back(0x0C); - if (p_len_octets > 1) { - p_stream.push_back(0x80 + p_len_octets); - } - for (int i = p_len_octets - 1; i >= 0; i--) { - uint8_t x = (size >> i * 8) & 0xFF; - p_stream.push_back(x); - } - for (uint32_t i = 0; i < size; i++) { - p_stream.push_back(cs[i]); - } - // Value. - valid = valid && it->value()->store_asn1(p_stream, p_len_octets); - } - } break; - } - return valid; -} - -void PListNode::store_text(String &p_stream, uint8_t p_indent) const { - // Convert to text XML stream. - switch (data_type) { - case PList::PLNodeType::PL_NODE_TYPE_NIL: { - // Nothing to store. - } break; - case PList::PLNodeType::PL_NODE_TYPE_DATA: { - p_stream += String("\t").repeat(p_indent); - p_stream += "\n"; - p_stream += String("\t").repeat(p_indent); - p_stream += data_string + "\n"; - p_stream += String("\t").repeat(p_indent); - p_stream += "\n"; - } break; - case PList::PLNodeType::PL_NODE_TYPE_DATE: { - p_stream += String("\t").repeat(p_indent); - p_stream += ""; - p_stream += data_string; - p_stream += "\n"; - } break; - case PList::PLNodeType::PL_NODE_TYPE_STRING: { - p_stream += String("\t").repeat(p_indent); - p_stream += ""; - p_stream += String::utf8(data_string); - p_stream += "\n"; - } break; - case PList::PLNodeType::PL_NODE_TYPE_BOOLEAN: { - p_stream += String("\t").repeat(p_indent); - if (data_bool) { - p_stream += "\n"; - } else { - p_stream += "\n"; - } - } break; - case PList::PLNodeType::PL_NODE_TYPE_INTEGER: { - p_stream += String("\t").repeat(p_indent); - p_stream += ""; - p_stream += itos(data_int); - p_stream += "\n"; - } break; - case PList::PLNodeType::PL_NODE_TYPE_REAL: { - p_stream += String("\t").repeat(p_indent); - p_stream += ""; - p_stream += rtos(data_real); - p_stream += "\n"; - } break; - case PList::PLNodeType::PL_NODE_TYPE_ARRAY: { - p_stream += String("\t").repeat(p_indent); - p_stream += "\n"; - for (int i = 0; i < data_array.size(); i++) { - data_array[i]->store_text(p_stream, p_indent + 1); - } - p_stream += String("\t").repeat(p_indent); - p_stream += "\n"; - } break; - case PList::PLNodeType::PL_NODE_TYPE_DICT: { - p_stream += String("\t").repeat(p_indent); - p_stream += "\n"; - for (const RBMap>::Element *it = data_dict.front(); it; it = it->next()) { - p_stream += String("\t").repeat(p_indent + 1); - p_stream += ""; - p_stream += it->key(); - p_stream += "\n"; - it->value()->store_text(p_stream, p_indent + 1); - } - p_stream += String("\t").repeat(p_indent); - p_stream += "\n"; - } break; - } -} - -/*************************************************************************/ - -PList::PList() { - root = PListNode::new_dict(); -} - -PList::PList(const String &p_string) { - load_string(p_string); -} - -bool PList::load_file(const String &p_filename) { - root = Ref(); - - FileAccessRef fb = FileAccess::open(p_filename, FileAccess::READ); - if (!fb) { - return false; - } - - unsigned char magic[8]; - fb->get_buffer(magic, 8); - - if (String::utf8((const char *)magic, 8) == "bplist00") { - ERR_FAIL_V_MSG(false, "PList: Binary property lists are not supported."); - } else { - // Load text plist. - Error err; - Vector array = FileAccess::get_file_as_array(p_filename, &err); - ERR_FAIL_COND_V(err != OK, false); - - String ret; - ret.parse_utf8((const char *)array.ptr(), array.size()); - return load_string(ret); - } -} - -bool PList::load_string(const String &p_string) { - root = Ref(); - - int pos = 0; - bool in_plist = false; - bool done_plist = false; - List> stack; - String key; - while (pos >= 0) { - int open_token_s = p_string.find("<", pos); - if (open_token_s == -1) { - ERR_FAIL_V_MSG(false, "PList: Unexpected end of data. No tags found."); - } - int open_token_e = p_string.find(">", open_token_s); - pos = open_token_e; - - String token = p_string.substr(open_token_s + 1, open_token_e - open_token_s - 1); - if (token.empty()) { - ERR_FAIL_V_MSG(false, "PList: Invalid token name."); - } - String value; - if (token[0] == '?' || token[0] == '!') { // Skip and - int end_token_e = p_string.find(">", open_token_s); - pos = end_token_e; - continue; - } - - if (token.find("plist", 0) == 0) { - in_plist = true; - continue; - } - - if (token == "/plist") { - in_plist = false; - done_plist = true; - break; - } - - if (!in_plist) { - ERR_FAIL_V_MSG(false, "PList: Node outside of tag."); - } - - if (token == "dict") { - if (!stack.empty()) { - // Add subnode end enter it. - Ref dict = PListNode::new_dict(); - dict->data_type = PList::PLNodeType::PL_NODE_TYPE_DICT; - if (!stack.back()->get()->push_subnode(dict, key)) { - ERR_FAIL_V_MSG(false, "PList: Can't push subnode, invalid parent type."); - } - stack.push_back(dict); - } else { - // Add root node. - if (!root.is_null()) { - ERR_FAIL_V_MSG(false, "PList: Root node already set."); - } - Ref dict = PListNode::new_dict(); - stack.push_back(dict); - root = dict; - } - continue; - } - - if (token == "/dict") { - // Exit current dict. - if (stack.empty() || stack.back()->get()->data_type != PList::PLNodeType::PL_NODE_TYPE_DICT) { - ERR_FAIL_V_MSG(false, "PList: Mismatched tag."); - } - stack.pop_back(); - continue; - } - - if (token == "array") { - if (!stack.empty()) { - // Add subnode end enter it. - Ref arr = PListNode::new_array(); - if (!stack.back()->get()->push_subnode(arr, key)) { - ERR_FAIL_V_MSG(false, "PList: Can't push subnode, invalid parent type."); - } - stack.push_back(arr); - } else { - // Add root node. - if (!root.is_null()) { - ERR_FAIL_V_MSG(false, "PList: Root node already set."); - } - Ref arr = PListNode::new_array(); - stack.push_back(arr); - root = arr; - } - continue; - } - - if (token == "/array") { - // Exit current array. - if (stack.empty() || stack.back()->get()->data_type != PList::PLNodeType::PL_NODE_TYPE_ARRAY) { - ERR_FAIL_V_MSG(false, "PList: Mismatched tag."); - } - stack.pop_back(); - continue; - } - - if (token[token.length() - 1] == '/') { - token = token.substr(0, token.length() - 1); - } else { - int end_token_s = p_string.find(" tag.", token)); - } - int end_token_e = p_string.find(">", end_token_s); - pos = end_token_e; - String end_token = p_string.substr(end_token_s + 2, end_token_e - end_token_s - 2); - if (end_token != token) { - ERR_FAIL_V_MSG(false, vformat("PList: Mismatched <%s> and <%s> tag pair.", token, end_token)); - } - value = p_string.substr(open_token_e + 1, end_token_s - open_token_e - 1); - } - if (token == "key") { - key = value; - } else { - Ref var = nullptr; - if (token == "true") { - var = PListNode::new_bool(true); - } else if (token == "false") { - var = PListNode::new_bool(false); - } else if (token == "integer") { - var = PListNode::new_int(value.to_int()); - } else if (token == "real") { - var = PListNode::new_real(value.to_float()); - } else if (token == "string") { - var = PListNode::new_string(value); - } else if (token == "data") { - var = PListNode::new_data(value); - } else if (token == "date") { - var = PListNode::new_date(value); - } else { - ERR_FAIL_V_MSG(false, "PList: Invalid value type."); - } - if (stack.empty() || !stack.back()->get()->push_subnode(var, key)) { - ERR_FAIL_V_MSG(false, "PList: Can't push subnode, invalid parent type."); - } - } - } - if (!stack.empty() || !done_plist) { - ERR_FAIL_V_MSG(false, "PList: Unexpected end of data. Root node is not closed."); - } - return true; -} - -PoolByteArray PList::save_asn1() const { - if (root == nullptr) { - ERR_FAIL_V_MSG(PoolByteArray(), "PList: Invalid PList, no root node."); - } - size_t size = root->get_asn1_size(1); - uint8_t len_octets = 0; - if (size < 0x80) { - len_octets = 1; - } else { - size = root->get_asn1_size(2); - if (size < 0xFFFF) { - len_octets = 2; - } else { - size = root->get_asn1_size(3); - if (size < 0xFFFFFF) { - len_octets = 3; - } else { - size = root->get_asn1_size(4); - if (size < 0xFFFFFFFF) { - len_octets = 4; - } else { - ERR_FAIL_V_MSG(PoolByteArray(), "PList: Data is too big for ASN.1 serializer, should be < 4 GiB."); - } - } - } - } - - PoolByteArray ret; - if (!root->store_asn1(ret, len_octets)) { - ERR_FAIL_V_MSG(PoolByteArray(), "PList: ASN.1 serializer error."); - } - return ret; -} - -String PList::save_text() const { - if (root == nullptr) { - ERR_FAIL_V_MSG(String(), "PList: Invalid PList, no root node."); - } - - String ret; - ret += "\n"; - ret += "\n"; - ret += "\n"; - - root->store_text(ret, 0); - - ret += "\n\n"; - return ret; -} - -Ref PList::get_root() { - return root; -} - -#endif // MODULE_REGEX_ENABLED diff --git a/platform/osx/export/plist.h b/platform/osx/export/plist.h deleted file mode 100644 index b7f6096..0000000 --- a/platform/osx/export/plist.h +++ /dev/null @@ -1,116 +0,0 @@ -/*************************************************************************/ -/* plist.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -// Property list file format (application/x-plist) parser, property list ASN-1 serialization. - -#ifndef PLIST_H -#define PLIST_H - -#include "core/crypto/crypto_core.h" -#include "core/os/file_access.h" -#include "modules/modules_enabled.gen.h" // For regex. - -#ifdef MODULE_REGEX_ENABLED - -class PListNode; - -class PList : public Reference { - friend class PListNode; - -public: - enum PLNodeType { - PL_NODE_TYPE_NIL, - PL_NODE_TYPE_STRING, - PL_NODE_TYPE_ARRAY, - PL_NODE_TYPE_DICT, - PL_NODE_TYPE_BOOLEAN, - PL_NODE_TYPE_INTEGER, - PL_NODE_TYPE_REAL, - PL_NODE_TYPE_DATA, - PL_NODE_TYPE_DATE, - }; - -private: - Ref root; - -public: - PList(); - PList(const String &p_string); - - bool load_file(const String &p_filename); - bool load_string(const String &p_string); - - PoolByteArray save_asn1() const; - String save_text() const; - - Ref get_root(); -}; - -/*************************************************************************/ - -class PListNode : public Reference { - static int _asn1_size_len(uint8_t p_len_octets); - -public: - PList::PLNodeType data_type = PList::PLNodeType::PL_NODE_TYPE_NIL; - - CharString data_string; - Vector> data_array; - RBMap> data_dict; - union { - int32_t data_int; - bool data_bool; - float data_real; - }; - - static Ref new_array(); - static Ref new_dict(); - static Ref new_string(const String &p_string); - static Ref new_data(const String &p_string); - static Ref new_date(const String &p_string); - static Ref new_bool(bool p_bool); - static Ref new_int(int32_t p_int); - static Ref new_real(float p_real); - - bool push_subnode(const Ref &p_node, const String &p_key = ""); - - size_t get_asn1_size(uint8_t p_len_octets) const; - - void store_asn1_size(PoolByteArray &p_stream, uint8_t p_len_octets) const; - bool store_asn1(PoolByteArray &p_stream, uint8_t p_len_octets) const; - void store_text(String &p_stream, uint8_t p_indent) const; - - PListNode() {} - ~PListNode() {} -}; - -#endif // MODULE_REGEX_ENABLED - -#endif // PLIST_H diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp deleted file mode 100644 index 0dc7dfc..0000000 --- a/platform/windows/export/export.cpp +++ /dev/null @@ -1,707 +0,0 @@ -/*************************************************************************/ -/* export.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "export.h" - -#include "core/io/image_loader.h" -#include "core/os/file_access.h" -#include "core/os/os.h" -#include "editor/editor_export.h" -#include "editor/editor_node.h" -#include "editor/editor_settings.h" -#include "platform/windows/logo.gen.h" - -#include "core/config/project_settings.h" - -class EditorExportPlatformWindows : public EditorExportPlatformPC { - Error _process_icon(const Ref &p_preset, const String &p_src_path, const String &p_dst_path); - Error _rcedit_add_data(const Ref &p_preset, const String &p_path); - Error _code_sign(const Ref &p_preset, const String &p_path); - -public: - virtual Error export_project(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags = 0); - virtual Error sign_shared_object(const Ref &p_preset, bool p_debug, const String &p_path); - virtual Error modify_template(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags); - virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size); - virtual void get_export_options(List *r_options); - virtual bool get_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const RBMap &p_options) const; - virtual bool has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; - virtual bool has_valid_project_configuration(const Ref &p_preset, String &r_error) const; -}; - -Error EditorExportPlatformWindows::_process_icon(const Ref &p_preset, const String &p_src_path, const String &p_dst_path) { - static const uint8_t icon_size[] = { 16, 32, 48, 64, 128, 0 /*256*/ }; - - struct IconData { - PoolVector data; - uint8_t pal_colors = 0; - uint16_t planes = 0; - uint16_t bpp = 32; - }; - - HashMap images; - Error err; - - if (p_src_path.get_extension() == "ico") { - FileAccess *f = FileAccess::open(p_src_path, FileAccess::READ, &err); - if (err != OK) { - return err; - } - - // Read ICONDIR. - f->get_16(); // Reserved. - uint16_t icon_type = f->get_16(); // Image type: 1 - ICO. - uint16_t icon_count = f->get_16(); // Number of images. - if (icon_type != 1) { - f->close(); - memdelete(f); - - ERR_FAIL_V(ERR_CANT_OPEN); - } - - for (uint16_t i = 0; i < icon_count; i++) { - // Read ICONDIRENTRY. - uint16_t w = f->get_8(); // Width in pixels. - uint16_t h = f->get_8(); // Height in pixels. - uint8_t pal_colors = f->get_8(); // Number of colors in the palette (0 - no palette). - f->get_8(); // Reserved. - uint16_t planes = f->get_16(); // Number of color planes. - uint16_t bpp = f->get_16(); // Bits per pixel. - uint32_t img_size = f->get_32(); // Image data size in bytes. - uint32_t img_offset = f->get_32(); // Image data offset. - if (w != h) { - continue; - } - - // Read image data. - uint64_t prev_offset = f->get_position(); - images[w].pal_colors = pal_colors; - images[w].planes = planes; - images[w].bpp = bpp; - images[w].data.resize(img_size); - PoolVector::Write wr = images[w].data.write(); - f->seek(img_offset); - f->get_buffer(wr.ptr(), img_size); - f->seek(prev_offset); - } - f->close(); - memdelete(f); - } else { - Ref src_image; - src_image.instance(); - err = ImageLoader::load_image(p_src_path, src_image.ptr()); - ERR_FAIL_COND_V(err != OK || src_image->empty(), ERR_CANT_OPEN); - for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) { - int size = (icon_size[i] == 0) ? 256 : icon_size[i]; - - Ref res_image = src_image->duplicate(); - ERR_FAIL_COND_V(res_image.is_null() || res_image->empty(), ERR_CANT_OPEN); - res_image->resize(size, size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int())); - images[icon_size[i]].data = res_image->save_png_to_buffer(); - } - } - - uint16_t valid_icon_count = 0; - for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) { - if (images.has(icon_size[i])) { - valid_icon_count++; - } else { - int size = (icon_size[i] == 0) ? 256 : icon_size[i]; - add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Icon size \"%d\" is missing."), size)); - } - } - ERR_FAIL_COND_V(valid_icon_count == 0, ERR_CANT_OPEN); - - FileAccess *fw = FileAccess::open(p_dst_path, FileAccess::WRITE, &err); - if (err != OK) { - return err; - } - - // Write ICONDIR. - fw->store_16(0); // Reserved. - fw->store_16(1); // Image type: 1 - ICO. - fw->store_16(valid_icon_count); // Number of images. - - // Write ICONDIRENTRY. - uint32_t img_offset = 6 + 16 * valid_icon_count; - for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) { - if (images.has(icon_size[i])) { - const IconData &di = images[icon_size[i]]; - fw->store_8(icon_size[i]); // Width in pixels. - fw->store_8(icon_size[i]); // Height in pixels. - fw->store_8(di.pal_colors); // Number of colors in the palette (0 - no palette). - fw->store_8(0); // Reserved. - fw->store_16(di.planes); // Number of color planes. - fw->store_16(di.bpp); // Bits per pixel. - fw->store_32(di.data.size()); // Image data size in bytes. - fw->store_32(img_offset); // Image data offset. - - img_offset += di.data.size(); - } - } - - // Write image data. - for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) { - if (images.has(icon_size[i])) { - const IconData &di = images[icon_size[i]]; - PoolVector::Read r = di.data.read(); - fw->store_buffer(r.ptr(), di.data.size()); - } - } - fw->close(); - memdelete(fw); - - return OK; -} - -Error EditorExportPlatformWindows::sign_shared_object(const Ref &p_preset, bool p_debug, const String &p_path) { - if (p_preset->get("codesign/enable")) { - return _code_sign(p_preset, p_path); - } else { - return OK; - } -} - -Error EditorExportPlatformWindows::modify_template(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags) { - if (p_preset->get("application/modify_resources")) { - _rcedit_add_data(p_preset, p_path); - } - return OK; -} - -Error EditorExportPlatformWindows::export_project(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags) { - String pck_path = p_path; - if (p_preset->get("binary_format/embed_pck")) { - pck_path = p_path.get_basename() + ".tmp"; - } - - Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, pck_path, p_flags); - if (p_preset->get("codesign/enable") && err == OK) { - _code_sign(p_preset, pck_path); - } - - if (p_preset->get("binary_format/embed_pck") && err == OK) { - DirAccessRef tmp_dir = DirAccess::create_for_path(p_path.get_base_dir()); - err = tmp_dir->rename(pck_path, p_path); - if (err != OK) { - add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to rename temporary file \"%s\"."), pck_path)); - } - } - - return err; -} - -bool EditorExportPlatformWindows::get_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const RBMap &p_options) const { - // This option is not supported by "osslsigncode", used on non-Windows host. - if (!OS::get_singleton()->has_feature("Windows") && p_option == "codesign/identity_type") { - return false; - } - return true; -} - -void EditorExportPlatformWindows::get_export_options(List *r_options) { - EditorExportPlatformPC::get_export_options(r_options); - - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/identity_type", PROPERTY_HINT_ENUM, "Select automatically,Use PKCS12 file (specify *.PFX/*.P12 file),Use certificate store (specify SHA1 hash)"), 0)); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/password"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/timestamp_server_url"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/digest_algorithm", PROPERTY_HINT_ENUM, "SHA1,SHA256"), 1)); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/description"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::POOL_STRING_ARRAY, "codesign/custom_options"), PoolStringArray())); - - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/modify_resources"), true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.ico,*.png,*.webp,*.svg"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4)); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0.0"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0.0"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/company_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_description"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), "")); -} - -Error EditorExportPlatformWindows::_rcedit_add_data(const Ref &p_preset, const String &p_path) { - String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit"); - - if (rcedit_path != String() && !FileAccess::exists(rcedit_path)) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Could not find rcedit executable at \"%s\"."), rcedit_path)); - return ERR_FILE_NOT_FOUND; - } - - if (rcedit_path == String()) { - rcedit_path = "rcedit"; // try to run rcedit from PATH - } - -#ifndef WINDOWS_ENABLED - // On non-Windows we need WINE to run rcedit - String wine_path = EditorSettings::get_singleton()->get("export/windows/wine"); - - if (wine_path != String() && !FileAccess::exists(wine_path)) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Could not find wine executable at \"%s\"."), wine_path)); - return ERR_FILE_NOT_FOUND; - } - - if (wine_path == String()) { - wine_path = "wine"; // try to run wine from PATH - } -#endif - - String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon")); - String tmp_icon_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("_rcedit.ico"); - if (!icon_path.empty()) { - if (_process_icon(p_preset, icon_path, tmp_icon_path) != OK) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Invalid icon file \"%s\"."), icon_path)); - icon_path = String(); - } - } - - String file_verion = p_preset->get("application/file_version"); - String product_version = p_preset->get("application/product_version"); - String company_name = p_preset->get("application/company_name"); - String product_name = p_preset->get("application/product_name"); - String file_description = p_preset->get("application/file_description"); - String copyright = p_preset->get("application/copyright"); - String trademarks = p_preset->get("application/trademarks"); - String comments = p_preset->get("application/comments"); - - List args; - args.push_back(p_path); - if (icon_path != String()) { - args.push_back("--set-icon"); - args.push_back(tmp_icon_path); - } - if (file_verion != String()) { - args.push_back("--set-file-version"); - args.push_back(file_verion); - } - if (product_version != String()) { - args.push_back("--set-product-version"); - args.push_back(product_version); - } - if (company_name != String()) { - args.push_back("--set-version-string"); - args.push_back("CompanyName"); - args.push_back(company_name); - } - if (product_name != String()) { - args.push_back("--set-version-string"); - args.push_back("ProductName"); - args.push_back(product_name); - } - if (file_description != String()) { - args.push_back("--set-version-string"); - args.push_back("FileDescription"); - args.push_back(file_description); - } - if (copyright != String()) { - args.push_back("--set-version-string"); - args.push_back("LegalCopyright"); - args.push_back(copyright); - } - if (trademarks != String()) { - args.push_back("--set-version-string"); - args.push_back("LegalTrademarks"); - args.push_back(trademarks); - } - -#ifndef WINDOWS_ENABLED - // On non-Windows we need WINE to run rcedit - args.push_front(rcedit_path); - rcedit_path = wine_path; -#endif - - String str; - Error err = OS::get_singleton()->execute(rcedit_path, args, true, nullptr, &str, nullptr, true); - - if (FileAccess::exists(tmp_icon_path)) { - DirAccess::remove_file_or_error(tmp_icon_path); - } - - if (err != OK || (str.find("not found") != -1) || (str.find("not recognized") != -1)) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), TTR("Could not start rcedit executable. Configure rcedit path in the Editor Settings (Export > Windows > rcedit), or disable \"Application > Modify Resources\" in the export preset.")); - return err; - } - - print_line("rcedit (" + p_path + "): " + str); - - if (str.find("Fatal error") != -1) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("rcedit failed to modify executable: %s."), str)); - return FAILED; - } - - return OK; -} - -Error EditorExportPlatformWindows::_code_sign(const Ref &p_preset, const String &p_path) { - List args; - -#ifdef WINDOWS_ENABLED - String signtool_path = EditorSettings::get_singleton()->get("export/windows/signtool"); - if (signtool_path != String() && !FileAccess::exists(signtool_path)) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start signtool executable. Configure signtool path in the Editor Settings (Export > Windows > Signtool), or disable \"Codesign\" in the export preset.")); - return ERR_FILE_NOT_FOUND; - } - if (signtool_path == String()) { - signtool_path = "signtool"; // try to run signtool from PATH - } -#else - String signtool_path = EditorSettings::get_singleton()->get("export/windows/osslsigncode"); - if (signtool_path != String() && !FileAccess::exists(signtool_path)) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Could not find osslsigncode executable at \"%s\"."), signtool_path)); - return ERR_FILE_NOT_FOUND; - } - if (signtool_path == String()) { - signtool_path = "osslsigncode"; // try to run signtool from PATH - } -#endif - - args.push_back("sign"); - - //identity -#ifdef WINDOWS_ENABLED - int id_type = p_preset->get("codesign/identity_type"); - if (id_type == 0) { //auto select - args.push_back("/a"); - } else if (id_type == 1) { //pkcs12 - if (p_preset->get("codesign/identity") != "") { - args.push_back("/f"); - args.push_back(p_preset->get("codesign/identity")); - } else { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found.")); - return FAILED; - } - } else if (id_type == 2) { //Windows certificate store - if (p_preset->get("codesign/identity") != "") { - args.push_back("/sha1"); - args.push_back(p_preset->get("codesign/identity")); - } else { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found.")); - return FAILED; - } - } else { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Invalid identity type.")); - return FAILED; - } -#else - if (p_preset->get("codesign/identity") != "") { - args.push_back("-pkcs12"); - args.push_back(p_preset->get("codesign/identity")); - } else { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found.")); - return FAILED; - } -#endif - - //password - if (p_preset->get("codesign/password") != "") { -#ifdef WINDOWS_ENABLED - args.push_back("/p"); -#else - args.push_back("-pass"); -#endif - args.push_back(p_preset->get("codesign/password")); - } - - //timestamp - if (p_preset->get("codesign/timestamp")) { - if (p_preset->get("codesign/timestamp_server") != "") { -#ifdef WINDOWS_ENABLED - args.push_back("/tr"); - args.push_back(p_preset->get("codesign/timestamp_server_url")); - args.push_back("/td"); - if ((int)p_preset->get("codesign/digest_algorithm") == 0) { - args.push_back("sha1"); - } else { - args.push_back("sha256"); - } -#else - args.push_back("-ts"); - args.push_back(p_preset->get("codesign/timestamp_server_url")); -#endif - } else { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Invalid timestamp server.")); - return FAILED; - } - } - - //digest -#ifdef WINDOWS_ENABLED - args.push_back("/fd"); -#else - args.push_back("-h"); -#endif - if ((int)p_preset->get("codesign/digest_algorithm") == 0) { - args.push_back("sha1"); - } else { - args.push_back("sha256"); - } - - //description - if (p_preset->get("codesign/description") != "") { -#ifdef WINDOWS_ENABLED - args.push_back("/d"); -#else - args.push_back("-n"); -#endif - args.push_back(p_preset->get("codesign/description")); - } - - //user options - PoolStringArray user_args = p_preset->get("codesign/custom_options"); - for (int i = 0; i < user_args.size(); i++) { - String user_arg = user_args[i].strip_edges(); - if (!user_arg.empty()) { - args.push_back(user_arg); - } - } - -#ifndef WINDOWS_ENABLED - args.push_back("-in"); -#endif - args.push_back(p_path); -#ifndef WINDOWS_ENABLED - args.push_back("-out"); - args.push_back(p_path + "_signed"); -#endif - - String str; - Error err = OS::get_singleton()->execute(signtool_path, args, true, nullptr, &str, nullptr, true); - if (err != OK || (str.find("not found") != -1) || (str.find("not recognized") != -1)) { -#ifndef WINDOWS_ENABLED - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start signtool executable. Configure signtool path in the Editor Settings (Export > Windows > signtool), or disable \"Codesign\" in the export preset.")); -#else - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start osslsigncode executable. Configure signtool path in the Editor Settings (Export > Windows > osslsigncode), or disable \"Codesign\" in the export preset.")); -#endif - return err; - } - - print_line("codesign (" + p_path + "): " + str); -#ifndef WINDOWS_ENABLED - if (str.find("SignTool Error") != -1) { -#else - if (str.find("Failed") != -1) { -#endif - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Signtool failed to sign executable: %s."), str)); - return FAILED; - } - -#ifndef WINDOWS_ENABLED - DirAccessRef tmp_dir = DirAccess::create_for_path(p_path.get_base_dir()); - - err = tmp_dir->remove(p_path); - if (err != OK) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Failed to remove temporary file \"%s\"."), p_path)); - return err; - } - - err = tmp_dir->rename(p_path + "_signed", p_path); - if (err != OK) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Failed to rename temporary file \"%s\"."), p_path + "_signed")); - return err; - } -#endif - - return OK; -} - -bool EditorExportPlatformWindows::has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { - String err = ""; - bool valid = EditorExportPlatformPC::has_valid_export_configuration(p_preset, err, r_missing_templates); - - String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit"); - if (p_preset->get("application/modify_resources") && rcedit_path.empty()) { - err += TTR("The rcedit tool must be configured in the Editor Settings (Export > Windows > rcedit) to change the icon or app information data.") + "\n"; - } - - if (!err.empty()) { - r_error = err; - } - - return valid; -} - -bool EditorExportPlatformWindows::has_valid_project_configuration(const Ref &p_preset, String &r_error) const { - String err = ""; - bool valid = true; - - String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon")); - if (!icon_path.empty() && !FileAccess::exists(icon_path)) { - err += TTR("Invalid icon path:") + " " + icon_path + "\n"; - } - - // Only non-negative integers can exist in the version string. - - String file_version = p_preset->get("application/file_version"); - if (!file_version.empty()) { - Vector version_array = file_version.split(".", false); - if (version_array.size() != 4 || !version_array[0].is_valid_integer() || - !version_array[1].is_valid_integer() || !version_array[2].is_valid_integer() || - !version_array[3].is_valid_integer() || file_version.find("-") > -1) { - err += TTR("Invalid file version:") + " " + file_version + "\n"; - } - } - - String product_version = p_preset->get("application/product_version"); - if (!product_version.empty()) { - Vector version_array = product_version.split(".", false); - if (version_array.size() != 4 || !version_array[0].is_valid_integer() || - !version_array[1].is_valid_integer() || !version_array[2].is_valid_integer() || - !version_array[3].is_valid_integer() || product_version.find("-") > -1) { - err += TTR("Invalid product version:") + " " + product_version + "\n"; - } - } - - if (!err.empty()) { - r_error = err; - } - - return valid; -} - -Error EditorExportPlatformWindows::fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) { - // Patch the header of the "pck" section in the PE file so that it corresponds to the embedded data - - if (p_embedded_size + p_embedded_start >= 0x100000000) { // Check for total executable size - add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Windows executables cannot be >= 4 GiB.")); - return ERR_INVALID_DATA; - } - - FileAccess *f = FileAccess::open(p_path, FileAccess::READ_WRITE); - if (!f) { - add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to open executable file \"%s\"."), p_path)); - return ERR_CANT_OPEN; - } - - // Jump to the PE header and check the magic number - { - f->seek(0x3c); - uint32_t pe_pos = f->get_32(); - - f->seek(pe_pos); - uint32_t magic = f->get_32(); - if (magic != 0x00004550) { - f->close(); - add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable file header corrupted.")); - return ERR_FILE_CORRUPT; - } - } - - // Process header - - int num_sections; - { - int64_t header_pos = f->get_position(); - - f->seek(header_pos + 2); - num_sections = f->get_16(); - f->seek(header_pos + 16); - uint16_t opt_header_size = f->get_16(); - - // Skip rest of header + optional header to go to the section headers - f->seek(f->get_position() + 2 + opt_header_size); - } - - // Search for the "pck" section - - int64_t section_table_pos = f->get_position(); - - bool found = false; - for (int i = 0; i < num_sections; ++i) { - int64_t section_header_pos = section_table_pos + i * 40; - f->seek(section_header_pos); - - uint8_t section_name[9]; - f->get_buffer(section_name, 8); - section_name[8] = '\0'; - - if (strcmp((char *)section_name, "pck") == 0) { - // "pck" section found, let's patch! - - // Set virtual size to a little to avoid it taking memory (zero would give issues) - f->seek(section_header_pos + 8); - f->store_32(8); - - f->seek(section_header_pos + 16); - f->store_32(p_embedded_size); - f->seek(section_header_pos + 20); - f->store_32(p_embedded_start); - - found = true; - break; - } - } - - f->close(); - - if (!found) { - add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable \"pck\" section not found.")); - return ERR_FILE_CORRUPT; - } - return OK; -} - -void register_windows_exporter() { -#ifndef ANDROID_ENABLED - EDITOR_DEF("export/windows/rcedit", ""); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/rcedit", PROPERTY_HINT_GLOBAL_FILE, "*.exe")); -#ifdef WINDOWS_ENABLED - EDITOR_DEF("export/windows/signtool", ""); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/signtool", PROPERTY_HINT_GLOBAL_FILE, "*.exe")); -#else - EDITOR_DEF("export/windows/osslsigncode", ""); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/osslsigncode", PROPERTY_HINT_GLOBAL_FILE)); - // On non-Windows we need WINE to run rcedit - EDITOR_DEF("export/windows/wine", ""); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/wine", PROPERTY_HINT_GLOBAL_FILE)); -#endif -#endif - - Ref platform; - platform.instance(); - - Ref img = memnew(Image(_windows_logo)); - Ref logo; - logo.instance(); - logo->create_from_image(img); - platform->set_logo(logo); - platform->set_name("Windows Desktop"); - platform->set_extension("exe"); - platform->set_release_32("windows_32_release.exe"); - platform->set_debug_32("windows_32_debug.exe"); - platform->set_release_64("windows_64_release.exe"); - platform->set_debug_64("windows_64_debug.exe"); - platform->set_os_name("Windows"); - - EditorExport::get_singleton()->add_export_platform(platform); -} diff --git a/platform/windows/export/export.h b/platform/windows/export/export.h deleted file mode 100644 index f053c3e..0000000 --- a/platform/windows/export/export.h +++ /dev/null @@ -1,31 +0,0 @@ -/*************************************************************************/ -/* export.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -void register_windows_exporter(); diff --git a/platform/x11/export/export.cpp b/platform/x11/export/export.cpp deleted file mode 100644 index 44225ac..0000000 --- a/platform/x11/export/export.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/*************************************************************************/ -/* export.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "export.h" - -#include "core/os/file_access.h" -#include "editor/editor_export.h" -#include "platform/x11/logo.gen.h" -#include "scene/resources/texture.h" - -class EditorExportPlatformX11 : public EditorExportPlatformPC { -public: - virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size); -}; - -Error EditorExportPlatformX11::fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) { - // Patch the header of the "pck" section in the ELF file so that it corresponds to the embedded data - - FileAccess *f = FileAccess::open(p_path, FileAccess::READ_WRITE); - if (!f) { - add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to open executable file \"%s\"."), p_path)); - return ERR_CANT_OPEN; - } - - // Read and check ELF magic number - { - uint32_t magic = f->get_32(); - if (magic != 0x464c457f) { // 0x7F + "ELF" - f->close(); - add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable file header corrupted.")); - return ERR_FILE_CORRUPT; - } - } - - // Read program architecture bits from class field - - int bits = f->get_8() * 32; - - if (bits == 32 && p_embedded_size >= 0x100000000) { - f->close(); - add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("32-bit executables cannot have embedded data >= 4 GiB.")); - return ERR_INVALID_DATA; - } - - // 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) { - f->close(); - return ERR_OUT_OF_MEMORY; - } - f->get_buffer(strings, string_data_size); - } - - // Search for the "pck" section - - bool found = false; - 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) { - // "pck" section found, let's patch! - - if (bits == 32) { - f->seek(section_header_pos + 0x10); - f->store_32(p_embedded_start); - f->store_32(p_embedded_size); - } else { // 64 - f->seek(section_header_pos + 0x18); - f->store_64(p_embedded_start); - f->store_64(p_embedded_size); - } - - found = true; - break; - } - } - - memfree(strings); - f->close(); - - if (!found) { - add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable \"pck\" section not found.")); - return ERR_FILE_CORRUPT; - } - return OK; -} - -void register_x11_exporter() { - Ref platform; - platform.instance(); - - Ref img = memnew(Image(_x11_logo)); - Ref logo; - logo.instance(); - logo->create_from_image(img); - platform->set_logo(logo); - platform->set_name("Linux/X11"); - platform->set_extension("x86"); - platform->set_extension("x86_64", "binary_format/64_bits"); - platform->set_release_32("linux_x11_32_release"); - platform->set_debug_32("linux_x11_32_debug"); - platform->set_release_64("linux_x11_64_release"); - platform->set_debug_64("linux_x11_64_debug"); - platform->set_os_name("X11"); - platform->set_chmod_flags(0755); - - EditorExport::get_singleton()->add_export_platform(platform); -} diff --git a/platform/x11/export/export.h b/platform/x11/export/export.h deleted file mode 100644 index 6a38e24..0000000 --- a/platform/x11/export/export.h +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************/ -/* export.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef X11_EXPORT_H -#define X11_EXPORT_H - -void register_x11_exporter(); - -#endif // X11_EXPORT_H diff --git a/scu_builders.py b/scu_builders.py index ad0c4d5..99ae4d9 100644 --- a/scu_builders.py +++ b/scu_builders.py @@ -314,10 +314,10 @@ def generate_scu_files(verbose, is_release_build, env): #"android/export", #"iphone/export", #"javascript/export", - "osx/export", + #"osx/export", #"uwp/export", - "windows/export", - "x11/export", + #"windows/export", + #"x11/export", ] )