Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ For certain functionality, GodMode9 may need 'support files'. Support files shou
* __`aeskeydb.bin`__: This should contain 0x25keyX, 0x18keyX and 0x1BkeyX to enable decryption of 7x / Secure3 / Secure4 encrypted NCCH files, 0x11key95 / 0x11key96 for FIRM decrypt support and 0x11keyOTP / 0x11keyIVOTP for 'secret' sector 0x96 crypto support. Entrypoints other than [boot9strap](https://github.com/SciresM/boot9strap) or [fastboot3ds](https://github.com/derrekr/fastboot3DS) may require a aeskeydb.bin file. This is now included in standard releases of GM9. No need to hunt down the file!
* __`seeddb.bin`__: This file is optional and required to decrypt and mount seed-encrypted NCCHs and CIAs (if the seed in question is not installed to your NAND). Note that your seeddb.bin must also contain the seed for the specific game you need to decrypt.
* __`encTitleKeys.bin`__ / __`decTitleKeys.bin`__: These files are optional and provide titlekeys, which are required to decrypt and install contents downloaded from CDN (for DSi and 3DS content).
* __`TwlBlowfishKeyDev.bin`__: This should contain the dev DSi blowfish key. It is optional and required to dump DSi developer or factory cartridges with dev software flashed on them.

### Fonts and translations
GodMode9 also supports custom fonts and translations as support files. These both use custom formats, fonts use FRF (Font RIFF) files which can be created using the `fontriff.py` Python script in the 'utils' folder. Translations use TRF (Translation RIFF) files from the `transriff.py` script. Examples of the inputs to these scripts can be found in the 'fonts' and 'languages' folders of the 'resources' folder respectively.
Expand Down
24 changes: 22 additions & 2 deletions arm9/source/gamecart/secure_ntr.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "card_ntr.h"
// #include "draw.h"
#include "timer.h"
#include "support.h"


#define BSWAP32(val) ((((val >> 24) & 0xFF)) | (((val >> 16) & 0xFF) << 8) | (((val >> 8) & 0xFF) << 16) | ((val & 0xFF) << 24))
Expand Down Expand Up @@ -119,7 +120,15 @@ void NTR_ApplyKey (u32* pCardHash, int nCardHash, u32* pKeyCode)

void NTR_InitKey (u32 aGameCode, u32* pCardHash, int nCardHash, u32* pKeyCode, int level, int iCardDevice)
{
if(iCardDevice)
if(iCardDevice == 2)
{
size_t len = LoadSupportFile(BLOWFISHKEYDEV_NAME, pCardHash, 0x1048);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len is set, but unused after. Did you mean to check for 0x1048? I think you should. Even if you checked the availaibility of the support file before this, something may happen in between.

pKeyCode[0] = 0;
pKeyCode[1] = 0;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and below: don't mix tabs and spaces. Everything else here uses spaces.

pKeyCode[2] = 0;
return;
}
else if(iCardDevice == 1)
{
const u8* BlowfishTwl = (const u8*)0x01FFD3E0;
memcpy (pCardHash, BlowfishTwl, 0x1048);
Expand Down Expand Up @@ -252,7 +261,18 @@ bool NTR_Secure_Init (u8* header, u8* sa_copy, u32 CartID, int iCardDevice)

iGameCode = *((vu32*)(void*)&header[0x0C]);
ReadDataFlags = cardControl13 & ~ NTRCARD_BLK_SIZE(7);
NTR_InitKey (iGameCode, iCardHash, nCardHash, iKeyCode, iCardDevice?1:2, iCardDevice);

if(iCardDevice && ((header[0x1BF] & 0x80) || (header[0x1C] & 0x04))) // dsi dev app
{
size_t fsize;
if (!CheckSupportFile(BLOWFISHKEYDEV_NAME, &fsize)) return false;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of just checking for the availability of the key file, you could load it right away, and react to any failures here. Example (be careful, though, I may be missing something here):

if (iCardDevice && ((header[0x1BF] & 0x80) || (header[0x1C] & 0x04))) // dsi dev app
{
size_t fsize;
if (!CheckSupportFile(BLOWFISHKEYDEV_NAME, &fsize) || (fsize != 0x1048)) return false;
if (LoadSupportFile(BLOWFISHKEYDEV_NAME, iCardHash, 0x1048) != 0x1048) return false;
memset(iKeyCode, 0, sizeof(iKeyCode));
}
else // retail
{
NTR_InitKey (iGameCode, iCardHash, nCardHash, iKeyCode, iCardDevice?1:2, iCardDevice);
}

if (fsize != 0x1048) return false;
NTR_InitKey (iGameCode, iCardHash, nCardHash, iKeyCode, 1, 2);
}
else // retail
{
NTR_InitKey (iGameCode, iCardHash, nCardHash, iKeyCode, iCardDevice?1:2, iCardDevice);
}

if(!iCheapCard) flagsKey1 |= NTRCARD_SEC_LARGE;
//Debug("iCheapCard=%d, readTimeout=%d", iCheapCard, readTimeout);
Expand Down
1 change: 1 addition & 0 deletions arm9/source/gamecart/secure_ntr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "common.h"

#define BLOWFISHKEYDEV_NAME "TwlBlowfishKeyDev.bin"

typedef struct _IKEY1{
u32 iii;
Expand Down