Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.
C++
phase-0 work: P0.5 veyra_base logger/result strings/file identity, self-test passes
Veyra Goal Agent98140bcb1713
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 3ca91019..66c6b954 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -24,6 +24,18 @@ include(VeyraWarnings)# ---------------------------------------------------------------------------# Targets grow phase by phase; only what actually compiles is declared.# ---------------------------------------------------------------------------+add_library(veyra_base STATIC+ src/base/Log.cpp+ src/base/NgxResult.cpp+ src/base/FileIdentity.cpp+)+veyra_apply_warnings(veyra_base)+target_compile_features(veyra_base PUBLIC cxx_std_20)+target_compile_definitions(veyra_base PUBLIC+ UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX)+target_include_directories(veyra_base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)+target_link_libraries(veyra_base PUBLIC bcrypt wintrust crypt32 version)+add_executable(veyra_runtime_probetools/runtime_probe/main.cpp)@@ -31,3 +43,4 @@ veyra_apply_warnings(veyra_runtime_probe)target_compile_features(veyra_runtime_probe PRIVATE cxx_std_20)target_compile_definitions(veyra_runtime_probe PRIVATEUNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX)+target_link_libraries(veyra_runtime_probe PRIVATE veyra_base)diff --git a/include/veyra/FileIdentity.h b/include/veyra/FileIdentity.hnew file mode 100644index 00000000..a5030d1f--- /dev/null+++ b/include/veyra/FileIdentity.h@@ -0,0 +1,36 @@+#pragma once++#include <cstdint>+#include <string>++namespace veyra {++struct FileIdentity {+ std::wstring path;+ uint64_t sizeBytes = 0;+ std::string sha256Upper; // 64 uppercase hex characters when computed+ std::wstring fileVersion; // "310.8.0.0" style, empty when absent+ std::wstring productVersion;+ bool signatureValid = false;+ uint32_t winTrustError = 0;+ std::wstring signerSubject; // certificate subject when signature valid+ bool signerIsNvidia = false;+};++enum class IdentityError : int32_t {+ None = 0,+ FileOpen = 1,+ Read = 2,+ Hash = 3,+ VersionInfo = 4,+ Signature = 5,+};++const char* identityErrorString(IdentityError error);++// Computes size + SHA-256 + version strings + Authenticode status + signer+// subject for one file. Returns false and fills `error` when a stage fails;+// partial results remain in `out` for logging.+bool computeFileIdentity(const std::wstring& path, FileIdentity& out, IdentityError& error);++} // namespace veyradiff --git a/include/veyra/Log.h b/include/veyra/Log.hnew file mode 100644index 00000000..20e335e4--- /dev/null+++ b/include/veyra/Log.h@@ -0,0 +1,71 @@+#pragma once++#include <cstdint>+#include <cstdio>+#include <mutex>+#include <string>++namespace veyra {++enum class LogLevel : uint8_t {+ Trace,+ Info,+ Warn,+ Error,+};++// Process-wide structured logger (Playbook section 17.1).+// Line shape:+// <UTC ISO8601 ms> t=<tid> [LEVEL] [component] message+// Thread-safe; writes to stdout and, when openFile() was called, to a file.+class Logger {+public:+ static Logger& instance();++ Logger() = default;+ ~Logger();++ Logger(const Logger&) = delete;+ Logger& operator=(const Logger&) = delete;++ // Creates parent directories; returns false and logs to console on failure.+ bool openFile(const std::wstring& path);+ void closeFile();+ void setConsoleEnabled(bool enabled);++ void write(LogLevel level, const char* component, const std::string& message);++private:+ std::mutex mutex_;+ std::FILE* file_ = nullptr;+ bool consoleEnabled_ = true;+};++namespace log {++void trace(const char* component, const std::string& message);+void info(const char* component, const std::string& message);+void warn(const char* component, const std::string& message);+void error(const char* component, const std::string& message);++// Key=value helper used by call sites that need structured fields.+inline std::string kv(const char* key, uint64_t value)+{+ return std::string(key) + "=" + std::to_string(value);+}++inline std::string kvHex(const char* key, uint64_t value)+{+ char buffer[32]{};+ std::snprintf(buffer, sizeof(buffer), "0x%llX", static_cast<unsigned long long>(value));+ return std::string(key) + "=" + buffer;+}++inline std::string kv(const char* key, const std::string& value)+{+ return std::string(key) + "=" + value;+}++} // namespace log++} // namespace veyradiff --git a/include/veyra/NgxResult.h b/include/veyra/NgxResult.hnew file mode 100644index 00000000..9ed8186e--- /dev/null+++ b/include/veyra/NgxResult.h@@ -0,0 +1,18 @@+#pragma once++#include <cstdint>+#include <string>++namespace veyra {++// HRESULT (a 32-bit `long` on Windows) formatting:+// "0x887A0005 (DXGI_ERROR_DEVICE_REMOVED)" style for well-known D3D/DXGI/+// common codes, plain hex for anything else.+std::string hresultString(long hr);++// NVSDK_NGX_Result formatting. Only codes verified from the official public+// SDK headers get names (Phase 1 replaces this minimal table once the pinned+// DLSS SDK 310.7 headers are staged); everything else prints as hex only.+std::string ngxResultString(uint64_t result);++} // namespace veyradiff --git a/include/veyra/Result.h b/include/veyra/Result.hnew file mode 100644index 00000000..e0eaec15--- /dev/null+++ b/include/veyra/Result.h@@ -0,0 +1,45 @@+#pragma once++#include <cstdint>++namespace veyra {++// Veyra-internal status codes, kept separate from HRESULT/NGX results which+// are always logged as their raw hex value plus a readable name.+enum class Status : int32_t {+ Ok = 0,+ InvalidArgument = 1,+ FileNotFound = 2,+ IoFailure = 3,+ CryptoFailure = 4,+ SignatureFailure = 5,+ VersionInfoFailure = 6,+ LoadLibraryFailure = 7,+ MissingExport = 8,+ DeviceFailure = 9,+ WindowFailure = 10,+ JsonFailure = 11,+ Cancelled = 12,+};++inline const char* statusString(Status status)+{+ switch (status) {+ case Status::Ok: return "Ok";+ case Status::InvalidArgument: return "InvalidArgument";+ case Status::FileNotFound: return "FileNotFound";+ case Status::IoFailure: return "IoFailure";+ case Status::CryptoFailure: return "CryptoFailure";+ case Status::SignatureFailure: return "SignatureFailure";+ case Status::VersionInfoFailure: return "VersionInfoFailure";+ case Status::LoadLibraryFailure: return "LoadLibraryFailure";+ case Status::MissingExport: return "MissingExport";+ case Status::DeviceFailure: return "DeviceFailure";+ case Status::WindowFailure: return "WindowFailure";+ case Status::JsonFailure: return "JsonFailure";+ case Status::Cancelled: return "Cancelled";+ default: return "Unknown";+ }+}++} // namespace veyradiff --git a/loop/BACKLOG.md b/loop/BACKLOG.mdindex b2b8d9f9..b8b8b68e 100644--- a/loop/BACKLOG.md+++ b/loop/BACKLOG.md@@ -8,7 +8,7 @@- [x] P0.2 确认 .gitignore 后按 LOOP_ENGINE 固定顺序初始化本地 Git;显式 staged allowlist、建立 baseline commit、切到 agent/veyra-v1-loop、写 baselineCommit 状态指针;验证两个二进制、runtime_local、third_party_local、reference_local、captures、logs 均未被跟踪。(2026-09-02:baseline=2086282,loop 指针提交=09abf5d,8/8 ignore 探针通过,17 文件 allowlist,Git 后 preflight 66/66。)- [x] P0.3 先创建 fail-closed 的 scripts/gates/phase0.ps1,编码 Playbook 的 Phase 0 门槛;此时因为工程/输出不存在必须失败。(2026-09-02:gate 建立并 AST-clean;负向运行 exit 1,5 项缺失输入全报;无项目变异。)- [x] P0.4 建立最小 CMake/C++20 Win32 x64 工程与 Debug/Release presets,不引入 FFmpeg/UI。(2026-09-02:Ninja presets 双配置构建 exit 0,stub 运行 exit 0,build.ps1 解析 vswhere/vcvars,presets 无机器路径。)-- [ ] P0.5 实现结构化 logger、HRESULT/NGX result 字符串、文件 size/hash/signature 检查。+- [x] P0.5 实现结构化 logger、HRESULT/NGX result 字符串、文件 size/hash/signature 检查。(2026-09-02:--self-test 实测 BCrypt SHA256、WinVerifyTrust、CryptQueryObject 签名者、版本提取;staged DLL 身份与固定契约全匹配;双 preset 构建 exit 0。)- [ ] P0.6 实现 D3D12DeviceContext:RTX adapter、device、direct queue、debug layer、4-slot command allocator/list/fence/event ring。- [ ] P0.7 实现 veyra_runtime_probe:受限绝对路径加载本地复制的 nvngx_dlssnr.dll,验证 required exports;不得加载 addon。- [ ] P0.8 Debug/Release 构建并实际运行 probe;D3D12 窗口循环 5 分钟无 device removed;记录命令、exit code、GPU/driver、hash/signature/exports、日志路径。diff --git a/loop/JOURNAL.md b/loop/JOURNAL.mdindex fddc4511..92c086e2 100644--- a/loop/JOURNAL.md+++ b/loop/JOURNAL.md@@ -142,6 +142,34 @@ Result:---+## Cycle 005 — P0.5 veyra_base:logger/result 字符串/文件身份++### Before++- Phase: 0+- 唯一任务: 实现 veyra_base 静态库(结构化 logger、Status/HRESULT/NGX result 字符串、文件 size/SHA256/version/Authenticode 签名检查),probe 增加 --self-test 模式实测这些功能。+- 可证伪假设: 若 SHA256/WinTrust/版本提取任一实现有误,--self-test 对 staged nvngx_dlssnr.dll 的固定身份(165840496/E16B…/Valid/NVIDIA)校验将失败并 exit 非零。+- 预计修改文件: include/veyra/{Log.h,Result.h,NgxResult.h,FileIdentity.h}、src/base/{Log.cpp,NgxResult.cpp,FileIdentity.cpp}、CMakeLists.txt(+veyra_base target)、tools/runtime_probe/main.cpp(--self-test)。+- 快速检查命令: `scripts/build.ps1 -Preset x64-debug` → 0;`veyra_runtime_probe.exe --self-test --runtime-dir <abs runtime_local/nvidia>` → 0。+- 预期新增证据: self-test 真实输出 exe/DLL 的 SHA256、版本、签名链;staged DLL 与固定常量全匹配。++### After++- 实际修改: 新增 include/veyra/{Log.h,Result.h,NgxResult.h,FileIdentity.h}、src/base/{Log.cpp,NgxResult.cpp,FileIdentity.cpp};CMakeLists 增加 veyra_base 静态库(bcrypt/wintrust/crypt32/version);main.cpp 增加 --self-test。+- 实际命令与 exit code:+ - `scripts/build.ps1 -Preset x64-debug` → 前两次 exit 6:C4838(DXGI 字面量 unsigned→long 收缩)、WinVerifyTrust 形参需非 const GUID*、匿名命名空间内 log:: 未限定、wchar→char range 构造 C4244;逐一修复后 exit 0。+ - `scripts/build.ps1 -Preset x64-release` → exit 0。+ - `veyra_runtime_probe.exe --self-test --runtime-dir <abs>` → exit 0,输出:result-strings ok(S_OK / DXGI_ERROR_DEVICE_REMOVED / NVSDK_NGX_Result_Success);exe 自身 identity(1235456 字节,sha256=75F9F06F…,签名 Invalid(2148204800)=TRUST_E_NOSIGNATURE,符合未签名自编程序预期);staged DLL identity 全匹配(165840496 / E16B…FC8E / 310.8.0.0 / Valid / NVIDIA Corporation)。+ - 教训记录:一次构建失败后误跑了旧 stub exe 并显示 exit 0——陈旧产物陷阱,phase0 gate 的 runId+exeSha256 契约正是为此设计。+- 新证据/日志路径: self-test 控制台输出(已记录于上);无新 capture。+- 失败 fingerprint: phase0|build x64-debug|6|C4838/WinVerifyTrust const/log 未限定/C4244 —— 4 个不同编译错误在同一指纹序列内全部修复。+- 本 fingerprint 第几次不同尝试: 每个错误独立修复;当前无遗留。+- 是否有进展,依据: 是——veyra_base 的 hash/签名/版本/日志/字符串功能全部经真实运行验证,DLL 身份校验与 preflight 的 PowerShell 结果一致。+- STATE/BACKLOG 更新: cycle.completed=5、currentTask 指向 P0.6;BACKLOG P0.5 → DONE。+- 下一唯一动作: P0.6 veyra_gfx:D3D12DeviceContext(RTX adapter、device、direct queue、debug layer、4-slot allocator/list/fence/event ring)+ probe --device-info 实测。++---+复制下面模板开始每个新 cycle。必须先填 Before,再改代码;完成后填 After。## Cycle NNN — 简短任务名diff --git a/loop/STATE.json b/loop/STATE.jsonindex 3916f914..b14cf3ec 100644--- a/loop/STATE.json+++ b/loop/STATE.json@@ -76,14 +76,14 @@}],"cycle": {- "completed": 4,+ "completed": 5,"maximum": 80,"sameFailureAttempts": 0,"maximumSameFailureAttempts": 3,"noProgressCycles": 0,"maximumNoProgressCycles": 5},- "currentTask": "P0.5: implement veyra_base (structured logger, HRESULT/NGX result strings, file size/hash/signature checks) and verify with a real probe self-test.",+ "currentTask": "P0.6: implement veyra_gfx D3D12DeviceContext (RTX adapter, device, direct queue, debug layer, 4-slot allocator/list/fence/event ring) and verify with probe --device-info on the real GPU.","lastGate": {"name": "phase0","status": "failed",@@ -96,6 +96,6 @@"lastGoodCommit": null,"openP0P1Findings": [],"blockers": [],- "nextAction": "Implement P0.5 veyra_base, then P0.6 gfx, P0.7 probe, P0.8 gate runs.",- "updatedAt": "2026-09-02T21:00:00+08:00"+ "nextAction": "Implement P0.6 veyra_gfx, P0.7 probe DLL load/window/JSON, P0.8 gate runs.",+ "updatedAt": "2026-09-02T21:40:00+08:00"}diff --git a/src/base/FileIdentity.cpp b/src/base/FileIdentity.cppnew file mode 100644index 00000000..b17e7bd2--- /dev/null+++ b/src/base/FileIdentity.cpp@@ -0,0 +1,267 @@+#include "veyra/FileIdentity.h"++#include <windows.h>+#include <bcrypt.h>+#include <softpub.h>+#include <wintrust.h>+#include <wincrypt.h>++#include <array>+#include <format>+#include <vector>++#include "veyra/Log.h"++#pragma comment(lib, "bcrypt.lib")+#pragma comment(lib, "wintrust.lib")+#pragma comment(lib, "crypt32.lib")+#pragma comment(lib, "version.lib")++namespace veyra {++namespace {++std::string narrow(const std::wstring& text)+{+ if (text.empty()) {+ return {};+ }+ const int length = WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), nullptr, 0, nullptr, nullptr);+ if (length <= 0) {+ return {};+ }+ std::string converted(static_cast<size_t>(length), '\0');+ WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), converted.data(), length, nullptr, nullptr);+ return converted;+}++constexpr size_t kHashChunkBytes = 1u << 20; // 1 MiB read chunks++std::string bytesToHexUpper(const std::array<unsigned char, 32>& bytes)+{+ static const char* kHex = "0123456789ABCDEF";+ std::string hex;+ hex.reserve(bytes.size() * 2);+ for (const unsigned char byte : bytes) {+ hex.push_back(kHex[byte >> 4]);+ hex.push_back(kHex[byte & 0x0F]);+ }+ return hex;+}++bool computeSha256(const std::wstring& path, std::string& hexOut, uint64_t& sizeOut)+{+ BCRYPT_ALG_HANDLE algorithm = nullptr;+ NTSTATUS status = BCryptOpenAlgorithmProvider(&algorithm, BCRYPT_SHA256_ALGORITHM, nullptr, 0);+ if (!BCRYPT_SUCCESS(status)) {+ log::error("base", std::format("sha256: BCryptOpenAlgorithmProvider failed ntstatus=0x{:X}", static_cast<uint32_t>(status)));+ return false;+ }++ BCRYPT_HASH_HANDLE hash = nullptr;+ status = BCryptCreateHash(algorithm, &hash, nullptr, 0, nullptr, 0, 0);+ if (!BCRYPT_SUCCESS(status)) {+ BCryptCloseAlgorithmProvider(algorithm, 0);+ log::error("base", std::format("sha256: BCryptCreateHash failed ntstatus=0x{:X}", static_cast<uint32_t>(status)));+ return false;+ }++ HANDLE file = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,+ nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);+ if (file == INVALID_HANDLE_VALUE) {+ const DWORD lastError = GetLastError();+ BCryptDestroyHash(hash);+ BCryptCloseAlgorithmProvider(algorithm, 0);+ log::error("base", std::format("sha256: CreateFileW failed lastError={} path-suffix-check", lastError));+ return false;+ }++ LARGE_INTEGER size{};+ if (!GetFileSizeEx(file, &size)) {+ const DWORD lastError = GetLastError();+ CloseHandle(file);+ BCryptDestroyHash(hash);+ BCryptCloseAlgorithmProvider(algorithm, 0);+ log::error("base", std::format("sha256: GetFileSizeEx failed lastError={}", lastError));+ return false;+ }+ sizeOut = static_cast<uint64_t>(size.QuadPart);++ std::vector<unsigned char> buffer(kHashChunkBytes);+ for (;;) {+ DWORD readBytes = 0;+ if (!ReadFile(file, buffer.data(), static_cast<DWORD>(buffer.size()), &readBytes, nullptr)) {+ const DWORD lastError = GetLastError();+ CloseHandle(file);+ BCryptDestroyHash(hash);+ BCryptCloseAlgorithmProvider(algorithm, 0);+ log::error("base", std::format("sha256: ReadFile failed lastError={}", lastError));+ return false;+ }+ if (readBytes == 0) {+ break;+ }+ status = BCryptHashData(hash, buffer.data(), readBytes, 0);+ if (!BCRYPT_SUCCESS(status)) {+ CloseHandle(file);+ BCryptDestroyHash(hash);+ BCryptCloseAlgorithmProvider(algorithm, 0);+ log::error("base", std::format("sha256: BCryptHashData failed ntstatus=0x{:X}", static_cast<uint32_t>(status)));+ return false;+ }+ }+ CloseHandle(file);++ std::array<unsigned char, 32> digest{};+ status = BCryptFinishHash(hash, digest.data(), static_cast<ULONG>(digest.size()), 0);+ BCryptDestroyHash(hash);+ BCryptCloseAlgorithmProvider(algorithm, 0);+ if (!BCRYPT_SUCCESS(status)) {+ log::error("base", std::format("sha256: BCryptFinishHash failed ntstatus=0x{:X}", static_cast<uint32_t>(status)));+ return false;+ }++ hexOut = bytesToHexUpper(digest);+ return true;+}++bool queryVersionStrings(const std::wstring& path, std::wstring& fileVersion, std::wstring& productVersion)+{+ DWORD handle = 0;+ const DWORD size = GetFileVersionInfoSizeW(path.c_str(), &handle);+ if (size == 0) {+ return false;+ }+ std::vector<unsigned char> buffer(size);+ if (!GetFileVersionInfoW(path.c_str(), 0, size, buffer.data())) {+ return false;+ }+ VS_FIXEDFILEINFO* fixedInfo = nullptr;+ UINT fixedInfoLength = 0;+ if (VerQueryValueW(buffer.data(), L"\\", reinterpret_cast<void**>(&fixedInfo), &fixedInfoLength) && fixedInfoLength >= sizeof(VS_FIXEDFILEINFO)) {+ fileVersion = std::format(L"{}.{}.{}.{}",+ HIWORD(fixedInfo->dwFileVersionMS), LOWORD(fixedInfo->dwFileVersionMS),+ HIWORD(fixedInfo->dwFileVersionLS), LOWORD(fixedInfo->dwFileVersionLS));+ productVersion = std::format(L"{}.{}.{}.{}",+ HIWORD(fixedInfo->dwProductVersionMS), LOWORD(fixedInfo->dwProductVersionMS),+ HIWORD(fixedInfo->dwProductVersionLS), LOWORD(fixedInfo->dwProductVersionLS));+ return true;+ }+ return false;+}++bool verifyAuthenticode(const std::wstring& path, uint32_t& winTrustError)+{+ WINTRUST_FILE_INFO fileInfo{};+ fileInfo.cbStruct = sizeof(fileInfo);+ fileInfo.pcwszFilePath = path.c_str();++ WINTRUST_DATA trustData{};+ trustData.cbStruct = sizeof(trustData);+ trustData.dwUIChoice = WTD_UI_NONE;+ trustData.fdwRevocationChecks = WTD_REVOKE_NONE;+ trustData.dwUnionChoice = WTD_CHOICE_FILE;+ trustData.pFile = &fileInfo;+ trustData.dwStateAction = WTD_STATEACTION_VERIFY;+ trustData.dwProvFlags = WTD_SAFER_FLAG;++ GUID verifyAction = WINTRUST_ACTION_GENERIC_VERIFY_V2;+ const LONG result = WinVerifyTrust(nullptr, &verifyAction, &trustData);+ winTrustError = static_cast<uint32_t>(result);++ WINTRUST_DATA closeData = trustData;+ closeData.dwStateAction = WTD_STATEACTION_CLOSE;+ WinVerifyTrust(nullptr, &verifyAction, &closeData);++ return result == 0;+}++std::wstring querySignerSubject(const std::wstring& path)+{+ HCERTSTORE store = nullptr;+ HCRYPTMSG message = nullptr;+ if (!CryptQueryObject(CERT_QUERY_OBJECT_FILE, path.c_str(),+ CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED,+ CERT_QUERY_FORMAT_FLAG_BINARY,+ 0, nullptr, nullptr, nullptr, &store, &message, nullptr)) {+ return {};+ }++ std::wstring subject;+ DWORD signerInfoSize = 0;+ if (CryptMsgGetParam(message, CMSG_SIGNER_INFO_PARAM, 0, nullptr, &signerInfoSize) && signerInfoSize > 0) {+ std::vector<unsigned char> signerBuffer(signerInfoSize);+ auto* signerInfo = reinterpret_cast<PCMSG_SIGNER_INFO>(signerBuffer.data());+ if (CryptMsgGetParam(message, CMSG_SIGNER_INFO_PARAM, 0, signerInfo, &signerInfoSize)) {+ CERT_INFO searchInfo{};+ searchInfo.Issuer = signerInfo->Issuer;+ searchInfo.SerialNumber = signerInfo->SerialNumber;+ const PCCERT_CONTEXT certificate = CertFindCertificateInStore(+ store, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_SUBJECT_CERT, &searchInfo, nullptr);+ if (certificate != nullptr) {+ wchar_t nameBuffer[512]{};+ const DWORD nameLength = CertGetNameStringW(certificate, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, nullptr, nameBuffer, 512);+ if (nameLength > 0) {+ subject = nameBuffer;+ }+ CertFreeCertificateContext(certificate);+ }+ }+ }++ CryptMsgClose(message);+ CertCloseStore(store, CERT_CLOSE_STORE_FORCE_FLAG);+ return subject;+}++} // namespace++const char* identityErrorString(IdentityError error)+{+ switch (error) {+ case IdentityError::None: return "None";+ case IdentityError::FileOpen: return "FileOpen";+ case IdentityError::Read: return "Read";+ case IdentityError::Hash: return "Hash";+ case IdentityError::VersionInfo: return "VersionInfo";+ case IdentityError::Signature: return "Signature";+ default: return "Unknown";+ }+}++bool computeFileIdentity(const std::wstring& path, FileIdentity& out, IdentityError& error)+{+ error = IdentityError::None;+ out = FileIdentity{};+ out.path = path;++ const DWORD attributes = GetFileAttributesW(path.c_str());+ if (attributes == INVALID_FILE_ATTRIBUTES || (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {+ error = IdentityError::FileOpen;+ return false;+ }++ if (!computeSha256(path, out.sha256Upper, out.sizeBytes)) {+ error = IdentityError::Hash;+ return false;+ }++ // Version strings are optional: unsigned binaries may lack them entirely.+ (void)queryVersionStrings(path, out.fileVersion, out.productVersion);++ out.signatureValid = verifyAuthenticode(path, out.winTrustError);+ if (out.signatureValid) {+ out.signerSubject = querySignerSubject(path);+ out.signerIsNvidia = out.signerSubject.find(L"NVIDIA") != std::wstring::npos;+ }++ log::info("base", std::format("file-identity path-size={} sha256={} fileVersion={} signature={} signer={}",+ out.sizeBytes,+ out.sha256Upper.empty() ? std::string("<none>") : out.sha256Upper,+ out.fileVersion.empty() ? std::string("<none>") : narrow(out.fileVersion),+ out.signatureValid ? std::string("Valid") : std::string("Invalid(") + std::to_string(out.winTrustError) + ")",+ out.signerSubject.empty() ? std::string("<none>") : narrow(out.signerSubject)));+ return true;+}++} // namespace veyradiff --git a/src/base/Log.cpp b/src/base/Log.cppnew file mode 100644index 00000000..19807867--- /dev/null+++ b/src/base/Log.cpp@@ -0,0 +1,127 @@+#include "veyra/Log.h"++#include <windows.h>++#include <chrono>+#include <filesystem>+#include <format>++namespace veyra {++namespace {++const char* levelTag(LogLevel level)+{+ switch (level) {+ case LogLevel::Trace: return "TRACE";+ case LogLevel::Info: return "INFO ";+ case LogLevel::Warn: return "WARN ";+ case LogLevel::Error: return "ERROR";+ default: return "?????";+ }+}++std::string timestampUtc()+{+ const auto now = std::chrono::system_clock::now();+ const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();+ const std::time_t seconds = static_cast<std::time_t>(ms / 1000);+ const int milliseconds = static_cast<int>(ms % 1000);+ std::tm utc{};+ gmtime_s(&utc, &seconds);+ return std::format("{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}.{:03d}Z",+ utc.tm_year + 1900, utc.tm_mon + 1, utc.tm_mday,+ utc.tm_hour, utc.tm_min, utc.tm_sec, milliseconds);+}++} // namespace++Logger& Logger::instance()+{+ static Logger logger;+ return logger;+}++Logger::~Logger()+{+ closeFile();+}++bool Logger::openFile(const std::wstring& path)+{+ std::error_code ec;+ const std::filesystem::path fsPath(path);+ if (fsPath.has_parent_path()) {+ std::filesystem::create_directories(fsPath.parent_path(), ec);+ if (ec) {+ return false;+ }+ }+ std::lock_guard<std::mutex> lock(mutex_);+ if (file_ != nullptr) {+ std::fclose(file_);+ file_ = nullptr;+ }+ if (_wfopen_s(&file_, path.c_str(), L"wb") != 0 || file_ == nullptr) {+ return false;+ }+ return true;+}++void Logger::closeFile()+{+ std::lock_guard<std::mutex> lock(mutex_);+ if (file_ != nullptr) {+ std::fclose(file_);+ file_ = nullptr;+ }+}++void Logger::setConsoleEnabled(bool enabled)+{+ std::lock_guard<std::mutex> lock(mutex_);+ consoleEnabled_ = enabled;+}++void Logger::write(LogLevel level, const char* component, const std::string& message)+{+ const unsigned long threadId = GetCurrentThreadId();+ const std::string line = std::format("{} t={} [{}] [{}] {}",+ timestampUtc(), threadId, levelTag(level), component, message);++ std::lock_guard<std::mutex> lock(mutex_);+ if (consoleEnabled_) {+ std::fprintf(stdout, "%s\n", line.c_str());+ std::fflush(stdout);+ }+ if (file_ != nullptr) {+ std::fprintf(file_, "%s\n", line.c_str());+ std::fflush(file_);+ }+}++namespace log {++void trace(const char* component, const std::string& message)+{+ Logger::instance().write(LogLevel::Trace, component, message);+}++void info(const char* component, const std::string& message)+{+ Logger::instance().write(LogLevel::Info, component, message);+}++void warn(const char* component, const std::string& message)+{+ Logger::instance().write(LogLevel::Warn, component, message);+}++void error(const char* component, const std::string& message)+{+ Logger::instance().write(LogLevel::Error, component, message);+}++} // namespace log++} // namespace veyradiff --git a/src/base/NgxResult.cpp b/src/base/NgxResult.cppnew file mode 100644index 00000000..e490265c--- /dev/null+++ b/src/base/NgxResult.cpp@@ -0,0 +1,84 @@+#include "veyra/NgxResult.h"++#include <format>++namespace veyra {++namespace {++struct KnownHResult {+ uint32_t value;+ const char* name;+};++// Well-known COM/DXGI/D3D12 codes only; unlisted values print as plain hex.+// DXGI/D3D12 failure codes exceed LONG_MAX so they are stored unsigned.+const KnownHResult kKnownHResults[] = {+ {0x00000000u, "S_OK"},+ {0x00000001u, "S_FALSE"},+ {0x80004005u, "E_FAIL"},+ {0x80070057u, "E_INVALIDARG"},+ {0x8007000Eu, "E_OUTOFMEMORY"},+ {0x80004002u, "E_NOINTERFACE"},+ {0x80004001u, "E_NOTIMPL"},+ {0x80070006u, "E_HANDLE"},+ {0x80040154u, "REGDB_E_CLASSNOTREG"},+ {0x887A0001u, "DXGI_ERROR_INVALID_CALL"},+ {0x887A0002u, "DXGI_ERROR_NOT_FOUND"},+ {0x887A0005u, "DXGI_ERROR_DEVICE_REMOVED"},+ {0x887A0006u, "DXGI_ERROR_DEVICE_HUNG"},+ {0x887A0007u, "DXGI_ERROR_DEVICE_RESET"},+ {0x887A0008u, "DXGI_ERROR_WAS_STILL_DRAWING"},+ {0x887A0009u, "DXGI_ERROR_FRAME_STATISTICS_DISJOINT"},+ {0x887A000Au, "DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE"},+ {0x887A000Bu, "DXGI_ERROR_DRIVER_INTERNAL_ERROR"},+ {0x887A000Cu, "DXGI_ERROR_NONEXCLUSIVE"},+ {0x887A000Du, "DXGI_ERROR_NOT_CURRENTLY_AVAILABLE"},+ {0x887A000Eu, "DXGI_ERROR_TIMEOUT"},+ {0x887A0010u, "DXGI_ERROR_WAS_STILL_DRAWING_PENDING"},+ {0x887A0020u, "DXGI_ERROR_UNSUPPORTED"},+ {0x887A0022u, "DXGI_ERROR_ACCESS_LOST"},+ {0x887A0027u, "DXGI_ERROR_SESSION_DISCONNECTED"},+ {0x887E0001u, "D3D12_ERROR_ADAPTER_NOT_FOUND"},+ {0x887E0002u, "D3D12_ERROR_DRIVER_VERSION_MISMATCH"},+ {0x887E0003u, "D3D12_ERROR_INVALID_REDIST"},+ {0x887E0116u, "D3D12_ERROR_DRIVER_PROCESS_CRASHED"},+};++const KnownHResult* findKnownHResult(uint32_t hr)+{+ for (const auto& entry : kKnownHResults) {+ if (entry.value == hr) {+ return &entry;+ }+ }+ return nullptr;+}++// The single NGX result code whose numeric value is verified against the+// public NVIDIA NGX SDK headers at this stage. The full named table lands in+// Phase 1 together with the pinned DLSS SDK 310.7 headers; unknown values+// intentionally print hex-only instead of a guessed name.+constexpr uint64_t kNgxResultSuccess = 0x300000ull;++} // namespace++std::string hresultString(long hr)+{+ const uint32_t value = static_cast<uint32_t>(hr);+ const KnownHResult* known = findKnownHResult(value);+ if (known != nullptr) {+ return std::format("0x{:08X} ({})", value, known->name);+ }+ return std::format("0x{:08X}", value);+}++std::string ngxResultString(uint64_t result)+{+ if (result == kNgxResultSuccess) {+ return std::format("0x{:X} (NVSDK_NGX_Result_Success)", result);+ }+ return std::format("0x{:X}", result);+}++} // namespace veyradiff --git a/tools/runtime_probe/main.cpp b/tools/runtime_probe/main.cppindex 8bd27c2b..4694b4ac 100644--- a/tools/runtime_probe/main.cpp+++ b/tools/runtime_probe/main.cpp@@ -1,16 +1,136 @@-// veyra_runtime_probe - Phase 0 skeleton stub.-// Real probe behavior (logger, file identity, D3D12 device context, runtime-// loading, window loop) lands in P0.5-P0.7; this stub only proves that the-// CMake/C++20 x64 skeleton configures, builds and runs.-#include <cstdio>+// veyra_runtime_probe - Phase 0 runtime/D3D12 probe.+// Modes (added phase by phase):+// --self-test [--runtime-dir <abs>] verify veyra_base file identity + strings+// full probe mode arrives with P0.6/P0.7 (device context + runtime loading)+#include <windows.h>++#include <format>#include <string>+#include <vector>++#include "veyra/FileIdentity.h"+#include "veyra/Log.h"+#include "veyra/NgxResult.h"+#include "veyra/Result.h"++namespace {++constexpr uint64_t kExpectedDllSize = 165840496ull;+const char* kExpectedDllSha256 = "E16BCF15E16E13F527491CDF7845B2FE6521A738D8F7C9C721866A8496E1FC8E";++std::wstring ownExePath()+{+ wchar_t buffer[MAX_PATH * 2]{};+ const DWORD length = GetModuleFileNameW(nullptr, buffer, static_cast<DWORD>(std::size(buffer)));+ if (length == 0 || length >= std::size(buffer)) {+ return {};+ }+ return std::wstring(buffer, length);+}++// Narrow copy for logging; only used for non-critical display strings.+std::string narrow(const std::wstring& text)+{+ if (text.empty()) {+ return {};+ }+ const int length = WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), nullptr, 0, nullptr, nullptr);+ if (length <= 0) {+ return {};+ }+ std::string converted(static_cast<size_t>(length), '\0');+ WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), converted.data(), length, nullptr, nullptr);+ return converted;+}++int runSelfTest(const std::wstring& runtimeDir)+{+ const std::wstring exe = ownExePath();+ if (exe.empty()) {+ veyra::log::error("probe", "self-test: GetModuleFileNameW failed");+ return 2;+ }++ // 1. HRESULT / NGX result string sanity.+ const std::string hrOk = veyra::hresultString(0);+ const std::string hrRemoved = veyra::hresultString(0x887A0005L);+ const std::string hrUnknown = veyra::hresultString(0x8000FFFFL);+ const std::string ngxOk = veyra::ngxResultString(0x300000ull);+ if (hrOk.find("S_OK") == std::string::npos ||+ hrRemoved.find("DXGI_ERROR_DEVICE_REMOVED") == std::string::npos ||+ hrUnknown.find("0x8000FFFF") == std::string::npos ||+ ngxOk.find("NVSDK_NGX_Result_Success") == std::string::npos) {+ veyra::log::error("probe", std::format("self-test: result-string mapping broken hrOk={} hrRemoved={} hrUnknown={} ngxOk={}",+ hrOk, hrRemoved, hrUnknown, ngxOk));+ return 3;+ }+ veyra::log::info("probe", std::format("self-test: result-strings ok ({}, {}, {})", hrOk, hrRemoved, ngxOk));++ // 2. File identity of the running exe (SHA256 + version + signature state).+ veyra::FileIdentity exeIdentity{};+ veyra::IdentityError exeError = veyra::IdentityError::None;+ if (!veyra::computeFileIdentity(exe, exeIdentity, exeError)) {+ veyra::log::error("probe", std::format("self-test: exe identity failed error={}", veyra::identityErrorString(exeError)));+ return 4;+ }+ if (exeIdentity.sha256Upper.size() != 64) {+ veyra::log::error("probe", std::format("self-test: exe sha256 malformed length={}", exeIdentity.sha256Upper.size()));+ return 4;+ }+ veyra::log::info("probe", std::format("self-test: exe identity ok size={} sha256={}", exeIdentity.sizeBytes, exeIdentity.sha256Upper));++ // 3. Staged DLSSNR runtime identity against the pinned contract.+ if (!runtimeDir.empty()) {+ std::wstring dllPath = runtimeDir;+ if (!dllPath.empty() && dllPath.back() != L'\\' && dllPath.back() != L'/') {+ dllPath.push_back(L'\\');+ }+ dllPath += L"nvngx_dlssnr.dll";++ veyra::FileIdentity dllIdentity{};+ veyra::IdentityError dllError = veyra::IdentityError::None;+ if (!veyra::computeFileIdentity(dllPath, dllIdentity, dllError)) {+ veyra::log::error("probe", std::format("self-test: runtime identity failed error={} path={}",+ veyra::identityErrorString(dllError), narrow(dllPath)));+ return 5;+ }+ if (dllIdentity.sizeBytes != kExpectedDllSize ||+ dllIdentity.sha256Upper != kExpectedDllSha256 ||+ !dllIdentity.signatureValid ||+ !dllIdentity.signerIsNvidia ||+ dllIdentity.fileVersion != L"310.8.0.0") {+ veyra::log::error("probe", std::format("self-test: runtime identity mismatch size={} sha256={} valid={} nvidia={} version={}",+ dllIdentity.sizeBytes, dllIdentity.sha256Upper, dllIdentity.signatureValid, dllIdentity.signerIsNvidia,+ narrow(dllIdentity.fileVersion)));+ return 5;+ }+ veyra::log::info("probe", "self-test: staged runtime identity matches the pinned contract");+ }++ veyra::log::info("probe", "self-test: PASS");+ return 0;+}++} // namespaceint wmain(int argc, wchar_t** argv){- std::wprintf(L"veyra_runtime_probe skeleton (phase 0 stub)\n");- std::wprintf(L"argc=%d\n", argc);- for (int i = 0; i < argc; ++i) {- std::wprintf(L"argv[%d]=%ls\n", i, argv[i]);+ std::wstring runtimeDir;+ bool selfTest = false;+ for (int i = 1; i < argc; ++i) {+ const std::wstring arg = argv[i];+ if (arg == L"--self-test") {+ selfTest = true;+ }+ else if (arg == L"--runtime-dir" && i + 1 < argc) {+ runtimeDir = argv[++i];+ }}++ if (selfTest) {+ return runSelfTest(runtimeDir);+ }++ veyra::log::info("probe", "no mode selected; use --self-test (full probe arrives in P0.6/P0.7)");return 0;}