Skip to content

Commit

Permalink
Common - Check extensions hash (#10144)
Browse files Browse the repository at this point in the history
Co-authored-by: johnb432 <[email protected]>
Co-authored-by: Grim <[email protected]>
  • Loading branch information
3 people authored Jan 13, 2025
1 parent ca4ea2f commit 2bfb226
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 15 deletions.
6 changes: 6 additions & 0 deletions addons/common/ACE_ExtensionsHashes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ACE_ExtensionsHashes {
class ace {
dll = "b83c2c9c7c989eaf888c885d13a2fdf4a61d1c5f";
dll_x64 = "356a61c4bd2aa13556a8ba0b467c819b3b438d6c";
};
};
2 changes: 2 additions & 0 deletions addons/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ class ACE_Tests {
mapConfigs = QPATHTOF(dev\test_mapConfigs.sqf);
cfgPatches = QPATHTOF(dev\test_cfgPatches.sqf);
};

#include "ACE_ExtensionsHashes.hpp"
45 changes: 33 additions & 12 deletions addons/common/functions/fnc_checkFiles.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -116,31 +116,52 @@ if (_oldCompats isNotEqualTo []) then {
///////////////
// Check extensions
///////////////
private _platform = toLowerANSI (productVersion select 6);
if (hasInterface) then {
private _platform = toLowerANSI (productVersion select 6);

if (_platform in ["linux", "osx"]) then {
// Linux and OSX client ports do not support extensions at all
if (hasInterface) then {
// Check for presence
if (_platform in ["linux", "osx"]) exitWith {
// Linux and OSX client ports do not support extensions at all
WARNING("Operating system does not support extensions");
} else {
INFO("Operating system does not support extensions");
};
} else {

("ace" callExtension ["version", []]) params [["_versionEx", "", [""]], ["_returnCode", -1, [-1]]];

if (_returnCode != 0 || {_versionEx == ""}) then {
private _errorMsg = format ["Extension not found. [Return Code: %1]", _returnCode];
ERROR(_errorMsg);

if (hasInterface) then {
["[ACE] ERROR", _errorMsg] call FUNC(errorMessage);
};
["[ACE] ERROR", _errorMsg] call FUNC(errorMessage);
} else {
_versionEx = _versionEx select [0, 8]; // git hash
INFO_1("Extension [Version: %1]",_versionEx);
};
};

// Check for correct hash
if (GVAR(checkExtensions)) then {
private _allExtensions = allExtensions;

{
private _extName = configName _x;
private _extensionType = "dll";
if (productVersion select 7 == "x64") then { _extensionType = format ["%1_x64", _extensionType]; };
private _expectedHash = getText (_x >> _extensionType);

private _extensionHash = "";
{
if ((_x getOrDefault ["name", ""]) == _extName) exitWith {
_extensionHash = _x getOrDefault ["hash", ""];
};
} forEach _allExtensions;
TRACE_3("",_extName,_expectedHash,_extensionHash);

if (_extensionHash != _expectedHash) then {
private _errorMsg = format ["Extension %1 wrong version [%2 vs %3].", _extName, _extensionHash, _expectedHash];
ERROR(_errorMsg);
["[ACE] ERROR", _errorMsg] call FUNC(errorMessage);
};
} forEach ("true" configClasses (configFile >> "ACE_ExtensionsHashes"));
};
};

///////////////
// Check server version/addons
Expand Down
9 changes: 9 additions & 0 deletions addons/common/initSettings.inc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ private _categorySway = [_category, LSTRING(subcategory_sway)];
1
] call CBA_fnc_addSetting;

[
QGVAR(checkExtensions),
"CHECKBOX",
[LSTRING(checkExtensions_DisplayName)],
_category,
false,
1
] call CBA_fnc_addSetting;

[
QGVAR(settingFeedbackIcons),
"LIST",
Expand Down
3 changes: 3 additions & 0 deletions addons/common/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@
<Chinesesimp>检查 PBO</Chinesesimp>
<Hungarian>PBO-k ellenőrzése</Hungarian>
</Key>
<Key ID="STR_ACE_Common_checkExtensions_DisplayName">
<English>Check Extensions</English>
</Key>
<Key ID="STR_ACE_Common_CheckPBO_Whitelist_Description">
<English>What addons are allowed regardless?</English>
<Czech>Jaké addony jsou povoleny?</Czech>
Expand Down
10 changes: 9 additions & 1 deletion extension/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,13 @@ dependencies = ["build_x32_release"]
[tasks.debug]
dependencies = ["move_x32_debug", "move_x64_debug"]

[tasks.release]
[tasks.updateSigs]
script_runner = "python"
script_extension = "py"
script_runner_args = ["../tools/getExtensionHash.py"]
script = '''
'''
dependencies = ["move_x32_release", "move_x64_release"]

[tasks.release]
dependencies = ["updateSigs"]
4 changes: 2 additions & 2 deletions tools/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
}
},
{
"label": "Extension: x64",
"label": "Extension: make move_x64_release",
"command": "cargo",
"options": {
"cwd": "${workspaceFolder}"
Expand All @@ -133,7 +133,7 @@
}
},
{
"label": "Extension: Release",
"label": "Extension: make release",
"command": "cargo",
"options": {
"cwd": "${workspaceFolder}"
Expand Down
36 changes: 36 additions & 0 deletions tools/getExtensionHash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pathlib
import os
import hashlib

addon_base_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

extensions = {}

for file in os.listdir(addon_base_path):
path = pathlib.Path(addon_base_path, file)
extension_type = "dll"
if path.suffix == ".dll":
key = path.stem
if key.endswith("_x64"):
key = key.removesuffix("_x64")
extension_type += "_x64"
print(f"looking at {path}")
with open(path, 'rb') as file_read:
sha1 = hashlib.sha1()
data = file_read.read()
sha1.update(data)
arr = extensions.get(key, {})
arr[extension_type] = sha1.hexdigest()
extensions[key] = arr

file_out = pathlib.Path(addon_base_path, "addons", "common", "ACE_ExtensionsHashes.hpp")
with open(file_out, 'w') as file_write:
print(f"class ACE_ExtensionsHashes {{", file=file_write)
for key, values in extensions.items():
print(f" class {key} {{", file=file_write)
for type, hash in values.items():
print(f" {type} = \"{hash}\";", file=file_write)
print(f" }};", file=file_write)
print(f"}};", file=file_write)

print(f"Wrote {len(extensions)} to {file_out}")

0 comments on commit 2bfb226

Please sign in to comment.