diff --git a/trunk/ConsoleDataMigration/sources/ConsoleBackup/ConsoleBackup.cpp b/trunk/ConsoleDataMigration/sources/ConsoleBackup/ConsoleBackup.cpp index d37a148..c499cbb 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleBackup/ConsoleBackup.cpp +++ b/trunk/ConsoleDataMigration/sources/ConsoleBackup/ConsoleBackup.cpp @@ -103,7 +103,7 @@ extern "C" void nnMain(void) nn::ps::Initialize(); // amの初期化 - nn::am::InitializeForSystemMenu(); + nn::am::InitializeForLocalImporter(); // ヒープの確保 common::InitializeHeap(); diff --git a/trunk/ConsoleDataMigration/sources/ConsoleBackup/Exporter.cpp b/trunk/ConsoleDataMigration/sources/ConsoleBackup/Exporter.cpp index b7e6470..763c99a 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleBackup/Exporter.cpp +++ b/trunk/ConsoleDataMigration/sources/ConsoleBackup/Exporter.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include // cfg:norの初期化に必要 #include @@ -485,7 +486,7 @@ void WriteTwlData(enum common::TWL_PATH_INDEX path) COMMON_LOGGER_RETURN_VOID_SET_BOOL_IF_FAILED(result, s_IsExportSucceeded); NN_LOG("File Number = %d\n", fileNum); - NN_LOG("File Size = %d\n", fileSize); + NN_LOG("File Size = %lld\n", fileSize); // 進捗表示用 common::InitializeTransferProgress(fileSize); @@ -816,7 +817,24 @@ void ExportThreadFunc() NN_LOG("Export Thread Finalize\n"); } -nn::Result WriteSaveData(::std::string& sysSaveRoot) +nn::Result WriteExportContext() +{ + nn::Result result; + nn::fs::DeviceMoveContext context; + + result = nn::fs::StartDeviceMoveAsSource(&context); + NN_UTIL_RETURN_IF_FAILED(result); + + common::SdMountManager::Mount(); + common::SdReaderWriter sdWriter; + result = sdWriter.WriteBufWithCmac(common::MOVE_CONTEXT_PATHNAME, &context, sizeof(context)); + NN_UTIL_RETURN_IF_FAILED(result); + + common::SdMountManager::Unmount(); + return nn::ResultSuccess(); +} + +nn::Result WriteSaveData() { // NANDからSDカードに書き出し nn::Result result; @@ -833,14 +851,10 @@ nn::Result WriteSaveData(::std::string& sysSaveRoot) COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); NN_LOG("File Number = %d\n", fileNum); - NN_LOG("File Size = %d\n", fileSize); + NN_LOG("File Size = %lld\n", fileSize); // 進捗表示用 common::InitializeTransferProgress(fileSize); - ::std::mbstowcs(s_RootName, sysSaveRoot.c_str(), sysSaveRoot.size() + 1); - - NN_LOG("%ls\n", (::std::wstring(common::NAND_DATA_ROOT_PATHNAME_WITH_SLASH) + ::std::wstring(s_RootName) + ::std::wstring(L"/")).c_str()); - // セーブデータディレクトリ以下のデータをSDカードにコピー // コピー用ディレクトリ作成 common::SdReaderWriter sdWriter; @@ -949,15 +963,8 @@ bool ExportData(common::HardwareStateManager& manager) result = WriteVersionData(manager); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); - ::std::string systemSaveRoot; - void* ivs; - size_t size; - manager.GetIvs(&ivs, &size); - // IVSからセーブデータディレクトリ名を計算 - common::Util::GetSaveDataDirectoryRoot(systemSaveRoot, ivs, size); - // NANDのセーブデータをSDに書き出す - result = WriteSaveData(systemSaveRoot); + result = WriteSaveData(); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); init = false; diff --git a/trunk/ConsoleDataMigration/sources/ConsoleBackup/OMakefile b/trunk/ConsoleDataMigration/sources/ConsoleBackup/OMakefile index d8e8323..ecec1f6 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleBackup/OMakefile +++ b/trunk/ConsoleDataMigration/sources/ConsoleBackup/OMakefile @@ -67,7 +67,7 @@ LIBS += libnn_cfg \ INSTALL_SDK_TOOL = true ROM_SPEC_FILE = $(TARGET_PROGRAM).rsf -DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/RepairTool.desc +DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/private/RepairTool.desc include $(ROOT_OMAKE)/modulerules diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/ConsoleRestore.cpp b/trunk/ConsoleDataMigration/sources/ConsoleRestore/ConsoleRestore.cpp index 17699d1..46c715f 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/ConsoleRestore.cpp +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/ConsoleRestore.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "demo.h" #include @@ -128,7 +129,7 @@ extern "C" void nnMain(void) nn::ps::Initialize(); // amの初期化 - nn::am::InitializeForSystemMenu(); + nn::am::InitializeForLocalImporter(); // ヒープの確保 common::InitializeHeap(); diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/Controller.cpp b/trunk/ConsoleDataMigration/sources/ConsoleRestore/Controller.cpp index 62b0d87..f2f959e 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/Controller.cpp +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/Controller.cpp @@ -998,12 +998,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector #include #include +#include #include #include // cfg:norの初期化に必要 #include @@ -659,10 +660,21 @@ nn::Result ImportIvs() { if (result.IsSuccess()) { - s32 writeSize; - result = fos.TryWrite(&writeSize, dec, readSize, true); - if (result.IsSuccess()) + if (s_SDVersionData.cup.majorVersion < common::CUP_MAJOR_VER_2ND_NUP) { + s32 writeSize; + result = fos.TryWrite(&writeSize, dec, readSize, true); + if (result.IsSuccess()) + { + COMMON_LOGGER("Import SDCI.\n"); + } + } + // 2ndNUPからはAPI経由で書き込む + else + { + result = nn::fs::CTR::ImportIntegrityVerificationSeed( + *reinterpret_cast(dec)); + NN_UTIL_RETURN_IF_FAILED(result); COMMON_LOGGER("Import SDCI.\n"); } } diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile b/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile index a09ecd0..c9196a3 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile @@ -70,7 +70,7 @@ LIBS += libnn_cfg \ INSTALL_SDK_TOOL = true ROM_SPEC_FILE = $(TARGET_PROGRAM).rsf -DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/RepairTool.desc +DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/private/RepairTool.desc include $(ROOT_OMAKE)/modulerules diff --git a/trunk/ConsoleDataMigration/sources/common/FileChecker.cpp b/trunk/ConsoleDataMigration/sources/common/FileChecker.cpp index 80893ed..5397e29 100644 --- a/trunk/ConsoleDataMigration/sources/common/FileChecker.cpp +++ b/trunk/ConsoleDataMigration/sources/common/FileChecker.cpp @@ -141,6 +141,11 @@ bool ExistsTwlTitleListFile() return ExistsFile(EXISTS_TWL_TITLELIST); } +bool ExistsFileMoveContextFile() +{ + return ExistsFile(EXISTS_MOVE_CONTEXT); +} + void InitializeFileCheck() { for(u32 i = 0; i < EXISTS_MAX; i++) diff --git a/trunk/ConsoleDataMigration/sources/common/FileChecker.h b/trunk/ConsoleDataMigration/sources/common/FileChecker.h index 2172ec1..47576c2 100644 --- a/trunk/ConsoleDataMigration/sources/common/FileChecker.h +++ b/trunk/ConsoleDataMigration/sources/common/FileChecker.h @@ -37,6 +37,8 @@ typedef enum FILE_EXISTS_CHECK EXISTS_TRANSFER_ACCOUNT, // アカウント移行完了 EXISTS_DOWNLOAD_IVS, // IVSダウロード完了 EXISTS_TWL_TITLELIST, // TWLタイトルリストファイル + EXISTS_MOVE_CONTEXT, // ファイル移動用コンテキスト + EXISTS_MAX } FileExistsCheck; @@ -55,7 +57,8 @@ const wchar_t* const FILENAME_TABLE[EXISTS_MAX] = common::DELETE_ACCOUNT_CHECK_PATHNAME, common::TRANSFER_ACCOUNT_CHECK_PATHNAME, common::DOWNLOAD_IVS_CHECK_PATHNAME, - common::TWL_TITLELIST_PATHNAME + common::TWL_TITLELIST_PATHNAME, + common::MOVE_CONTEXT_PATHNAME }; // ファイルが存在するかどうか @@ -74,6 +77,7 @@ bool ExistsDeleteAccountChecked(); bool ExistsTransferAccountChecked(); bool ExistsDownloadIvsCheckedFile(); bool ExistsTwlTitleListFile(); +bool ExistsFileMoveContextFile(); // ファイルチェックの結果を初期化する // 一度チェックするとその結果を保持するため diff --git a/trunk/ConsoleDataMigration/sources/common/FileName.h b/trunk/ConsoleDataMigration/sources/common/FileName.h index dd92c30..8a47206 100644 --- a/trunk/ConsoleDataMigration/sources/common/FileName.h +++ b/trunk/ConsoleDataMigration/sources/common/FileName.h @@ -65,6 +65,7 @@ const wchar_t* const REGION_DATA_PATHNAME = L"sdmc:/CTR_Console_Repair/Region.bi const wchar_t* const DEVICE_ID_PATHNAME = L"sdmc:/CTR_Console_Repair/deviceId.bin"; const wchar_t* const FILE_LIST_PATHNAME = L"sdmc:/CTR_Console_Repair/FileList.txt"; const wchar_t* const TWL_TITLELIST_PATHNAME = L"sdmc:/CTR_Console_Repair/TwlTitleList.txt"; +const wchar_t* const MOVE_CONTEXT_PATHNAME = L"sdmc:/CTR_Console_Repair/MoveContext.bin"; const wchar_t* const SD_NINTENDO_3DS_ROOT_PATH = L"sdmc:/Nintendo 3DS/"; enum TWL_PATH_INDEX diff --git a/trunk/ConsoleDataMigration/sources/common/Util.cpp b/trunk/ConsoleDataMigration/sources/common/Util.cpp index bb52b06..f18399c 100644 --- a/trunk/ConsoleDataMigration/sources/common/Util.cpp +++ b/trunk/ConsoleDataMigration/sources/common/Util.cpp @@ -1,24 +1,24 @@ /*---------------------------------------------------------------------------* - Project: Horizon - File: Util.cpp + Project: Horizon + File: Util.cpp - Copyright 2009 Nintendo. All rights reserved. + Copyright (C)2010-2011 Nintendo Co., Ltd. All rights reserved. - These coded instructions, statements, and computer programs contain - proprietary information of Nintendo of America Inc. and/or Nintendo - Company Ltd., and are protected by Federal copyright law. They may - not be disclosed to third parties or copied or duplicated in any form, - in whole or in part, without the prior written consent of Nintendo. + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. - $Rev$ + $Rev$ *---------------------------------------------------------------------------*/ - #include #include #include #include #include +#include #include #include #include @@ -32,13 +32,15 @@ #include "FileName.h" #include "CommonLogger.h" #include "HeapManager.h" +#include "FileTransfer.h" namespace common { Util::Util() : - m_FriendCode(0), m_BatteryRemain(100), m_CanReadSerialNumber(false), m_CanReadIvs(false), m_HasReadFriendCode(false) + m_FriendCode(0), mp_Ivs(NULL), m_SizeofIvs(0), m_BatteryRemain(100), m_CanReadSerialNumber(false), m_CanReadIvs( + false), m_HasReadFriendCode(false) { } @@ -77,37 +79,6 @@ void Util::Initialize() nn::mcu::CTR::InitializeHwCheck(&m_McuSession); mp_Mcu = new nn::mcu::CTR::HwCheck(m_McuSession); - // 完全性検証SEEDの取得 - result = nn::fs::MountSpecialArchive(common::NAND_ARCHIVE_NAME, nn::fs::CTR::ARCHIVE_TYPE_CTR_NAND); - if (result.IsSuccess()) - { - nn::fs::FileInputStream fis; - - result = fis.TryInitialize(common::IVS_NAND_PATHNAME); - if (result.IsSuccess()) - { - s64 fileSize = fis.GetSize(); - s32 ret; - void* addr = NULL; - addr = ForceAllocate(fileSize); - if (addr != NULL) - { - mp_Ivs = addr; - m_SizeofIvs = fileSize; - result = fis.TryRead(&ret, addr, fileSize); - if (result.IsSuccess()) - { - m_CanReadIvs = true; - } - // 後でIVSを参照するのでFreeしない - } - } - fis.Finalize(); - } - // 一旦アンマウントしておく - nn::fs::Unmount(common::NAND_ARCHIVE_NAME); - - // シリアルナンバーの取得 std::memset(m_SerialNo, '\0', nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN); @@ -130,6 +101,9 @@ void Util::Initialize() // バージョンの取得 common::GetSystemVersion(&m_VerData, m_Region); + // IVSの取得 + ReadIvs(m_VerData.cup.majorVersion); + // MACアドレスの取得 nn::nwm::Mac mac; @@ -154,6 +128,61 @@ void Util::Finalize() nn::mcu::CTR::FinalizeHwCheck(&m_McuSession); } +void Util::ReadIvs(u8 cupMajorVersion) +{ + if (cupMajorVersion < common::CUP_MAJOR_VER_2ND_NUP) + { + nn::Result result; + // 完全性検証SEEDの取得 + result = nn::fs::MountSpecialArchive(common::NAND_ARCHIVE_NAME, nn::fs::CTR::ARCHIVE_TYPE_CTR_NAND); + if (result.IsSuccess()) + { + nn::fs::FileInputStream fis; + + result = fis.TryInitialize(common::IVS_NAND_PATHNAME); + if (result.IsSuccess()) + { + s64 fileSize = fis.GetSize(); + s32 ret; + void* addr = NULL; + addr = ForceAllocate(fileSize); + if (addr != NULL) + { + mp_Ivs = addr; + m_SizeofIvs = fileSize; + result = fis.TryRead(&ret, addr, fileSize); + if (result.IsSuccess()) + { + m_CanReadIvs = true; + } + // 後でIVSを参照するのでFreeしない + } + } + fis.Finalize(); + } + // 一旦アンマウントしておく + nn::fs::Unmount(common::NAND_ARCHIVE_NAME); + } + else + { + nn::Result result; + void* pSeed = ForceAllocate(sizeof(nn::fs::CTR::IntegrityVerificationSeed)); + if(pSeed != NULL) + { + result = nn::fs::CTR::ExportIntegrityVerificationSeed( + reinterpret_cast(pSeed)); + nn::dbg::PrintResult(result); + if(result.IsSuccess()) + { + mp_Ivs = pSeed; + m_SizeofIvs = sizeof(nn::fs::CTR::IntegrityVerificationSeed); + m_CanReadIvs = true; + } + // 後でIVSを参照するのでFreeしない + } + } +} + // NULL終端されたシリアルナンバーを受け取る // NULL終端された場所にチェックデジットを付加して新たにNULL終端する void Util::AddCheckDigit(char* serial) @@ -187,45 +216,20 @@ void Util::AddCheckDigit(char* serial) serial[len + 1] = '\0'; } -// IVSからセーブデータディレクトリ名を生成する -void Util::GetSaveDataDirectoryRoot(::std::string& sysSaveRoot, void* ivs, size_t size) +// /Nintendo 3DS/6ea6b9d6ab70493ea9edd8b947d5d819/853600b24760a87f534430320002544d +// から、6ea6b9d6ab70493ea9edd8b947d5d819 を取り出す +void Util::GetSaveDataDirectoryRoot(::std::string& sysSaveRoot) { nn::Result result; - using namespace nn::dbg; - const size_t SEED_SIZE = 16; - bit8 hash[nn::crypto::Sha256Context::HASH_SIZE]; - const size_t SYS_SAVE_ROOT_LENGTH = 16; - char rootHash[SYS_SAVE_ROOT_LENGTH]; - char rootStr[SYS_SAVE_ROOT_LENGTH * 2 + 1]; + wchar_t path[512]; + result = nn::fs::GetSdmcCtrRootPath(path, sizeof(path)); + COMMON_LOGGER_RETURN_VOID_IF_FAILED(result); + NN_LOG("%ls\n", path); - // 最後の16バイトのハッシュを使う - nn::crypto::CalculateSha256(hash, &reinterpret_cast (ivs)[size - SEED_SIZE], SEED_SIZE); - - for (u8 i = 0; i < SEED_SIZE / 4; i++) - { - for (u8 j = 0; j < SEED_SIZE / 4; j++) - { - rootHash[i * 4 + j] = hash[i * 4 + 3 - j]; - } - } - - // 得られたハッシュから文字列を生成 - for (s32 k = 0; k < SEED_SIZE; k++) - { - for (s32 i = 6; i < 8; ++i) - { - bit32 n = (rootHash[k] >> ((7 - i) * 4)) & 0xf; - NN_TASSERT_(n < 16); - rootStr[i - 6 + k * 2] = static_cast (n < 10 ? '0' + n : 'a' + (n - 10)); - } - } - rootStr[SYS_SAVE_ROOT_LENGTH * 2] = '\0'; - - // セーブデータディレクトリ名を保存する - sysSaveRoot = ::std::string(rootStr); - - NN_LOG("%s\n", sysSaveRoot.c_str()); + std::string sdmcRootPath = common::GetCharStr(path); + sysSaveRoot = sdmcRootPath.substr(sizeof("Nintendo 3DS/"), 32); + NN_LOG("saveRoot = %s\n", sysSaveRoot.c_str()); } bool Util::IsAdapterConnected() diff --git a/trunk/ConsoleDataMigration/sources/common/Util.h b/trunk/ConsoleDataMigration/sources/common/Util.h index ebcf875..2f6a6e7 100644 --- a/trunk/ConsoleDataMigration/sources/common/Util.h +++ b/trunk/ConsoleDataMigration/sources/common/Util.h @@ -43,7 +43,7 @@ public: static void AddCheckDigit(char* serial); // IVSから計算されるセーブデータディレクトリ名を取得する - static void GetSaveDataDirectoryRoot(::std::string& sysSaveRoot, void* ivs, size_t size); + static void GetSaveDataDirectoryRoot(::std::string& sysSaveRoot); // ACアダプタが接続されているかどうか bool IsAdapterConnected(); @@ -111,6 +111,7 @@ public: private: void Initialize(); void Finalize(); + void ReadIvs(u8 cupMajorVersion); NN_PADDING4; // フレンドコード diff --git a/trunk/ConsoleDataMigration/sources/common/common_Types.h b/trunk/ConsoleDataMigration/sources/common/common_Types.h index 581b718..e158c53 100644 --- a/trunk/ConsoleDataMigration/sources/common/common_Types.h +++ b/trunk/ConsoleDataMigration/sources/common/common_Types.h @@ -41,6 +41,8 @@ const u64 INFRA_DEVICE_ID_OFFSET = 0x400000000; const size_t FILE_COPY_HEAP_SIZE = 16 * 1024 * 1024; +const u8 CUP_MAJOR_VER_2ND_NUP = 3; + // NOR領域のみにある設定データ用構造体 struct NtrNorData {