diff --git a/Makefile b/Makefile index 5c84f4f..6097965 100644 --- a/Makefile +++ b/Makefile @@ -33,9 +33,9 @@ include $(DEVKITPRO)/libnx/switch_rules VERSION_MAJOR := 1 VERSION_MINOR := 0 -VERSION_MICRO := 1 +VERSION_MICRO := 2 -APP_TITLE := Game Card Dump Tool +APP_TITLE := gcdumptool APP_AUTHOR := MCMrARM, DarkMatterCore APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO} diff --git a/README.md b/README.md index c25dd1f..b277994 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,10 @@ Thanks to Changelog -------------- +**v1.0.2:** + +* Fixed a silly bug in the file splitting code. + **v1.0.1:** * Minor UI fixes and tweaks. diff --git a/source/dumper.c b/source/dumper.c index 01fd2e6..f4a5c65 100644 --- a/source/dumper.c +++ b/source/dumper.c @@ -380,7 +380,7 @@ bool dumpGameCartridge(FsDeviceOperator* fsOperator, bool isFat32, bool dumpCert if (new_file_chunk_size > 0) { - if (fwrite(buf, 1, new_file_chunk_size, outFile) != new_file_chunk_size) + if (fwrite(buf + old_file_chunk_size, 1, new_file_chunk_size, outFile) != new_file_chunk_size) { snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to write chunk to offset 0x%016lX", fileOffset + old_file_chunk_size); uiDrawString(strbuf, 0, (breaks + 7) * 8, 255, 0, 0); @@ -517,7 +517,7 @@ bool dumpGameCartridge(FsDeviceOperator* fsOperator, bool isFat32, bool dumpCert if (new_file_chunk_size > 0) { - if (fwrite(buf, 1, new_file_chunk_size, outFile) != new_file_chunk_size) + if (fwrite(buf + old_file_chunk_size, 1, new_file_chunk_size, outFile) != new_file_chunk_size) { snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to write chunk to offset 0x%016lX", fileOffset + old_file_chunk_size); uiDrawString(strbuf, 0, (breaks + 7) * 8, 255, 0, 0); @@ -770,7 +770,7 @@ bool dumpRawPartition(FsDeviceOperator* fsOperator, u32 partition, bool doSplitt if (new_file_chunk_size > 0) { - if (fwrite(buf, 1, new_file_chunk_size, outFile) != new_file_chunk_size) + if (fwrite(buf + old_file_chunk_size, 1, new_file_chunk_size, outFile) != new_file_chunk_size) { snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to write chunk to offset 0x%016lX", off + old_file_chunk_size); uiDrawString(strbuf, 0, (breaks + 4) * 8, 255, 0, 0); @@ -989,11 +989,14 @@ bool copyFile(const char* source, const char* dest, bool doSplitting) break; } - if (fwrite(buf, 1, new_file_chunk_size, outFile) != new_file_chunk_size) + if (new_file_chunk_size > 0) { - snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to write chunk to offset 0x%016lX", off + old_file_chunk_size); - uiDrawString(strbuf, 0, (breaks + 7) * 8, 255, 0, 0); - break; + if (fwrite(buf + old_file_chunk_size, 1, new_file_chunk_size, outFile) != new_file_chunk_size) + { + snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to write chunk to offset 0x%016lX", off + old_file_chunk_size); + uiDrawString(strbuf, 0, (breaks + 7) * 8, 255, 0, 0); + break; + } } } else { if (fwrite(buf, 1, n, outFile) != n) diff --git a/source/main.c b/source/main.c index 2c229f3..7e8a9ab 100644 --- a/source/main.c +++ b/source/main.c @@ -2,7 +2,6 @@ #include #include #include -#include #include "dumper.h" #include "ncmext.h" @@ -37,127 +36,142 @@ int main(int argc, char **argv) currentFB = gfxGetFramebuffer(¤tFBWidth, ¤tFBHeight); int ret = 0; + Result result; + char strbuf[512] = {'\0'}; - if (R_SUCCEEDED(ncmInitialize())) + if (R_SUCCEEDED(result = fsInitialize())) { - if (R_SUCCEEDED(nsInitialize())) + if (R_SUCCEEDED(result = fsOpenDeviceOperator(&fsOperatorInstance))) { - if (R_SUCCEEDED(fsOpenDeviceOperator(&fsOperatorInstance))) + if (R_SUCCEEDED(result = ncmInitialize())) { - bool exitLoop = false; - - while(appletMainLoop()) + if (R_SUCCEEDED(result = nsInitialize())) { - currentFB = gfxGetFramebuffer(¤tFBWidth, ¤tFBHeight); + bool exitLoop = false; - uiPrintHeadline(); - - gameCardInserted = isGameCardInserted(&fsOperatorInstance); - - if (gameCardInserted) + while(appletMainLoop()) { - if (hfs0_header == NULL) + currentFB = gfxGetFramebuffer(¤tFBWidth, ¤tFBHeight); + + uiPrintHeadline(); + + gameCardInserted = isGameCardInserted(&fsOperatorInstance); + + if (gameCardInserted) { - // Don't access the gamecard immediately to avoid conflicts with the fs-srv, ncm and ns services - uiPleaseWait(); - - getRootHfs0Header(&fsOperatorInstance); - getGameCardTitleID(&gameCardTitleID); - getGameCardControlNacp(gameCardTitleID, gameCardName, sizeof(gameCardName), gameCardAuthor, sizeof(gameCardAuthor), gameCardVersion, sizeof(gameCardVersion)); - - uiPrintHeadline(); - uiUpdateStatusMsg(); + if (hfs0_header == NULL) + { + // Don't access the gamecard immediately to avoid conflicts with the fsp-srv, ncm and ns services + uiPleaseWait(); + + getRootHfs0Header(&fsOperatorInstance); + getGameCardTitleID(&gameCardTitleID); + getGameCardControlNacp(gameCardTitleID, gameCardName, sizeof(gameCardName), gameCardAuthor, sizeof(gameCardAuthor), gameCardVersion, sizeof(gameCardVersion)); + + uiPrintHeadline(); + uiUpdateStatusMsg(); + } + } else { + if (hfs0_header != NULL) + { + gameCardSize = 0; + memset(gameCardSizeStr, 0, sizeof(gameCardSizeStr)); + + free(hfs0_header); + hfs0_header = NULL; + hfs0_offset = hfs0_size = 0; + hfs0_partition_cnt = 0; + + gameCardTitleID = 0; + + memset(gameCardName, 0, sizeof(gameCardName)); + memset(gameCardAuthor, 0, sizeof(gameCardAuthor)); + memset(gameCardVersion, 0, sizeof(gameCardVersion)); + } } - } else { - if (hfs0_header != NULL) + + hidScanInput(); + u32 keysDown = hidKeysDown(CONTROLLER_P1_AUTO); + + UIResult result = uiLoop(keysDown); + switch(result) { - gameCardSize = 0; - memset(gameCardSizeStr, 0, sizeof(gameCardSizeStr)); - - free(hfs0_header); - hfs0_header = NULL; - hfs0_offset = hfs0_size = 0; - hfs0_partition_cnt = 0; - - gameCardTitleID = 0; - - memset(gameCardName, 0, sizeof(gameCardName)); - memset(gameCardAuthor, 0, sizeof(gameCardAuthor)); - memset(gameCardVersion, 0, sizeof(gameCardVersion)); + case resultShowMainMenu: + uiSetState(stateMainMenu); + break; + case resultShowXciDumpMenu: + uiSetState(stateXciDumpMenu); + break; + case resultDumpXci: + uiSetState(stateDumpXci); + break; + case resultShowRawPartitionDumpMenu: + uiSetState(stateRawPartitionDumpMenu); + break; + case resultDumpRawPartition: + uiSetState(stateDumpRawPartition); + break; + case resultShowPartitionDataDumpMenu: + uiSetState(statePartitionDataDumpMenu); + break; + case resultDumpPartitionData: + uiSetState(stateDumpPartitionData); + break; + case resultShowViewGameCardFsMenu: + uiSetState(stateViewGameCardFsMenu); + break; + case resultShowViewGameCardFsGetList: + uiSetState(stateViewGameCardFsGetList); + break; + case resultShowViewGameCardFsBrowser: + uiSetState(stateViewGameCardFsBrowser); + break; + case resultViewGameCardFsBrowserCopyFile: + uiSetState(stateViewGameCardFsBrowserCopyFile); + break; + case resultDumpGameCardCertificate: + uiSetState(stateDumpGameCardCertificate); + break; + case resultExit: + exitLoop = true; + break; + default: + break; } + + if (exitLoop) break; + + syncDisplay(); } - hidScanInput(); - u32 keysDown = hidKeysDown(CONTROLLER_P1_AUTO); - - UIResult result = uiLoop(keysDown); - switch(result) - { - case resultShowMainMenu: - uiSetState(stateMainMenu); - break; - case resultShowXciDumpMenu: - uiSetState(stateXciDumpMenu); - break; - case resultDumpXci: - uiSetState(stateDumpXci); - break; - case resultShowRawPartitionDumpMenu: - uiSetState(stateRawPartitionDumpMenu); - break; - case resultDumpRawPartition: - uiSetState(stateDumpRawPartition); - break; - case resultShowPartitionDataDumpMenu: - uiSetState(statePartitionDataDumpMenu); - break; - case resultDumpPartitionData: - uiSetState(stateDumpPartitionData); - break; - case resultShowViewGameCardFsMenu: - uiSetState(stateViewGameCardFsMenu); - break; - case resultShowViewGameCardFsGetList: - uiSetState(stateViewGameCardFsGetList); - break; - case resultShowViewGameCardFsBrowser: - uiSetState(stateViewGameCardFsBrowser); - break; - case resultViewGameCardFsBrowserCopyFile: - uiSetState(stateViewGameCardFsBrowserCopyFile); - break; - case resultDumpGameCardCertificate: - uiSetState(stateDumpGameCardCertificate); - break; - case resultExit: - exitLoop = true; - break; - default: - break; - } - - if (exitLoop) break; - - syncDisplay(); + nsExit(); + } else { + snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to initialize the ns service! (0x%08x)", result); + uiDrawString(strbuf, 0, 0, 255, 255, 255); + delay(5); + ret = -4; } - fsDeviceOperatorClose(&fsOperatorInstance); + ncmExit(); } else { - uiDrawString("Failed to open device operator.", 0, 0, 255, 255, 255); + snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to initialize the ncm service! (0x%08x)", result); + uiDrawString(strbuf, 0, 0, 255, 255, 255); delay(5); ret = -3; } - nsExit(); + fsDeviceOperatorClose(&fsOperatorInstance); } else { - uiDrawString("Failed to initialize the NS service.", 0, 0, 255, 255, 255); + snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to open device operator! (0x%08x)", result); + uiDrawString(strbuf, 0, 0, 255, 255, 255); delay(5); ret = -2; } - ncmExit(); + fsExit(); } else { - uiDrawString("Failed to initialize the NCM service.", 0, 0, 255, 255, 255); + snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to initialize the fsp-srv service! (0x%08x)", result); + uiDrawString(strbuf, 0, 0, 255, 255, 255); delay(5); ret = -1; } diff --git a/source/util.h b/source/util.h index 774875b..ab55dcc 100644 --- a/source/util.h +++ b/source/util.h @@ -5,7 +5,7 @@ #include -#define APP_VERSION "1.0.1" +#define APP_VERSION "1.0.2" #define NAME_BUF_LEN 4096 bool isGameCardInserted(FsDeviceOperator* o);