[3.x] Export: Modify Windows template without rcedit
Co-Authored-By: Pawel Kowal <pkowal1982@gmail.com>
This commit is contained in:
@ -205,7 +205,6 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
|
|||||||
capitalize_string_remaps["po2"] = "(Power of 2)"; // Unit.
|
capitalize_string_remaps["po2"] = "(Power of 2)"; // Unit.
|
||||||
capitalize_string_remaps["pvrtc"] = "PVRTC";
|
capitalize_string_remaps["pvrtc"] = "PVRTC";
|
||||||
capitalize_string_remaps["pvs"] = "PVS";
|
capitalize_string_remaps["pvs"] = "PVS";
|
||||||
capitalize_string_remaps["rcedit"] = "rcedit";
|
|
||||||
capitalize_string_remaps["rcodesign"] = "rcodesign";
|
capitalize_string_remaps["rcodesign"] = "rcodesign";
|
||||||
capitalize_string_remaps["rgb"] = "RGB";
|
capitalize_string_remaps["rgb"] = "RGB";
|
||||||
capitalize_string_remaps["rid"] = "RID";
|
capitalize_string_remaps["rid"] = "RID";
|
||||||
|
|||||||
@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
|
|
||||||
|
#include "template_modifier.h"
|
||||||
|
|
||||||
#include "core/io/image_loader.h"
|
#include "core/io/image_loader.h"
|
||||||
#include "core/os/file_access.h"
|
#include "core/os/file_access.h"
|
||||||
#include "core/os/os.h"
|
#include "core/os/os.h"
|
||||||
@ -40,7 +42,7 @@
|
|||||||
|
|
||||||
class EditorExportPlatformWindows : public EditorExportPlatformPC {
|
class EditorExportPlatformWindows : public EditorExportPlatformPC {
|
||||||
Error _process_icon(const Ref<EditorExportPreset> &p_preset, const String &p_src_path, const String &p_dst_path);
|
Error _process_icon(const Ref<EditorExportPreset> &p_preset, const String &p_src_path, const String &p_dst_path);
|
||||||
Error _rcedit_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
Error _add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||||
Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -189,7 +191,7 @@ Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPres
|
|||||||
|
|
||||||
Error EditorExportPlatformWindows::modify_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
Error EditorExportPlatformWindows::modify_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
||||||
if (p_preset->get("application/modify_resources")) {
|
if (p_preset->get("application/modify_resources")) {
|
||||||
_rcedit_add_data(p_preset, p_path);
|
_add_data(p_preset, p_path);
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -249,34 +251,9 @@ void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_optio
|
|||||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), ""));
|
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
Error EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
|
Error EditorExportPlatformWindows::_add_data(const Ref<EditorExportPreset> &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 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");
|
String tmp_icon_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("_tmp.ico");
|
||||||
if (!icon_path.empty()) {
|
if (!icon_path.empty()) {
|
||||||
if (_process_icon(p_preset, icon_path, tmp_icon_path) != OK) {
|
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));
|
add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Invalid icon file \"%s\"."), icon_path));
|
||||||
@ -284,78 +261,7 @@ Error EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String file_verion = p_preset->get("application/file_version");
|
TemplateModifier::modify(p_preset, p_path, tmp_icon_path);
|
||||||
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<String> 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;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -536,11 +442,6 @@ bool EditorExportPlatformWindows::has_valid_export_configuration(const Ref<Edito
|
|||||||
String err = "";
|
String err = "";
|
||||||
bool valid = EditorExportPlatformPC::has_valid_export_configuration(p_preset, err, r_missing_templates);
|
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()) {
|
if (!err.empty()) {
|
||||||
r_error = err;
|
r_error = err;
|
||||||
}
|
}
|
||||||
@ -670,17 +571,12 @@ Error EditorExportPlatformWindows::fixup_embedded_pck(const String &p_path, int6
|
|||||||
|
|
||||||
void register_windows_exporter() {
|
void register_windows_exporter() {
|
||||||
#ifndef ANDROID_ENABLED
|
#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
|
#ifdef WINDOWS_ENABLED
|
||||||
EDITOR_DEF("export/windows/signtool", "");
|
EDITOR_DEF("export/windows/signtool", "");
|
||||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/signtool", PROPERTY_HINT_GLOBAL_FILE, "*.exe"));
|
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/signtool", PROPERTY_HINT_GLOBAL_FILE, "*.exe"));
|
||||||
#else
|
#else
|
||||||
EDITOR_DEF("export/windows/osslsigncode", "");
|
EDITOR_DEF("export/windows/osslsigncode", "");
|
||||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/osslsigncode", PROPERTY_HINT_GLOBAL_FILE));
|
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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
867
platform/windows/export/template_modifier.cpp
Normal file
867
platform/windows/export/template_modifier.cpp
Normal file
@ -0,0 +1,867 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* template_modifier.cpp */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* This file is part of: */
|
||||||
|
/* GODOT ENGINE */
|
||||||
|
/* https://godotengine.org */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||||
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||||
|
/* */
|
||||||
|
/* 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 "template_modifier.h"
|
||||||
|
|
||||||
|
Vector<uint8_t> str_to_utf16(const String &p_string) {
|
||||||
|
int l = p_string.length();
|
||||||
|
if (!l) {
|
||||||
|
return Vector<uint8_t>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> utf16s;
|
||||||
|
#if defined(WINDOWS_ENABLED)
|
||||||
|
utf16s.resize(l * sizeof(char16_t));
|
||||||
|
memcpy(utf16s.ptrw(), p_string.ptr(), l * sizeof(char16_t));
|
||||||
|
#else
|
||||||
|
const CharType *d = &p_string[0];
|
||||||
|
int fl = 0;
|
||||||
|
for (int i = 0; i < l; i++) {
|
||||||
|
uint32_t c = d[i];
|
||||||
|
if (c <= 0xffff) { // 16 bits.
|
||||||
|
fl += 1;
|
||||||
|
} else if (c <= 0x10ffff) { // 32 bits.
|
||||||
|
fl += 2;
|
||||||
|
} else {
|
||||||
|
print_error("Unicode parsing error: Invalid unicode codepoint " + String::num_int64(c, 16) + ".");
|
||||||
|
return Vector<uint8_t>();
|
||||||
|
}
|
||||||
|
if (c >= 0xd800 && c <= 0xdfff) {
|
||||||
|
print_error("Unicode parsing error: Invalid unicode codepoint " + String::num_int64(c, 16) + ".");
|
||||||
|
return Vector<uint8_t>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fl == 0) {
|
||||||
|
return utf16s;
|
||||||
|
}
|
||||||
|
|
||||||
|
utf16s.resize(fl * sizeof(char16_t));
|
||||||
|
uint16_t *cdst = (uint16_t *)utf16s.ptrw();
|
||||||
|
|
||||||
|
#define APPEND_CHAR(m_c) *(cdst++) = m_c
|
||||||
|
for (int i = 0; i < l; i++) {
|
||||||
|
uint32_t c = d[i];
|
||||||
|
|
||||||
|
if (c <= 0xffff) { // 16 bits.
|
||||||
|
APPEND_CHAR(c);
|
||||||
|
} else { // 32 bits.
|
||||||
|
APPEND_CHAR(uint32_t((c >> 10) + 0xd7c0)); // lead surrogate.
|
||||||
|
APPEND_CHAR(uint32_t((c & 0x3ff) | 0xdc00)); // trail surrogate.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#undef APPEND_CHAR
|
||||||
|
#endif
|
||||||
|
return utf16s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::ByteStream::save(uint8_t p_value, Vector<uint8_t> &r_bytes) const {
|
||||||
|
save(p_value, r_bytes, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::ByteStream::save(uint16_t p_value, Vector<uint8_t> &r_bytes) const {
|
||||||
|
save(p_value, r_bytes, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::ByteStream::save(uint32_t p_value, Vector<uint8_t> &r_bytes) const {
|
||||||
|
save(p_value, r_bytes, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::ByteStream::save(const String &p_value, Vector<uint8_t> &r_bytes) const {
|
||||||
|
const Vector<uint8_t> &data = str_to_utf16(p_value);
|
||||||
|
r_bytes.append_array(data);
|
||||||
|
save((uint16_t)0, r_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::ByteStream::save(uint32_t p_value, Vector<uint8_t> &r_bytes, uint32_t p_count) const {
|
||||||
|
for (uint32_t i = 0; i < p_count; i++) {
|
||||||
|
r_bytes.push_back((uint8_t)(p_value & 0xff));
|
||||||
|
p_value >>= 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::ByteStream::save() const {
|
||||||
|
return Vector<uint8_t>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::Structure::save() const {
|
||||||
|
Vector<uint8_t> bytes;
|
||||||
|
ByteStream::save(length, bytes);
|
||||||
|
ByteStream::save(value_length, bytes);
|
||||||
|
ByteStream::save(type, bytes);
|
||||||
|
ByteStream::save(key, bytes);
|
||||||
|
while (bytes.size() % 4) {
|
||||||
|
bytes.push_back(0);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> &TemplateModifier::Structure::add_length(Vector<uint8_t> &r_bytes) const {
|
||||||
|
r_bytes.ptrw()[0] = r_bytes.size() & 0xff;
|
||||||
|
r_bytes.ptrw()[1] = r_bytes.size() >> 8 & 0xff;
|
||||||
|
return r_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::ResourceDirectoryTable::save() const {
|
||||||
|
Vector<uint8_t> bytes;
|
||||||
|
for (int i = 0; i < 12; i++) {
|
||||||
|
bytes.push_back(0);
|
||||||
|
}
|
||||||
|
ByteStream::save(name_entry_count, bytes);
|
||||||
|
ByteStream::save(id_entry_count, bytes);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::ResourceDirectoryEntry::save() const {
|
||||||
|
Vector<uint8_t> bytes;
|
||||||
|
ByteStream::save(id | (name ? HIGH_BIT : 0), bytes);
|
||||||
|
ByteStream::save(data_offset | (subdirectory ? HIGH_BIT : 0), bytes);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::FixedFileInfo::save() const {
|
||||||
|
Vector<uint8_t> bytes;
|
||||||
|
ByteStream::save(signature, bytes);
|
||||||
|
ByteStream::save(struct_version, bytes);
|
||||||
|
ByteStream::save(file_version_ms, bytes);
|
||||||
|
ByteStream::save(file_version_ls, bytes);
|
||||||
|
ByteStream::save(product_version_ms, bytes);
|
||||||
|
ByteStream::save(product_version_ls, bytes);
|
||||||
|
ByteStream::save(file_flags_mask, bytes);
|
||||||
|
ByteStream::save(file_flags, bytes);
|
||||||
|
ByteStream::save(file_os, bytes);
|
||||||
|
ByteStream::save(file_type, bytes);
|
||||||
|
ByteStream::save(file_subtype, bytes);
|
||||||
|
ByteStream::save(file_date_ms, bytes);
|
||||||
|
ByteStream::save(file_date_ls, bytes);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::FixedFileInfo::set_file_version(const String &p_file_version) {
|
||||||
|
Vector<String> parts = p_file_version.split(".");
|
||||||
|
while (parts.size() < 4) {
|
||||||
|
parts.push_back("0");
|
||||||
|
}
|
||||||
|
file_version_ms = parts[0].to_int() << 16 | (parts[1].to_int() & 0xffff);
|
||||||
|
file_version_ls = parts[2].to_int() << 16 | (parts[3].to_int() & 0xffff);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::FixedFileInfo::set_product_version(const String &p_product_version) {
|
||||||
|
Vector<String> parts = p_product_version.split(".");
|
||||||
|
while (parts.size() < 4) {
|
||||||
|
parts.push_back("0");
|
||||||
|
}
|
||||||
|
product_version_ms = parts[0].to_int() << 16 | (parts[1].to_int() & 0xffff);
|
||||||
|
product_version_ls = parts[2].to_int() << 16 | (parts[3].to_int() & 0xffff);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::StringStructure::save() const {
|
||||||
|
Vector<uint8_t> bytes = Structure::save();
|
||||||
|
ByteStream::save(value, bytes);
|
||||||
|
return add_length(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModifier::StringStructure::StringStructure() {
|
||||||
|
type = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModifier::StringStructure::StringStructure(const String &p_key, const String &p_value) {
|
||||||
|
type = 1;
|
||||||
|
value_length = p_value.length() + 1;
|
||||||
|
key = p_key;
|
||||||
|
value = p_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::StringTable::save() const {
|
||||||
|
Vector<uint8_t> bytes = Structure::save();
|
||||||
|
for (int i = 0; i < strings.size(); i++) {
|
||||||
|
const StringStructure &string = strings[i];
|
||||||
|
bytes.append_array(string.save());
|
||||||
|
while (bytes.size() % 4) {
|
||||||
|
bytes.push_back(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return add_length(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::StringTable::put(const String &p_key, const String &p_value) {
|
||||||
|
strings.push_back(StringStructure(p_key, p_value));
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModifier::StringTable::StringTable() {
|
||||||
|
key = "040904b0";
|
||||||
|
type = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModifier::StringFileInfo::StringFileInfo() {
|
||||||
|
key = "StringFileInfo";
|
||||||
|
value_length = 0;
|
||||||
|
type = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::StringFileInfo::save() const {
|
||||||
|
Vector<uint8_t> bytes = Structure::save();
|
||||||
|
bytes.append_array(string_table.save());
|
||||||
|
return add_length(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::Var::save() const {
|
||||||
|
Vector<uint8_t> bytes = Structure::save();
|
||||||
|
ByteStream::save(value, bytes);
|
||||||
|
return add_length(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModifier::Var::Var() {
|
||||||
|
value_length = 4;
|
||||||
|
key = "Translation";
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::VarFileInfo::save() const {
|
||||||
|
Vector<uint8_t> bytes = Structure::save();
|
||||||
|
bytes.append_array(var.save());
|
||||||
|
return add_length(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModifier::VarFileInfo::VarFileInfo() {
|
||||||
|
type = 1;
|
||||||
|
key = "VarFileInfo";
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::VersionInfo::save() const {
|
||||||
|
Vector<uint8_t> fixed_file_info = value.save();
|
||||||
|
Vector<uint8_t> bytes = Structure::save();
|
||||||
|
bytes.append_array(fixed_file_info);
|
||||||
|
bytes.append_array(string_file_info.save());
|
||||||
|
while (bytes.size() % 4) {
|
||||||
|
bytes.push_back(0);
|
||||||
|
}
|
||||||
|
bytes.append_array(var_file_info.save());
|
||||||
|
return add_length(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModifier::VersionInfo::VersionInfo() {
|
||||||
|
key = "VS_VERSION_INFO";
|
||||||
|
value_length = 52;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::ManifestInfo::save() const {
|
||||||
|
Vector<uint8_t> bytes;
|
||||||
|
CharString cs = manifest.utf8();
|
||||||
|
for (int i = 0; i < cs.length(); i++) {
|
||||||
|
bytes.push_back(cs[i]);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::IconEntry::save() const {
|
||||||
|
Vector<uint8_t> bytes;
|
||||||
|
ByteStream::save(width, bytes);
|
||||||
|
ByteStream::save(height, bytes);
|
||||||
|
ByteStream::save(colors, bytes);
|
||||||
|
ByteStream::save((uint8_t)0, bytes);
|
||||||
|
ByteStream::save(planes, bytes);
|
||||||
|
ByteStream::save(bits_per_pixel, bytes);
|
||||||
|
ByteStream::save(image_size, bytes);
|
||||||
|
ByteStream::save((uint16_t)image_offset, bytes);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::IconEntry::load(FileAccess *p_file) {
|
||||||
|
width = p_file->get_8(); // Width in pixels.
|
||||||
|
height = p_file->get_8(); // Height in pixels.
|
||||||
|
colors = p_file->get_8(); // Number of colors in the palette (0 - no palette).
|
||||||
|
p_file->get_8(); // Reserved.
|
||||||
|
planes = p_file->get_16(); // Number of color planes.
|
||||||
|
bits_per_pixel = p_file->get_16(); // Bits per pixel.
|
||||||
|
image_size = p_file->get_32(); // Image data size in bytes.
|
||||||
|
image_offset = p_file->get_32(); // Image data offset.
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::GroupIcon::save() const {
|
||||||
|
Vector<uint8_t> bytes;
|
||||||
|
ByteStream::save(reserved, bytes);
|
||||||
|
ByteStream::save(type, bytes);
|
||||||
|
ByteStream::save(image_count, bytes);
|
||||||
|
for (int i = 0; i < icon_entries.size(); i++) {
|
||||||
|
const IconEntry &icon_entry = icon_entries[i];
|
||||||
|
bytes.append_array(icon_entry.save());
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::GroupIcon::load(FileAccess *p_icon_file) {
|
||||||
|
if (p_icon_file->get_32() != 0x10000) { // Wrong reserved bytes
|
||||||
|
ERR_FAIL_MSG("Wrong icon file type.");
|
||||||
|
}
|
||||||
|
|
||||||
|
image_count = p_icon_file->get_16();
|
||||||
|
for (uint16_t i = 0; i < image_count; i++) {
|
||||||
|
IconEntry icon_entry;
|
||||||
|
icon_entry.load(p_icon_file);
|
||||||
|
icon_entries.push_back(icon_entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = 1;
|
||||||
|
for (int i = 0; i < icon_entries.size(); i++) {
|
||||||
|
IconEntry &icon_entry = icon_entries.write[i];
|
||||||
|
Vector<uint8_t> image;
|
||||||
|
image.resize(icon_entry.image_size);
|
||||||
|
p_icon_file->seek(icon_entry.image_offset);
|
||||||
|
p_icon_file->get_buffer(image.ptrw(), image.size());
|
||||||
|
icon_entry.image_offset = id++;
|
||||||
|
images.push_back(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::GroupIcon::fill_with_godot_blue() {
|
||||||
|
uint32_t id = 1;
|
||||||
|
for (uint8_t size : SIZES) {
|
||||||
|
Ref<Image> image = memnew(Image(size ? size : 256, size ? size : 256, 0, Image::FORMAT_RGB8));
|
||||||
|
image->fill(Color::hex(0x478cbfff));
|
||||||
|
PoolVector<uint8_t> pool_data = image->save_png_to_buffer();
|
||||||
|
Vector<uint8_t> data;
|
||||||
|
data.resize(pool_data.size());
|
||||||
|
memcpy(data.ptrw(), pool_data.read().ptr(), pool_data.size());
|
||||||
|
IconEntry icon_entry;
|
||||||
|
icon_entry.width = size;
|
||||||
|
icon_entry.height = size;
|
||||||
|
icon_entry.bits_per_pixel = 24;
|
||||||
|
icon_entry.image_size = data.size();
|
||||||
|
icon_entry.image_offset = id++;
|
||||||
|
icon_entries.push_back(icon_entry);
|
||||||
|
images.push_back(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::SectionEntry::save() const {
|
||||||
|
Vector<uint8_t> bytes;
|
||||||
|
CharString cs = name.utf8();
|
||||||
|
for (int i = 0; i < cs.length(); i++) {
|
||||||
|
bytes.push_back(cs[i]);
|
||||||
|
}
|
||||||
|
while (bytes.size() < 8) {
|
||||||
|
bytes.push_back(0);
|
||||||
|
}
|
||||||
|
ByteStream::save(virtual_size, bytes);
|
||||||
|
ByteStream::save(virtual_address, bytes);
|
||||||
|
ByteStream::save(size_of_raw_data, bytes);
|
||||||
|
ByteStream::save(pointer_to_raw_data, bytes);
|
||||||
|
ByteStream::save(pointer_to_relocations, bytes);
|
||||||
|
ByteStream::save(pointer_to_line_numbers, bytes);
|
||||||
|
ByteStream::save(number_of_relocations, bytes);
|
||||||
|
ByteStream::save(number_of_line_numbers, bytes);
|
||||||
|
ByteStream::save(characteristics, bytes);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemplateModifier::SectionEntry::load(FileAccess *p_file) {
|
||||||
|
uint8_t section_name[8];
|
||||||
|
p_file->get_buffer(section_name, 8);
|
||||||
|
name = String::utf8((char *)section_name, 8);
|
||||||
|
virtual_size = p_file->get_32();
|
||||||
|
virtual_address = p_file->get_32();
|
||||||
|
size_of_raw_data = p_file->get_32();
|
||||||
|
pointer_to_raw_data = p_file->get_32();
|
||||||
|
pointer_to_relocations = p_file->get_32();
|
||||||
|
pointer_to_line_numbers = p_file->get_32();
|
||||||
|
number_of_relocations = p_file->get_16();
|
||||||
|
number_of_line_numbers = p_file->get_16();
|
||||||
|
characteristics = p_file->get_32();
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::ResourceDataEntry::save() const {
|
||||||
|
Vector<uint8_t> bytes;
|
||||||
|
ByteStream::save(rva, bytes);
|
||||||
|
ByteStream::save(size, bytes);
|
||||||
|
ByteStream::save(0, bytes, 8);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t TemplateModifier::_get_pe_header_offset(FileAccess *p_executable) const {
|
||||||
|
p_executable->seek(POINTER_TO_PE_HEADER_OFFSET);
|
||||||
|
uint32_t pe_header_offset = p_executable->get_32();
|
||||||
|
|
||||||
|
p_executable->seek(pe_header_offset);
|
||||||
|
uint32_t magic = p_executable->get_32();
|
||||||
|
|
||||||
|
return magic == 0x00004550 ? pe_header_offset : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t TemplateModifier::_snap(uint32_t p_value, uint32_t p_size) const {
|
||||||
|
return p_value + (p_value % p_size ? p_size - (p_value % p_size) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint8_t> TemplateModifier::_create_resources(uint32_t p_virtual_address, const GroupIcon &p_group_icon, const VersionInfo &p_version_info, const ManifestInfo &p_manifest_info) const {
|
||||||
|
// 0x04, 0x00 as string length ICON in UTF16 and padding to 32 bits
|
||||||
|
const uint8_t ICON_DIRECTORY_STRING[] = { 0x04, 0x00, 0x49, 0x00, 0x43, 0x00, 0x4f, 0x00, 0x4e, 0x00, 0x00, 0x00 };
|
||||||
|
const uint16_t RT_ENTRY_COUNT = 4;
|
||||||
|
const uint32_t icon_count = p_group_icon.images.size();
|
||||||
|
|
||||||
|
ResourceDirectoryTable root_directory_table;
|
||||||
|
root_directory_table.id_entry_count = RT_ENTRY_COUNT;
|
||||||
|
|
||||||
|
Vector<uint8_t> resources = root_directory_table.save();
|
||||||
|
|
||||||
|
ResourceDirectoryEntry rt_icon_entry;
|
||||||
|
rt_icon_entry.id = ResourceDirectoryEntry::ICON;
|
||||||
|
rt_icon_entry.data_offset = ResourceDirectoryTable::SIZE + RT_ENTRY_COUNT * ResourceDirectoryEntry::SIZE;
|
||||||
|
rt_icon_entry.subdirectory = true;
|
||||||
|
resources.append_array(rt_icon_entry.save());
|
||||||
|
|
||||||
|
ResourceDirectoryEntry rt_group_icon_entry;
|
||||||
|
rt_group_icon_entry.id = ResourceDirectoryEntry::GROUP_ICON;
|
||||||
|
rt_group_icon_entry.data_offset = (2 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count) * ResourceDirectoryEntry::SIZE;
|
||||||
|
rt_group_icon_entry.subdirectory = true;
|
||||||
|
resources.append_array(rt_group_icon_entry.save());
|
||||||
|
|
||||||
|
ResourceDirectoryEntry rt_version_entry;
|
||||||
|
rt_version_entry.id = ResourceDirectoryEntry::VERSION;
|
||||||
|
rt_version_entry.data_offset = (4 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 2) * ResourceDirectoryEntry::SIZE;
|
||||||
|
rt_version_entry.subdirectory = true;
|
||||||
|
resources.append_array(rt_version_entry.save());
|
||||||
|
|
||||||
|
ResourceDirectoryEntry rt_manifest_entry;
|
||||||
|
rt_manifest_entry.id = ResourceDirectoryEntry::MANIFEST;
|
||||||
|
rt_manifest_entry.data_offset = (6 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 4) * ResourceDirectoryEntry::SIZE;
|
||||||
|
rt_manifest_entry.subdirectory = true;
|
||||||
|
resources.append_array(rt_manifest_entry.save());
|
||||||
|
|
||||||
|
ResourceDirectoryTable icon_table;
|
||||||
|
icon_table.id_entry_count = icon_count;
|
||||||
|
resources.append_array(icon_table.save());
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < icon_count; i++) {
|
||||||
|
ResourceDirectoryEntry icon_entry;
|
||||||
|
icon_entry.id = i + 1;
|
||||||
|
icon_entry.data_offset = (2 + i) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + icon_count + i) * ResourceDirectoryEntry::SIZE;
|
||||||
|
icon_entry.subdirectory = true;
|
||||||
|
resources.append_array(icon_entry.save());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < icon_count; i++) {
|
||||||
|
ResourceDirectoryTable language_icon_table;
|
||||||
|
language_icon_table.id_entry_count = 1;
|
||||||
|
resources.append_array(language_icon_table.save());
|
||||||
|
|
||||||
|
ResourceDirectoryEntry language_icon_entry;
|
||||||
|
language_icon_entry.id = ResourceDirectoryEntry::ENGLISH;
|
||||||
|
language_icon_entry.data_offset = (8 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + icon_count * 2 + 6) * ResourceDirectoryEntry::SIZE + sizeof(ICON_DIRECTORY_STRING) + i * ResourceDataEntry::SIZE;
|
||||||
|
resources.append_array(language_icon_entry.save());
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceDirectoryTable group_icon_name_table;
|
||||||
|
group_icon_name_table.name_entry_count = 1;
|
||||||
|
resources.append_array(group_icon_name_table.save());
|
||||||
|
|
||||||
|
ResourceDirectoryEntry group_icon_name_entry;
|
||||||
|
group_icon_name_entry.id = (6 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + icon_count * 2 + 4) * ResourceDirectoryEntry::SIZE;
|
||||||
|
group_icon_name_entry.data_offset = (3 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 1) * ResourceDirectoryEntry::SIZE;
|
||||||
|
group_icon_name_entry.name = true;
|
||||||
|
group_icon_name_entry.subdirectory = true;
|
||||||
|
resources.append_array(group_icon_name_entry.save());
|
||||||
|
|
||||||
|
ResourceDirectoryTable group_icon_language_table;
|
||||||
|
group_icon_language_table.id_entry_count = 1;
|
||||||
|
resources.append_array(group_icon_language_table.save());
|
||||||
|
|
||||||
|
ResourceDirectoryEntry group_icon_language_entry;
|
||||||
|
group_icon_language_entry.id = ResourceDirectoryEntry::ENGLISH;
|
||||||
|
group_icon_language_entry.data_offset = (8 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 6) * ResourceDirectoryEntry::SIZE + sizeof(ICON_DIRECTORY_STRING) + icon_count * ResourceDataEntry::SIZE;
|
||||||
|
resources.append_array(group_icon_language_entry.save());
|
||||||
|
|
||||||
|
ResourceDirectoryTable version_table;
|
||||||
|
version_table.id_entry_count = 1;
|
||||||
|
resources.append_array(version_table.save());
|
||||||
|
|
||||||
|
ResourceDirectoryEntry version_entry;
|
||||||
|
version_entry.id = 1;
|
||||||
|
version_entry.data_offset = (5 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 3) * ResourceDirectoryEntry::SIZE;
|
||||||
|
version_entry.subdirectory = true;
|
||||||
|
resources.append_array(version_entry.save());
|
||||||
|
|
||||||
|
ResourceDirectoryTable version_language_table;
|
||||||
|
version_language_table.id_entry_count = 1;
|
||||||
|
resources.append_array(version_language_table.save());
|
||||||
|
|
||||||
|
ResourceDirectoryEntry version_language_entry;
|
||||||
|
version_language_entry.id = ResourceDirectoryEntry::ENGLISH;
|
||||||
|
version_language_entry.data_offset = (8 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 6) * ResourceDirectoryEntry::SIZE + sizeof(ICON_DIRECTORY_STRING) + (icon_count + 1) * ResourceDataEntry::SIZE;
|
||||||
|
resources.append_array(version_language_entry.save());
|
||||||
|
|
||||||
|
ResourceDirectoryTable manifest_table;
|
||||||
|
manifest_table.id_entry_count = 1;
|
||||||
|
resources.append_array(manifest_table.save());
|
||||||
|
|
||||||
|
ResourceDirectoryEntry manifest_entry;
|
||||||
|
manifest_entry.id = 1;
|
||||||
|
manifest_entry.data_offset = (7 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 5) * ResourceDirectoryEntry::SIZE;
|
||||||
|
manifest_entry.subdirectory = true;
|
||||||
|
resources.append_array(manifest_entry.save());
|
||||||
|
|
||||||
|
ResourceDirectoryTable manifest_language_table;
|
||||||
|
manifest_language_table.id_entry_count = 1;
|
||||||
|
resources.append_array(manifest_language_table.save());
|
||||||
|
|
||||||
|
ResourceDirectoryEntry manifest_language_entry;
|
||||||
|
manifest_language_entry.id = ResourceDirectoryEntry::ENGLISH;
|
||||||
|
manifest_language_entry.data_offset = (8 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 6) * ResourceDirectoryEntry::SIZE + sizeof(ICON_DIRECTORY_STRING) + (icon_count + 2) * ResourceDataEntry::SIZE;
|
||||||
|
resources.append_array(manifest_language_entry.save());
|
||||||
|
|
||||||
|
Vector<uint8_t> icon_directory_string;
|
||||||
|
icon_directory_string.resize(sizeof(ICON_DIRECTORY_STRING));
|
||||||
|
memcpy(icon_directory_string.ptrw(), ICON_DIRECTORY_STRING, sizeof(ICON_DIRECTORY_STRING));
|
||||||
|
resources.append_array(icon_directory_string);
|
||||||
|
|
||||||
|
Vector<Vector<uint8_t>> data_entries;
|
||||||
|
for (int i = 0; i < p_group_icon.images.size(); i++) {
|
||||||
|
const Vector<uint8_t> &image = p_group_icon.images[i];
|
||||||
|
data_entries.push_back(image);
|
||||||
|
}
|
||||||
|
data_entries.push_back(p_group_icon.save());
|
||||||
|
data_entries.push_back(p_version_info.save());
|
||||||
|
data_entries.push_back(p_manifest_info.save());
|
||||||
|
|
||||||
|
uint32_t offset = resources.size() + data_entries.size() * ResourceDataEntry::SIZE;
|
||||||
|
|
||||||
|
for (int i = 0; i < data_entries.size(); i++) {
|
||||||
|
const Vector<uint8_t> &data_entry = data_entries[i];
|
||||||
|
ResourceDataEntry resource_data_entry;
|
||||||
|
resource_data_entry.rva = p_virtual_address + offset;
|
||||||
|
resource_data_entry.size = data_entry.size();
|
||||||
|
resources.append_array(resource_data_entry.save());
|
||||||
|
offset += resource_data_entry.size;
|
||||||
|
while (offset % 4) {
|
||||||
|
offset += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < data_entries.size(); i++) {
|
||||||
|
const Vector<uint8_t> &data_entry = data_entries[i];
|
||||||
|
resources.append_array(data_entry);
|
||||||
|
while (resources.size() % 4) {
|
||||||
|
resources.push_back(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModifier::VersionInfo TemplateModifier::_create_version_info(const HashMap<String, String> &p_strings) const {
|
||||||
|
StringTable string_table;
|
||||||
|
for (const String *key = p_strings.next(nullptr); key != nullptr; key = p_strings.next(key)) {
|
||||||
|
string_table.put(*key, p_strings[*key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringFileInfo string_file_info;
|
||||||
|
string_file_info.string_table = string_table;
|
||||||
|
|
||||||
|
FixedFileInfo fixed_file_info;
|
||||||
|
if (p_strings.has("FileVersion")) {
|
||||||
|
fixed_file_info.set_file_version(p_strings["FileVersion"]);
|
||||||
|
}
|
||||||
|
if (p_strings.has("ProductVersion")) {
|
||||||
|
fixed_file_info.set_product_version(p_strings["ProductVersion"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionInfo version_info;
|
||||||
|
version_info.value = fixed_file_info;
|
||||||
|
version_info.string_file_info = string_file_info;
|
||||||
|
|
||||||
|
return version_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModifier::ManifestInfo TemplateModifier::_create_manifest_info() const {
|
||||||
|
ManifestInfo manifest_info;
|
||||||
|
manifest_info.manifest = R"MANIFEST(<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||||
|
<dependency>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'/>
|
||||||
|
</dependentAssembly>
|
||||||
|
</dependency>
|
||||||
|
</assembly>)MANIFEST";
|
||||||
|
return manifest_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModifier::GroupIcon TemplateModifier::_create_group_icon(const String &p_icon_path) const {
|
||||||
|
GroupIcon group_icon;
|
||||||
|
|
||||||
|
Error error;
|
||||||
|
FileAccess *icon_file = FileAccess::open(p_icon_path, FileAccess::READ, &error);
|
||||||
|
if (error != OK) {
|
||||||
|
group_icon.fill_with_godot_blue();
|
||||||
|
return group_icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
group_icon.load(icon_file);
|
||||||
|
memdelete(icon_file);
|
||||||
|
|
||||||
|
return group_icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
Error TemplateModifier::_truncate(const String &p_path, uint32_t p_size) const {
|
||||||
|
Error error;
|
||||||
|
|
||||||
|
FileAccess *file = FileAccess::open(p_path, FileAccess::READ, &error);
|
||||||
|
ERR_FAIL_COND_V(error != OK, ERR_CANT_OPEN);
|
||||||
|
|
||||||
|
String truncated_path = p_path + ".truncated";
|
||||||
|
FileAccess *truncated = FileAccess::open(truncated_path, FileAccess::WRITE, &error);
|
||||||
|
ERR_FAIL_COND_V(error != OK, ERR_CANT_CREATE);
|
||||||
|
|
||||||
|
Vector<uint8_t> buf;
|
||||||
|
buf.resize(p_size);
|
||||||
|
file->get_buffer(buf.ptrw(), p_size);
|
||||||
|
truncated->store_buffer(buf.ptr(), p_size);
|
||||||
|
|
||||||
|
file->close();
|
||||||
|
truncated->close();
|
||||||
|
|
||||||
|
memdelete(file);
|
||||||
|
memdelete(truncated);
|
||||||
|
|
||||||
|
DirAccessRef dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||||
|
dir_access->remove(p_path);
|
||||||
|
dir_access->rename(truncated_path, p_path);
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, String> TemplateModifier::_get_strings(const Ref<EditorExportPreset> &p_preset) const {
|
||||||
|
String file_version = 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");
|
||||||
|
|
||||||
|
HashMap<String, String> strings;
|
||||||
|
if (!file_version.empty()) {
|
||||||
|
strings["FileVersion"] = file_version;
|
||||||
|
}
|
||||||
|
if (!product_version.empty()) {
|
||||||
|
strings["ProductVersion"] = product_version;
|
||||||
|
}
|
||||||
|
if (!company_name.empty()) {
|
||||||
|
strings["CompanyName"] = company_name;
|
||||||
|
}
|
||||||
|
if (!product_name.empty()) {
|
||||||
|
strings["ProductName"] = product_name;
|
||||||
|
}
|
||||||
|
if (!file_description.empty()) {
|
||||||
|
strings["FileDescription"] = file_description;
|
||||||
|
}
|
||||||
|
if (!copyright.empty()) {
|
||||||
|
strings["LegalCopyright"] = copyright;
|
||||||
|
}
|
||||||
|
if (!trademarks.empty()) {
|
||||||
|
strings["LegalTrademarks"] = trademarks;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
Error TemplateModifier::_modify_template(const Ref<EditorExportPreset> &p_preset, const String &p_template_path, const String &p_icon_path) const {
|
||||||
|
Error error;
|
||||||
|
FileAccess *template_file = FileAccess::open(p_template_path, FileAccess::READ_WRITE, &error);
|
||||||
|
ERR_FAIL_COND_V(error != OK, ERR_CANT_OPEN);
|
||||||
|
|
||||||
|
Vector<SectionEntry> section_entries = _get_section_entries(template_file);
|
||||||
|
if (section_entries.size() < 2) {
|
||||||
|
memdelete(template_file);
|
||||||
|
ERR_FAIL_V(ERR_CANT_OPEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find resource (".rsrc") and relocation (".reloc") sections, usually last two, but ".debug_*" sections (referenced as "/[n]"), symbol table, and string table can follow.
|
||||||
|
int resource_index = section_entries.size() - 2;
|
||||||
|
int relocations_index = section_entries.size() - 1;
|
||||||
|
for (int i = 0; i < section_entries.size(); i++) {
|
||||||
|
if (section_entries[i].name == ".rsrc") {
|
||||||
|
resource_index = i;
|
||||||
|
} else if (section_entries[i].name == ".reloc") {
|
||||||
|
relocations_index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (section_entries[resource_index].name != ".rsrc" || section_entries[relocations_index].name != ".reloc") {
|
||||||
|
memdelete(template_file);
|
||||||
|
ERR_FAIL_V(ERR_CANT_OPEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t original_template_size = template_file->get_len();
|
||||||
|
|
||||||
|
GroupIcon group_icon = _create_group_icon(p_icon_path);
|
||||||
|
|
||||||
|
VersionInfo version_info = _create_version_info(_get_strings(p_preset));
|
||||||
|
ManifestInfo manifest_info = _create_manifest_info();
|
||||||
|
|
||||||
|
SectionEntry &resources_section_entry = section_entries.write[resource_index];
|
||||||
|
uint32_t old_resources_size_of_raw_data = resources_section_entry.size_of_raw_data;
|
||||||
|
Vector<uint8_t> resources = _create_resources(resources_section_entry.virtual_address, group_icon, version_info, manifest_info);
|
||||||
|
resources_section_entry.virtual_size = resources.size();
|
||||||
|
int64_t aligned_size = _snap(resources.size(), BLOCK_SIZE);
|
||||||
|
for (int i = resources.size(); i < aligned_size; i++) {
|
||||||
|
resources.push_back(0);
|
||||||
|
}
|
||||||
|
resources_section_entry.size_of_raw_data = resources.size();
|
||||||
|
|
||||||
|
int32_t raw_size_delta = resources_section_entry.size_of_raw_data - old_resources_size_of_raw_data;
|
||||||
|
uint32_t old_last_section_virtual_address = section_entries.get(section_entries.size() - 1).virtual_address;
|
||||||
|
|
||||||
|
// Some data (e.g. DWARF debug symbols) can be placed after the last section.
|
||||||
|
uint32_t old_footer_offset = section_entries.get(section_entries.size() - 1).pointer_to_raw_data + section_entries.get(section_entries.size() - 1).size_of_raw_data;
|
||||||
|
|
||||||
|
// Copy and update sections after ".rsrc".
|
||||||
|
Vector<Vector<uint8_t>> moved_section_data;
|
||||||
|
uint32_t prev_virtual_address = resources_section_entry.virtual_address;
|
||||||
|
uint32_t prev_virtual_size = resources_section_entry.virtual_size;
|
||||||
|
for (int i = resource_index + 1; i < section_entries.size(); i++) {
|
||||||
|
SectionEntry §ion_entry = section_entries.write[i];
|
||||||
|
template_file->seek(section_entry.pointer_to_raw_data);
|
||||||
|
Vector<uint8_t> data;
|
||||||
|
data.resize(section_entry.size_of_raw_data);
|
||||||
|
template_file->get_buffer(data.ptrw(), section_entry.size_of_raw_data);
|
||||||
|
moved_section_data.push_back(data);
|
||||||
|
section_entry.pointer_to_raw_data += raw_size_delta;
|
||||||
|
section_entry.virtual_address = prev_virtual_address + _snap(prev_virtual_size, PE_PAGE_SIZE);
|
||||||
|
prev_virtual_address = section_entry.virtual_address;
|
||||||
|
prev_virtual_size = section_entry.virtual_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy COFF symbol table and string table after the last section.
|
||||||
|
uint32_t footer_size = template_file->get_len() - old_footer_offset;
|
||||||
|
template_file->seek(old_footer_offset);
|
||||||
|
Vector<uint8_t> footer;
|
||||||
|
if (footer_size > 0) {
|
||||||
|
footer.resize(footer_size);
|
||||||
|
template_file->get_buffer(footer.ptrw(), footer_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t pe_header_offset = _get_pe_header_offset(template_file);
|
||||||
|
|
||||||
|
// Update symbol table pointer.
|
||||||
|
template_file->seek(pe_header_offset + 12);
|
||||||
|
uint32_t symbols_offset = template_file->get_32();
|
||||||
|
if (symbols_offset > resources_section_entry.pointer_to_raw_data) {
|
||||||
|
template_file->seek(pe_header_offset + 12);
|
||||||
|
template_file->store_32(symbols_offset + raw_size_delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
template_file->seek(pe_header_offset + MAGIC_NUMBER_OFFSET);
|
||||||
|
uint16_t magic_number = template_file->get_16();
|
||||||
|
if (magic_number != 0x10b && magic_number != 0x20b) {
|
||||||
|
memdelete(template_file);
|
||||||
|
ERR_FAIL_V_MSG(ERR_CANT_OPEN, vformat("Magic number has wrong value: %04x", magic_number));
|
||||||
|
}
|
||||||
|
bool pe32plus = magic_number == 0x20b;
|
||||||
|
|
||||||
|
// Update image size.
|
||||||
|
template_file->seek(pe_header_offset + SIZE_OF_INITIALIZED_DATA_OFFSET);
|
||||||
|
uint32_t size_of_initialized_data = template_file->get_32();
|
||||||
|
size_of_initialized_data += resources_section_entry.size_of_raw_data - old_resources_size_of_raw_data;
|
||||||
|
template_file->seek(pe_header_offset + SIZE_OF_INITIALIZED_DATA_OFFSET);
|
||||||
|
template_file->store_32(size_of_initialized_data);
|
||||||
|
|
||||||
|
template_file->seek(pe_header_offset + SIZE_OF_IMAGE_OFFSET);
|
||||||
|
uint32_t size_of_image = template_file->get_32();
|
||||||
|
size_of_image += section_entries.get(section_entries.size() - 1).virtual_address - old_last_section_virtual_address;
|
||||||
|
template_file->seek(pe_header_offset + SIZE_OF_IMAGE_OFFSET);
|
||||||
|
template_file->store_32(size_of_image);
|
||||||
|
|
||||||
|
uint32_t optional_header_offset = pe_header_offset + COFF_HEADER_SIZE;
|
||||||
|
|
||||||
|
// Update resource section size.
|
||||||
|
template_file->seek(optional_header_offset + (pe32plus ? 132 : 116));
|
||||||
|
template_file->store_32(resources_section_entry.virtual_size);
|
||||||
|
|
||||||
|
// Update relocation section size and pointer.
|
||||||
|
template_file->seek(optional_header_offset + (pe32plus ? 152 : 136));
|
||||||
|
template_file->store_32(section_entries[relocations_index].virtual_address);
|
||||||
|
template_file->store_32(section_entries[relocations_index].virtual_size);
|
||||||
|
|
||||||
|
template_file->seek(optional_header_offset + (pe32plus ? 240 : 224) + SectionEntry::SIZE * resource_index);
|
||||||
|
const Vector<uint8_t> &buf = resources_section_entry.save();
|
||||||
|
template_file->store_buffer(buf.ptr(), buf.size());
|
||||||
|
for (int i = resource_index + 1; i < section_entries.size(); i++) {
|
||||||
|
template_file->seek(optional_header_offset + (pe32plus ? 240 : 224) + SectionEntry::SIZE * i);
|
||||||
|
const Vector<uint8_t> §ion = section_entries[i].save();
|
||||||
|
template_file->store_buffer(section.ptr(), buf.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write new resource section.
|
||||||
|
template_file->seek(resources_section_entry.pointer_to_raw_data);
|
||||||
|
template_file->store_buffer(resources.ptr(), resources.size());
|
||||||
|
// Write the rest of sections.
|
||||||
|
for (int i = 0; i < moved_section_data.size(); i++) {
|
||||||
|
const Vector<uint8_t> &data = moved_section_data[i];
|
||||||
|
template_file->store_buffer(data.ptr(), data.size());
|
||||||
|
}
|
||||||
|
// Write footer data.
|
||||||
|
if (footer_size > 0) {
|
||||||
|
template_file->store_buffer(footer.ptr(), footer.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (template_file->get_position() < original_template_size) {
|
||||||
|
template_file->close();
|
||||||
|
_truncate(p_template_path, section_entries.get(section_entries.size() - 1).pointer_to_raw_data + section_entries.get(section_entries.size() - 1).size_of_raw_data + footer_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
memdelete(template_file);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<TemplateModifier::SectionEntry> TemplateModifier::_get_section_entries(FileAccess *p_executable) const {
|
||||||
|
Vector<SectionEntry> section_entries;
|
||||||
|
|
||||||
|
uint32_t pe_header_offset = _get_pe_header_offset(p_executable);
|
||||||
|
if (pe_header_offset == 0) {
|
||||||
|
return section_entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_executable->seek(pe_header_offset + 6);
|
||||||
|
int num_sections = p_executable->get_16();
|
||||||
|
p_executable->seek(pe_header_offset + 20);
|
||||||
|
uint16_t size_of_optional_header = p_executable->get_16();
|
||||||
|
p_executable->seek(pe_header_offset + COFF_HEADER_SIZE + size_of_optional_header);
|
||||||
|
|
||||||
|
for (int i = 0; i < num_sections; ++i) {
|
||||||
|
SectionEntry section_entry;
|
||||||
|
section_entry.load(p_executable);
|
||||||
|
section_entries.push_back(section_entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return section_entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
Error TemplateModifier::modify(const Ref<EditorExportPreset> &p_preset, const String &p_template_path, const String &p_icon_path) {
|
||||||
|
TemplateModifier template_modifier;
|
||||||
|
return template_modifier._modify_template(p_preset, p_template_path, p_icon_path);
|
||||||
|
}
|
||||||
235
platform/windows/export/template_modifier.h
Normal file
235
platform/windows/export/template_modifier.h
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* template_modifier.h */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* This file is part of: */
|
||||||
|
/* GODOT ENGINE */
|
||||||
|
/* https://godotengine.org */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||||
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||||
|
/* */
|
||||||
|
/* 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. */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/os/file_access.h"
|
||||||
|
#include "editor/editor_export.h"
|
||||||
|
|
||||||
|
class TemplateModifier {
|
||||||
|
const uint32_t PE_PAGE_SIZE = 4096;
|
||||||
|
const uint32_t BLOCK_SIZE = 512;
|
||||||
|
const uint32_t COFF_HEADER_SIZE = 24;
|
||||||
|
const uint32_t POINTER_TO_PE_HEADER_OFFSET = 0x3c;
|
||||||
|
// all offsets below are calculated from POINTER_TO_PE_HEADER_OFFSET value, at 0 is magic string PE (0x50450000)
|
||||||
|
const uint32_t MAGIC_NUMBER_OFFSET = 24;
|
||||||
|
const uint32_t SIZE_OF_INITIALIZED_DATA_OFFSET = 32;
|
||||||
|
const uint32_t SIZE_OF_IMAGE_OFFSET = 80;
|
||||||
|
|
||||||
|
struct ByteStream {
|
||||||
|
void save(uint8_t p_value, Vector<uint8_t> &r_bytes) const;
|
||||||
|
void save(uint16_t p_value, Vector<uint8_t> &r_bytes) const;
|
||||||
|
void save(uint32_t p_value, Vector<uint8_t> &r_bytes) const;
|
||||||
|
void save(const String &p_value, Vector<uint8_t> &r_bytes) const;
|
||||||
|
void save(uint32_t p_value, Vector<uint8_t> &r_bytes, uint32_t p_count) const;
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ResourceDirectoryTable : ByteStream {
|
||||||
|
static const uint16_t SIZE = 16;
|
||||||
|
|
||||||
|
uint16_t name_entry_count = 0;
|
||||||
|
uint16_t id_entry_count = 0;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ResourceDirectoryEntry : ByteStream {
|
||||||
|
static const uint16_t SIZE = 8;
|
||||||
|
static const uint32_t ICON = 0x03;
|
||||||
|
static const uint32_t GROUP_ICON = 0x0e;
|
||||||
|
static const uint32_t MANIFEST = 0x18;
|
||||||
|
static const uint32_t VERSION = 0x10;
|
||||||
|
static const uint32_t ENGLISH = 0x0409;
|
||||||
|
static const uint32_t HIGH_BIT = 0x80000000;
|
||||||
|
|
||||||
|
uint32_t id = 0;
|
||||||
|
uint32_t data_offset = 0;
|
||||||
|
bool name = false;
|
||||||
|
bool subdirectory = false;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FixedFileInfo : ByteStream {
|
||||||
|
uint32_t signature = 0xfeef04bd;
|
||||||
|
uint32_t struct_version = 0x10000;
|
||||||
|
uint32_t file_version_ms = 0;
|
||||||
|
uint32_t file_version_ls = 0;
|
||||||
|
uint32_t product_version_ms = 0;
|
||||||
|
uint32_t product_version_ls = 0;
|
||||||
|
uint32_t file_flags_mask = 0;
|
||||||
|
uint32_t file_flags = 0;
|
||||||
|
uint32_t file_os = 0x00000004;
|
||||||
|
uint32_t file_type = 0x00000001;
|
||||||
|
uint32_t file_subtype = 0;
|
||||||
|
uint32_t file_date_ms = 0;
|
||||||
|
uint32_t file_date_ls = 0;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
void set_file_version(const String &p_file_version);
|
||||||
|
void set_product_version(const String &p_product_version);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Structure : ByteStream {
|
||||||
|
uint16_t length = 0;
|
||||||
|
uint16_t value_length = 0;
|
||||||
|
uint16_t type = 0;
|
||||||
|
String key;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
Vector<uint8_t> &add_length(Vector<uint8_t> &r_bytes) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct StringStructure : Structure {
|
||||||
|
String value;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
StringStructure();
|
||||||
|
StringStructure(const String &p_key, const String &p_value);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct StringTable : Structure {
|
||||||
|
Vector<StringStructure> strings;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
void put(const String &p_key, const String &p_value);
|
||||||
|
StringTable();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct StringFileInfo : Structure {
|
||||||
|
StringTable string_table;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
StringFileInfo();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Var : Structure {
|
||||||
|
const uint32_t value = 0x04b00409;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
Var();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VarFileInfo : Structure {
|
||||||
|
Var var;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
VarFileInfo();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VersionInfo : Structure {
|
||||||
|
FixedFileInfo value;
|
||||||
|
StringFileInfo string_file_info;
|
||||||
|
VarFileInfo var_file_info;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
VersionInfo();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ManifestInfo : Structure {
|
||||||
|
String manifest;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
ManifestInfo() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IconEntry : ByteStream {
|
||||||
|
static const uint32_t SIZE = 16;
|
||||||
|
|
||||||
|
uint8_t width = 0;
|
||||||
|
uint8_t height = 0;
|
||||||
|
uint8_t colors = 0;
|
||||||
|
uint8_t reserved = 0;
|
||||||
|
uint16_t planes = 0;
|
||||||
|
uint16_t bits_per_pixel = 32;
|
||||||
|
uint32_t image_size = 0;
|
||||||
|
uint32_t image_offset = 0;
|
||||||
|
Vector<uint8_t> data;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
void load(FileAccess *p_file);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GroupIcon : ByteStream {
|
||||||
|
static constexpr uint8_t SIZES[6] = { 16, 32, 48, 64, 128, 0 };
|
||||||
|
|
||||||
|
uint16_t reserved = 0;
|
||||||
|
uint16_t type = 1;
|
||||||
|
uint16_t image_count = 0;
|
||||||
|
Vector<IconEntry> icon_entries;
|
||||||
|
Vector<Vector<uint8_t>> images;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
void load(FileAccess *p_icon_file);
|
||||||
|
void fill_with_godot_blue();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SectionEntry : ByteStream {
|
||||||
|
static const uint32_t SIZE = 40;
|
||||||
|
|
||||||
|
String name;
|
||||||
|
uint32_t virtual_size = 0;
|
||||||
|
uint32_t virtual_address = 0;
|
||||||
|
uint32_t size_of_raw_data = 0;
|
||||||
|
uint32_t pointer_to_raw_data = 0;
|
||||||
|
uint32_t pointer_to_relocations = 0;
|
||||||
|
uint32_t pointer_to_line_numbers = 0;
|
||||||
|
uint16_t number_of_relocations = 0;
|
||||||
|
uint16_t number_of_line_numbers = 0;
|
||||||
|
uint32_t characteristics = 0;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
void load(FileAccess *p_file);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ResourceDataEntry : ByteStream {
|
||||||
|
static const uint16_t SIZE = 16;
|
||||||
|
|
||||||
|
uint32_t rva = 0;
|
||||||
|
uint32_t size = 0;
|
||||||
|
|
||||||
|
Vector<uint8_t> save() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t _snap(uint32_t p_value, uint32_t p_size) const;
|
||||||
|
uint32_t _get_pe_header_offset(FileAccess *p_executable) const;
|
||||||
|
Vector<SectionEntry> _get_section_entries(FileAccess *p_executable) const;
|
||||||
|
GroupIcon _create_group_icon(const String &p_icon_path) const;
|
||||||
|
ManifestInfo _create_manifest_info() const;
|
||||||
|
VersionInfo _create_version_info(const HashMap<String, String> &p_strings) const;
|
||||||
|
Vector<uint8_t> _create_resources(uint32_t p_virtual_address, const GroupIcon &p_group_icon, const VersionInfo &p_version_info, const ManifestInfo &p_manifest_info) const;
|
||||||
|
Error _truncate(const String &p_executable_path, uint32_t p_size) const;
|
||||||
|
HashMap<String, String> _get_strings(const Ref<EditorExportPreset> &p_preset) const;
|
||||||
|
Error _modify_template(const Ref<EditorExportPreset> &p_preset, const String &p_template_path, const String &p_icon_path) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Error modify(const Ref<EditorExportPreset> &p_preset, const String &p_template_path, const String &p_icon_path);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user