export.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /*************************************************************************/
  2. /* export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "export.h"
  31. #include "core/os/file_access.h"
  32. #include "core/os/os.h"
  33. #include "editor/editor_export.h"
  34. #include "editor/editor_node.h"
  35. #include "editor/editor_settings.h"
  36. #include "platform/windows/logo.gen.h"
  37. class EditorExportPlatformWindows : public EditorExportPlatformPC {
  38. Error _rcedit_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path);
  39. Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path);
  40. public:
  41. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  42. virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
  43. virtual Error modify_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags);
  44. virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size);
  45. virtual void get_export_options(List<ExportOption> *r_options);
  46. virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
  47. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  48. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;
  49. };
  50. Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
  51. if (p_preset->get("codesign/enable")) {
  52. return _code_sign(p_preset, p_path);
  53. } else {
  54. return OK;
  55. }
  56. }
  57. Error EditorExportPlatformWindows::modify_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  58. if (p_preset->get("application/modify_resources")) {
  59. _rcedit_add_data(p_preset, p_path);
  60. }
  61. return OK;
  62. }
  63. Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  64. String pck_path = p_path;
  65. if (p_preset->get("binary_format/embed_pck")) {
  66. pck_path = p_path.get_basename() + ".tmp";
  67. }
  68. Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, pck_path, p_flags);
  69. if (p_preset->get("codesign/enable") && err == OK) {
  70. _code_sign(p_preset, pck_path);
  71. }
  72. if (p_preset->get("binary_format/embed_pck") && err == OK) {
  73. DirAccessRef tmp_dir = DirAccess::create_for_path(p_path.get_base_dir());
  74. err = tmp_dir->rename(pck_path, p_path);
  75. if (err != OK) {
  76. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to rename temporary file \"%s\"."), pck_path));
  77. }
  78. }
  79. return err;
  80. }
  81. bool EditorExportPlatformWindows::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
  82. // This option is not supported by "osslsigncode", used on non-Windows host.
  83. if (!OS::get_singleton()->has_feature("Windows") && p_option == "codesign/identity_type") {
  84. return false;
  85. }
  86. return true;
  87. }
  88. void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_options) {
  89. EditorExportPlatformPC::get_export_options(r_options);
  90. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), false));
  91. 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));
  92. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12"), ""));
  93. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/password"), ""));
  94. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true));
  95. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/timestamp_server_url"), ""));
  96. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/digest_algorithm", PROPERTY_HINT_ENUM, "SHA1,SHA256"), 1));
  97. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/description"), ""));
  98. r_options->push_back(ExportOption(PropertyInfo(Variant::POOL_STRING_ARRAY, "codesign/custom_options"), PoolStringArray()));
  99. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/modify_resources"), true));
  100. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.ico"), ""));
  101. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0.0"), ""));
  102. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0.0"), ""));
  103. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/company_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), ""));
  104. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
  105. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_description"), ""));
  106. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  107. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), ""));
  108. }
  109. Error EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  110. String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit");
  111. if (rcedit_path != String() && !FileAccess::exists(rcedit_path)) {
  112. add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Could not find rcedit executable at \"%s\"."), rcedit_path));
  113. return ERR_FILE_NOT_FOUND;
  114. }
  115. if (rcedit_path == String()) {
  116. rcedit_path = "rcedit"; // try to run rcedit from PATH
  117. }
  118. #ifndef WINDOWS_ENABLED
  119. // On non-Windows we need WINE to run rcedit
  120. String wine_path = EditorSettings::get_singleton()->get("export/windows/wine");
  121. if (wine_path != String() && !FileAccess::exists(wine_path)) {
  122. add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Could not find wine executable at \"%s\"."), wine_path));
  123. return ERR_FILE_NOT_FOUND;
  124. }
  125. if (wine_path == String()) {
  126. wine_path = "wine"; // try to run wine from PATH
  127. }
  128. #endif
  129. String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon"));
  130. String file_verion = p_preset->get("application/file_version");
  131. String product_version = p_preset->get("application/product_version");
  132. String company_name = p_preset->get("application/company_name");
  133. String product_name = p_preset->get("application/product_name");
  134. String file_description = p_preset->get("application/file_description");
  135. String copyright = p_preset->get("application/copyright");
  136. String trademarks = p_preset->get("application/trademarks");
  137. String comments = p_preset->get("application/comments");
  138. List<String> args;
  139. args.push_back(p_path);
  140. if (icon_path != String()) {
  141. args.push_back("--set-icon");
  142. args.push_back(icon_path);
  143. }
  144. if (file_verion != String()) {
  145. args.push_back("--set-file-version");
  146. args.push_back(file_verion);
  147. }
  148. if (product_version != String()) {
  149. args.push_back("--set-product-version");
  150. args.push_back(product_version);
  151. }
  152. if (company_name != String()) {
  153. args.push_back("--set-version-string");
  154. args.push_back("CompanyName");
  155. args.push_back(company_name);
  156. }
  157. if (product_name != String()) {
  158. args.push_back("--set-version-string");
  159. args.push_back("ProductName");
  160. args.push_back(product_name);
  161. }
  162. if (file_description != String()) {
  163. args.push_back("--set-version-string");
  164. args.push_back("FileDescription");
  165. args.push_back(file_description);
  166. }
  167. if (copyright != String()) {
  168. args.push_back("--set-version-string");
  169. args.push_back("LegalCopyright");
  170. args.push_back(copyright);
  171. }
  172. if (trademarks != String()) {
  173. args.push_back("--set-version-string");
  174. args.push_back("LegalTrademarks");
  175. args.push_back(trademarks);
  176. }
  177. #ifndef WINDOWS_ENABLED
  178. // On non-Windows we need WINE to run rcedit
  179. args.push_front(rcedit_path);
  180. rcedit_path = wine_path;
  181. #endif
  182. String str;
  183. Error err = OS::get_singleton()->execute(rcedit_path, args, true, nullptr, &str, nullptr, true);
  184. if (err != OK || (str.find("not found") != -1) || (str.find("not recognized") != -1)) {
  185. 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."));
  186. return err;
  187. }
  188. print_line("rcedit (" + p_path + "): " + str);
  189. if (str.find("Fatal error") != -1) {
  190. add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("rcedit failed to modify executable: %s."), str));
  191. return FAILED;
  192. }
  193. return OK;
  194. }
  195. Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  196. List<String> args;
  197. #ifdef WINDOWS_ENABLED
  198. String signtool_path = EditorSettings::get_singleton()->get("export/windows/signtool");
  199. if (signtool_path != String() && !FileAccess::exists(signtool_path)) {
  200. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Could not find signtool executable at \"%s\"."), signtool_path));
  201. return ERR_FILE_NOT_FOUND;
  202. }
  203. if (signtool_path == String()) {
  204. signtool_path = "signtool"; // try to run signtool from PATH
  205. }
  206. #else
  207. String signtool_path = EditorSettings::get_singleton()->get("export/windows/osslsigncode");
  208. if (signtool_path != String() && !FileAccess::exists(signtool_path)) {
  209. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Could not find osslsigncode executable at \"%s\"."), signtool_path));
  210. return ERR_FILE_NOT_FOUND;
  211. }
  212. if (signtool_path == String()) {
  213. signtool_path = "osslsigncode"; // try to run signtool from PATH
  214. }
  215. #endif
  216. args.push_back("sign");
  217. //identity
  218. #ifdef WINDOWS_ENABLED
  219. int id_type = p_preset->get("codesign/identity_type");
  220. if (id_type == 0) { //auto select
  221. args.push_back("/a");
  222. } else if (id_type == 1) { //pkcs12
  223. if (p_preset->get("codesign/identity") != "") {
  224. args.push_back("/f");
  225. args.push_back(p_preset->get("codesign/identity"));
  226. } else {
  227. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
  228. return FAILED;
  229. }
  230. } else if (id_type == 2) { //Windows certificate store
  231. if (p_preset->get("codesign/identity") != "") {
  232. args.push_back("/sha1");
  233. args.push_back(p_preset->get("codesign/identity"));
  234. } else {
  235. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
  236. return FAILED;
  237. }
  238. } else {
  239. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Invalid identity type."));
  240. return FAILED;
  241. }
  242. #else
  243. if (p_preset->get("codesign/identity") != "") {
  244. args.push_back("-pkcs12");
  245. args.push_back(p_preset->get("codesign/identity"));
  246. } else {
  247. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
  248. return FAILED;
  249. }
  250. #endif
  251. //password
  252. if (p_preset->get("codesign/password") != "") {
  253. #ifdef WINDOWS_ENABLED
  254. args.push_back("/p");
  255. #else
  256. args.push_back("-pass");
  257. #endif
  258. args.push_back(p_preset->get("codesign/password"));
  259. }
  260. //timestamp
  261. if (p_preset->get("codesign/timestamp")) {
  262. if (p_preset->get("codesign/timestamp_server") != "") {
  263. #ifdef WINDOWS_ENABLED
  264. args.push_back("/tr");
  265. args.push_back(p_preset->get("codesign/timestamp_server_url"));
  266. args.push_back("/td");
  267. if ((int)p_preset->get("codesign/digest_algorithm") == 0) {
  268. args.push_back("sha1");
  269. } else {
  270. args.push_back("sha256");
  271. }
  272. #else
  273. args.push_back("-ts");
  274. args.push_back(p_preset->get("codesign/timestamp_server_url"));
  275. #endif
  276. } else {
  277. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Invalid timestamp server."));
  278. return FAILED;
  279. }
  280. }
  281. //digest
  282. #ifdef WINDOWS_ENABLED
  283. args.push_back("/fd");
  284. #else
  285. args.push_back("-h");
  286. #endif
  287. if ((int)p_preset->get("codesign/digest_algorithm") == 0) {
  288. args.push_back("sha1");
  289. } else {
  290. args.push_back("sha256");
  291. }
  292. //description
  293. if (p_preset->get("codesign/description") != "") {
  294. #ifdef WINDOWS_ENABLED
  295. args.push_back("/d");
  296. #else
  297. args.push_back("-n");
  298. #endif
  299. args.push_back(p_preset->get("codesign/description"));
  300. }
  301. //user options
  302. PoolStringArray user_args = p_preset->get("codesign/custom_options");
  303. for (int i = 0; i < user_args.size(); i++) {
  304. String user_arg = user_args[i].strip_edges();
  305. if (!user_arg.empty()) {
  306. args.push_back(user_arg);
  307. }
  308. }
  309. #ifndef WINDOWS_ENABLED
  310. args.push_back("-in");
  311. #endif
  312. args.push_back(p_path);
  313. #ifndef WINDOWS_ENABLED
  314. args.push_back("-out");
  315. args.push_back(p_path + "_signed");
  316. #endif
  317. String str;
  318. Error err = OS::get_singleton()->execute(signtool_path, args, true, nullptr, &str, nullptr, true);
  319. if (err != OK || (str.find("not found") != -1) || (str.find("not recognized") != -1)) {
  320. 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."));
  321. return err;
  322. }
  323. print_line("codesign (" + p_path + "): " + str);
  324. #ifndef WINDOWS_ENABLED
  325. if (str.find("SignTool Error") != -1) {
  326. #else
  327. if (str.find("Failed") != -1) {
  328. #endif
  329. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Signtool failed to sign executable: %s."), str));
  330. return FAILED;
  331. }
  332. #ifndef WINDOWS_ENABLED
  333. DirAccessRef tmp_dir = DirAccess::create_for_path(p_path.get_base_dir());
  334. err = tmp_dir->remove(p_path);
  335. if (err != OK) {
  336. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Failed to remove temporary file \"%s\"."), p_path));
  337. return err;
  338. }
  339. err = tmp_dir->rename(p_path + "_signed", p_path);
  340. if (err != OK) {
  341. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Failed to rename temporary file \"%s\"."), p_path + "_signed"));
  342. return err;
  343. }
  344. #endif
  345. return OK;
  346. }
  347. bool EditorExportPlatformWindows::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  348. String err = "";
  349. bool valid = EditorExportPlatformPC::has_valid_export_configuration(p_preset, err, r_missing_templates);
  350. String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit");
  351. if (p_preset->get("application/modify_resources") && rcedit_path.empty()) {
  352. err += TTR("The rcedit tool must be configured in the Editor Settings (Export > Windows > Rcedit) to change the icon or app information data.") + "\n";
  353. }
  354. if (!err.empty()) {
  355. r_error = err;
  356. }
  357. return valid;
  358. }
  359. bool EditorExportPlatformWindows::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  360. String err = "";
  361. bool valid = true;
  362. String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon"));
  363. if (!icon_path.empty() && !FileAccess::exists(icon_path)) {
  364. err += TTR("Invalid icon path:") + " " + icon_path + "\n";
  365. }
  366. // Only non-negative integers can exist in the version string.
  367. String file_version = p_preset->get("application/file_version");
  368. if (!file_version.empty()) {
  369. Vector<String> version_array = file_version.split(".", false);
  370. if (version_array.size() != 4 || !version_array[0].is_valid_integer() ||
  371. !version_array[1].is_valid_integer() || !version_array[2].is_valid_integer() ||
  372. !version_array[3].is_valid_integer() || file_version.find("-") > -1) {
  373. err += TTR("Invalid file version:") + " " + file_version + "\n";
  374. }
  375. }
  376. String product_version = p_preset->get("application/product_version");
  377. if (!product_version.empty()) {
  378. Vector<String> version_array = product_version.split(".", false);
  379. if (version_array.size() != 4 || !version_array[0].is_valid_integer() ||
  380. !version_array[1].is_valid_integer() || !version_array[2].is_valid_integer() ||
  381. !version_array[3].is_valid_integer() || product_version.find("-") > -1) {
  382. err += TTR("Invalid product version:") + " " + product_version + "\n";
  383. }
  384. }
  385. if (!err.empty()) {
  386. r_error = err;
  387. }
  388. return valid;
  389. }
  390. Error EditorExportPlatformWindows::fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) {
  391. // Patch the header of the "pck" section in the PE file so that it corresponds to the embedded data
  392. if (p_embedded_size + p_embedded_start >= 0x100000000) { // Check for total executable size
  393. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Windows executables cannot be >= 4 GiB."));
  394. return ERR_INVALID_DATA;
  395. }
  396. FileAccess *f = FileAccess::open(p_path, FileAccess::READ_WRITE);
  397. if (!f) {
  398. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to open executable file \"%s\"."), p_path));
  399. return ERR_CANT_OPEN;
  400. }
  401. // Jump to the PE header and check the magic number
  402. {
  403. f->seek(0x3c);
  404. uint32_t pe_pos = f->get_32();
  405. f->seek(pe_pos);
  406. uint32_t magic = f->get_32();
  407. if (magic != 0x00004550) {
  408. f->close();
  409. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable file header corrupted."));
  410. return ERR_FILE_CORRUPT;
  411. }
  412. }
  413. // Process header
  414. int num_sections;
  415. {
  416. int64_t header_pos = f->get_position();
  417. f->seek(header_pos + 2);
  418. num_sections = f->get_16();
  419. f->seek(header_pos + 16);
  420. uint16_t opt_header_size = f->get_16();
  421. // Skip rest of header + optional header to go to the section headers
  422. f->seek(f->get_position() + 2 + opt_header_size);
  423. }
  424. // Search for the "pck" section
  425. int64_t section_table_pos = f->get_position();
  426. bool found = false;
  427. for (int i = 0; i < num_sections; ++i) {
  428. int64_t section_header_pos = section_table_pos + i * 40;
  429. f->seek(section_header_pos);
  430. uint8_t section_name[9];
  431. f->get_buffer(section_name, 8);
  432. section_name[8] = '\0';
  433. if (strcmp((char *)section_name, "pck") == 0) {
  434. // "pck" section found, let's patch!
  435. // Set virtual size to a little to avoid it taking memory (zero would give issues)
  436. f->seek(section_header_pos + 8);
  437. f->store_32(8);
  438. f->seek(section_header_pos + 16);
  439. f->store_32(p_embedded_size);
  440. f->seek(section_header_pos + 20);
  441. f->store_32(p_embedded_start);
  442. found = true;
  443. break;
  444. }
  445. }
  446. f->close();
  447. if (!found) {
  448. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable \"pck\" section not found."));
  449. return ERR_FILE_CORRUPT;
  450. }
  451. return OK;
  452. }
  453. void register_windows_exporter() {
  454. EDITOR_DEF("export/windows/rcedit", "");
  455. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/rcedit", PROPERTY_HINT_GLOBAL_FILE, "*.exe"));
  456. #ifdef WINDOWS_ENABLED
  457. EDITOR_DEF("export/windows/signtool", "");
  458. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/signtool", PROPERTY_HINT_GLOBAL_FILE, "*.exe"));
  459. #else
  460. EDITOR_DEF("export/windows/osslsigncode", "");
  461. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/osslsigncode", PROPERTY_HINT_GLOBAL_FILE));
  462. // On non-Windows we need WINE to run rcedit
  463. EDITOR_DEF("export/windows/wine", "");
  464. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/wine", PROPERTY_HINT_GLOBAL_FILE));
  465. #endif
  466. Ref<EditorExportPlatformWindows> platform;
  467. platform.instance();
  468. Ref<Image> img = memnew(Image(_windows_logo));
  469. Ref<ImageTexture> logo;
  470. logo.instance();
  471. logo->create_from_image(img);
  472. platform->set_logo(logo);
  473. platform->set_name("Windows Desktop");
  474. platform->set_extension("exe");
  475. platform->set_release_32("windows_32_release.exe");
  476. platform->set_debug_32("windows_32_debug.exe");
  477. platform->set_release_64("windows_64_release.exe");
  478. platform->set_debug_64("windows_64_debug.exe");
  479. platform->set_os_name("Windows");
  480. EditorExport::get_singleton()->add_export_platform(platform);
  481. }