mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@175 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
d79e1c61ed
commit
820fa8fd94
@ -55,7 +55,7 @@ uptr heapForGx;
|
||||
|
||||
namespace
|
||||
{
|
||||
bit8 readBuf[64 * 1024];
|
||||
u8* readBuf;
|
||||
}
|
||||
|
||||
bool ImportFile(nn::fs::MediaType mediaType, wchar_t* filename)
|
||||
@ -78,9 +78,9 @@ bool ImportFile(nn::fs::MediaType mediaType, wchar_t* filename)
|
||||
return result.IsSuccess();
|
||||
}
|
||||
|
||||
|
||||
u8 s_list[200][nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN+1] NN_ATTRIBUTE_ALIGN(32);//シリアルリスト
|
||||
u8 sign[1024*10] NN_ATTRIBUTE_ALIGN(32);//署名
|
||||
#define LIST_MAX 4000
|
||||
u8 s_list[LIST_MAX][nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN+1] NN_ATTRIBUTE_ALIGN(32);//シリアルリスト
|
||||
u8 sign[256] NN_ATTRIBUTE_ALIGN(32);//署名
|
||||
//u8 key[1024*10] NN_ATTRIBUTE_ALIGN(32);//署名
|
||||
u8 serialNo[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN+1];
|
||||
|
||||
@ -127,23 +127,6 @@ void endfunc()
|
||||
}
|
||||
|
||||
//署名検証
|
||||
bool VeriRsa(u8* src,size_t sz,u8* sig,u8* pub)
|
||||
{
|
||||
nn::crypto::RsaKey key;
|
||||
//nn::crypto::Initialize();
|
||||
nn::ps::CTR::Initialize();
|
||||
nn::Result res = key.InitializePublicKey(pub,KEY_LENGTH);
|
||||
NN_LOG("inipubkey desc= %d\n",res.GetDescription());
|
||||
if (res.IsSuccess())
|
||||
{
|
||||
res = nn::ps::CTR::VerifyRsaSha256(src,sz,sig,key);
|
||||
NN_LOG("verisig desc= %d\n",res.GetDescription());
|
||||
}
|
||||
//nn::crypto::Finalize();
|
||||
nn::ps::CTR::Finalize();
|
||||
return res.IsSuccess();
|
||||
}
|
||||
|
||||
bool VeriRsa(u8* src,size_t sz,u8* sig)
|
||||
{
|
||||
nn::crypto::RsaKey key;
|
||||
@ -259,6 +242,12 @@ void nnMain( void )
|
||||
shf_SetScale(0.7,0.7);
|
||||
if (result.IsFailure())ErrorStop("Initialize Error");//am 初期化に失敗
|
||||
|
||||
//ファイルバッファ
|
||||
const size_t READ_BUFFER_SIZE = 64*1024;
|
||||
if (READ_BUFFER_SIZE > appHeap.GetTotalFreeSize())ErrorStop("memory allocate fail");
|
||||
readBuf = reinterpret_cast<u8*>(appHeap.Allocate(READ_BUFFER_SIZE,32));
|
||||
|
||||
|
||||
//シリアルチェック
|
||||
if( GetSerial() )
|
||||
{//シリアル取得成功
|
||||
@ -266,14 +255,16 @@ void nnMain( void )
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
int i,j,n;
|
||||
s32 fsize = FileRead(INF_FILE);
|
||||
if(fsize > 0)//設定ファイルがある
|
||||
s32 fsize = FileRead(INF_FILE);//設定ファイルがあるか
|
||||
if((fsize < 1024) && (fsize > 0))//サイズチェック
|
||||
{
|
||||
n = 0;
|
||||
while(n < fsize)
|
||||
{
|
||||
if (readBuf[n++] == '-'){
|
||||
switch (readBuf[n++]){
|
||||
if (readBuf[n] == '-'){
|
||||
if (n == fsize-1)break;//終端
|
||||
n++;
|
||||
switch (readBuf[n]){
|
||||
case 'p':// -p .. 本体シリアル表示
|
||||
strcpy(seri,"s/n: ");
|
||||
strcat(seri,(char *)serialNo);
|
||||
@ -286,27 +277,21 @@ void nnMain( void )
|
||||
break;
|
||||
}
|
||||
}
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fsize = FileRead(SIGN_FILE);
|
||||
if(fsize > 0)//署名リード成功
|
||||
fsize = FileRead(SIGN_FILE);//署名リード
|
||||
if(fsize == 256)//サイズチェック
|
||||
{
|
||||
if (fsize>sizeof(sign))fsize = sizeof(sign);
|
||||
memcpy(sign,readBuf,fsize);
|
||||
memcpy(sign,readBuf,256);//readBuf -> sign
|
||||
|
||||
//fsize = FileRead(PUBK_FILE);
|
||||
//if(fsize > 0)//公開鍵リード成功
|
||||
{
|
||||
//if (fsize>sizeof(key))fsize = sizeof(key);
|
||||
//memcpy(key,readBuf,fsize);
|
||||
|
||||
fsize = FileRead(LIST_FILE);
|
||||
if(fsize > 0)//リストリード成功
|
||||
fsize = FileRead(LIST_FILE);//リストリード
|
||||
if((fsize < LIST_MAX * (nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN+1)) && (fsize > 0))//サイズチェック
|
||||
{
|
||||
|
||||
//if (VeriRsa(readBuf,fsize,sign,key))
|
||||
if (VeriRsa(readBuf,fsize,sign))
|
||||
{//署名検証OK
|
||||
int list_ct = 0;
|
||||
@ -318,10 +303,12 @@ void nnMain( void )
|
||||
else j = fsize-n;
|
||||
for (i=0;i<j;i++)
|
||||
{
|
||||
d = readBuf[n++];
|
||||
if ((d==0x0d)||(d==0x0a))
|
||||
d = readBuf[n];
|
||||
n++;
|
||||
if ((d==0x0d)||(d==0x0a)) //改行コード
|
||||
{
|
||||
if (readBuf[n]==0x0a)n++;
|
||||
if (readBuf[n]==0x0a)n++;//CR+LF,LF+LF
|
||||
else ErrorStop("list broken");//CRのみは異常、署名時にファイル壊れてた?
|
||||
break;
|
||||
}
|
||||
s_list[list_ct][i] = d;
|
||||
@ -329,6 +316,10 @@ void nnMain( void )
|
||||
if (i>0){
|
||||
s_list[list_ct][i] = 0;//終端
|
||||
list_ct++;
|
||||
if (list_ct>=LIST_MAX)
|
||||
{//上限オーバー: おそらくリスト作成ミス
|
||||
ErrorStop("List too Long");
|
||||
}
|
||||
}
|
||||
}
|
||||
//本体シリアルがリストにあるかチェック
|
||||
@ -354,7 +345,7 @@ void nnMain( void )
|
||||
}//MountSdmc
|
||||
}//GetSerial
|
||||
|
||||
nn::fs::MountRom(16, 16, buffer, ROMFS_BUFFER_SIZE);
|
||||
NN_LOG("result = %d\n",result.GetDescription());
|
||||
|
||||
u32 mask = 0;
|
||||
|
||||
@ -379,6 +370,9 @@ void nnMain( void )
|
||||
shf_SetScale(0.6,0.6);
|
||||
TestMain();//テストデータへ
|
||||
}
|
||||
|
||||
nn::fs::MountRom(16, 16, buffer, ROMFS_BUFFER_SIZE);
|
||||
|
||||
shf_SetScale(0.8,0.8);
|
||||
// CIA のプログラム ID を取得する。
|
||||
nn::am::ProgramInfo programInfo;
|
||||
@ -390,36 +384,35 @@ void nnMain( void )
|
||||
|
||||
} else
|
||||
{
|
||||
s_RenderSystem.Clear();
|
||||
if(padStatus.trigger & nn::hid::BUTTON_X)
|
||||
drawText(10,120,"Importing");
|
||||
else drawText(10,120,"Delete");
|
||||
s_RenderSystem.SwapBuffers();
|
||||
s_RenderSystem.Clear();
|
||||
if(trg & nn::hid::BUTTON_X) drawText(10,120,"Importing");
|
||||
else drawText(10,120,"Delete");
|
||||
s_RenderSystem.SwapBuffers();
|
||||
|
||||
// 既に存在するものをインポートするとエラーが返ってくるので、あらかじめ消しておく。
|
||||
nn::am::DeleteProgram(nn::fs::MEDIA_TYPE_NAND, programInfo.id);
|
||||
// タイトル鍵が違うケースに対応するために、チケットも消しておく。
|
||||
nn::am::DeleteTicket(programInfo.id);
|
||||
// 既に存在するものをインポートするとエラーが返ってくるので、あらかじめ消しておく。
|
||||
nn::am::DeleteProgram(nn::fs::MEDIA_TYPE_NAND, programInfo.id);
|
||||
// タイトル鍵が違うケースに対応するために、チケットも消しておく。
|
||||
nn::am::DeleteTicket(programInfo.id);
|
||||
|
||||
if(padStatus.trigger & nn::hid::BUTTON_X)
|
||||
{
|
||||
// CIA をインポート
|
||||
if (ImportFile(nn::fs::MEDIA_TYPE_NAND, ROMFS_IMPORTEE_PATH)==false)
|
||||
if(trg & nn::hid::BUTTON_X)
|
||||
{
|
||||
s_RenderSystem.Clear();
|
||||
setColor(1.0, 0.0, 0.0,1.0);
|
||||
drawText(10,50,"Impoprt fail");
|
||||
s_RenderSystem.SwapBuffers();
|
||||
// CIA をインポート
|
||||
if (ImportFile(nn::fs::MEDIA_TYPE_NAND, ROMFS_IMPORTEE_PATH)==false)
|
||||
{
|
||||
s_RenderSystem.Clear();
|
||||
setColor(1.0, 0.0, 0.0,1.0);
|
||||
drawText(10,50,"Impoprt fail");
|
||||
s_RenderSystem.SwapBuffers();
|
||||
}
|
||||
}
|
||||
}
|
||||
s_RenderSystem.Clear();
|
||||
drawText(10,50,"Complate");
|
||||
s_RenderSystem.Clear();
|
||||
drawText(10,50,"Complate");
|
||||
}
|
||||
|
||||
drawText(10,120,"Push Power Button & Power Off");
|
||||
s_RenderSystem.SwapBuffers();
|
||||
drawText(10,120,"Push Power Button & Power Off");
|
||||
s_RenderSystem.SwapBuffers();
|
||||
|
||||
WaitKey(0);
|
||||
WaitKey(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user