mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-08-03 20:24:14 +02:00
Merge pull request #14770 from JoshuaVandaele/gen-approved-hash
AchievementApprovedHash: Automatically generate hash using CMake
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
# This file exists to be consumed via `add_custom_command`
|
||||||
|
# so that file changes are picked up without needing a full reconfigure
|
||||||
|
|
||||||
|
file(SHA1 ${JSON_FILE} ACHIEVEMENT_APPROVED_LIST_HASH)
|
||||||
|
configure_file(${TEMPLATE_FILE} ${OUTPUT_FILE} @ONLY)
|
||||||
@@ -394,8 +394,4 @@ std::string DigestToString(const Digest& digest)
|
|||||||
return fmt::format("{:02X}", fmt::join(digest, ""));
|
return fmt::format("{:02X}", fmt::join(digest, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DigestToSource(const Digest& digest)
|
|
||||||
{
|
|
||||||
return fmt::format("{{0x{:02X}}}", fmt::join(digest, ", 0x"));
|
|
||||||
}
|
|
||||||
} // namespace Common::SHA1
|
} // namespace Common::SHA1
|
||||||
|
|||||||
@@ -58,5 +58,30 @@ inline Digest CalculateDigest(const std::array<T, Size>& msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string DigestToString(const Digest& digest);
|
std::string DigestToString(const Digest& digest);
|
||||||
std::string DigestToSource(const Digest& digest);
|
|
||||||
|
constexpr Digest StringToDigest(std::string_view str)
|
||||||
|
{
|
||||||
|
Digest digest{};
|
||||||
|
ASSERT(str.size() == digest.size() * 2);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < str.size(); ++i)
|
||||||
|
{
|
||||||
|
const char c = str[i];
|
||||||
|
u8 quartet;
|
||||||
|
if (c >= '0' && c <= '9')
|
||||||
|
quartet = c - '0';
|
||||||
|
else if (c >= 'A' && c <= 'F')
|
||||||
|
quartet = c - 'A' + 10;
|
||||||
|
else if (c >= 'a' && c <= 'f')
|
||||||
|
quartet = c - 'a' + 10;
|
||||||
|
else
|
||||||
|
ASSERT(false);
|
||||||
|
|
||||||
|
if (i % 2 == 0)
|
||||||
|
digest[i / 2] = quartet << 4;
|
||||||
|
else
|
||||||
|
digest[i / 2] |= quartet;
|
||||||
|
}
|
||||||
|
return digest;
|
||||||
|
}
|
||||||
} // namespace Common::SHA1
|
} // namespace Common::SHA1
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
// Copyright 2026 Dolphin Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Common/Crypto/SHA1.h"
|
|
||||||
|
|
||||||
static constexpr std::string_view ACHIEVEMENT_APPROVED_LIST_FILENAME = "ApprovedInis.json";
|
|
||||||
// After building tests, find the new hash with:
|
|
||||||
// ./Binaries/Tests/tests --gtest_filter=PatchAllowlist.VerifyHashes
|
|
||||||
static const inline Common::SHA1::Digest ACHIEVEMENT_APPROVED_LIST_HASH = {
|
|
||||||
0xE6, 0xCD, 0xD7, 0x85, 0x7A, 0xBA, 0x72, 0xEC, 0x34, 0x11,
|
|
||||||
0x2B, 0x16, 0xB1, 0x31, 0xD0, 0x0A, 0x0A, 0xD7, 0xFC, 0xCC};
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright 2026 Dolphin Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Common/Crypto/SHA1.h"
|
||||||
|
|
||||||
|
static constexpr std::string_view ACHIEVEMENT_APPROVED_LIST_FILENAME = "ApprovedInis.json";
|
||||||
|
static constinit inline Common::SHA1::Digest ACHIEVEMENT_APPROVED_LIST_HASH =
|
||||||
|
Common::SHA1::StringToDigest("@ACHIEVEMENT_APPROVED_LIST_HASH@");
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
add_library(core
|
add_library(core
|
||||||
AchievementApprovedHash.h
|
|
||||||
AchievementManager.cpp
|
AchievementManager.cpp
|
||||||
AchievementManager.h
|
AchievementManager.h
|
||||||
ActionReplay.cpp
|
ActionReplay.cpp
|
||||||
@@ -591,6 +590,20 @@ add_library(core
|
|||||||
WiiUtils.h
|
WiiUtils.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/AchievementApprovedHash.h
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DJSON_FILE=${CMAKE_SOURCE_DIR}/Data/Sys/ApprovedInis.json
|
||||||
|
-DTEMPLATE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/AchievementApprovedHash.h.in
|
||||||
|
-DOUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/AchievementApprovedHash.h
|
||||||
|
-P ${CMAKE_SOURCE_DIR}/CMake/GenerateAchievementHash.cmake
|
||||||
|
DEPENDS ${CMAKE_SOURCE_DIR}/Data/Sys/ApprovedInis.json
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/AchievementApprovedHash.h.in
|
||||||
|
COMMENT "Generating AchievementApprovedHash.h"
|
||||||
|
)
|
||||||
|
|
||||||
|
target_sources(core PRIVATE AchievementApprovedHash.h)
|
||||||
|
|
||||||
if(_M_X86_64)
|
if(_M_X86_64)
|
||||||
target_sources(core PRIVATE
|
target_sources(core PRIVATE
|
||||||
DSP/Jit/x64/DSPEmitter.cpp
|
DSP/Jit/x64/DSPEmitter.cpp
|
||||||
|
|||||||
@@ -131,9 +131,7 @@ TEST(PatchAllowlist, VerifyHashes)
|
|||||||
if (digest != ACHIEVEMENT_APPROVED_LIST_HASH)
|
if (digest != ACHIEVEMENT_APPROVED_LIST_HASH)
|
||||||
{
|
{
|
||||||
ADD_FAILURE() << "Approved list hash does not match the one in AchievementApprovedHash.h."
|
ADD_FAILURE() << "Approved list hash does not match the one in AchievementApprovedHash.h."
|
||||||
<< std::endl
|
<< std::endl;
|
||||||
<< "Please update ACHIEVEMENT_APPROVED_LIST_HASH to the following:" << std::endl
|
|
||||||
<< Common::SHA1::DigestToSource(digest);
|
|
||||||
}
|
}
|
||||||
// Compare with old allowlist
|
// Compare with old allowlist
|
||||||
std::string old_allowlist;
|
std::string old_allowlist;
|
||||||
|
|||||||
Reference in New Issue
Block a user