mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
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
112 lines
2.9 KiB
C++
112 lines
2.9 KiB
C++
/*---------------------------------------------------------------------------*
|
|
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());
|
|
}
|
|
|
|
|
|
|
|
}
|