Skip to content

Commit

Permalink
Enable hidden NAND switch feature
Browse files Browse the repository at this point in the history
  • Loading branch information
d0k3 committed Aug 21, 2015
1 parent 04754ef commit 428f8ce
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
3 changes: 2 additions & 1 deletion source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })

// customizations - careful with DANGER_ZONE!
// customizations - careful with DANGER_ZONE and NAND_SWITCH!
// #define DANGER_ZONE
// #define NAND_SWITCH
// #define WORKDIR "/Decrypt9"

inline char* strupper(const char* str) {
Expand Down
24 changes: 21 additions & 3 deletions source/decryptor/decryptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
#define NAND_SECTOR_SIZE 0x200
#define SECTORS_PER_READ (BUFFER_MAX_SIZE / NAND_SECTOR_SIZE)

// #define sdmmc_nand_readsectors sdmmc_sdcard_readsectors
// #define sdmmc_nand_writesectors sdmmc_sdcard_writesectors

#ifdef NAND_SWITCH
#define sdmmc_nand_readsectors sdmmc_uni_readsectors
#define sdmmc_nand_writesectors sdmmc_uni_writesectors
int (*sdmmc_uni_readsectors)(u32, u32, u8*);
int (*sdmmc_uni_writesectors)(u32, u32, u8*);
#endif

// From https://github.com/profi200/Project_CTR/blob/master/makerom/pki/prod.h#L19
static const u8 common_keyy[6][16] = {
Expand All @@ -40,6 +43,21 @@ static PartitionInfo partitions[] = {
{ "CTRNAND", {0xE9, 0x00, 0x00, 0x43, 0x54, 0x52, 0x20, 0x20}, 0x0B95AE00, 0x41D2D200, 0x5, AES_CNT_CTRNAND_MODE } // N3DS
};

#ifdef NAND_SWITCH
u32 SetNand(bool use_emunand)
{
if (use_emunand) {
sdmmc_uni_readsectors = sdmmc_sdcard_readsectors;
sdmmc_uni_writesectors = sdmmc_sdcard_writesectors;
} else {
sdmmc_uni_readsectors = sdmmc_nand_readsectors;
sdmmc_uni_writesectors = sdmmc_nand_writesectors;
}

return 0;
}
#endif

u32 DecryptBuffer(DecryptBufferInfo *info)
{
u8 ctr[16] __attribute__((aligned(32)));
Expand Down
21 changes: 20 additions & 1 deletion source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ void ProcessMenu(MenuInfo* info, u32 nMenus) {
MenuInfo* currMenu = info;
MenuInfo* nextMenu = (nMenus > 1) ? info + 1 : NULL;
bool drawMenu = true;
#ifdef NAND_SWITCH
bool useEmuNand = false;
#endif

while (true) {
if (drawMenu) {
Expand All @@ -25,9 +28,15 @@ void ProcessMenu(MenuInfo* info, u32 nMenus) {
Debug("");
if (nextMenu != NULL)
Debug("R: %s", nextMenu->name);
#ifdef NAND_SWITCH
Debug("L: Switch NAND");
#endif
Debug("START: Reboot");
Debug("");
Debug("");
#ifdef NAND_SWITCH
Debug("Current NAND: %s", (useEmuNand) ? "EmuNAND" : "SysNAND");
#endif
#ifdef WORKDIR
Debug("Working directory: %s", WORKDIR);
#endif
Expand All @@ -39,6 +48,9 @@ void ProcessMenu(MenuInfo* info, u32 nMenus) {
for (u32 i = 0; i < 4; i++) {
char* name = currMenu->entries[i].name;
u32 (*function)(void) = currMenu->entries[i].function;
#ifdef NAND_SWITCH
SetNand(useEmuNand);
#endif
if ((pad_state & buttonCode[i]) && (name != NULL) && (function != NULL)) {
DebugClear();
Debug("%s: %s!", name, (*function)() == 0 ? "succeeded" : "failed");
Expand All @@ -53,7 +65,14 @@ void ProcessMenu(MenuInfo* info, u32 nMenus) {
currMenu = nextMenu;
if (++nextMenu - info >= nMenus) nextMenu -= nMenus;
drawMenu = true;
} else if (pad_state & BUTTON_START) {
}
#ifdef NAND_SWITCH
else if (pad_state & BUTTON_L1) {
useEmuNand = !useEmuNand;
drawMenu = true;
}
#endif
else if (pad_state & BUTTON_START) {
break;
}
}
Expand Down

0 comments on commit 428f8ce

Please sign in to comment.