From 1ae76e76742a25bb8d8a9e14a1f8c83e1806ecde Mon Sep 17 00:00:00 2001 From: beu Date: Mon, 13 Jan 2025 22:48:36 +0100 Subject: [PATCH] Add support of hashes --- Classes/LayerConfig.as | 18 ++++++++++++++++++ Hashes.as | 2 ++ PackManager.as | 15 +++++++++++++++ Settings.as | 3 +++ 4 files changed, 38 insertions(+) create mode 100644 Hashes.as diff --git a/Classes/LayerConfig.as b/Classes/LayerConfig.as index 2376aab..c323843 100644 --- a/Classes/LayerConfig.as +++ b/Classes/LayerConfig.as @@ -1,6 +1,7 @@ class LayerConfig { string Name; string Path; + string Hash; CGameUILayer::EUILayerType LayerType = CGameUILayer::EUILayerType::Normal; string AttachId = ''; @@ -9,6 +10,7 @@ class LayerConfig { LayerConfig(const string &in _ParentPath, const Json::Value &in _Data) { Path = Path::Join(_ParentPath, _Data['Path']); + Hash = _Data['Hash']; const string Manialink = GetManialink(); Name = PacksManager::GetLayerName(Manialink); @@ -33,6 +35,22 @@ class LayerConfig { IO::File File(Path, IO::FileMode::Read); const string Manialink = File.ReadToEnd(); + + const string FileHash = Crypto::Sha256(Manialink); + + if (Hash != FileHash) { + print('Cannot load layer "'+ Path +'": Invalid hash'); + trace('info.json Layer hash: '+ Hash); + trace('file hash: '+ FileHash); + if (S_DisplayHashWarning) { + RenderManager::NotifyWarning('Cannot load layer "'+ Path +'": Invalid hash'); + } + + if (!Meta::IsDeveloperMode()) { + throw('Cannot load layer "'+ Path +'": Invalid hash'); + } + } + return Manialink; } diff --git a/Hashes.as b/Hashes.as new file mode 100644 index 0000000..cddf556 --- /dev/null +++ b/Hashes.as @@ -0,0 +1,2 @@ +const array C_InterfacesPacksHashes = { +}; \ No newline at end of file diff --git a/PackManager.as b/PackManager.as index 4bc2cb0..be53d4f 100644 --- a/PackManager.as +++ b/PackManager.as @@ -41,6 +41,21 @@ namespace PacksManager { const string FileContent = File.ReadToEnd(); + const string InfoFileHash = Crypto::Sha256(FileContent); + + if (C_InterfacesPacksHashes.Find(InfoFileHash) < 0) { + print('Invalid Pack Config "'+ Id +'": Invalid hash'); + trace('info.json hash: '+ InfoFileHash); + if (S_DisplayHashWarning) { + RenderManager::NotifyWarning('Invalid Pack Config "'+ Id +'": Invalid hash'); + } + + if (!Meta::IsDeveloperMode()) { + trace('Invalid Pack Config "'+ Id +'": Invalid hash'); + continue; + } + } + try { const PackConfig Config(Path, FileContent); G_Configs[Id] = Config; diff --git a/Settings.as b/Settings.as index f685e57..a33c4f0 100644 --- a/Settings.as +++ b/Settings.as @@ -1,3 +1,6 @@ +[Setting name="Display hash mismatch warning"] +bool S_DisplayHashWarning = true; + [Setting hidden] string S_EnabledConfigs = ''; \ No newline at end of file