From 411abde5d13ec15ae6b3070550b856596e6d081c Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Mon, 17 Mar 2025 19:19:38 +0100 Subject: [PATCH] Add support for uninitialized movable --- src/core/hw/unique_data.cpp | 13 +++++++------ src/core/hw/unique_data.h | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/core/hw/unique_data.cpp b/src/core/hw/unique_data.cpp index 99ed5d871..3f11da2a7 100644 --- a/src/core/hw/unique_data.cpp +++ b/src/core/hw/unique_data.cpp @@ -158,13 +158,14 @@ SecureDataLoadStatus LoadMovable() { if (!file.IsOpen()) { return SecureDataLoadStatus::IOError; } - if (file.GetSize() != sizeof(MovableSedFull)) { - if (file.GetSize() == sizeof(MovableSed)) { - LOG_WARNING(HW, "Uninitialized movable.sed files are not supported"); - } + + std::size_t size = file.GetSize(); + if (size != sizeof(MovableSedFull) && size != sizeof(MovableSed)) { return SecureDataLoadStatus::Invalid; } - if (file.ReadBytes(&movable, sizeof(MovableSedFull)) != sizeof(MovableSedFull)) { + + std::memset(&movable, 0, sizeof(movable)); + if (file.ReadBytes(&movable, size) != size) { movable.Invalidate(); return SecureDataLoadStatus::IOError; } @@ -172,7 +173,7 @@ SecureDataLoadStatus LoadMovable() { HW::AES::InitKeys(); movable_signature_valid = movable.VerifySignature(); if (!movable_signature_valid) { - LOG_WARNING(HW, "LocalFriendCodeSeed_B signature check failed"); + LOG_WARNING(HW, "movable.sed signature check failed"); } return movable_signature_valid ? SecureDataLoadStatus::Loaded diff --git a/src/core/hw/unique_data.h b/src/core/hw/unique_data.h index b8cafe030..294484ffa 100644 --- a/src/core/hw/unique_data.h +++ b/src/core/hw/unique_data.h @@ -66,7 +66,10 @@ struct MovableSed { static constexpr std::array seed_magic{0x53, 0x45, 0x45, 0x44}; std::array magic; - u32 seed_info; + u8 unk0; + u8 is_full; + u8 unk1; + u8 unk2; LocalFriendCodeSeedB lfcs; std::array key_y; @@ -79,6 +82,10 @@ struct MovableSed { } bool VerifySignature() const; + + bool IsFull() { + return is_full != 0; + } }; static_assert(sizeof(MovableSed) == 0x120); @@ -101,6 +108,14 @@ struct MovableSedFull { // TODO(PabloMK7): Implement AES MAC verification return body.sed.VerifySignature(); } + + bool IsFull() { + return body.sed.IsFull(); + } + + size_t GetRealSize() { + return IsFull() ? sizeof(MovableSedFull) : sizeof(MovableSed); + } }; static_assert(sizeof(MovableSedFull) == 0x140);