From c24113f20d33ab62ee2c17f7ecaa3d66430ac1df Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Wed, 2 Dec 2020 22:57:53 -0700 Subject: [PATCH] Add NAND restore option Sectors are compared before writing one to NAND --- .gitignore | 6 ++++ Makefile | 6 ++-- arm9/source/arm9.c | 87 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 85 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eeb4603 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*/build +*.nds +*.elf +data/* +.vscode +*.DS_Store \ No newline at end of file diff --git a/Makefile b/Makefile index 45255f0..53b807f 100644 --- a/Makefile +++ b/Makefile @@ -13,9 +13,9 @@ export TOPDIR := $(CURDIR) NITRO_FILES := # These set the information text in the nds file -GAME_TITLE := dumpTool -GAME_SUBTITLE1 := zoogie -GAME_SUBTITLE2 := Dump DSi NAND w/ nocash footer +GAME_TITLE := SafeNANDManager +GAME_SUBTITLE1 := Dump or Restore DSi NAND +GAME_SUBTITLE2 := zoogie & Rocket Robz include $(DEVKITARM)/ds_rules diff --git a/arm9/source/arm9.c b/arm9/source/arm9.c index ae0dce4..4ef0a0f 100644 --- a/arm9/source/arm9.c +++ b/arm9/source/arm9.c @@ -71,7 +71,7 @@ int dumpNAND(nocash_footer_t *footer){ u32 rwTotal=nand_GetSize()*0x200; //240MB or 245.5MB printf("NAND size: %.2fMB\n", (float)rwTotal/(float)0x100000); - if(rwTotal != 0xF000000 && rwTotal != 0xF580000) death("Unknown NAND size. Please\ncontact zoogie at:\nhttps://github.com/zoogie/dumpTool/issues"); //there's no documented nand chip with sizes different from these two. + if(rwTotal != 0xF000000 && rwTotal != 0xF580000) death("Unknown NAND size."); //there's no documented nand chip with sizes different from these two. while(getBatteryLevel() < 0x4){ iprintf("Battery low: plug in to proceed\r"); //user can charge to 2 bars or more OR just plug in the charger. charging state adds +0x80 to battery level. low 4 bits are the battery charge level. @@ -143,6 +143,63 @@ int dumpNAND(nocash_footer_t *footer){ return fail; } +int restoreNAND(nocash_footer_t *footer){ + + u32 rwTotal=nand_GetSize()*0x200; //240MB or 245.5MB + printf("NAND size: %.2fMB\n", (float)rwTotal/(float)0x100000); + + if(rwTotal != 0xF000000 && rwTotal != 0xF580000) death("Unknown NAND size."); //there's no documented nand chip with sizes different from these two. + + while(getBatteryLevel() < 0x4){ + iprintf("Battery low: plug in to proceed\r"); //user can charge to 2 bars or more OR just plug in the charger. charging state adds +0x80 to battery level. low 4 bits are the battery charge level. + wait(60); //don't spam getbatterylevel too much + } + + char *filename="nand.bin"; + int fail=0; + + FILE *f = fopen("nand.bin", "rb"); + if(!f) death("Could not open nand file"); + + iprintf("Restoring... \n"); + iprintf("Do not turn off the power.\n"); + iprintf("Progress: 0%% \r"); + + for(int i=0;i 600*0x100000) death("This isn't a DSi!"); //I'll give you a kidney if there's unmodified DSi out there with a 600MB NAND. - + snprintf(dirname, 32, "DT%016llX", *(u64*)CID); //that 'certain other tool' uses MAC for console-unique ID, while this one uses part of the nand CID. either is fine but I don't want to overwrite the other app's dump. mkdir(dirname, 0777); chdir(dirname); - + + bool nandFound = (access("nand.bin", F_OK) == 0); + iprintf("Verifying nocash_footer: "); iprintf("%s\n", verifyNocashFooter(&nocash_footer) ? "GOOD":"BAD\nThis dump can't be decrypted\nwith this footer!"); iprintf("\n"); + if (nandFound) { + iprintf("Press Y to begin NAND restore\n"); + } iprintf("Press A to begin NAND dump\nPress START to exit\n\n"); - + while(1) { swiWaitForVBlank(); scanKeys(); - if (keysDown() & KEY_A && !done) dumpNAND(&nocash_footer); + if ((keysDown() & KEY_Y) && nandFound && !done) restoreNAND(&nocash_footer); + if ((keysDown() & KEY_A) && !done) dumpNAND(&nocash_footer); else if (keysDown() & KEY_START) break; } - + free(workbuffer); + return 0; } \ No newline at end of file