Add support of hashes

This commit is contained in:
Beu
2025-01-13 22:48:36 +01:00
parent f2cfefda0f
commit 1ae76e7674
4 changed files with 38 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
class LayerConfig { class LayerConfig {
string Name; string Name;
string Path; string Path;
string Hash;
CGameUILayer::EUILayerType LayerType = CGameUILayer::EUILayerType::Normal; CGameUILayer::EUILayerType LayerType = CGameUILayer::EUILayerType::Normal;
string AttachId = ''; string AttachId = '';
@@ -9,6 +10,7 @@ class LayerConfig {
LayerConfig(const string &in _ParentPath, const Json::Value &in _Data) { LayerConfig(const string &in _ParentPath, const Json::Value &in _Data) {
Path = Path::Join(_ParentPath, _Data['Path']); Path = Path::Join(_ParentPath, _Data['Path']);
Hash = _Data['Hash'];
const string Manialink = GetManialink(); const string Manialink = GetManialink();
Name = PacksManager::GetLayerName(Manialink); Name = PacksManager::GetLayerName(Manialink);
@@ -33,6 +35,22 @@ class LayerConfig {
IO::File File(Path, IO::FileMode::Read); IO::File File(Path, IO::FileMode::Read);
const string Manialink = File.ReadToEnd(); 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; return Manialink;
} }

2
Hashes.as Normal file
View File

@@ -0,0 +1,2 @@
const array<string> C_InterfacesPacksHashes = {
};

View File

@@ -41,6 +41,21 @@ namespace PacksManager {
const string FileContent = File.ReadToEnd(); 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 { try {
const PackConfig Config(Path, FileContent); const PackConfig Config(Path, FileContent);
G_Configs[Id] = Config; G_Configs[Id] = Config;

View File

@@ -1,3 +1,6 @@
[Setting name="Display hash mismatch warning"]
bool S_DisplayHashWarning = true;
[Setting hidden] [Setting hidden]
string S_EnabledConfigs = ''; string S_EnabledConfigs = '';