クラス名変更 HardwareInfo -> Util

IVS取得モードのシーケンス実装

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@218 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2011-04-22 10:30:35 +00:00
parent 53e4f388aa
commit d94579f71f
14 changed files with 300 additions and 168 deletions

View File

@ -53,7 +53,7 @@
#include "PlayHistoryManager.h" #include "PlayHistoryManager.h"
#include "common_Types.h" #include "common_Types.h"
#include "VersionDetect.h" #include "VersionDetect.h"
#include "HardwareInfo.h" #include "Util.h"
#include "ResFont.h" #include "ResFont.h"
// svnリビジョン埋め込み用 // svnリビジョン埋め込み用
@ -267,8 +267,7 @@ extern "C" void nnMain(void)
} }
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
common::HardwareInfo hwInfo; common::Util::AddCheckDigit(reinterpret_cast<char*>(s_SerialNo));
hwInfo.AddCheckDigit(reinterpret_cast<char*>(s_SerialNo));
// デバイスIDの取得 // デバイスIDの取得
result = nn::ps::CTR::GetDeviceId(&s_DeviceId); result = nn::ps::CTR::GetDeviceId(&s_DeviceId);

View File

@ -45,6 +45,7 @@
#include "Aes_define.h" #include "Aes_define.h"
#include "PlayHistoryManager.h" #include "PlayHistoryManager.h"
#include "VersionDetect.h" #include "VersionDetect.h"
#include "Util.h"
namespace ConsoleBackup namespace ConsoleBackup
{ {
@ -56,8 +57,6 @@ common::SdReaderWriter s_SdWriter;
common::NtrNorData s_NtrNorData; common::NtrNorData s_NtrNorData;
common::CfgCountryLanguage s_CountryLanguage; common::CfgCountryLanguage s_CountryLanguage;
::std::string s_SysSaveRoot;
const size_t EXPORT_THREAD_STACK_SIZE = 0x4000; const size_t EXPORT_THREAD_STACK_SIZE = 0x4000;
nn::os::Thread s_ExportThread; nn::os::Thread s_ExportThread;
nn::os::StackBuffer<EXPORT_THREAD_STACK_SIZE> s_ExportThreadStack; nn::os::StackBuffer<EXPORT_THREAD_STACK_SIZE> s_ExportThreadStack;
@ -318,51 +317,6 @@ void WriteIvs()
} }
} }
// IVSからセーブデータディレクトリ名を生成する
void GetSaveDataDirectoryRoot()
{
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];
void* addr;
size_t size;
GetIvs(&addr, &size);
// 最後の16バイトのハッシュを使う
nn::crypto::CalculateSha256(hash, &reinterpret_cast<bit8*> (addr)[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<char> (n < 10 ? '0' + n : 'a' + (n - 10));
}
}
rootStr[SYS_SAVE_ROOT_LENGTH * 2] = '\0';
// セーブデータディレクトリ名を保存する
s_SysSaveRoot = ::std::string(rootStr);
NN_LOG("%s\n", s_SysSaveRoot.c_str());
}
void CreateTwlDirectory(enum common::TWL_PATH_INDEX path) void CreateTwlDirectory(enum common::TWL_PATH_INDEX path)
{ {
NN_ASSERT(path < common::TWL_PATHNAME_MAX); NN_ASSERT(path < common::TWL_PATHNAME_MAX);
@ -799,7 +753,7 @@ void ExportThreadFunc()
NN_LOG("Export Thread Finalize\n"); NN_LOG("Export Thread Finalize\n");
} }
nn::Result WriteSaveData() nn::Result WriteSaveData(::std::string& sysSaveRoot)
{ {
// NANDからSDカードに書き出し // NANDからSDカードに書き出し
nn::Result result; nn::Result result;
@ -818,7 +772,7 @@ nn::Result WriteSaveData()
// 進捗表示用 // 進捗表示用
common::InitializeTransferProgress(fileSize); common::InitializeTransferProgress(fileSize);
::std::mbstowcs(s_RootName, s_SysSaveRoot.c_str(), s_SysSaveRoot.size() + 1); ::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()); NN_LOG("%ls\n", (::std::wstring(common::NAND_DATA_ROOT_PATHNAME_WITH_SLASH) + ::std::wstring(s_RootName) + ::std::wstring(L"/")).c_str());
@ -903,8 +857,12 @@ void ExportData()
// 完全性検証SEEDをSDカードに書き込む // 完全性検証SEEDをSDカードに書き込む
WriteIvs(); WriteIvs();
::std::string systemSaveRoot;
void* ivs;
size_t size;
GetIvs(&ivs, &size);
// IVSからセーブデータディレクトリ名を計算 // IVSからセーブデータディレクトリ名を計算
GetSaveDataDirectoryRoot(); common::Util::GetSaveDataDirectoryRoot(systemSaveRoot, ivs, size);
// プレイ履歴をSDに書き出す // プレイ履歴をSDに書き出す
//WritePlayHistory(); //WritePlayHistory();
@ -916,7 +874,7 @@ void ExportData()
WriteVersionData(); WriteVersionData();
// NANDのセーブデータをSDに書き出す // NANDのセーブデータをSDに書き出す
WriteSaveData(); WriteSaveData(systemSaveRoot);
init = false; init = false;
} }

View File

@ -29,7 +29,7 @@ SOURCES[] =
ConsoleBackup.cpp ConsoleBackup.cpp
Controller.cpp Controller.cpp
Exporter.cpp Exporter.cpp
../common/HardwareInfo.cpp ../common/Util.cpp
../common/DrawSystemState.cpp ../common/DrawSystemState.cpp
../common/FileTransfer.cpp ../common/FileTransfer.cpp
../common/FileChecker.cpp ../common/FileChecker.cpp

View File

@ -46,7 +46,7 @@
#include "SDMountManager.h" #include "SDMountManager.h"
#include "HeapManager.h" #include "HeapManager.h"
#include "VersionDetect.h" #include "VersionDetect.h"
#include "HardwareInfo.h" #include "Util.h"
#include "ResFont.h" #include "ResFont.h"
// svnリビジョン埋め込み用 // svnリビジョン埋め込み用
@ -228,6 +228,7 @@ extern "C" void nnMain(void)
// RenderSystemを作ってからログが出せる // RenderSystemを作ってからログが出せる
common::Logger::InitializeEjectThread(); common::Logger::InitializeEjectThread();
common::Logger::SetEjectHandler(OnSdEjected); common::Logger::SetEjectHandler(OnSdEjected);
common::Logger::SetInsertHandler(OnSdEjected);
COMMON_LOGGER("\n"); COMMON_LOGGER("\n");
COMMON_LOGGER("CTR Console Restore start\n"); COMMON_LOGGER("CTR Console Restore start\n");
@ -274,8 +275,7 @@ extern "C" void nnMain(void)
std::memset(s_SerialNo, '\0', std::memset(s_SerialNo, '\0',
nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN); nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN);
result = nn::cfg::CTR::system::GetSerialNo(s_SerialNo); result = nn::cfg::CTR::system::GetSerialNo(s_SerialNo);
common::HardwareInfo hwInfo; common::Util::AddCheckDigit(reinterpret_cast<char*>(s_SerialNo));
hwInfo.AddCheckDigit(reinterpret_cast<char*>(s_SerialNo));
if(result.IsSuccess()) if(result.IsSuccess())
{ {
s_CanReadSerialNumber = true; s_CanReadSerialNumber = true;
@ -399,6 +399,12 @@ extern "C" void nnMain(void)
titleColor.g = 0.35f; titleColor.g = 0.35f;
titleColor.b = 0.f; titleColor.b = 0.f;
} }
else if(GetRestoreMode() == RESTORE_MODE_GET_IVS)
{
titleColor.r = 1.0f;
titleColor.g = 0.2f;
titleColor.b = 0.2f;
}
// 上画面表示 // 上画面表示
common::DrawSystemState("CTR Console Restore", common::DrawSystemState("CTR Console Restore",
@ -420,14 +426,23 @@ extern "C" void nnMain(void)
s_SerialNo s_SerialNo
); );
if (GetRestoreMode() == RESTORE_MODE_NUP_ONLY) if (GetRestoreMode() != RESTORE_MODE_RESTORE)
{ {
const u8 spaceSize = 10; const u8 spaceSize = 10;
const u8 lineBottom = 23; const u8 lineBottom = 23;
const u32 screenWidth = 400; const u32 screenWidth = 400;
s_RenderSystem.SetColor(1.f, 1.f, 1.f); s_RenderSystem.SetColor(1.f, 1.f, 1.f);
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "NUP-Only Mode");
if (GetRestoreMode() == RESTORE_MODE_NUP_ONLY)
{
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "NUP-Only Mode");
}
else if (GetRestoreMode() == RESTORE_MODE_GET_IVS)
{
s_RenderSystem.DrawText(0, lineBottom * spaceSize, "GET-IVS Mode");
}
s_RenderSystem.SetColor(titleColor.r, titleColor.g, titleColor.b); s_RenderSystem.SetColor(titleColor.r, titleColor.g, titleColor.b);
s_RenderSystem.FillRectangle(0, lineBottom * spaceSize, screenWidth, spaceSize); s_RenderSystem.FillRectangle(0, lineBottom * spaceSize, screenWidth, spaceSize);
s_RenderSystem.SetColor(1.f, 1.f, 1.f); s_RenderSystem.SetColor(1.f, 1.f, 1.f);

View File

@ -43,9 +43,11 @@ namespace
// インターネット設定を読んだかどうか // インターネット設定を読んだかどうか
bool s_ReadSettingDone = false; bool s_ReadSettingDone = false;
// インターネット設定を読んだ結果 // インターネット設定を読んだ結果
bool s_ReadSettingSuccess = false; bool s_ReadSettingIsSuccess = false;
// NUP専用モードかどうか // NUP専用モードかどうか
bool s_NupOnlyMode = false; bool s_NupOnlyMode = false;
// IVS取得専用モードかどうか
bool s_GetIvsOnlyMode = false;
// APSettingの書式が無い警告サウンドを鳴らしたかどうか // APSettingの書式が無い警告サウンドを鳴らしたかどうか
bool s_ExistAPSettingAnnotation = false; bool s_ExistAPSettingAnnotation = false;
@ -106,6 +108,9 @@ typedef enum RestoreState
NUP_ONLY_WAIT_NEXT, // NUP_ONLYモードでキー入力待ち NUP_ONLY_WAIT_NEXT, // NUP_ONLYモードでキー入力待ち
DOWNLOAD_IVS, // インフラからIVSを取得する DOWNLOAD_IVS, // インフラからIVSを取得する
DOWNLOAD_IVS_DONE, // インフラからIVSを取得完了 DOWNLOAD_IVS_DONE, // インフラからIVSを取得完了
CHECK_IVS, // IVSとSDカードのセーブデータディレクトリの一致を確認
CHECK_SD_DIRECTORY, // SDカードのIVS依存ディレクトリを探す
CHECK_SD_DIRECTORY_DONE, // SDカードのIVS依存ディレクトリチェック完了
DELETE_ACCOUNT, // ショップアカウントを削除する DELETE_ACCOUNT, // ショップアカウントを削除する
DELETE_ACCOUNT_DONE, // ショップアカウント削除完了 DELETE_ACCOUNT_DONE, // ショップアカウント削除完了
SYNC_TICKET, // eTicketを同期する SYNC_TICKET, // eTicketを同期する
@ -217,7 +222,11 @@ void CheckNupExecuted(::std::vector<std::string>& message, bool& goNextStep)
{ {
if (common::ExistsUpdateCheckedFile()) if (common::ExistsUpdateCheckedFile())
{ {
if (s_NupOnlyMode) if(s_GetIvsOnlyMode)
{
CheckDownloadIvs(message, goNextStep);
}
else if (s_NupOnlyMode)
{ {
s_RestoreState = NUP_ONLY_WAIT_SD_EJECT; s_RestoreState = NUP_ONLY_WAIT_SD_EJECT;
@ -263,7 +272,14 @@ void CheckDownloadIvs(::std::vector<std::string>& message, bool& goNextStep)
// IVS取得確認ファイルがあるか // IVS取得確認ファイルがあるか
if (common::ExistsDownloadIvsCheckedFile()) if (common::ExistsDownloadIvsCheckedFile())
{ {
CheckWriteFinished(message, goNextStep); if(s_GetIvsOnlyMode)
{
s_RestoreState = CHECK_IVS;
}
else
{
CheckWriteFinished(message, goNextStep);
}
} }
else else
{ {
@ -431,11 +447,27 @@ void CheckRegioinSd(::std::vector<std::string>& message, bool& goNextStep)
} }
} }
void ShopOperationSuccess(ShopOperation op, const char* logMessage, RestoreState nextState)
{
COMMON_LOGGER("%s", logMessage);
if (op == SHOP_OPERATION_UNREGISTER)
{
CreateDeleteAccountFinishedFile();
}
else if (op == SHOP_OPERATION_GET_IVS)
{
CreateDownloadIvsFinishedFile();
}
s_RestoreState = nextState;
}
void ShopOperationSingleTemplate( void ShopOperationSingleTemplate(
std::vector<std::string>& message, std::vector<std::string>& message,
ShopOperation op, ShopOperation op,
const char* aliveMessage, const char* aliveMessage,
const char* logMesasge, const char* logMessage,
const char* retryLogMessage, const char* retryLogMessage,
RestoreState nextState RestoreState nextState
) )
@ -480,11 +512,13 @@ void ShopOperationSingleTemplate(
if (GetShopOperationSingleResult().IsSuccess()) if (GetShopOperationSingleResult().IsSuccess())
{ {
COMMON_LOGGER("%s", logMesasge); ShopOperationSuccess(op, logMessage, nextState);
// アカウント削除完了ファイルを作成 }
CreateDeleteAccountFinishedFile(); // IVSがアップロードされていない場合もあるため
// IVSを取得できない状況も成功として扱う
s_RestoreState = nextState; else if(op == SHOP_OPERATION_GET_IVS && GetShopOperationSingleResult() == nn::nim::ResultCannotGetIvs())
{
ShopOperationSuccess(op, logMessage, nextState);
} }
else else
{ {
@ -596,15 +630,28 @@ bool CheckAndReadAPSetting(::std::vector<std::string>& operationMessage)
if (!s_ReadSettingDone) if (!s_ReadSettingDone)
{ {
s_ReadSettingDone = true; s_ReadSettingDone = true;
s_ReadSettingSuccess = ReadSetting(&s_NupOnlyMode); s_ReadSettingIsSuccess = ReadSetting(&s_NupOnlyMode, &s_GetIvsOnlyMode);
} }
if(s_NupOnlyMode) if(s_NupOnlyMode && s_GetIvsOnlyMode)
{ {
s_RestoreMode = RESTORE_MODE_NUP_ONLY; COMMON_LOGGER("Both NUP_ONLY and GET_IVS settings are described!!");
s_ReadSettingIsSuccess = false;
}
else
{
if (s_NupOnlyMode)
{
s_RestoreMode = RESTORE_MODE_NUP_ONLY;
}
if (s_GetIvsOnlyMode)
{
s_RestoreMode = RESTORE_MODE_GET_IVS;
}
} }
if (!s_ReadSettingSuccess) if (!s_ReadSettingIsSuccess)
{ {
operationMessage.push_back(::std::string("Invalid Accsess_Point_Setting format!")); operationMessage.push_back(::std::string("Invalid Accsess_Point_Setting format!"));
if(!s_APSettingAnnotation) if(!s_APSettingAnnotation)
@ -612,10 +659,9 @@ bool CheckAndReadAPSetting(::std::vector<std::string>& operationMessage)
s_APSettingAnnotation = true; s_APSettingAnnotation = true;
common::PlaySound(common::SOUND_ANNOTATION); common::PlaySound(common::SOUND_ANNOTATION);
} }
} }
return s_ReadSettingSuccess; return s_ReadSettingIsSuccess;
} }
void PutAliveMessage(::std::vector<std::string>& operationMessage, const char* str) void PutAliveMessage(::std::vector<std::string>& operationMessage, const char* str)
@ -839,6 +885,46 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
} }
break; break;
case CHECK_IVS:
{
operationMessage.push_back(::std::string("Insert User's SD Card"));
}
break;
case CHECK_SD_DIRECTORY:
{
if (nn::fs::IsSdmcInserted())
{
// ユーザのSDカードにはAP設定ファイルは無いはず
if (ExistsAPSetting())
{
s_RestoreState = CHECK_IVS;
}
else
{
if(ExistsIvsDirectory())
{
s_RestoreState = CHECK_SD_DIRECTORY_DONE;
}
}
}
}
break;
case CHECK_SD_DIRECTORY_DONE:
{
static bool init = true;
if(init)
{
DeleteAllCheckFiles();
init = false;
}
operationMessage.push_back(::std::string("Check User's SD Card Done."));
operationMessage.push_back(::std::string("Pull Out SD Card"));
}
break;
case DELETE_ACCOUNT: case DELETE_ACCOUNT:
{ {
@ -1054,7 +1140,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
} }
break; break;
// NUPすることでIVSが送信される // 本体更新が発生しない状況でNUPすることでIVSが送信される
// UPLOAD_IN_PROGRESSでのNUP実行後、サーバが更新されないという前提なので注意 // UPLOAD_IN_PROGRESSでのNUP実行後、サーバが更新されないという前提なので注意
case UPLOAD_IVS: case UPLOAD_IVS:
{ {
@ -1257,7 +1343,7 @@ bool IsRestoreFailed()
void OnSdEjected() void OnSdEjected()
{ {
if(s_RestoreState == WAIT_SD_EJECT || s_RestoreState == ALL_DONE) if (s_RestoreState == WAIT_SD_EJECT || s_RestoreState == ALL_DONE || s_RestoreState == CHECK_SD_DIRECTORY_DONE)
{ {
s_RestoreState = ALL_DONE; s_RestoreState = ALL_DONE;
} }
@ -1266,13 +1352,23 @@ void OnSdEjected()
s_RestoreState = NUP_ONLY_WAIT_NEXT; s_RestoreState = NUP_ONLY_WAIT_NEXT;
} }
// FAILのときは一旦電源を切らないと動かないようにしておく // FAILのときは一旦電源を切らないと動かないようにしておく
else if(s_RestoreState != FAIL) // IVSチェック時はユーザのSDカードを挿入してもらうため
else if(s_RestoreState != FAIL &&
s_RestoreState != CHECK_IVS)
{ {
InitializeState(); InitializeState();
ClearFileReadResult(); ClearFileReadResult();
} }
} }
void OnSdInserted()
{
if(s_RestoreState == CHECK_IVS)
{
s_RestoreState = CHECK_SD_DIRECTORY;
}
}
void InitializeState() void InitializeState()
{ {
s_RestoreState = STARTUP; s_RestoreState = STARTUP;
@ -1288,7 +1384,7 @@ void InitializeState()
s_ExistAPSettingAnnotation = false; s_ExistAPSettingAnnotation = false;
s_ReadSettingDone = false; s_ReadSettingDone = false;
s_ReadSettingSuccess = false; s_ReadSettingIsSuccess = false;
s_APSettingAnnotation = false; s_APSettingAnnotation = false;
s_SerialNumberAnnotation = false; s_SerialNumberAnnotation = false;
s_PlayedFailSound = false; s_PlayedFailSound = false;

View File

@ -26,7 +26,8 @@ namespace ConsoleRestore
typedef enum RestoreMode typedef enum RestoreMode
{ {
RESTORE_MODE_RESTORE, RESTORE_MODE_RESTORE,
RESTORE_MODE_NUP_ONLY RESTORE_MODE_NUP_ONLY,
RESTORE_MODE_GET_IVS
} RestoreMode; } RestoreMode;
const u32 RETRY_MAX = 3; const u32 RETRY_MAX = 3;
@ -38,6 +39,7 @@ bool IsRestoreFailed();
u32 GetProgress(); u32 GetProgress();
void OnSdEjected(); void OnSdEjected();
void OnSdInserted();
void InitializeState(); void InitializeState();
RestoreMode GetRestoreMode(); RestoreMode GetRestoreMode();

View File

@ -820,9 +820,10 @@ nn::Result ReadVersionData()
return result; return result;
} }
bool AlreadyExecutedNup() bool ExistsIvsDirectory()
{ {
return s_SDVersionData.nup.majorVersion != 0; // TODO: Nintendo 3DS ディレクトリを検索する
return true;
} }
void Cleanup() void Cleanup()
@ -956,7 +957,7 @@ bool UpdateNetworkSetting(nn::ac::NetworkSetting& networkSetting)
return retval; return retval;
} }
bool ReadSetting(bool* nupOnly) bool ReadSetting(bool* nupOnly, bool* getIvs)
{ {
nn::Result result; nn::Result result;
bool retval = true; bool retval = true;
@ -1258,10 +1259,11 @@ bool ReadSetting(bool* nupOnly)
} }
{ {
const wchar_t* const NUP_ONLY_STR = L"NUP_ONLY";
NN_NULL_ASSERT(nupOnly); NN_NULL_ASSERT(nupOnly);
if (configfileLoader.ReadAsChar(L"NUP_ONLY") != NULL) if (configfileLoader.ReadAsChar(NUP_ONLY_STR) != NULL)
{ {
s32 num = configfileLoader.ReadAsInteger(L"NUP_ONLY"); s32 num = configfileLoader.ReadAsInteger(NUP_ONLY_STR);
if (num == 1) if (num == 1)
{ {
*nupOnly = true; *nupOnly = true;
@ -1270,6 +1272,20 @@ bool ReadSetting(bool* nupOnly)
} }
} }
{
const wchar_t* const GET_IVS_STR = L"GET_IVS";
NN_NULL_ASSERT(getIvs);
if (configfileLoader.ReadAsChar(GET_IVS_STR) != NULL)
{
s32 num = configfileLoader.ReadAsInteger(GET_IVS_STR);
if (num == 1)
{
*getIvs = true;
COMMON_LOGGER("GET IVS Mode.\n");
}
}
}
configfileLoader.Finalize(); configfileLoader.Finalize();
// 書き込み完了しなければfalse // 書き込み完了しなければfalse

View File

@ -65,7 +65,7 @@ struct TimeZone
NN_PADDING3; NN_PADDING3;
}; };
bool ReadSetting(bool* nupOnly); bool ReadSetting(bool* nupOnly, bool* getIvs);
char* GetNtpServerName(); char* GetNtpServerName();
TimeZone GetTimeZone(); TimeZone GetTimeZone();
@ -93,8 +93,9 @@ nn::Result InitializeHardwareDependentSetting();
// SDカード上のバージョン情報を読みます // SDカード上のバージョン情報を読みます
nn::Result ReadVersionData(); nn::Result ReadVersionData();
// 移行元本体がNUP済みかどうか
bool AlreadyExecutedNup(); // SDカードのNintendo 3DS以下ににIVSと一致するディレクトリがあるかどうか
bool ExistsIvsDirectory();
} }

View File

@ -33,7 +33,7 @@ SOURCES[] =
Ntpclient.cpp Ntpclient.cpp
TitleDownloader.cpp TitleDownloader.cpp
Shop.cpp Shop.cpp
../common/HardwareInfo.cpp ../common/Util.cpp
../common/DrawSystemState.cpp ../common/DrawSystemState.cpp
../common/FileTransfer.cpp ../common/FileTransfer.cpp
../common/FileChecker.cpp ../common/FileChecker.cpp

View File

@ -1,69 +0,0 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: HardwareInfo.cpp
Copyright 2009 Nintendo. 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.
$Rev$
*---------------------------------------------------------------------------*/
#include <nn.h>
#include "HardwareInfo.h"
#include <cctype>
namespace common
{
HardwareInfo::HardwareInfo()
{
// TODO 自動生成されたコンストラクター・スタブ
}
HardwareInfo::~HardwareInfo()
{
// TODO Auto-generated destructor stub
}
// NULL終端されたシリアルナンバーを受け取る
// NULL終端された場所にチェックデジットを付加して新たにNULL終端する
void HardwareInfo::AddCheckDigit(char* serial)
{
size_t len = std::strlen(serial);
u8 digit = 0;
bool odd = true;
for(u8 i = len - 1; i > 0 && std::isdigit(serial[i]); i--)
{
if(odd)
{
digit += (serial[i] - '0') * 3;
}
else
{
digit += (serial[i] - '0');
}
odd = !odd;
}
if(digit % 10 != 0)
{
serial[len] = 10 - (digit % 10) + '0';
}
else
{
serial[len] = '0';
}
serial[len + 1] = '\0';
}
}

View File

@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: Util.cpp
Copyright 2009 Nintendo. 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.
$Rev$
*---------------------------------------------------------------------------*/
#include <nn.h>
#include "Util.h"
#include <cctype>
namespace common
{
Util::Util()
{
// TODO 自動生成されたコンストラクター・スタブ
}
Util::~Util()
{
// TODO Auto-generated destructor stub
}
// NULL終端されたシリアルナンバーを受け取る
// NULL終端された場所にチェックデジットを付加して新たにNULL終端する
void Util::AddCheckDigit(char* serial)
{
size_t len = std::strlen(serial);
u8 digit = 0;
bool odd = true;
for(u8 i = len - 1; i > 0 && std::isdigit(serial[i]); i--)
{
if(odd)
{
digit += (serial[i] - '0') * 3;
}
else
{
digit += (serial[i] - '0');
}
odd = !odd;
}
if(digit % 10 != 0)
{
serial[len] = 10 - (digit % 10) + '0';
}
else
{
serial[len] = '0';
}
serial[len + 1] = '\0';
}
// IVSからセーブデータディレクトリ名を生成する
void Util::GetSaveDataDirectoryRoot(::std::string& sysSaveRoot, void* ivs, size_t size)
{
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];
// 最後の16バイトのハッシュを使う
nn::crypto::CalculateSha256(hash, &reinterpret_cast<bit8*> (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<char> (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());
}
}

View File

@ -1,6 +1,6 @@
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Project: Horizon Project: Horizon
File: HardwareInfo.h File: Util.h
Copyright 2009 Nintendo. All rights reserved. Copyright 2009 Nintendo. All rights reserved.
@ -13,21 +13,24 @@
$Rev$ $Rev$
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
#ifndef HARDWAREINFO_H_ #ifndef UTIL_H_
#define HARDWAREINFO_H_ #define UTIL_H_
#include <string>
namespace common namespace common
{ {
class HardwareInfo class Util
{ {
public: public:
HardwareInfo(); Util();
virtual ~HardwareInfo(); virtual ~Util();
void AddCheckDigit(char* serial); static void AddCheckDigit(char* serial);
static void GetSaveDataDirectoryRoot(::std::string& sysSaveRoot, void* ivs, size_t size);
}; };
} }
#endif /* HARDWAREINFO_H_ */ #endif /* UTIL_H_ */

View File

@ -25,7 +25,7 @@ INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \
SOURCES[] = SOURCES[] =
main.cpp main.cpp
../../common/HardwareInfo.cpp ../../common/Util.cpp
../../common/FileTransfer.cpp ../../common/FileTransfer.cpp
../../common/FileChecker.cpp ../../common/FileChecker.cpp
../../common/SdReaderWriter.cpp ../../common/SdReaderWriter.cpp

View File

@ -58,7 +58,7 @@
#include "PlayHistoryManager.h" #include "PlayHistoryManager.h"
#include "common_Types.h" #include "common_Types.h"
#include "VersionDetect.h" #include "VersionDetect.h"
#include "HardwareInfo.h" #include "Util.h"
#include "CommonLogger.h" #include "CommonLogger.h"
namespace namespace