From fc0324adb45da36f53dd3cb0f050cc62d1807060 Mon Sep 17 00:00:00 2001 From: N2614 Date: Thu, 24 Mar 2011 02:57:39 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=B5?= =?UTF-8?q?=E3=82=A4=E3=82=BA=E3=82=82=E3=83=86=E3=82=AD=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=81=A7=E5=87=BA=E5=8A=9B=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=20ReadBufWithCmac=E3=81=A7=E8=AA=AD=E3=81=BF=E3=81=93?= =?UTF-8?q?=E3=82=93=E3=81=A0=E3=83=90=E3=83=83=E3=83=95=E3=82=A1=E3=81=AE?= =?UTF-8?q?CMAC=E3=81=AF0=E3=82=AF=E3=83=AA=E3=82=A2=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=20=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E4=B8=80=E8=A6=A7=E3=82=92=E5=8F=96=E5=BE=97=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@154 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../ConsoleRestore/Importer.cpp | 98 +++++++++++++++++++ .../common/FileTransfer.cpp | 9 +- .../common/SdReaderWriter.cpp | 3 + 3 files changed, 107 insertions(+), 3 deletions(-) diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp index b9e48fc..3ea970d 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp @@ -84,6 +84,13 @@ nn::Result ImportNorData(); // SDカードに保存してあるバージョン情報 common::VerDef s_SDVersionData; +struct ImportDataEntry +{ + std::string fileName; + NN_PADDING3; + bool isDirectory; +}; + } CheckedNetworkSetting s_CurrentNetowrkSetting1; @@ -1518,6 +1525,91 @@ nn::Result InitializeHardwareDependentSetting() return result; } +nn::Result ReadFileList(s64* totalFileSize, std::vector* fileList) +{ + nn::Result result = nn::ResultSuccess(); + + COMMON_LOGGER("Read File List\n"); + + size_t readSize; + common::SdReaderWriter sdReader; + s64 fileSize; + { + nn::fs::FileInputStream file; + + // サイズ取得のため一時的に開く + result = file.TryInitialize(common::FILE_LIST_PATHNAME); + NN_UTIL_RETURN_IF_FAILED(result); + + result = file.TryGetSize(&fileSize); + if (result.IsFailure()) + { + file.Finalize(); + return result; + } + file.Finalize(); + } + + void* buf = common::HeapManager::GetHeap()->Allocate(fileSize); + if(buf != NULL) + { + result = sdReader.ReadBufWithCmac(common::FILE_LIST_PATHNAME, buf, fileSize, &readSize); + if(result.IsSuccess()) + { + // ファイル一覧 + const char comma[] = ","; + const char newLine[] = "\n"; + char *token = NULL; + token = std::strtok(reinterpret_cast(buf), comma); + bool parseFileName = false; + ImportDataEntry entry; + + entry.fileName = std::string(token); + while( token != NULL) + { + if(parseFileName) + { + token = std::strtok(NULL, comma); + if(token != NULL) + { + entry.fileName = std::string(token); + } + } + else + { + token = std::strtok(NULL, newLine); + if(token != NULL) + { + s64 size = std::atoll(token); + if(size != -1) + { + *totalFileSize += size; + entry.isDirectory = false; + } + else + { + entry.isDirectory = true; + } + + fileList->push_back(entry); + } + } + parseFileName = !parseFileName; + + } + + } + common::HeapManager::GetHeap()->Free(buf); + } + else + { + result = nn::Result(nn::Result::LEVEL_FATAL, nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_COMMON, + nn::Result::DESCRIPTION_OUT_OF_MEMORY); + } + return result; + +} + nn::Result ImportData() { static nn::Result result = nn::ResultSuccess(); @@ -1529,6 +1621,12 @@ nn::Result ImportData() // NANDのごみを削除する Cleanup(); + // ファイル一覧を読み込む + s64 totalFileSize = 0; + std::vector fileList; + result = ReadFileList(&totalFileSize, &fileList); + NN_UTIL_RETURN_IF_FAILED(result); + // SDカードのIVSファイルを書き込む result = ImportIvs(); NN_UTIL_RETURN_IF_FAILED(result); diff --git a/trunk/ConsoleDataMigration/common/FileTransfer.cpp b/trunk/ConsoleDataMigration/common/FileTransfer.cpp index f22507f..eb80e54 100644 --- a/trunk/ConsoleDataMigration/common/FileTransfer.cpp +++ b/trunk/ConsoleDataMigration/common/FileTransfer.cpp @@ -170,7 +170,7 @@ bool CopyDirectory(const wchar_t * from_path, const wchar_t * to_path, void* buf target_to << L"/"; if(encode) { - AddPathNameAndUpdateContext(list, target_to.str().c_str(), 0, listContext); + AddPathNameAndUpdateContext(list, target_to.str().c_str(), -1, listContext); } @@ -644,8 +644,11 @@ void AddPathNameAndUpdateContext(nn::fs::FileOutputStream* file, const wchar_t * context->Update(&comma, sizeof(comma)); COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); - result = file->TryWrite(&writeSize, &fileSize, sizeof(fileSize), true); - context->Update(&fileSize, sizeof(fileSize)); + char sizeStr[10]; + std::memset(sizeStr, 0, sizeof(sizeStr)); + s32 sizeStrSize = std::snprintf(sizeStr, sizeof(sizeStr), "%lld", fileSize); + result = file->TryWrite(&writeSize, sizeStr, sizeStrSize, true); + context->Update(sizeStr, sizeStrSize); COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); char newLine = '\n'; diff --git a/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp b/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp index 4bea638..3a72428 100644 --- a/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp +++ b/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp @@ -225,6 +225,9 @@ nn::Result SdReaderWriter::ReadBufWithCmac(const wchar_t* path, void* buf, size_ return nn::fs::ResultVerificationFailed(); } + // CMACを0埋め + std::memset(reinterpret_cast(buf) + *totalSize, 0, sizeof(cmac)); + return result; }