2018-05-15 13:57:40 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2018-05-16 17:06:57 +01:00
|
|
|
#include <malloc.h>
|
2018-05-15 13:57:40 +01:00
|
|
|
#include <switch.h>
|
2018-05-16 17:06:57 +01:00
|
|
|
#include <memory.h>
|
2018-05-15 17:00:19 +01:00
|
|
|
#include "menu.h"
|
|
|
|
#include "dumper.h"
|
|
|
|
#include "ccolor.h"
|
2018-05-16 17:21:13 +01:00
|
|
|
#include "filebrowser.h"
|
2018-05-15 13:57:40 +01:00
|
|
|
|
2018-05-15 17:00:19 +01:00
|
|
|
FsDeviceOperator fsOperatorInstance;
|
2018-05-15 13:57:40 +01:00
|
|
|
|
2018-05-16 16:34:05 +01:00
|
|
|
bool shouldExit = false;
|
2018-05-15 17:00:19 +01:00
|
|
|
bool shouldWaitForAnyButton = false;
|
2018-05-15 13:57:40 +01:00
|
|
|
|
2018-05-16 17:21:13 +01:00
|
|
|
|
|
|
|
|
2018-05-16 16:34:05 +01:00
|
|
|
void menuExit() {
|
|
|
|
shouldExit = true;
|
|
|
|
}
|
|
|
|
|
2018-05-15 17:00:19 +01:00
|
|
|
void menuWaitForAnyButton() {
|
|
|
|
printf(C_DIM "Press any button to return to menu\n");
|
|
|
|
shouldWaitForAnyButton = true;
|
|
|
|
}
|
2018-05-15 13:57:40 +01:00
|
|
|
|
2018-05-15 17:00:19 +01:00
|
|
|
void startOperation(const char* title) {
|
|
|
|
consoleClear();
|
|
|
|
printf(C_DIM "%s\n\n" C_RESET, title);
|
|
|
|
}
|
2018-05-15 13:57:40 +01:00
|
|
|
|
2018-05-16 18:46:55 +01:00
|
|
|
void dumpPartitionRawMenuItem(MenuItem* item) {
|
|
|
|
u32 partition = (u32) (size_t) item->userdata;
|
|
|
|
|
|
|
|
char titlebuf[64];
|
|
|
|
sprintf(titlebuf, "Dump Partition %i (Raw)", partition);
|
|
|
|
startOperation(titlebuf);
|
|
|
|
if (partition == 0 || partition == 1)
|
|
|
|
workaroundPartitionZeroAccess(&fsOperatorInstance);
|
|
|
|
dumpPartitionRaw(&fsOperatorInstance, partition);
|
2018-05-15 17:00:19 +01:00
|
|
|
menuWaitForAnyButton();
|
2018-05-15 13:57:40 +01:00
|
|
|
}
|
|
|
|
|
2018-05-16 18:46:55 +01:00
|
|
|
void dumpPartitionDataMenuItem(MenuItem* item) {
|
|
|
|
u32 partition = (u32) (size_t) item->userdata;
|
|
|
|
|
|
|
|
char titlebuf[64];
|
|
|
|
sprintf(titlebuf, "Dump Partition %i", partition);
|
|
|
|
startOperation(titlebuf);
|
|
|
|
if (partition == 0 || partition == 1)
|
|
|
|
workaroundPartitionZeroAccess(&fsOperatorInstance);
|
2018-05-16 18:08:20 +01:00
|
|
|
FsFileSystem fs;
|
2018-05-16 18:46:55 +01:00
|
|
|
if (openPartitionFs(&fs, &fsOperatorInstance, partition) &&
|
2018-05-16 18:08:20 +01:00
|
|
|
fsdevMountDevice("gamecard", fs) != -1) {
|
2018-05-16 18:46:55 +01:00
|
|
|
char outbuf[64];
|
|
|
|
sprintf(outbuf, "/dump_%u", partition);
|
|
|
|
printf("Copying to %s\n", outbuf);
|
2018-05-16 22:29:43 +01:00
|
|
|
if (copyDirectory("gamecard:/", outbuf, true)) {
|
2018-05-16 18:08:20 +01:00
|
|
|
printf("Done!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fsdevUnmountDevice("dump");
|
|
|
|
menuWaitForAnyButton();
|
|
|
|
}
|
|
|
|
|
2018-05-16 19:03:47 +01:00
|
|
|
void openMainMenu();
|
|
|
|
void viewPartitionExitCb() {
|
|
|
|
fsdevUnmountDevice("view");
|
|
|
|
openMainMenu();
|
|
|
|
}
|
2018-05-16 18:46:55 +01:00
|
|
|
void viewPartitionMenuItem(MenuItem* item) {
|
|
|
|
u32 partition = (u32) (size_t) item->userdata;
|
|
|
|
|
|
|
|
startOperation("View Files");
|
|
|
|
if (partition == 0 || partition == 1)
|
|
|
|
workaroundPartitionZeroAccess(&fsOperatorInstance);
|
2018-05-16 17:21:13 +01:00
|
|
|
FsFileSystem fs;
|
2018-05-16 18:46:55 +01:00
|
|
|
if (!openPartitionFs(&fs, &fsOperatorInstance, partition)) {
|
2018-05-16 17:21:13 +01:00
|
|
|
menuWaitForAnyButton();
|
|
|
|
return;
|
|
|
|
}
|
2018-05-16 18:46:55 +01:00
|
|
|
if (fsdevMountDevice("view", fs) == -1) {
|
2018-05-16 17:21:13 +01:00
|
|
|
printf("fsdevMountDevice failed\n");
|
|
|
|
menuWaitForAnyButton();
|
|
|
|
return;
|
|
|
|
}
|
2018-05-16 19:03:47 +01:00
|
|
|
printFilesInDir("view://", "view://", viewPartitionExitCb);
|
2018-05-16 17:21:13 +01:00
|
|
|
}
|
|
|
|
|
2018-05-16 17:06:57 +01:00
|
|
|
|
2018-05-15 17:00:19 +01:00
|
|
|
MenuItem mainMenu[] = {
|
2018-05-16 18:46:55 +01:00
|
|
|
{ .text = "Dump Partition 0 (SysUpdate)", .callback = dumpPartitionDataMenuItem, .userdata = (void*) 0 },
|
|
|
|
{ .text = "Dump Partition 1 (Normal)", .callback = dumpPartitionDataMenuItem, .userdata = (void*) 1 },
|
|
|
|
{ .text = "Dump Partition 2 (Secure)", .callback = dumpPartitionDataMenuItem, .userdata = (void*) 2 },
|
|
|
|
{ .text = "Raw Dump Partition 0 (SysUpdate)", .callback = dumpPartitionRawMenuItem, .userdata = (void*) 0 },
|
2018-05-16 22:29:43 +01:00
|
|
|
{ .text = "Raw Dump Partition 1 (Normal)", .callback = dumpPartitionRawMenuItem, .userdata = (void*) 1 },
|
|
|
|
{ .text = "Raw Dump Partition 2 (Secure)", .callback = dumpPartitionRawMenuItem, .userdata = (void*) 2 },
|
2018-05-16 18:46:55 +01:00
|
|
|
{ .text = "View files on Game Card (SysUpdate)", .callback = viewPartitionMenuItem, .userdata = (void*) 0 },
|
|
|
|
{ .text = "View files on Game Card (Normal)", .callback = viewPartitionMenuItem, .userdata = (void*) 1 },
|
|
|
|
{ .text = "View files on Game Card (Secure)", .callback = viewPartitionMenuItem, .userdata = (void*) 2 },
|
2018-05-15 17:00:19 +01:00
|
|
|
{ .text = NULL }
|
|
|
|
};
|
2018-05-16 17:21:13 +01:00
|
|
|
void openMainMenu() {
|
2018-05-16 17:06:57 +01:00
|
|
|
menuSetCurrent(mainMenu, menuExit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-16 16:10:30 +01:00
|
|
|
int main(int argc, char **argv) {
|
2018-05-15 13:57:40 +01:00
|
|
|
gfxInitDefault();
|
|
|
|
consoleInit(NULL);
|
|
|
|
|
2018-05-15 17:00:19 +01:00
|
|
|
if (R_FAILED(fsOpenDeviceOperator(&fsOperatorInstance))) {
|
2018-05-15 13:57:40 +01:00
|
|
|
printf("Failed to open device operator\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2018-05-16 17:21:13 +01:00
|
|
|
openMainMenu();
|
2018-05-15 13:57:40 +01:00
|
|
|
|
|
|
|
while(appletMainLoop())
|
|
|
|
{
|
2018-05-15 17:00:19 +01:00
|
|
|
bool btnWait = shouldWaitForAnyButton;
|
|
|
|
|
2018-05-15 13:57:40 +01:00
|
|
|
hidScanInput();
|
|
|
|
|
2018-05-15 17:00:19 +01:00
|
|
|
if (!btnWait)
|
|
|
|
menuUpdate(&fsOperatorInstance);
|
2018-05-15 13:57:40 +01:00
|
|
|
|
|
|
|
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
|
|
|
if (kDown & KEY_PLUS) break;
|
2018-05-17 16:29:05 +01:00
|
|
|
if (btnWait && (kDown & (KEY_A | KEY_B | KEY_X | KEY_Y | KEY_L | KEY_R | KEY_ZL | KEY_ZR | KEY_MINUS |
|
|
|
|
KEY_DLEFT | KEY_DRIGHT | KEY_DUP | KEY_DDOWN))) {
|
2018-05-15 17:00:19 +01:00
|
|
|
shouldWaitForAnyButton = false;
|
|
|
|
menuPrint();
|
|
|
|
}
|
2018-05-16 16:34:05 +01:00
|
|
|
if (shouldExit)
|
|
|
|
break;
|
2018-05-15 13:57:40 +01:00
|
|
|
|
|
|
|
gfxFlushBuffers();
|
|
|
|
gfxSwapBuffers();
|
|
|
|
gfxWaitForVsync();
|
|
|
|
}
|
|
|
|
|
2018-05-15 17:00:19 +01:00
|
|
|
fsDeviceOperatorClose(&fsOperatorInstance);
|
|
|
|
|
2018-05-15 13:57:40 +01:00
|
|
|
gfxExit();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|