mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
Improve devkit support for NCCH / CIA
This commit is contained in:
parent
7d08bebf99
commit
c031e6e03b
@ -47,7 +47,7 @@ u32 IdentifyFileType(const char* path) {
|
||||
return GAME_EXEFS; // ExeFS file (false positives possible)
|
||||
} else if (memcmp(header, romfs_magic, sizeof(romfs_magic)) == 0) {
|
||||
return GAME_ROMFS; // RomFS file (check could be better)
|
||||
} else if (strncmp(TMD_ISSUER, (char*) (header + 0x140), 0x40) == 0) {
|
||||
} else if (ValidateTmd((TitleMetaData*) data) == 0) {
|
||||
if (fsize == TMD_SIZE_N(getbe16(header + 0x1DE)) + TMD_CDNCERT_SIZE)
|
||||
return GAME_TMD | FLAG_NUSCDN; // TMD file from NUS/CDN
|
||||
else if (fsize >= TMD_SIZE_N(getbe16(header + 0x1DE)))
|
||||
|
@ -1,8 +1,7 @@
|
||||
#include "cia.h"
|
||||
#include "ncch.h"
|
||||
#include "exefs.h"
|
||||
#include "unittype.h"
|
||||
#include "ff.h"
|
||||
#include "sddata.h"
|
||||
#include "aes.h"
|
||||
#include "sha.h"
|
||||
|
||||
@ -55,6 +54,10 @@ u32 BuildCiaCert(u8* ciacert) {
|
||||
0xC7, 0x2E, 0x1C, 0xA5, 0x61, 0xDC, 0x9B, 0xC8, 0x05, 0x58, 0x58, 0x9C, 0x63, 0x08, 0x1C, 0x8A,
|
||||
0x10, 0x78, 0xDF, 0x42, 0x99, 0x80, 0x3A, 0x68, 0x58, 0xF0, 0x41, 0xF9, 0xCB, 0x10, 0xE6, 0x35
|
||||
};
|
||||
const u8 cert_hash_expected_dev[0x20] = {
|
||||
0xFB, 0xD2, 0xC0, 0x47, 0x95, 0xB9, 0x4C, 0xC8, 0x0B, 0x64, 0x58, 0x96, 0xF6, 0x61, 0x0F, 0x52,
|
||||
0x18, 0x83, 0xAF, 0xE0, 0xF4, 0xE5, 0x62, 0xBA, 0x69, 0xEE, 0x72, 0x2A, 0xC2, 0x4E, 0x95, 0xB3
|
||||
};
|
||||
|
||||
// open certs.db file on SysNAND
|
||||
FIL db;
|
||||
@ -75,7 +78,7 @@ u32 BuildCiaCert(u8* ciacert) {
|
||||
// check the certificate hash
|
||||
u8 cert_hash[0x20];
|
||||
sha_quick(cert_hash, ciacert, CIA_CERT_SIZE, SHA256_MODE);
|
||||
if (memcmp(cert_hash, cert_hash_expected, 0x20) != 0)
|
||||
if (memcmp(cert_hash, IS_DEVKIT ? cert_hash_expected_dev : cert_hash_expected, 0x20) != 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "ticket.h"
|
||||
#include "unittype.h"
|
||||
#include "aes.h"
|
||||
#include "sha.h"
|
||||
#include "ff.h"
|
||||
@ -36,7 +37,7 @@ u32 CryptTitleKey(TitleKeyEntry* tik, bool encrypt, bool devkit) {
|
||||
{0x5E, 0x66, 0x99, 0x8A, 0xB4, 0xE8, 0x93, 0x16, 0x06, 0x85, 0x0F, 0xD7, 0xA1, 0x6D, 0xD7, 0x55} , // 5
|
||||
};
|
||||
// From https://github.com/profi200/Project_CTR/blob/master/makerom/pki/dev.h#L21
|
||||
static const u8 common_key_devkit[6][16] __attribute__((aligned(16))) = {
|
||||
static const u8 common_key_dev[6][16] __attribute__((aligned(16))) = {
|
||||
{0x55, 0xA3, 0xF8, 0x72, 0xBD, 0xC8, 0x0C, 0x55, 0x5A, 0x65, 0x43, 0x81, 0x13, 0x9E, 0x15, 0x3B} , // 0 - eShop Titles
|
||||
{0x44, 0x34, 0xED, 0x14, 0x82, 0x0C, 0xA1, 0xEB, 0xAB, 0x82, 0xC1, 0x6E, 0x7B, 0xEF, 0x0C, 0x25} , // 1 - System Titles
|
||||
{0xF6, 0x2E, 0x3F, 0x95, 0x8E, 0x28, 0xA2, 0x1F, 0x28, 0x9E, 0xEC, 0x71, 0xA8, 0x66, 0x29, 0xDC} , // 2
|
||||
@ -51,7 +52,7 @@ u32 CryptTitleKey(TitleKeyEntry* tik, bool encrypt, bool devkit) {
|
||||
// setup key 0x3D // ctr
|
||||
if (tik->commonkey_idx >= 6) return 1;
|
||||
if (!devkit) setup_aeskeyY(0x3D, (void*) common_keyy[tik->commonkey_idx]);
|
||||
else setup_aeskey(0x3D, (void*) common_key_devkit[tik->commonkey_idx]);
|
||||
else setup_aeskey(0x3D, (void*) common_key_dev[tik->commonkey_idx]);
|
||||
use_aeskey(0x3D);
|
||||
memcpy(ctr, tik->title_id, 8);
|
||||
set_ctr(ctr);
|
||||
@ -176,7 +177,7 @@ u32 BuildFakeTicket(Ticket* ticket, u8* title_id) {
|
||||
// fill ticket values
|
||||
memcpy(ticket->sig_type, sig_type, 4);
|
||||
memset(ticket->signature, 0xFF, 0x100);
|
||||
snprintf((char*) ticket->issuer, 0x40, TICKET_ISSUER);
|
||||
snprintf((char*) ticket->issuer, 0x40, IS_DEVKIT ? TICKET_ISSUER_DEV : TICKET_ISSUER);
|
||||
memset(ticket->ecdsa, 0xFF, 0x3C);
|
||||
ticket->version = 0x01;
|
||||
memset(ticket->titlekey, 0xFF, 16);
|
||||
@ -193,6 +194,10 @@ u32 BuildTicketCert(u8* tickcert) {
|
||||
0xDC, 0x15, 0x3C, 0x2B, 0x8A, 0x0A, 0xC8, 0x74, 0xA9, 0xDC, 0x78, 0x61, 0x0E, 0x6A, 0x8F, 0xE3,
|
||||
0xE6, 0xB1, 0x34, 0xD5, 0x52, 0x88, 0x73, 0xC9, 0x61, 0xFB, 0xC7, 0x95, 0xCB, 0x47, 0xE6, 0x97
|
||||
};
|
||||
const u8 cert_hash_expected_dev[0x20] = {
|
||||
0x97, 0x2A, 0x32, 0xFF, 0x9D, 0x4B, 0xAA, 0x2F, 0x1A, 0x24, 0xCF, 0x21, 0x13, 0x87, 0xF5, 0x38,
|
||||
0xC6, 0x4B, 0xD4, 0x8F, 0xDF, 0x13, 0x21, 0x3D, 0xFC, 0x72, 0xFC, 0x8D, 0x9F, 0xDD, 0x01, 0x0E
|
||||
};
|
||||
|
||||
// open certs.db file on SysNAND
|
||||
FIL db;
|
||||
@ -211,7 +216,7 @@ u32 BuildTicketCert(u8* tickcert) {
|
||||
// check the certificate hash
|
||||
u8 cert_hash[0x20];
|
||||
sha_quick(cert_hash, tickcert, TICKET_CDNCERT_SIZE, SHA256_MODE);
|
||||
if (memcmp(cert_hash, cert_hash_expected, 0x20) != 0)
|
||||
if (memcmp(cert_hash, IS_DEVKIT ? cert_hash_expected_dev : cert_hash_expected, 0x20) != 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
@ -1,7 +1,17 @@
|
||||
#include "tmd.h"
|
||||
#include "unittype.h"
|
||||
#include "sha.h"
|
||||
#include "ff.h"
|
||||
|
||||
u32 ValidateTmd(TitleMetaData* tmd) {
|
||||
const u8 magic[] = { TMD_SIG_TYPE };
|
||||
if ((memcmp(tmd->sig_type, magic, sizeof(magic)) != 0) ||
|
||||
((strncmp((char*) tmd->issuer, TMD_ISSUER, 0x40) != 0) &&
|
||||
(strncmp((char*) tmd->issuer, TMD_ISSUER_DEV, 0x40) != 0)))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 GetTmdCtr(u8* ctr, TmdContentChunk* chunk) {
|
||||
memset(ctr, 0, 16);
|
||||
memcpy(ctr, chunk->index, 2);
|
||||
@ -31,7 +41,7 @@ u32 BuildFakeTmd(TitleMetaData* tmd, u8* title_id, u32 n_contents, u32 save_size
|
||||
// file TMD values
|
||||
memcpy(tmd->sig_type, sig_type, 4);
|
||||
memset(tmd->signature, 0xFF, 0x100);
|
||||
snprintf((char*) tmd->issuer, 0x40, TMD_ISSUER);
|
||||
snprintf((char*) tmd->issuer, 0x40, IS_DEVKIT ? TMD_ISSUER_DEV : TMD_ISSUER);
|
||||
tmd->version = 0x01;
|
||||
memcpy(tmd->title_id, title_id, 8);
|
||||
tmd->title_type[3] = 0x40; // whatever
|
||||
@ -50,6 +60,10 @@ u32 BuildTmdCert(u8* tmdcert) {
|
||||
0x91, 0x5F, 0x77, 0x3A, 0x07, 0x82, 0xD4, 0x27, 0xC4, 0xCE, 0xF5, 0x49, 0x25, 0x33, 0xE8, 0xEC,
|
||||
0xF6, 0xFE, 0xA1, 0xEB, 0x8C, 0xCF, 0x59, 0x6E, 0x69, 0xBA, 0x2A, 0x38, 0x8D, 0x73, 0x8A, 0xE1
|
||||
};
|
||||
const u8 cert_hash_expected_dev[0x20] = {
|
||||
0x49, 0xC9, 0x41, 0x56, 0xCA, 0x86, 0xBD, 0x1F, 0x36, 0x51, 0x51, 0x6A, 0x4A, 0x9F, 0x54, 0xA1,
|
||||
0xC2, 0xE9, 0xCA, 0x93, 0x94, 0xF4, 0x29, 0xA0, 0x38, 0x54, 0x75, 0xFF, 0xAB, 0x6E, 0x8E, 0x71
|
||||
};
|
||||
|
||||
// open certs.db file on SysNAND
|
||||
FIL db;
|
||||
@ -68,7 +82,7 @@ u32 BuildTmdCert(u8* tmdcert) {
|
||||
// check the certificate hash
|
||||
u8 cert_hash[0x20];
|
||||
sha_quick(cert_hash, tmdcert, TMD_CDNCERT_SIZE, SHA256_MODE);
|
||||
if (memcmp(cert_hash, cert_hash_expected, 0x20) != 0)
|
||||
if (memcmp(cert_hash, IS_DEVKIT ? cert_hash_expected_dev : cert_hash_expected, 0x20) != 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#define TMD_CDNCERT_SIZE 0x700
|
||||
|
||||
#define TMD_ISSUER "Root-CA00000003-CP0000000b"
|
||||
#define TMD_ISSUER_DEV "Root-CA00000004-CP0000000a"
|
||||
#define TMD_SIG_TYPE 0x00, 0x01, 0x00, 0x04 // RSA_2048 SHA256
|
||||
|
||||
#define DLC_TID_HIGH 0x00, 0x04, 0x00, 0x8C // title id high for DLC
|
||||
@ -56,6 +57,7 @@ typedef struct {
|
||||
TmdContentInfo contentinfo[64];
|
||||
} __attribute__((packed)) TitleMetaData;
|
||||
|
||||
u32 ValidateTmd(TitleMetaData* tmd);
|
||||
u32 GetTmdCtr(u8* ctr, TmdContentChunk* chunk);
|
||||
u32 FixTmdHashes(TitleMetaData* tmd);
|
||||
u32 BuildFakeTmd(TitleMetaData* tmd, u8* title_id, u32 n_contents, u32 save_size);
|
||||
|
Loading…
x
Reference in New Issue
Block a user