tadファイルのタイトルversion情報を取得。

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlToolsRED@389 7061adef-622a-194b-ae81-725974e89856
This commit is contained in:
miya 2009-07-31 09:17:10 +00:00
parent 72d3a76d98
commit fd1ea05039
4 changed files with 597 additions and 221 deletions

View File

@ -58,13 +58,79 @@ NAMTadInfo;
c:/twlsdk/add-ins/es/es-sdk-20090216/twl/include/estypes.h
typedef u32 ESContentId; // 32-bit content identity
typedef u64 ESTitleId; // 64-bit title identity
typedef u8 ESVersion; // 8-bit data structure version
typedef u16 ESTitleVersion; // 16-bit title version
typedef ESTitleId ESSysVersion; // 64-bit system software version
typedef u32 ESTitleType; // title type
typedef u16 ESContentType; // content type
typedef u8 IOSCHash[20];
*/
#if 0
/* TMD */
typedef struct {
4 ESContentId cid; /* 32 bit content id */
2 u16 index; /* content index, unique per title */
2 ESContentType type; /* content type*/
8 u64 size; /* unencrypted content size in bytes */
IOSCHash hash; /* 160-bit SHA1 hash of the content */
} ESContentMeta;
typedef struct {
1 ESVersion version; /* TMD version number */
1 ESVersion caCrlVersion; /* CA CRL version number */
1 ESVersion signerCrlVersion; /* signer CRL version number */
8 ESSysVersion sysVersion; /* required system software version number */
8 ESTitleId titleId; /* 64 bit title id */
4 ESTitleType type; /* 32 bit title type */
2 u16 groupId;
62 ESTmdReserved reserved; /* 62 bytes reserved info for Nintendo */
4 u32 accessRights; /* title's access rights to use
system resources */
8 ESTitleVersion titleVersion; /* 16 bit title version */
2 u16 numContents; /* number of contents per title */
2 u16 bootIndex; /* boot content index */
} ESTitleMetaHeader; 104
typedef struct {
256 IOSCSigRsa2048 sig; /* RSA 2048bit sign of all the data in
the TMD file */
ESTitleMetaHeader head;
ESContentMeta contents[ES_MAX_CONTENT];
} ESTitleMeta;
typedef struct {
1 ESVersion version; /* TMD data structure version */
8 ESSysVersion sysVersion; /* required system software
version number */
8 ESTitleId titleId; /* 64 bit title id */
4 ESTitleType type; /* 32 bit title type */
2 u16 groupId;
62 ESTmdReserved reserved; /* 62 bytes reserved info */
2 ESTitleVersion titleVersion; /* 16 bit title version */
2 u16 numContents; /* number of contents in the title */
} ESTmdViewHeader;
typedef struct {
ESContentId cid; /* 32 bit content id */
u16 index; /* 16 bit content index */
ESContentType type; /* 16 bit content type */
u64 size; /* 64 bit content size */
} ESCmdView;
typedef struct {
ESTmdViewHeader head;
ESCmdView contents[ES_MAX_CONTENT];
} ESTmdView;
#endif
#include <twl.h>
#include <nitro/nvram/nvram.h>
@ -1815,9 +1881,9 @@ BOOL myImportTad(char* full_path, int org_version, FSFile *log_fd)
return FALSE;
}
miya_log_fprintf(log_fd,"tadfile.ver=%d org.ver=%d\n", tadInfo.titleInfo.version,org_version);
miya_log_fprintf(log_fd,"tadfile.ver=%d org.ver=%d\n", tadInfo.titleInfo.version, org_version);
if( org_version > tadInfo.titleInfo.version ) {
miya_log_fprintf(log_fd,"Error:org.ver=%d tadfile.ver=%d %s\n",full_path);
miya_log_fprintf(log_fd,"Error:org.ver=%d tadfile.ver=%d %s\n",org_version, tadInfo.titleInfo.version, full_path);
return FALSE;
}
@ -1921,7 +1987,7 @@ BOOL myImportTad_sign(char* full_path, int org_version, FSFile *log_fd)
miya_log_fprintf(log_fd,"tadfile.ver=%d org.ver=%d\n", tadInfo.titleInfo.version,org_version);
if( org_version > tadInfo.titleInfo.version ) {
miya_log_fprintf(log_fd,"Error:org.ver=%d tadfile.ver=%d %s\n",full_path);
miya_log_fprintf(log_fd,"Error:org.ver=%d tadfile.ver=%d %s\n",org_version, tadInfo.titleInfo.version, full_path);
return FALSE;
}

View File

@ -157,7 +157,7 @@ typedef struct {
}
static BOOL pre_install_add_list(u64 tid, u8 region, u8 country_code, char *temp_file_name, FSFile *log_fd)
static BOOL pre_install_add_list(u64 tid, u16 version, u16 groupid, char *temp_file_name, FSFile *log_fd)
{
PRE_INSTALL_FILE *temp_pre_install_file = NULL;
PRE_INSTALL_FILE *temp_list;
@ -172,8 +172,8 @@ static BOOL pre_install_add_list(u64 tid, u8 region, u8 country_code, char *temp
return FALSE;
}
temp_pre_install_file->tid = tid;
temp_pre_install_file->region = region;
temp_pre_install_file->country = country_code;
temp_pre_install_file->version = version;
temp_pre_install_file->groupid = groupid;
temp_pre_install_file->next = NULL;
STD_StrCpy(temp_pre_install_file->file_name, temp_file_name);
@ -196,21 +196,46 @@ static BOOL pre_install_add_list(u64 tid, u8 region, u8 country_code, char *temp
static char *pre_install_search_tid(u64 tid, FSFile *log_fd, BOOL *is_in_sd)
{
PRE_INSTALL_FILE *temp_list;
PRE_INSTALL_FILE *latest_list;
// OS_TPrintf("%s\n",__FUNCTION__);
// pre_install_print_list(log_fd);
latest_list = NULL;
for( temp_list = pre_install_file_list ; temp_list != NULL ; temp_list = temp_list->next ) {
if( temp_list->tid == tid ) {
miya_log_fprintf(log_fd,"\ntad file entry tid=0x%08x%08x\n%s\n",
(u32)(tid >> 32) , (u32)(tid & 0xffffffff), temp_list->file_name );
if( !STD_StrNCmp( temp_list->file_name, "sdmc:" , STD_StrLen("sdmc:")) ) {
*is_in_sd = TRUE;
if( latest_list == NULL ) {
latest_list = temp_list;
}
else {
*is_in_sd = FALSE;
miya_log_fprintf(log_fd,"\n 1 tid=0x%08x%08x ver=0x%04x %s\n",
(u32)(tid >> 32) , (u32)(tid & 0xffffffff), latest_list->version , latest_list->file_name );
miya_log_fprintf(log_fd," 2 tid=0x%08x%08x ver=0x%04x %s\n",
(u32)(tid >> 32) , (u32)(tid & 0xffffffff), temp_list->version, temp_list->file_name );
if( latest_list->version < temp_list->version ) {
latest_list = temp_list;
}
}
return temp_list->file_name;
}
}
if( latest_list ) {
if( !STD_StrNCmp( latest_list->file_name, "sdmc:" , STD_StrLen("sdmc:")) ) {
*is_in_sd = TRUE;
}
else {
*is_in_sd = FALSE;
}
miya_log_fprintf(log_fd,"\ntad file entry tid=0x%08x%08x\n%s\n",
(u32)(tid >> 32) , (u32)(tid & 0xffffffff), latest_list->file_name );
return latest_list->file_name;
}
miya_log_fprintf(log_fd,"\n%s:No entry\ntid 0x%08x%08x\n",__FUNCTION__,
(u32)(tid >> 32) , (u32)(tid & 0xffffffff));
return NULL;
@ -317,13 +342,19 @@ static int my_char_to_hex(char c)
else if( 'a' <= c && c <= 'f' ) {
return (int)( c - 'a' + 10 );
}
else if( ('x' == c) || ('X' == c) ) {
return -2;
}
return -1; /* error */
}
/* main() -> pre_install_process() -> pre_install_load_file()ÅŒÄÎêé<E2809A>B */
static BOOL pre_install_load_file(char *path, FSFile *log_fd)
static MY_SIGN_File ms_file;
static BOOL pre_install_load_file(char *path, FSFile *log_fd, BOOL encrypt_flag)
{
FSFile file;
BOOL bSuccess = TRUE;
// s32 result;
s32 readSize;
@ -338,31 +369,51 @@ static BOOL pre_install_load_file(char *path, FSFile *log_fd)
char temp_file_name[FS_FILE_NAME_MAX];
u64 temp_tid;
u8 temp_region;
u8 temp_country_code;
u16 temp_version;
u16 temp_groupid;
// u8 temp_region;
// u8 temp_country_code;
int temp_hex;
int temp_filename_count;
char c;
int scan_counter;
FS_InitFile(&file);
bSuccess = FS_OpenFile(&file, path);
if( ! bSuccess ) {
fsres = FS_GetArchiveResultCode(path);
miya_log_fprintf(log_fd,"Error:%s %s open file\n",__FILE__,__FUNCTION__);
miya_log_fprintf(log_fd, " Failed open file:%s\n", my_fs_util_get_fs_result_word( fsres ));
return FALSE; /* open error! */
if( encrypt_flag == TRUE ) {
my_sign_FS_InitFile(&ms_file);
bSuccess = my_sign_FS_OpenFile(&ms_file, path);
if( ! bSuccess ) {
// fsres = FS_GetArchiveResultCode(path);
miya_log_fprintf(log_fd,"Error:%s %s open file failed %s\n",__FILE__,__FUNCTION__,path);
// miya_log_fprintf(log_fd, " Failed open file:%s\n", my_fs_util_get_fs_result_word( fsres ));
return FALSE; /* open error! */
}
}
else {
FS_InitFile(&file);
bSuccess = FS_OpenFile(&file, path);
if( ! bSuccess ) {
fsres = FS_GetArchiveResultCode(path);
miya_log_fprintf(log_fd,"Error:%s %s open file\n",__FILE__,__FUNCTION__);
miya_log_fprintf(log_fd, " Failed open file:%s\n", my_fs_util_get_fs_result_word( fsres ));
return FALSE; /* open error! */
}
}
/*
title id
0x00000000 00000000, region , country code, file name,
0x00000000 00000000, version , groupid, file name,
*/
OS_TPrintf("%s %s %d : Start of File\n", __FILE__,__FUNCTION__,__LINE__);
while( 1 ) {
next_line_read:
buf_state = 0;
readSize = ReadLine(&file, line_buf, LINE_BUF_SIZE );
if( encrypt_flag == TRUE ) {
readSize = my_sign_ReadLine(&ms_file, line_buf, LINE_BUF_SIZE );
}
else {
readSize = ReadLine(&file, line_buf, LINE_BUF_SIZE );
}
if( readSize == 0 ) {
/* EOF */
OS_TPrintf("%s %s %d : End of File\n", __FILE__,__FUNCTION__,__LINE__);
@ -376,8 +427,8 @@ static BOOL pre_install_load_file(char *path, FSFile *log_fd)
buf_counter = STD_StrLen("0x");
buf_state = 1;
temp_tid = 0;
temp_region = 0;
temp_country_code = 0;
temp_version = 0;
temp_groupid = 0;
temp_filename_count = 0;
while( readSize > buf_counter ) {
@ -389,6 +440,7 @@ static BOOL pre_install_load_file(char *path, FSFile *log_fd)
if( buf_counter == 18 ) {
// OS_TPrintf("temp_tid=0x%08x %08x\n", (u32)(temp_tid >> 32) , (u32)(temp_tid & 0xffffffff));
buf_state = 2; /* next state */
scan_counter = 0;
}
else {
/* format error */
@ -399,7 +451,7 @@ static BOOL pre_install_load_file(char *path, FSFile *log_fd)
}
else {
temp_hex = my_char_to_hex(c);
if( temp_hex != -1 ) {
if( temp_hex != -1 && temp_hex != -2 ) {
temp_tid |= ( ((u64)temp_hex) << (64 - (4 * (buf_counter-1))) );
}
else {
@ -410,16 +462,51 @@ static BOOL pre_install_load_file(char *path, FSFile *log_fd)
}
}
break;
case 2: /* region */
case 2: /* version */
if( c == ' ' ) {
}
else if( c == ',' ) {
buf_state = 3; /* next state */
scan_counter = 0;
}
else {
temp_hex = my_char_to_hex(c);
if( temp_hex != -1 ) {
temp_region = (u8)temp_hex;
switch( scan_counter ) {
case 0:
//OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__);
if( temp_hex != 0 ) {
/* error */
goto next_line_read;
}
else {
scan_counter++;
}
break;
case 1:
if( temp_hex != -2 /* x or X */ ) {
/* error */
goto next_line_read;
}
else {
scan_counter++;
temp_version = 0;
}
break;
case 2:
case 3:
case 4:
case 5:
temp_version |= ( ((u16)temp_hex) << (16 - (4 * (scan_counter-1))) );
scan_counter++;
break;
case 6:
break;
default:
break;
}
}
else {
/* format error */
@ -428,7 +515,7 @@ static BOOL pre_install_load_file(char *path, FSFile *log_fd)
}
}
break;
case 3: /* country code */
case 3: /* group id */
if( c == ' ' ) {
}
else if( c == ',' ) {
@ -437,7 +524,38 @@ static BOOL pre_install_load_file(char *path, FSFile *log_fd)
else {
temp_hex = my_char_to_hex(c);
if( temp_hex != -1 ) {
temp_country_code = (u8)temp_hex;
switch( scan_counter ) {
case 0:
if( temp_hex != 0 ) {
/* error */
goto next_line_read;
}
else {
scan_counter++;
}
break;
case 1:
if( temp_hex != -2 ) {
/* error */
goto next_line_read;
}
else {
scan_counter++;
temp_groupid = 0;
}
break;
case 2:
case 3:
case 4:
case 5:
temp_groupid |= ( ((u16)temp_hex) << (16 - (4 * (scan_counter-1))) );
scan_counter++;
break;
case 6:
break;
default:
break;
}
}
else {
/* format error */
@ -451,7 +569,7 @@ static BOOL pre_install_load_file(char *path, FSFile *log_fd)
if( c == ',' ) {
temp_file_name[temp_filename_count] = '\0';
/* add list */
if( TRUE != pre_install_add_list(temp_tid, temp_region, temp_country_code, temp_file_name, log_fd) ) {
if( TRUE != pre_install_add_list(temp_tid, temp_version, temp_groupid, temp_file_name, log_fd) ) {
OS_TPrintf("Error: add list error %s %s %d\n", __FILE__,__FUNCTION__,__LINE__);
}
buf_state = 5; /* next state */
@ -478,176 +596,17 @@ static BOOL pre_install_load_file(char *path, FSFile *log_fd)
}
label_last:
(void)FS_CloseFile(&file);
if( encrypt_flag == TRUE) {
(void)my_sign_FS_CloseFile(&ms_file);
}
else {
(void)FS_CloseFile(&file);
}
return bSuccess;
}
static BOOL pre_install_load_sd_file(char *path, FSFile *log_fd)
{
MY_SIGN_File file;
BOOL bSuccess = TRUE;
// s32 result;
s32 readSize;
// FSResult fsres;
int buf_counter;
int buf_state;
#define LINE_BUF_SIZE 512
char line_buf[LINE_BUF_SIZE];
// PRE_INSTALL_FILE temp_pre_install_file;
char temp_file_name[FS_FILE_NAME_MAX];
u64 temp_tid;
u8 temp_region;
u8 temp_country_code;
int temp_hex;
int temp_filename_count;
char c;
OS_TPrintf("%s %d path=%s\n", __FUNCTION__,__LINE__,path);
my_sign_FS_InitFile(&file);
bSuccess = my_sign_FS_OpenFile(&file, path);
if( ! bSuccess ) {
// fsres = FS_GetArchiveResultCode(path);
miya_log_fprintf(log_fd,"Error:%s %s open file failed %s\n",__FILE__,__FUNCTION__,path);
// miya_log_fprintf(log_fd, " Failed open file:%s\n", my_fs_util_get_fs_result_word( fsres ));
return FALSE; /* open error! */
}
/*
title id
0x00000000 00000000, region , country code, file name,
*/
while( 1 ) {
next_line_read:
buf_state = 0;
readSize = my_sign_ReadLine(&file, line_buf, LINE_BUF_SIZE );
if( readSize == 0 ) {
/* EOF */
OS_TPrintf("%s %s %d : End of File\n", __FILE__,__FUNCTION__,__LINE__);
break;
}
if( !STD_StrNCmp( line_buf, "0x" , STD_StrLen("0x")) ) {
OS_TPrintf("%s\n", line_buf);
buf_counter = STD_StrLen("0x");
buf_state = 1;
temp_tid = 0;
temp_region = 0;
temp_country_code = 0;
temp_filename_count = 0;
while( readSize > buf_counter ) {
c = line_buf[buf_counter];
switch( buf_state ) {
case 1: /* TID */
if( c == ',') {
if( buf_counter == 18 ) {
// OS_TPrintf("temp_tid=0x%08x %08x\n", (u32)(temp_tid >> 32) , (u32)(temp_tid & 0xffffffff));
buf_state = 2; /* next state */
}
else {
/* format error */
miya_log_fprintf(log_fd,"Error:%s %s %d format error \n",__FILE__,__FUNCTION__,__LINE__);
goto next_line_read;
// break;
}
}
else {
temp_hex = my_char_to_hex(c);
if( temp_hex != -1 ) {
temp_tid |= ( ((u64)temp_hex) << (64 - (4 * (buf_counter-1))) );
}
else {
/* format error */
miya_log_fprintf(log_fd,"Error:%s %s %d format error\n",__FILE__,__FUNCTION__,__LINE__);
goto next_line_read;
// break;
}
}
break;
case 2: /* region */
if( c == ' ' ) {
}
else if( c == ',' ) {
buf_state = 3; /* next state */
}
else {
temp_hex = my_char_to_hex(c);
if( temp_hex != -1 ) {
temp_region = (u8)temp_hex;
}
else {
/* format error */
miya_log_fprintf(log_fd,"Error:%s %s %d format error\n",__FILE__,__FUNCTION__,__LINE__);
goto next_line_read;
}
}
break;
case 3: /* country code */
if( c == ' ' ) {
}
else if( c == ',' ) {
buf_state = 4; /* next state */
}
else {
temp_hex = my_char_to_hex(c);
if( temp_hex != -1 ) {
temp_country_code = (u8)temp_hex;
}
else {
/* format error */
miya_log_fprintf(log_fd,"Error:%s %s %d format error\n",__FILE__,__FUNCTION__,__LINE__);
goto next_line_read;
}
}
break;
case 4: /* file name */
if( c == ',' ) {
temp_file_name[temp_filename_count] = '\0';
/* add list */
if( TRUE != pre_install_add_list(temp_tid, temp_region, temp_country_code, temp_file_name, log_fd) ) {
OS_TPrintf("Error: add list error %s %s %d\n", __FILE__,__FUNCTION__,__LINE__);
}
buf_state = 5; /* next state */
}
else {
if( c != ' ' ) {
temp_file_name[temp_filename_count] = c;
temp_filename_count++;
}
}
break;
case 5: /* until line end */
break;
default:
/* error */
break;
}
buf_counter++;
}
}
else {
/* 妙なフォーマットは全部コメント扱い. */
}
}
label_last:
(void)my_sign_FS_CloseFile(&file);
return bSuccess;
}
@ -742,12 +701,12 @@ BOOL pre_install_command(FSFile *log_fd, u64 *tid_array, int tid_count, int com
int org_version =-1;
if( development_version_flag ) {
(void)pre_install_load_sd_file(PRE_INSTALL_TABLE_DEV_FILE_SD, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_DEV_FILE_NAND, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_DEV_FILE_SD, log_fd, TRUE);
(void)pre_install_load_file(PRE_INSTALL_TABLE_DEV_FILE_NAND, log_fd, FALSE);
}
else {
(void)pre_install_load_sd_file(PRE_INSTALL_TABLE_FILE_SD, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_FILE_NAND, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_FILE_SD, log_fd, TRUE);
(void)pre_install_load_file(PRE_INSTALL_TABLE_FILE_NAND, log_fd, FALSE);
}
pre_install_print_list(log_fd);
@ -795,6 +754,9 @@ BOOL pre_install_command(FSFile *log_fd, u64 *tid_array, int tid_count, int com
ret_flag = myImportTad( tad_file_name , org_version, log_fd );
}
}
else {
ret_flag = FALSE;
}
break;
case 2:
@ -809,6 +771,10 @@ BOOL pre_install_command(FSFile *log_fd, u64 *tid_array, int tid_count, int com
ret_flag = my_NAM_ImportTadTicketOnly( tad_file_name );
}
}
else {
ret_flag = FALSE;
}
break;
case 3:
mprintf("DA ");
@ -855,12 +821,12 @@ BOOL pre_install_command(FSFile *log_fd, u64 *tid_array, int tid_count, int com
BOOL pre_install_debug(FSFile *log_fd, BOOL development_version_flag )
{
if( development_version_flag ) {
(void)pre_install_load_sd_file(PRE_INSTALL_TABLE_DEV_FILE_SD, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_DEV_FILE_NAND, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_DEV_FILE_SD, log_fd, TRUE);
(void)pre_install_load_file(PRE_INSTALL_TABLE_DEV_FILE_NAND, log_fd, FALSE);
}
else {
(void)pre_install_load_sd_file(PRE_INSTALL_TABLE_FILE_SD, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_FILE_NAND, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_FILE_SD, log_fd, TRUE);
(void)pre_install_load_file(PRE_INSTALL_TABLE_FILE_NAND, log_fd, FALSE);
}
pre_install_print_list(NULL);
@ -879,12 +845,12 @@ BOOL pre_install_process( FSFile *log_fd, MY_USER_APP_TID *title_id_buf_ptr, int
int version;
if( development_version_flag ) {
(void)pre_install_load_sd_file(PRE_INSTALL_TABLE_DEV_FILE_SD, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_DEV_FILE_NAND, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_DEV_FILE_SD, log_fd, TRUE);
(void)pre_install_load_file(PRE_INSTALL_TABLE_DEV_FILE_NAND, log_fd, FALSE);
}
else {
(void)pre_install_load_sd_file(PRE_INSTALL_TABLE_FILE_SD, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_FILE_NAND, log_fd);
(void)pre_install_load_file(PRE_INSTALL_TABLE_FILE_SD, log_fd, TRUE);
(void)pre_install_load_file(PRE_INSTALL_TABLE_FILE_NAND, log_fd, FALSE);
}

View File

@ -5,8 +5,8 @@
typedef struct _PRE_INSTALL_FILE {
struct _PRE_INSTALL_FILE *next;
u64 tid;
u8 region;
u8 country;
u16 version;
u16 groupid;
char file_name[FS_FILE_NAME_MAX];
} PRE_INSTALL_FILE;

View File

@ -3,6 +3,7 @@
[SD用] make_tad_table.exe -sd -dir . -o table_file.txt -fdir sdtads
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -25,6 +26,9 @@ typedef int BOOL;
#define FALSE 0
#endif
/* tadのデータは基本的にビッグエンディアン */
typedef struct {
@ -37,6 +41,7 @@ typedef struct {
u32 tmdSize;
u32 contentSize;
u32 metaSize;
u32 certOffset;
u32 crlOffset;
u32 ticketOffset;
@ -46,6 +51,336 @@ typedef struct {
u32 fileSize;
} TAD_INFO;
typedef struct NAMiTADHeader
{
u32 hdrSize; // Size of TADHeader1 96
u8 tadType[2];
u16 tadVersion; // TAD_VERSION_1
u32 certSize;
u32 crlSize;
u32 ticketSize;
u32 tmdSize;
u32 contentSize;
u32 metaSize;
} NAMiTADHeader;
typedef u64 OSTitleId;
typedef OSTitleId NAMTitleId;
typedef struct NAMTitleInfo
{
NAMTitleId titleId;
u16 companyCode;
u16 version;
u32 publicSaveSize;
u32 privateSaveSize;
u32 blockSize;
} NAMTitleInfo;
typedef struct NAMTadInfo
{
NAMTitleInfo titleInfo;
u32 fileSize;
} NAMTadInfo;
#if 0
pInfo->sizes.cert = NAMi_EndianU32(pHeader->certSize);
pInfo->sizes.crl = NAMi_EndianU32(pHeader->crlSize);
pInfo->sizes.ticket = NAMi_EndianU32(pHeader->ticketSize);
pInfo->sizes.tmd = NAMi_EndianU32(pHeader->tmdSize);
pInfo->sizes.content = NAMi_EndianU32(pHeader->contentSize);
pInfo->sizes.meta = NAMi_EndianU32(pHeader->metaSize);
pInfo->offsets.cert = MATH_ROUNDUP(sizeof(NAMiTADHeader), TAD_ALIGN);
pInfo->offsets.crl = pInfo->offsets.cert + MATH_ROUNDUP(pInfo->sizes.cert, TAD_ALIGN);
pInfo->offsets.ticket = pInfo->offsets.crl + MATH_ROUNDUP(pInfo->sizes.crl, TAD_ALIGN);
pInfo->offsets.tmd = pInfo->offsets.ticket + MATH_ROUNDUP(pInfo->sizes.ticket, TAD_ALIGN);
pInfo->offsets.content = pInfo->offsets.tmd + MATH_ROUNDUP(pInfo->sizes.tmd, TAD_ALIGN);
pInfo->offsets.meta = pInfo->offsets.content + MATH_ROUNDUP(pInfo->sizes.content, TAD_ALIGN);
#endif
#define ES_APP_ENC_HANDLE 6
#define ES_ROOT_NAME "Root"
#define ES_CA_PREFIX "CA"
#define ES_XS_PREFIX "XS"
#define ES_MS_PREFIX "MS"
#define ES_CP_PREFIX "CP"
#define ES_APP_CERT_PREFIX "AP"
#define ES_BUF_SIZE 256
typedef u32 ESId; /* 32-bit device identity */
typedef u32 ESContentId; /* 32-bit content identity */
typedef u64 ESTitleId; /* 64-bit title identity */
typedef u64 ESTicketId; /* 64-bit ticket id */
typedef u8 ESVersion; /* 8-bit data structure version */
typedef u16 ESTitleVersion; /* 16-bit title version */
typedef ESTitleId ESSysVersion; /* 64-bit system software version */
typedef u32 ESTitleType; /* title type */
typedef u16 ESContentType; /* content type */
typedef u8 ESTmdReserved[62]; /* reserved field in TMD structure */
typedef u8 ESTicketReserved[47]; /* reserved field in eTicket structure */
typedef u8 ESSysAccessMask[2]; /* 16 bit cidx Mask to indicate which
content can be accessed by sys app */
#if !defined(__ES_INTERNAL__)
/* IOSC types */
typedef u8 IOSCAesKey[16];
typedef u8 IOSCHash[20];
typedef u8 IOSCName[64];
typedef u8 IOSCSigDummy[60];
typedef u8 IOSCCertPad[52];
typedef u8 IOSCEccCertPad[4];
typedef u8 IOSCRsaSig2048[256];
typedef enum {
IOSC_SIG_RSA4096 = 0x00010000, /* RSA 4096 bit signature */
IOSC_SIG_RSA2048, /* RSA 2048 bit signature */
IOSC_SIG_ECC /* ECC signature 512 bits*/
} IOSCCertSigType;
typedef enum {
IOSC_PUBKEY_RSA4096, /* RSA 4096 bit key */
IOSC_PUBKEY_RSA2048, /* RSA 2048 bit key */
IOSC_PUBKEY_ECC /* ECC pub key 512 bits*/
} IOSCCertPubKeyType;
typedef u8 IOSCEccSig[60];
typedef u8 IOSCEccPublicKey[60];
typedef struct {
IOSCCertSigType sigType;
IOSCRsaSig2048 sig;
IOSCSigDummy dummy;
IOSCName issuer;
} IOSCSigRsa2048;
typedef u8 IOSCEccPrivatePad[2];
typedef u8 IOSCEccPublicPad[4];
typedef struct {
IOSCCertSigType sigType;
IOSCEccSig sig;
IOSCEccPublicPad eccPad;
IOSCSigDummy dummy;
IOSCName issuer;
} IOSCSigEcc;
typedef u8 IOSCDeviceId[64];
typedef u8 IOSCServerId[64];
typedef struct {
IOSCCertPubKeyType pubKeyType;
union {
IOSCServerId serverId;
IOSCDeviceId deviceId;
} name;
u32 date;
} IOSCCertHeader;
typedef struct {
IOSCSigEcc sig; /* ECC signature struct */
IOSCCertHeader head;
IOSCEccPublicKey pubKey; /* 60 byte ECC public key */
IOSCEccPublicPad eccPad;
IOSCCertPad pad;
IOSCEccCertPad pad2;
} IOSCEccEccCert;
#endif
#define ES_TMD_VERSION 0
#define ES_TICKET_VERSION 0
/* TMD View */
#define ES_MAX_CONTENT 512
#define ES_TITLE_TYPE_NC_TITLE 0 /* NC title */
#define ES_TITLE_TYPE_NG_TITLE 1 /* NG title */
#define ES_TITLE_TYPE_DS_TITLE 2 /* DS title for NC */
#define ES_TITLE_TYPE_STREAM 4 /* stream title */
#define ES_TITLE_TYPE_DATA 8 /* data title */
#define ES_CONTENT_TYPE_SHARED (1<<15) /* shared content */
#define ES_CONTENT_TYPE_OPTIONAL (1<<14) /* optional content */
#define ES_CONTENT_TYPE_DISC (1<< 1) /* disc content */
#define ES_CONTENT_TYPE_NC_EXE 0 /* NC merged elf */
#define ES_CONTENT_TYPE_NG_EXE 1 /* NG content */
#define ES_LICENSE_MASK 0x0f /* allow 16 licensing types */
#define ES_LICENSE_PERMANENT 0x00 /* e.g., regular game with permanent rights */
#define ES_LICENSE_DEMO 0x01 /* e.g., demo game with permanent rights */
#define ES_LICENSE_TRIAL 0x02 /* e.g., regular game with limited rights */
#define ES_LICENSE_RENTAL 0x03 /* TBD */
#define ES_LICENSE_SUBSCRIPTION 0x04 /* TBD */
#define ES_LICENSE_GIFT_MASK 0x80 /* this is a gift */
/* TMD */
typedef struct {
ESContentId cid; /* 32 bit content id */
u16 index; /* content index, unique per title */
ESContentType type; /* content type*/
u64 size; /* unencrypted content size in bytes */
IOSCHash hash; /* 160-bit SHA1 hash of the content */
} ESContentMeta;
typedef struct {
ESVersion version; /* TMD version number */
ESVersion caCrlVersion; /* CA CRL version number */
ESVersion signerCrlVersion; /* signer CRL version number */
ESSysVersion sysVersion; /* required system software version number */
ESTitleId titleId; /* 64 bit title id */
ESTitleType type; /* 32 bit title type */
u16 groupId;
ESTmdReserved reserved; /* 62 bytes reserved info for Nintendo */
u32 accessRights; /* title's access rights to use
system resources */
ESTitleVersion titleVersion; /* 16 bit title version */
u16 numContents; /* number of contents per title */
u16 bootIndex; /* boot content index */
} ESTitleMetaHeader;
typedef struct {
IOSCSigRsa2048 sig; /* RSA 2048bit sign of all the data in
the TMD file */
ESTitleMetaHeader head;
ESContentMeta contents[ES_MAX_CONTENT];
} ESTitleMeta;
/* TMD View */
typedef struct {
ESVersion version; /* TMD data structure version */
ESSysVersion sysVersion; /* required system software
version number */
ESTitleId titleId; /* 64 bit title id */
ESTitleType type; /* 32 bit title type */
u16 groupId;
ESTmdReserved reserved; /* 62 bytes reserved info */
ESTitleVersion titleVersion; /* 16 bit title version */
u16 numContents; /* number of contents in the title */
} ESTmdViewHeader;
typedef struct {
ESContentId cid; /* 32 bit content id */
u16 index; /* 16 bit content index */
ESContentType type; /* 16 bit content type */
u64 size; /* 64 bit content size */
} ESCmdView;
typedef struct {
ESTmdViewHeader head;
ESCmdView contents[ES_MAX_CONTENT];
} ESTmdView;
typedef struct NAMiTadParams
{
u32 cert;
u32 crl;
u32 ticket;
u32 tmd;
u32 content;
u32 meta;
}
NAMiTadParams;
//---- tad 構成情報
typedef struct NAMiTadInfo
{
NAMiTadParams sizes; // 各領域のサイズ
NAMiTadParams offsets; // ファイル先頭から各領域へのオフセット
}
NAMiTadInfo;
#if 0
static my_NAM_ReadTadInfoWithFile(FILE *fp, TAD_INFO *tad_info)
{
NAMiTadInfo tadInfo;
ESTitleMeta tmd;
int result;
result = my_sign_ReadTadHeader(fp, &tadInfo);
// TMD を読む
fread(&tmd, tmd-size, fp);
result = NAMi_Load_sign( fp, (void*)tmd, tadInfo.sizes.tmd,
tadInfo.offsets.tmd,
NAMi_CopyTmdReservedInfo(&pInfo->titleInfo, &pTmd->head.reserved);
pInfo->titleInfo.titleId = NAMi_EndianU64(pTmd->head.titleId);
pInfo->titleInfo.companyCode = NAMi_EndianU16(pTmd->head.groupId);
pInfo->titleInfo.version = NAMi_EndianU16(pTmd->head.titleVersion);
pInfo->titleInfo.blockSize = my_NAMi_CalcTitleBlocksFromTmd(pTmd);
pInfo->fileSize = my_sign_FS_GetLength(pTadFile);
NAMi_Free(pTmd);
}
#endif
#if 0
static void test(void)
{
NAMiTadInfo* pInfo;
// ESTitleMeta tmd;
#if 0
typedef struct {
ESVersion version; /* TMD version number */
ESVersion caCrlVersion; /* CA CRL version number */
ESVersion signerCrlVersion; /* signer CRL version number */
ESSysVersion sysVersion; /* required system software version number */
ESTitleId titleId; // 8
ESTitleType type; // 4
u16 groupId; // 2
ESTmdReserved reserved; /* 62 bytes reserved info for Nintendo */
u32 accessRights; /* title's access rights to use
system resources */
ESTitleVersion titleVersion; /* 16 bit title version */
u16 numContents; /* number of contents per title */
u16 bootIndex; /* boot content index */
} ESTitleMetaHeader;
#endif
printf("TMD head offset = %d 0x%04x\n", offsetof(ESTitleMeta, head), offsetof(ESTitleMeta, head));
printf("ESTitleMetaHeader titleId offset = %d 0x%04x\n", offsetof(ESTitleMetaHeader ,titleId ), offsetof(ESTitleMetaHeader ,titleId));
printf("ESTitleMetaHeader titleVersion offset = %d 0x%04x\n", offsetof(ESTitleMetaHeader ,titleVersion ), offsetof(ESTitleMetaHeader ,titleVersion));
printf("ESTitleMetaHeader groupId offset = %d 0x%04x\n", offsetof(ESTitleMetaHeader ,groupId ), offsetof(ESTitleMetaHeader ,groupId));
printf("ESTitleMetaHeader numContents offset = %d 0x%04x\n", offsetof(ESTitleMetaHeader ,numContents ), offsetof(ESTitleMetaHeader ,numContents));
printf("NAMiTADHeader = %d 0x%04x\n",sizeof(NAMiTADHeader),sizeof(NAMiTADHeader));
printf("ESTmdView = %d 0x%04x\n",sizeof(ESTmdView),sizeof(ESTmdView));
printf("ESTmdViewHeader = %d 0x%04x\n",sizeof(ESTmdViewHeader),sizeof(ESTmdViewHeader));
printf("ESCmdView = %d 0x%04x\n",sizeof(ESCmdView),sizeof(ESCmdView));
#if 0
printf(" = %d 0x%04x\n",sizeof(),sizeof());
printf(" = %d 0x%04x\n",sizeof(),sizeof());
printf(" = %d 0x%04x\n",sizeof(),sizeof());
printf(" = %d 0x%04x\n",sizeof(),sizeof());
printf(" = %d 0x%04x\n",sizeof(),sizeof());
#endif
}
#endif
static BOOL debug_print_flag = FALSE;
@ -208,12 +543,14 @@ static void read_file_and_print_titleid( char *path , char *d_name, FILE *fp_out
u8 *tmd = NULL;
u32 titleid_hi = 0;
u32 titleid_lo = 0;
u16 t_ver;
u16 gid;
fp_in = fopen(path,"rb"); /* fseek効かすため */
if( fp_in == NULL ) {
fprintf(stderr, "error: file open %s\n",path);
goto end_file;
}
goto end_file;
}
/* TADファイルかどうかチェック */
if( FALSE == read_tad_info(fp_in, &tad_info) ) {
@ -233,7 +570,13 @@ static void read_file_and_print_titleid( char *path , char *d_name, FILE *fp_out
titleid_hi = reverseEndian4( *((u32 *)( tmd + 0x18C )) );
titleid_lo = reverseEndian4( *((u32 *)( tmd + 0x18C + 4 )) );
t_ver = reverseEndian2( *((u16 *)( tmd + 0x1DC )) );
gid = reverseEndian2( *((u16 *)( tmd + 0x198)) );
#if 0
printf("0x%08x%08x ver=0x%04x gid=0x%04x\n",titleid_hi, titleid_lo,
t_ver,groupId);
#endif
if( debug_print_flag ) {
printf("inputfile = %s\n", path);
@ -241,10 +584,10 @@ static void read_file_and_print_titleid( char *path , char *d_name, FILE *fp_out
if( fp_out ) {
if( is_sd == FALSE ) {
fprintf(fp_out, "0x%08x%08x, %d , %d , rom:/%s,\n", titleid_hi, titleid_lo, 0 , 0 , d_name);
fprintf(fp_out, "0x%08x%08x, 0x%04x , 0x%04x , rom:/%s,\n", titleid_hi, titleid_lo, t_ver , gid , d_name);
}
else {
fprintf(fp_out, "0x%08x%08x, %d , %d , sdmc:/%s,\n", titleid_hi, titleid_lo, 0 , 0 , d_name);
fprintf(fp_out, "0x%08x%08x, 0x%04x , 0x%04x , sdmc:/%s,\n", titleid_hi, titleid_lo, t_ver , gid , d_name);
}
if( fp_mk ) {
fprintf(fp_mk, "\t\t%s \\\n", d_name);
@ -252,10 +595,10 @@ static void read_file_and_print_titleid( char *path , char *d_name, FILE *fp_out
}
else {
if( is_sd == FALSE ) {
printf("0x%08x%08x, %d , %d , rom:/%s,\n", titleid_hi, titleid_lo, 0 , 0 , d_name);
printf("0x%08x%08x, 0x%04x , 0x%04x , rom:/%s,\n", titleid_hi, titleid_lo, t_ver , gid , d_name);
}
else {
printf("0x%08x%08x, %d , %d , sdmc:/%s,\n", titleid_hi, titleid_lo, 0 , 0 , d_name);
printf("0x%08x%08x, 0x%04x , 0x%04x , sdmc:/%s,\n", titleid_hi, titleid_lo, t_ver , gid , d_name);
}
}
@ -308,6 +651,7 @@ int main(int argc, char **argv)
char *full_path;
char rom_file_full_path[256];
// test();
prog=argv[0];
argc--;