From 6a699af8d8a9ec69fd5b94e81c92140b4972853b Mon Sep 17 00:00:00 2001 From: cool073 Date: Tue, 3 Sep 2024 16:56:11 +0800 Subject: [PATCH 1/3] Change the version number to "v5.2.1" --- NxNandManager/gui/mainwindow.ui | 2 +- NxNandManager/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NxNandManager/gui/mainwindow.ui b/NxNandManager/gui/mainwindow.ui index fff172f1..a05b52af 100644 --- a/NxNandManager/gui/mainwindow.ui +++ b/NxNandManager/gui/mainwindow.ui @@ -26,7 +26,7 @@ Qt::NoFocus - NxNandManager v5.2 by eliboa + NxNandManager v5.2.1 by eliboa diff --git a/NxNandManager/main.cpp b/NxNandManager/main.cpp index c6331a86..c7ab68d7 100644 --- a/NxNandManager/main.cpp +++ b/NxNandManager/main.cpp @@ -194,7 +194,7 @@ int main(int argc, char *argv[]) //std::setlocale(LC_ALL, "en_US.utf8"); std::setlocale(LC_ALL, ""); std::locale::global(std::locale("")); - printf("[ NxNandManager v5.2 by eliboa ]\n\n"); + printf("[ NxNandManager v5.2.1 by eliboa ]\n\n"); const char *input = nullptr, *output = nullptr, *partitions = nullptr, *keyset = nullptr, *user_resize = nullptr, *boot0 = nullptr, *boot1 = nullptr, *std_redir_output = nullptr; wchar_t driveLetter = L'\0'; BOOL dokan_install = false, info = false, gui = false, setAutoRCM = false, autoRCM = false, decrypt = false, encrypt = false; From 5953b2a7f21fa9c252a49d93b950eb791ef14802 Mon Sep 17 00:00:00 2001 From: cool073 Date: Tue, 3 Sep 2024 16:58:52 +0800 Subject: [PATCH 2/3] Fix some compiler warnings. --- NxNandManager/gui/NxNandManager.pro | 19 ++++++++++--------- NxNandManager/lib/fatfs/ff.h | 8 +++++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/NxNandManager/gui/NxNandManager.pro b/NxNandManager/gui/NxNandManager.pro index 6f7cda17..05e1bcea 100644 --- a/NxNandManager/gui/NxNandManager.pro +++ b/NxNandManager/gui/NxNandManager.pro @@ -114,19 +114,20 @@ HEADERS += \ dump.h \ progress.h \ emunand.h \ - ../lib/ZipLib/*.h \ - ../lib/ZipLib/utils/*.h \ - ../lib/ZipLib/detail/*.h \ - ../lib/ZipLib/extlibs/bzip2/*.h \ - ../lib/ZipLib/extlibs/lzma/*.h \ + $$files(../lib/ZipLib/*.h, false) \ + $$files(../lib/ZipLib/utils/*.h, false) \ + $$files(../lib/ZipLib/detail/*.h, false) \ + $$files(../lib/ZipLib/extlibs/bzip2/*.h, false) \ + $$files(../lib/ZipLib/extlibs/lzma/*.h, false) \ debug.h CONFIG(STATIC) { - HEADERS -= ../lib/ZipLib/extlibs/zlib/zconf.h + SOURCES += $$files(../lib/ZipLib/extlibs/zlib/*.c, false) + HEADERS += $$files(../lib/ZipLib/extlibs/zlib/*.h) } CONFIG(DYNAMIC) { SOURCES += $$files(../lib/ZipLib/extlibs/zlib/*.c, false) - HEADERS += ../lib/ZipLib/extlibs/zlib/*.h \ + HEADERS += $$files(../lib/ZipLib/extlibs/zlib/*.h) } FORMS += \ @@ -158,14 +159,14 @@ RC_FILE = NxNandManager.rc CONFIG(ARCH32) { DEFINES += ARCH32 #OPENSSL PATH - OPENSSL_LIB_PATH = $$PWD/../../../../../mingw32 + OPENSSL_LIB_PATH = $$PWD/../../../OpenSSL_mingw32 LIBS += -L$$PWD/../virtual_fs/dokan/x86/lib/ -ldokan1 } CONFIG(ARCH64) { DEFINES += ARCH64 #OPENSSL PATH - OPENSSL_LIB_PATH = $$PWD/../../../../../mingw64 + OPENSSL_LIB_PATH = $$PWD/../../../OpenSSL_mingw64 LIBS += -L$$PWD/../virtual_fs/dokan/x64/lib/ -ldokan1 } diff --git a/NxNandManager/lib/fatfs/ff.h b/NxNandManager/lib/fatfs/ff.h index ec71349f..5d2994c2 100644 --- a/NxNandManager/lib/fatfs/ff.h +++ b/NxNandManager/lib/fatfs/ff.h @@ -101,10 +101,16 @@ typedef DWORD TCHAR; #elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3) #error Wrong FF_LFN_UNICODE setting #else /* ANSI/OEM code in SBCS/DBCS */ -//typedef char TCHAR; +#ifndef _TCHAR_DEFINED +typedef char TCHAR; +#endif +#ifndef _T #define _T(x) x +#endif +#ifndef _TEXT #define _TEXT(x) x #endif +#endif From bd645a640fcd589c0c6665a84b10d247d2386ac7 Mon Sep 17 00:00:00 2001 From: cool073 Date: Tue, 3 Sep 2024 17:00:32 +0800 Subject: [PATCH 3/3] Fix the issue of generating incorrect GPT backup --- NxNandManager/NxStorage.cpp | 59 +++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/NxNandManager/NxStorage.cpp b/NxNandManager/NxStorage.cpp index c36718aa..7aab706e 100644 --- a/NxNandManager/NxStorage.cpp +++ b/NxNandManager/NxStorage.cpp @@ -1147,7 +1147,9 @@ int NxStorage::dump(NxHandle *outHandle, params_t par, void(*updateProgress)(Pro return error(ERR_WHILE_COPY); // NAND resize => Update GPT - unsigned char gpt_header_backup[0x200]; + bool gen_gpt_backup = false; + BYTE gpt_header_backup[0x200]; + BYTE *gpt_entries_backup = new BYTE[0x4000]; if (par.user_new_size) { // Cluster align new size (32 sectors per cluster) @@ -1172,18 +1174,31 @@ int NxStorage::dump(NxHandle *outHandle, params_t par, void(*updateProgress)(Pro hdr->alt_lba = hdr->last_use_lba + 33; // New CRC32 for header - unsigned char header[92]; - memcpy(&header[0], &hdr[0], 92); - memset(&header[16], 0, 4); - hdr->c_crc32 = crc32Hash(header, 92); + hdr->c_crc32 = 0; // clear old crc32 before compute new crc32 + hdr->c_crc32 = crc32Hash(hdr, hdr->size); - // Save GPT header - memcpy(gpt_header_backup, &hdr[0], 0x200); + gen_gpt_backup = true; } else if (isBackupGptMissing()) { - // Backup GPT header - memcpy(gpt_header_backup, buffer + 0x200, 0x200); + gen_gpt_backup = true; + } + + // Generate gpt backup + if (gen_gpt_backup) { + // Copy GPT backup + memcpy(gpt_header_backup, &buffer[0x200], 0x200); + memcpy(gpt_entries_backup, &buffer[0x400], 0x4000); + + GptHeader *hdr = (GptHeader *)(buffer + 0x200); + GptHeader *hdr_bak = (GptHeader *)gpt_header_backup; + hdr_bak->my_lba = hdr->alt_lba; + hdr_bak->alt_lba = hdr->my_lba; + hdr_bak->part_ent_lba = hdr_bak->my_lba - 32; + + // New CRC32 for header + hdr_bak->c_crc32 = 0; // clear old crc32 before compute new crc32 + hdr_bak->c_crc32 = crc32Hash(hdr_bak, hdr_bak->size); } // Write UserDataRoot @@ -1380,9 +1395,9 @@ int NxStorage::dump(NxHandle *outHandle, params_t par, void(*updateProgress)(Pro } // Ovewrite backup GPT after resize or if backup GPT is missing from input + bool save_gpt_backup = false; if (par.user_new_size) { - GptHeader *hdr = (GptHeader *)(gpt_header_backup); outHandle->clearHandle(); if (outHandle->getChunkSize()) { @@ -1392,13 +1407,27 @@ int NxStorage::dump(NxHandle *outHandle, params_t par, void(*updateProgress)(Pro } else outHandle->createHandle(); - u64 alt_off = (u64)(hdr->alt_lba * NX_BLOCKSIZE) + rawnand_off; - auto res = outHandle->setPointer(alt_off); - if(!outHandle->write(gpt_header_backup, &bytesWrite, NX_BLOCKSIZE)) + save_gpt_backup = true; + } + else if (isBackupGptMissing()) { + save_gpt_backup = true; + } + + // Save gpt backup + if (save_gpt_backup) { + // Write gpt partition entries backup + GptHeader *hdr_bak = (GptHeader *)gpt_header_backup; + u64 write_off = (u64)(hdr_bak->part_ent_lba * NX_BLOCKSIZE) + rawnand_off; + outHandle->setPointer(write_off); + if(!outHandle->write(gpt_entries_backup, &bytesWrite, NX_BLOCKSIZE * 32)) + return error(ERR_WHILE_COPY); + + // Write gpt header backup + write_off = (u64)(hdr_bak->my_lba * NX_BLOCKSIZE) + rawnand_off; + outHandle->setPointer(write_off); + if(!outHandle->write(gpt_header_backup, &bytesWrite, NX_BLOCKSIZE)) return error(ERR_WHILE_COPY); } - else if (isBackupGptMissing() && !outHandle->write(gpt_header_backup, &bytesWrite, NX_BLOCKSIZE)) - return error(ERR_WHILE_COPY); if (isDrive()) nxHandle->unlockVolume();