2018-05-15 17:00:19 +01:00
|
|
|
#include "dumper.h"
|
|
|
|
#include "fsext.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include "ccolor.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2018-05-16 16:10:30 +01:00
|
|
|
void workaroundPartitionZeroAccess(FsDeviceOperator* fsOperator) {
|
|
|
|
u32 handle;
|
|
|
|
if (R_FAILED(fsDeviceOperatorGetGameCardHandle(fsOperator, &handle)))
|
|
|
|
return;
|
|
|
|
FsStorage gameCardStorage;
|
2018-05-16 17:21:13 +01:00
|
|
|
if (R_FAILED(fsOpenGameCardStorage(&gameCardStorage, handle, 0)))
|
2018-05-16 16:10:30 +01:00
|
|
|
return;
|
|
|
|
fsStorageClose(&gameCardStorage);
|
|
|
|
}
|
|
|
|
|
2018-05-16 17:21:13 +01:00
|
|
|
bool openPartitionFs(FsFileSystem* ret, FsDeviceOperator* fsOperator, u32 partition) {
|
|
|
|
u32 handle;
|
|
|
|
if (R_FAILED(fsDeviceOperatorGetGameCardHandle(fsOperator, &handle))) {
|
|
|
|
printf("GetGameCardHandle failed\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Result result;
|
|
|
|
if (R_FAILED(result = fsMountGameCard(ret, handle, partition))) {
|
|
|
|
printf("MountGameCard failed %x\n", result);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
printf("Opened card\n");
|
|
|
|
}
|
|
|
|
|
2018-05-15 17:00:19 +01:00
|
|
|
bool dumpPartitionRaw(FsDeviceOperator* fsOperator, u32 partition) {
|
|
|
|
u32 handle;
|
|
|
|
if (R_FAILED(fsDeviceOperatorGetGameCardHandle(fsOperator, &handle))) {
|
|
|
|
printf("GetGameCardHandle failed\n");
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-15 17:31:46 +01:00
|
|
|
|
2018-05-15 17:53:26 +01:00
|
|
|
printf("Handle = %x\n", handle);
|
|
|
|
|
2018-05-15 17:31:46 +01:00
|
|
|
if (partition == 0) {
|
|
|
|
u32 title_ver;
|
|
|
|
fsDeviceOperatorUpdatePartitionInfo(fsOperator, handle, &title_ver, NULL);
|
|
|
|
printf("System title-version = %i\n", title_ver);
|
|
|
|
}
|
|
|
|
|
2018-05-15 17:00:19 +01:00
|
|
|
FsStorage gameCardStorage;
|
|
|
|
Result result;
|
2018-05-16 17:21:13 +01:00
|
|
|
if (R_FAILED(result = fsOpenGameCardStorage(&gameCardStorage, handle, partition))) {
|
2018-05-15 17:00:19 +01:00
|
|
|
printf("MountGameCard failed %x\n", result);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
printf("Opened card\n");
|
|
|
|
|
|
|
|
u64 size;
|
|
|
|
fsStorageGetSize(&gameCardStorage, &size);
|
|
|
|
printf("Total size = %li\n", size);
|
|
|
|
FILE* outFile = fopen("out.bin", "wb");
|
|
|
|
if (!outFile) {
|
|
|
|
printf("Failed to open output file!\n");
|
|
|
|
fsStorageClose(&gameCardStorage);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Starting...");
|
|
|
|
syncDisplay();
|
|
|
|
|
|
|
|
const size_t bufs = 1024 * 1024;
|
|
|
|
char* buf = (char*) malloc(bufs);
|
2018-05-15 18:05:13 +01:00
|
|
|
bool success = true;
|
2018-05-15 17:00:19 +01:00
|
|
|
for (u64 off = 0; off < size; off += bufs) {
|
|
|
|
u64 n = bufs;
|
|
|
|
if (size - off < n)
|
|
|
|
n = size - off;
|
|
|
|
if (R_FAILED(result = fsStorageRead(&gameCardStorage, off, buf, n))) {
|
2018-05-15 18:05:13 +01:00
|
|
|
printf("\nfsStorageRead error\n");
|
|
|
|
success = false;
|
|
|
|
break;
|
2018-05-15 17:00:19 +01:00
|
|
|
}
|
|
|
|
if (fwrite(buf, 1, n, outFile) != n) {
|
2018-05-15 18:05:13 +01:00
|
|
|
printf("\nfwrite error\n");
|
|
|
|
success = false;
|
|
|
|
break;
|
2018-05-15 17:00:19 +01:00
|
|
|
}
|
|
|
|
if (((off / bufs) % 10) == 0) {
|
2018-05-15 17:53:26 +01:00
|
|
|
hidScanInput();
|
|
|
|
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
|
|
|
if (kDown & KEY_B) {
|
|
|
|
printf("\nCancelled\n");
|
2018-05-15 18:05:13 +01:00
|
|
|
success = false;
|
|
|
|
break;
|
2018-05-15 17:53:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-15 17:00:19 +01:00
|
|
|
printf(C_CLEAR_LINE "\rDumping %i%% [%li / %li bytes]", (int) (off * 100 / size), off, size);
|
|
|
|
syncDisplay();
|
|
|
|
}
|
|
|
|
}
|
2018-05-15 18:05:13 +01:00
|
|
|
if (success) {
|
|
|
|
printf(C_CLEAR_LINE "\rDone!\n");
|
|
|
|
syncDisplay();
|
|
|
|
}
|
2018-05-15 17:00:19 +01:00
|
|
|
|
2018-05-15 18:05:13 +01:00
|
|
|
free(buf);
|
2018-05-15 17:00:19 +01:00
|
|
|
fclose(outFile);
|
|
|
|
fsStorageClose(&gameCardStorage);
|
|
|
|
|
2018-05-15 18:05:13 +01:00
|
|
|
return success;
|
2018-05-15 17:00:19 +01:00
|
|
|
}
|