mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
マスタリング済みDSソフト対応 (DHT_TEST=TRUE時)
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1142 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
parent
003982a6b5
commit
fd9db3ca3a
@ -238,22 +238,22 @@ void DHT_CheckHashPhase1Update(SVCHMACSHA1Context* ctx, const void* ptr, u32 len
|
||||
// ARM9 or ARM7 static
|
||||
SVC_HMACSHA1Update(ctx, ptr, length);
|
||||
}
|
||||
BOOL DHT_CheckHashPhase1Final(SVCHMACSHA1Context* ctx, const DHTDatabase *db)
|
||||
BOOL DHT_CheckHashPhase1Final(SVCHMACSHA1Context* ctx, const u8 *hash)
|
||||
{
|
||||
u8 md[20];
|
||||
BOOL result;
|
||||
SVC_HMACSHA1GetHash(ctx, md);
|
||||
result = SVC_CompareSHA1(db->hash[0], md);
|
||||
result = SVC_CompareSHA1(hash, md);
|
||||
if ( !result )
|
||||
{
|
||||
OS_TPrintf("\n");
|
||||
OS_TPrintfEx("DB = % 20B\n", db->hash[0]);
|
||||
OS_TPrintfEx("DB = % 20B\n", hash);
|
||||
OS_TPrintfEx("HASH = % 20B\n", md);
|
||||
OS_TPrintf("%s: hash[0] is not valid.\n", __func__);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
BOOL DHT_CheckHashPhase1(const DHTDatabase *db, const ROM_Header_Short* pROMHeader, const void* pARM9, const void* pARM7)
|
||||
BOOL DHT_CheckHashPhase1(const u8* hash, const ROM_Header_Short* pROMHeader, const void* pARM9, const void* pARM7)
|
||||
{
|
||||
SVCHMACSHA1Context ctx;
|
||||
BOOL result;
|
||||
@ -271,7 +271,7 @@ BOOL DHT_CheckHashPhase1(const DHTDatabase *db, const ROM_Header_Short* pROMHead
|
||||
DHT_CheckHashPhase1Update(&ctx, pARM7, pROMHeader->sub_size);
|
||||
// ŒŸ<C592>Ø
|
||||
PROFILE_COUNT();
|
||||
result = DHT_CheckHashPhase1Final(&ctx, db);
|
||||
result = DHT_CheckHashPhase1Final(&ctx, hash);
|
||||
// Œ‹‰Ê•ñ<E280A2><C3B1>
|
||||
#ifdef PRINT_PROFILE
|
||||
PROFILE_COUNT();
|
||||
@ -303,14 +303,25 @@ static BOOL ImageHMACSHA1Update(SVCHMACSHA1Context* ctx, s32 offset, s32 length,
|
||||
static BOOL GetOverlayInfo(int no, int fat_offset, int* pOffset, int* pLength)
|
||||
{
|
||||
ROM_FAT *fat;
|
||||
static u8 fat_cache[PAGE_SIZE]; // 本当にページをまたがないのか?
|
||||
static u8 fat_cache[PAGE_SIZE*2];
|
||||
static int last_page = 0;
|
||||
int page = (fat_offset + no * (s32)sizeof(ROM_FAT)) / PAGE_SIZE;
|
||||
if ( last_page != page )
|
||||
{
|
||||
if ( !ReadFunc(&fat_cache, page * PAGE_SIZE, PAGE_SIZE, readArg) )
|
||||
if ( last_page + 1 == page ) // 1ページはキャッシュ済み
|
||||
{
|
||||
return FALSE;
|
||||
MI_CpuCopy8( &fat_cache[PAGE_SIZE], &fat_cache[0], PAGE_SIZE );
|
||||
if ( !ReadFunc(&fat_cache[PAGE_SIZE], (page+1) * PAGE_SIZE, PAGE_SIZE, readArg) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else // 通常は2ページ読み
|
||||
{
|
||||
if ( !ReadFunc(fat_cache, page * PAGE_SIZE, PAGE_SIZE*2, readArg) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
last_page = page;
|
||||
}
|
||||
@ -326,7 +337,7 @@ static BOOL GetOverlayInfo(int no, int fat_offset, int* pOffset, int* pLength)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL DHT_CheckHashPhase2(const DHTDatabase *db, const ROM_Header_Short* pROMHeader, void* buffer, DHTReadFunc func, void* arg)
|
||||
BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, void* buffer, DHTReadFunc func, void* arg)
|
||||
{
|
||||
int overlay_nums = (int)(pROMHeader->main_ovt_size / sizeof(ROM_OVT));
|
||||
u8 md[20];
|
||||
@ -400,10 +411,10 @@ BOOL DHT_CheckHashPhase2(const DHTDatabase *db, const ROM_Header_Short* pROMHead
|
||||
PROFILE_COUNT();
|
||||
MI_CpuClear8(md, sizeof(md));
|
||||
}
|
||||
if ( !SVC_CompareSHA1(md, db->hash[1]) )
|
||||
if ( !SVC_CompareSHA1(md, hash) )
|
||||
{
|
||||
OS_TPrintf("\n");
|
||||
OS_TPrintfEx("DB = % 20B\n", db->hash[1]);
|
||||
OS_TPrintfEx("DB = % 20B\n", hash);
|
||||
OS_TPrintfEx("HASH = % 20B\n", md);
|
||||
OS_TPrintf("%s: hash[1] is not valid.\n", __func__);
|
||||
return FALSE;
|
||||
|
||||
@ -894,11 +894,12 @@ static HotSwState LoadStaticModule(void)
|
||||
#ifdef DHT_TEST
|
||||
else
|
||||
{
|
||||
if ( !s_cbData.pBootSegBuf->rh.s.enable_signature )
|
||||
SVCHMACSHA1Context ctx;
|
||||
const u8* hash0;
|
||||
const u8* hash1;
|
||||
if ( !s_cbData.pBootSegBuf->rh.s.enable_signature ) // ホワイトリストエントリ
|
||||
{
|
||||
SVCHMACSHA1Context ctx;
|
||||
const DHTDatabase* db;
|
||||
|
||||
while (!dht)
|
||||
{
|
||||
OS_Sleep(1);
|
||||
@ -912,35 +913,42 @@ static HotSwState LoadStaticModule(void)
|
||||
return HOTSW_HASH_CHECK_ERROR;
|
||||
}
|
||||
OS_TPrintf(" Done.\n");
|
||||
|
||||
OS_TPrintf("DHT Pahse1...");
|
||||
DHT_CheckHashPhase1Init(&ctx, (ROM_Header_Short*)s_cbData.pBootSegBuf);
|
||||
if( s_cbData.pBootSegBuf->rh.s.main_size > SECURE_SEGMENT_SIZE )
|
||||
{
|
||||
DHT_CheckHashPhase1Update(&ctx, s_cbData.pSecureSegBuf, SECURE_SEGMENT_SIZE);
|
||||
DHT_CheckHashPhase1Update(&ctx, (u32 *)(s_cbData.arm9Stc + SECURE_SEGMENT_SIZE), s_cbData.pBootSegBuf->rh.s.main_size - SECURE_SEGMENT_SIZE );
|
||||
}
|
||||
else
|
||||
{
|
||||
DHT_CheckHashPhase1Update(&ctx, s_cbData.pSecureSegBuf, s_cbData.pBootSegBuf->rh.s.main_size);
|
||||
}
|
||||
|
||||
DHT_CheckHashPhase1Update(&ctx, (u32 *)s_cbData.arm7Stc, s_cbData.pBootSegBuf->rh.s.sub_size);
|
||||
if ( !DHT_CheckHashPhase1Final(&ctx, db) )
|
||||
{
|
||||
OS_TPrintf(" Failed.\n");
|
||||
return HOTSW_HASH_CHECK_ERROR;
|
||||
}
|
||||
OS_TPrintf(" Done.\n");
|
||||
|
||||
OS_TPrintf("DHT Pahse2...");
|
||||
if ( !DHT_CheckHashPhase2(db, &s_cbData.pBootSegBuf->rh.s, ov_buffer, ReadImage, &s_cbData) )
|
||||
{
|
||||
OS_TPrintf(" Failed.\n");
|
||||
return HOTSW_HASH_CHECK_ERROR;
|
||||
}
|
||||
OS_TPrintf(" Done.\n");
|
||||
hash0 = db->hash[0];
|
||||
hash1 = db->hash[1];
|
||||
}
|
||||
else // マスタリング済みエントリ
|
||||
{
|
||||
hash0 = s_cbData.pBootSegBuf->rh.s.main_static_digest;
|
||||
hash1 = s_cbData.pBootSegBuf->rh.s.sub_static_digest;
|
||||
}
|
||||
|
||||
OS_TPrintf("DHT Pahse1...");
|
||||
DHT_CheckHashPhase1Init(&ctx, (ROM_Header_Short*)s_cbData.pBootSegBuf);
|
||||
if( s_cbData.pBootSegBuf->rh.s.main_size > SECURE_SEGMENT_SIZE )
|
||||
{
|
||||
DHT_CheckHashPhase1Update(&ctx, s_cbData.pSecureSegBuf, SECURE_SEGMENT_SIZE);
|
||||
DHT_CheckHashPhase1Update(&ctx, (u32 *)(s_cbData.arm9Stc + SECURE_SEGMENT_SIZE), s_cbData.pBootSegBuf->rh.s.main_size - SECURE_SEGMENT_SIZE );
|
||||
}
|
||||
else
|
||||
{
|
||||
DHT_CheckHashPhase1Update(&ctx, s_cbData.pSecureSegBuf, s_cbData.pBootSegBuf->rh.s.main_size);
|
||||
}
|
||||
|
||||
DHT_CheckHashPhase1Update(&ctx, (u32 *)s_cbData.arm7Stc, s_cbData.pBootSegBuf->rh.s.sub_size);
|
||||
if ( !DHT_CheckHashPhase1Final(&ctx, hash0) )
|
||||
{
|
||||
OS_TPrintf(" Failed.\n");
|
||||
return HOTSW_HASH_CHECK_ERROR;
|
||||
}
|
||||
OS_TPrintf(" Done.\n");
|
||||
|
||||
OS_TPrintf("DHT Pahse2...");
|
||||
if ( !DHT_CheckHashPhase2(hash1, &s_cbData.pBootSegBuf->rh.s, ov_buffer, ReadImage, &s_cbData) )
|
||||
{
|
||||
OS_TPrintf(" Failed.\n");
|
||||
return HOTSW_HASH_CHECK_ERROR;
|
||||
}
|
||||
OS_TPrintf(" Done.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1044,7 +1052,7 @@ static void GenVA_VB_VD(void)
|
||||
SYSM_work* sw = SYSMi_GetWork();
|
||||
u32 dummy = 0;
|
||||
MATHRandContext32 rnd;
|
||||
|
||||
|
||||
// 乱数を初期化
|
||||
// チック&RTC初回ロード値を種とする。
|
||||
// (起動する度に変化するパラメータと組み合わせる。
|
||||
|
||||
@ -154,12 +154,12 @@ static BOOL CheckValidation(FSFile* fp)
|
||||
}
|
||||
//OS_TPrintf("FOUND: 0x%08X: %.4s(%d)\n", db, db->game_code, db->rom_version);
|
||||
// ハッシュ計算 (1) - 隠蔽可能なはず
|
||||
if ( !DHT_CheckHashPhase1(db, &rom_header, rom_arm9, rom_arm7) )
|
||||
if ( !DHT_CheckHashPhase1(db->hash[0], &rom_header, rom_arm9, rom_arm7) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
// ハッシュ計算 (2) - 隠蔽は難しいか
|
||||
if ( !DHT_CheckHashPhase2(db, &rom_header, ov_buffer, ReadImage, fp) )
|
||||
if ( !DHT_CheckHashPhase2(db->hash[1], &rom_header, ov_buffer, ReadImage, fp) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -106,25 +106,25 @@ void DHT_CheckHashPhase1Update(SVCHMACSHA1Context* ctx, const void* ptr, u32 len
|
||||
Description: ROMヘッダおよびARM9/ARM7スタティック領域の検証の結果判定
|
||||
|
||||
Arguments: ctx 検証用のSVCHMACSHA1コンテキスト
|
||||
db 対象データベースへのポインタ
|
||||
hash 対応するハッシュ (db->hash[0])
|
||||
|
||||
Returns: 問題なければTRUE
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL DHT_CheckHashPhase1Final(SVCHMACSHA1Context* ctx, const DHTDatabase *db);
|
||||
BOOL DHT_CheckHashPhase1Final(SVCHMACSHA1Context* ctx, const u8* hash);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: DHT_CheckHashPhase1
|
||||
|
||||
Description: ROMヘッダおよびARM9/ARM7スタティック領域の検証
|
||||
|
||||
Arguments: db 対象データベースへのポインタ
|
||||
Arguments: hash 対応するハッシュ (db->hash[0])
|
||||
pROMHeader 対象となるROMヘッダ格納先
|
||||
pARM9 対象となるARM9スタティック格納先
|
||||
pARM7 対象となるARM7スタティック格納先
|
||||
|
||||
Returns: 問題なければTRUE
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL DHT_CheckHashPhase1(const DHTDatabase *db, const ROM_Header_Short* pROMHeader, const void* pARM9, const void* pARM7);
|
||||
BOOL DHT_CheckHashPhase1(const u8* hash, const ROM_Header_Short* pROMHeader, const void* pARM9, const void* pARM7);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: DHT_CheckHashPhase2
|
||||
@ -132,7 +132,7 @@ BOOL DHT_CheckHashPhase1(const DHTDatabase *db, const ROM_Header_Short* pROMHead
|
||||
Description: オーバーレイ領域の検証
|
||||
(デバイスのRead APIを登録できるべき)
|
||||
|
||||
Arguments: db 対象データベースへのポインタ
|
||||
Arguments: hash 対応するハッシュ (db->hash[1])
|
||||
pROMHeader 対象となるROMヘッダ格納先
|
||||
fctx (FS版) FSFile構造体へのポインタ
|
||||
(CARD版) dma番号をvoid*にキャストしたもの
|
||||
@ -141,7 +141,7 @@ BOOL DHT_CheckHashPhase1(const DHTDatabase *db, const ROM_Header_Short* pROMHead
|
||||
|
||||
Returns: 問題なければTRUE
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL DHT_CheckHashPhase2(const DHTDatabase *db, const ROM_Header_Short* pROMHeader, void* buffer, DHTReadFunc func, void* arg);
|
||||
BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, void* buffer, DHTReadFunc func, void* arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user