SRL検索の高速版作成

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@465 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
yutaka 2008-01-16 01:42:49 +00:00
parent b008ccf24f
commit 6ee071b3e7
5 changed files with 208 additions and 2 deletions

View File

@ -24,7 +24,7 @@ SUBMAKES =
LINCLUDES = $(ES_ROOT)/twl/include
SRCS = fs_firm.c
SRCS = fs_firm.c fs_es.c
TARGET_LIB = libfs$(FIRM_LIBSUFFIX).a

View File

@ -0,0 +1,155 @@
/*---------------------------------------------------------------------------*
Project: TwlIPL - libraries - fs
File: fs_es.c
Copyright 2007 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.
$Date:: $
$Rev$
$Author$
*---------------------------------------------------------------------------*/
#include <firm.h>
#include <es.h>
#define PATH_FORMAT_TMD "nand:/title/%08x/%08x/content/title.tmd"
#define PATH_FORMAT_CONTENT "nand:/title/%08x/%08x/content/%08x.app"
/*---------------------------------------------------------------------------*
Name: LoadTMD
Description: TMD
NAMi_Free
Arguments: titleId: TitleID
Returns: TRUEを返します
FALSE
*---------------------------------------------------------------------------*/
static BOOL LoadTMD(ESTitleMeta* pTmd, u64 titleId)
{
char path[64];
FSFile f;
BOOL bSuccess;
u32 fileSize;
s32 readSize;
s32 readResult;
// TMD のパスを生成
STD_TSPrintf(path, PATH_FORMAT_TMD, (u32)(titleId >> 32), (u32)titleId);
FS_InitFile(&f);
bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R);
if( ! bSuccess )
{
// ファイルが開けなかった
return FALSE;
}
fileSize = FS_GetFileLength(&f);
// ファイルサイズをチェック 1
// 固定部分サイズ <= fileSize <= 固定部分サイズ + 可変長部分最大サイズ
if( (fileSize < sizeof(IOSCSigRsa2048) + sizeof(ESTitleMetaHeader))
|| (sizeof(ESTitleMeta) < fileSize) )
{
// ファイルサイズが異常
FS_CloseFile(&f);
return FALSE;
}
readSize = (s32)fileSize;
readResult = FS_ReadFile(&f, pTmd, readSize);
FS_CloseFile(&f);
if( readResult != readSize )
{
// ファイルからの読み込みに失敗
return FALSE;
}
// ファイルサイズをチェック 2
// 可変長部分を正しく考慮
if( fileSize != sizeof(IOSCSigRsa2048)
+ sizeof(ESTitleMetaHeader)
+ sizeof(ESContentMeta) * MI_SwapEndian16(pTmd->head.numContents) )
{
// ファイルサイズが異常
return FALSE;
}
// タイトル ID の一致をチェック
if( titleId != MI_SwapEndian64(pTmd->head.titleId) )
{
// タイトル ID が一致しない
return FALSE;
}
return TRUE;
}
/*---------------------------------------------------------------------------*
Name: FS_GetTitleBootContentPathFast
Description: NAND
Arguments: buf:
FS_ENTRY_LONGNAME_MAX
titleId: Title ID
Returns: TRUE
*---------------------------------------------------------------------------*/
BOOL FS_GetTitleBootContentPathFast(char* buf, u64 titleId)
{
ESTitleMeta tmd;
u32 bootContentId;
int bootContentIndex;
int numContents;
int i;
SDK_POINTER_ASSERT(buf);
if( !LoadTMD(&tmd, titleId) )
{
return FALSE;
}
// 生の TMD は BigEndian
bootContentIndex = MI_SwapEndian16(tmd.head.bootIndex);
numContents = MI_SwapEndian16(tmd.head.numContents);
// bootContentIndex に一致するコンテンツを探す
for( i = 0; i < numContents; ++i )
{
const ESContentMeta* pContent = &tmd.contents[i];
if( MI_SwapEndian16(pContent->index) == bootContentIndex )
{
bootContentId = MI_SwapEndian32(pContent->cid);
break;
}
}
if( i >= numContents )
{
return FALSE;
}
// コンテンツのパスを生成
STD_TSPrintf(buf, PATH_FORMAT_CONTENT, (u32)(titleId >> 32), (u32)titleId, bootContentId);
return TRUE;
}

View File

@ -114,7 +114,7 @@ void FS_DeleteAesKeySeed( void )
BOOL FS_ResolveSrl( u64 titleId )
{
if ( ES_ERR_OK != ES_InitLib() ||
ES_ERR_OK != ES_GetContentPath(titleId, CONTENT_INDEX_SRL, (char*)HW_TWL_FS_BOOT_SRL_PATH_BUF) ||
!FS_GetTitleBootContentPathFast((char*)HW_TWL_FS_BOOT_SRL_PATH_BUF, titleId) ||
ES_ERR_OK != ES_CloseLib() )
{
return FALSE;

View File

@ -22,6 +22,7 @@
#include <firm/fs/ARM7/fs_firm.h>
#else
#include <firm/fs/ARM9/fs_firm.h>
#include <firm/fs/ARM9/fs_es.h>
#endif // SDK_ARM7

View File

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*
Project: TwlIPL - include - fs
File: fs_es.h
Copyright 2007 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.
$Date:: 2007-09-06$
$Rev$
$Author$
*---------------------------------------------------------------------------*/
#ifndef FIRM_FS_ES_FIRM_H_
#define FIRM_FS_ES_FIRM_H_
#include <twl/types.h>
#ifdef __cplusplus
extern "C" {
#endif
/*---------------------------------------------------------------------------*
Name: FS_GetTitleBootContentPathFast
Description: NAND
Arguments: buf:
FS_ENTRY_LONGNAME_MAX
titleId: Title ID
Returns: TRUE
*---------------------------------------------------------------------------*/
BOOL FS_GetTitleBootContentPathFast(char* buf, u64 titleId);
#ifdef __cplusplus
} /* extern "C" */
#endif
/* FIRM_FS_ES_FIRM_H_ */
#endif