mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
データベースに余分なヘッダが追加できるように、ファイル名の代わりにシーク済みFSFileを取るようにした
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1163 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
parent
e0ba8d3d76
commit
b03934fb02
@ -139,67 +139,41 @@ BOOL DHT_CheckDatabase(const DHTFile* pDHT)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL DHT_PrepareDatabase(DHTFile* pDHT, const char* filepath)
|
BOOL DHT_PrepareDatabase(DHTFile* pDHT, FSFile* fp)
|
||||||
{
|
{
|
||||||
FSFile file;
|
|
||||||
s32 result;
|
s32 result;
|
||||||
s32 length;
|
s32 length;
|
||||||
u8 title[4] = { 'H','N','G','A' };
|
u8 title[4] = { 'H','N','G','A' };
|
||||||
PROFILE_INIT();
|
PROFILE_INIT();
|
||||||
|
|
||||||
if ( filepath )
|
if ( fp )
|
||||||
{
|
{
|
||||||
// ファイルオープン
|
|
||||||
PROFILE_COUNT();
|
|
||||||
if (!FS_OpenFileEx(&file, filepath, FS_FILEMODE_R))
|
|
||||||
{
|
|
||||||
OS_TPrintf("Cannot open %s.\n", filepath);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
// ヘッダ読み込み
|
// ヘッダ読み込み
|
||||||
PROFILE_COUNT();
|
PROFILE_COUNT();
|
||||||
result = FS_ReadFile(&file, &pDHT->header, sizeof(DHTHeader));
|
result = FS_ReadFile(fp, &pDHT->header, sizeof(DHTHeader));
|
||||||
if ( result != sizeof(DHTHeader) )
|
if ( result != sizeof(DHTHeader) )
|
||||||
{
|
{
|
||||||
OS_TPrintf("Cannot read the header of %s (result=%d).\n", filepath, result);
|
OS_TPrintf("Cannot read the DHT header (result=%d).\n", result);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
// magic_codeが HNGA のときはROM_Header分だけシークし直す
|
|
||||||
if ( pDHT->header.magic_code == *(u32*)title )
|
|
||||||
{
|
|
||||||
if ( !FS_SeekFile(&file, sizeof(ROM_Header), FS_SEEK_SET) )
|
|
||||||
{
|
|
||||||
OS_TPrintf("Cannot seek to the header of %s.\n", filepath);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
// 再びヘッダ読み込み
|
|
||||||
result = FS_ReadFile(&file, &pDHT->header, sizeof(DHTHeader));
|
|
||||||
if ( result != sizeof(DHTHeader) )
|
|
||||||
{
|
|
||||||
OS_TPrintf("Cannot read the header of %s (result=%d).\n", filepath, result);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// サイズチェック
|
// サイズチェック
|
||||||
PROFILE_COUNT();
|
PROFILE_COUNT();
|
||||||
length = (s32)DHT_GetDatabaseLength(pDHT);
|
length = (s32)DHT_GetDatabaseLength(pDHT);
|
||||||
if ( FS_GetFileLength(&file) < length ) // パディングがあり得る
|
if ( FS_GetFileLength(fp) < length ) // パディングがあり得る
|
||||||
{
|
{
|
||||||
OS_TPrintf("Invalid %s size (%d < %d).\n", filepath, FS_GetFileLength(&file), length);
|
OS_TPrintf("Invalid DHT file size (%d < %d).\n", FS_GetFileLength(fp), length);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
// ヘッダ分を削除
|
// ヘッダ分を削除
|
||||||
length -= sizeof(DHTHeader);
|
length -= sizeof(DHTHeader);
|
||||||
// データベース読み込み
|
// データベース読み込み
|
||||||
PROFILE_COUNT();
|
PROFILE_COUNT();
|
||||||
result = FS_ReadFile(&file, pDHT->database, length);
|
result = FS_ReadFile(fp, pDHT->database, length);
|
||||||
if ( result != length )
|
if ( result != length )
|
||||||
{
|
{
|
||||||
OS_TPrintf("Cannot read the database of %s (result=%d).\n", filepath, result);
|
OS_TPrintf("Cannot read the DHT database (result=%d).\n", result);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
FS_CloseFile(&file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// データベースの検証
|
// データベースの検証
|
||||||
|
|||||||
@ -104,7 +104,7 @@ void SYSM_InitPXI( u32 mcu_prio )
|
|||||||
#ifdef SDK_ARM9
|
#ifdef SDK_ARM9
|
||||||
static BOOL GetDatabaseFilepath(char *path)
|
static BOOL GetDatabaseFilepath(char *path)
|
||||||
{
|
{
|
||||||
u8 title[4] = { 'H','N','G','A' };
|
u8 title[4] = { 'H','N','H','A' };
|
||||||
|
|
||||||
#if( USE_LCFG_STRING == 0 )
|
#if( USE_LCFG_STRING == 0 )
|
||||||
char *title0 = "HNGA";
|
char *title0 = "HNGA";
|
||||||
@ -154,8 +154,16 @@ void SYSMi_PrepareDatabase(void)
|
|||||||
char path[256];
|
char path[256];
|
||||||
if ( GetDatabaseFilepath( path ) )
|
if ( GetDatabaseFilepath( path ) )
|
||||||
{
|
{
|
||||||
DHT_PrepareDatabase(dht, path);
|
FSFile file;
|
||||||
DC_FlushRange(dht, DHT_GetDatabaseLength(dht));
|
if ( FS_OpenFileEx(&file, path, FS_FILEMODE_R) )
|
||||||
|
{
|
||||||
|
if ( FS_SeekFile(&file, sizeof(ROM_Header), FS_SEEK_SET) )
|
||||||
|
{
|
||||||
|
DHT_PrepareDatabase(dht, &file);
|
||||||
|
DC_FlushRange(dht, DHT_GetDatabaseLength(dht));
|
||||||
|
}
|
||||||
|
FS_CloseFile(&file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -183,11 +183,18 @@ void TwlMain(void)
|
|||||||
(void)GX_VBlankIntr(TRUE);
|
(void)GX_VBlankIntr(TRUE);
|
||||||
|
|
||||||
FS_Init(FS_DMA_NOT_USE);
|
FS_Init(FS_DMA_NOT_USE);
|
||||||
|
|
||||||
// 署名ロード
|
|
||||||
if ( !DHT_PrepareDatabase(dht, HASH_PATH) )
|
|
||||||
{
|
{
|
||||||
OS_TPanic("Cannot prepare the database.\n");
|
FSFile file;
|
||||||
|
if ( !FS_OpenFileEx(&file, HASH_PATH, FS_FILEMODE_R) )
|
||||||
|
{
|
||||||
|
OS_TPanic("Cannot open %s.\n", HASH_PATH);
|
||||||
|
}
|
||||||
|
// 署名ロード
|
||||||
|
if ( !DHT_PrepareDatabase(dht, &file) )
|
||||||
|
{
|
||||||
|
OS_TPanic("Cannot prepare the database.\n");
|
||||||
|
}
|
||||||
|
FS_CloseFile(&file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// –{”Ô
|
// –{”Ô
|
||||||
|
|||||||
@ -65,11 +65,12 @@ BOOL DHT_CheckDatabase(const DHTFile* pDHT);
|
|||||||
Description: FS関数を利用して全データベースを読み込みと検証を行う
|
Description: FS関数を利用して全データベースを読み込みと検証を行う
|
||||||
|
|
||||||
Arguments: pDHT 全データベースの格納先
|
Arguments: pDHT 全データベースの格納先
|
||||||
filepath ファイルパス (NULLで格納済みと判定(真贋チェックのみ))
|
fp ファイル構造体へのポインタ
|
||||||
|
DHTHeaderの先頭までシーク済みである必要がある
|
||||||
|
|
||||||
Returns: 成功すればTRUE
|
Returns: 成功すればTRUE
|
||||||
*---------------------------------------------------------------------------*/
|
*---------------------------------------------------------------------------*/
|
||||||
BOOL DHT_PrepareDatabase(DHTFile* pDHT, const char* filepath);
|
BOOL DHT_PrepareDatabase(DHTFile* pDHT, FSFile* fp);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*
|
/*---------------------------------------------------------------------------*
|
||||||
Name: DHT_GetDatabase
|
Name: DHT_GetDatabase
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user