diff --git a/trunk/ConsoleDataMigration/sources/tools/CmacAdder/AutoBoot.bsf b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/AutoBoot.bsf new file mode 100644 index 0000000..104a94d Binary files /dev/null and b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/AutoBoot.bsf differ diff --git a/trunk/ConsoleDataMigration/sources/tools/CmacAdder/CmacAdder.rsf b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/CmacAdder.rsf new file mode 100644 index 0000000..8a8d47d --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/CmacAdder.rsf @@ -0,0 +1,44 @@ +BasicInfo: + Title : CmacAdder + ProductCode: CmacAdder + BackupMemoryType: None + +TitleInfo: + Use: Evaluation + Category: Application + UniqueId: 0xf8021 + Version: 0 + +SystemControlInfo: + AppType : Application + StackSize : 0x4000 + Dependency : + - codec + - hid + - gsp + - nwm + +AccessControlInfo: + Priority : 16 + DisableDebug : true + + FileSystemAccess: + - DirectSdmc + - Debug + - Core + - CategoryFileSystemTool + + IoAccessControl: + - FsMountCardSpi + - FsMountNand + - FsMountTwln + +Option: + FreeProductCode: true + +CardInfo: + CardDevice: None + +Rom: + # ROM に含めるファイルシステムのルートパスを指定します。 + HostRoot: "$(ROMFS_ROOT)" \ No newline at end of file diff --git a/trunk/ConsoleDataMigration/sources/tools/CmacAdder/OMakefile b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/OMakefile new file mode 100644 index 0000000..4001800 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/OMakefile @@ -0,0 +1,64 @@ +#!/usr/bin/env omake +#---------------------------------------------------------------------------- +# Project: Horizon +# File: OMakefile +# +# Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Rev$ +#---------------------------------------------------------------------------- +SUPPORTED_TARGETS = CTR-T*.Process.MPCore.* +CTR_APPTYPE = BOTH +CTR_MAKE_DEVELOPMENT_IMAGE = true + +TARGET_PROGRAM = CmacAdder + +SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include) +INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \ + ../../common + +SOURCES[] = + main.cpp + ../../common/Util.cpp + ../../common/FileTransfer.cpp + ../../common/FileChecker.cpp + ../../common/SdReaderWriter.cpp + ../../common/HeapManager.cpp + ../../common/SdLogger.cpp + ../../common/wave.cpp + ../../common/SimplePlayer.cpp + ../../common/LogConsole.cpp + ../../common/CommonLogger.cpp + ../../common/SdMountManager.cpp + ../../common/configLoader.cpp + ../../common/VersionDetect.cpp + +CTR_BANNER_SPEC = AutoBoot.bsf + +ROMFS_ROOT = ../../common/romfiles + +LIBS += libnn_cfg \ + libnn_crypto \ + libnn_mcu \ + libnn_ps \ + lib_demo \ + libnn_nwm \ + libnn_friends \ + libnn_ns \ + libnn_am \ + libnn_nim \ + +INSTALL_SDK_TOOL = true + +ROM_SPEC_FILE = $(TARGET_PROGRAM).rsf +DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/RepairTool.desc + +include $(ROOT_OMAKE)/modulerules + +build: $(DEFAULT_TARGETS) diff --git a/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/model.cbmd b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/model.cbmd new file mode 100644 index 0000000..f1c7b62 Binary files /dev/null and b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/model.cbmd differ diff --git a/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/sound.cbsd b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/sound.cbsd new file mode 100644 index 0000000..f1c7b62 Binary files /dev/null and b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/sound.cbsd differ diff --git a/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/unknown24x24.ctpk b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/unknown24x24.ctpk new file mode 100644 index 0000000..794b136 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/unknown24x24.ctpk @@ -0,0 +1 @@ +888yyYyYyyyYyyYyyyyYyYy8 \ No newline at end of file diff --git a/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/unknown48x48.ctpk b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/unknown48x48.ctpk new file mode 100644 index 0000000..8c7da16 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/banner/unknown48x48.ctpk @@ -0,0 +1 @@ +Y8888ƺ8888YYyyYYޚ޺yY8YyYYޚyY8ޚ8 \ No newline at end of file diff --git a/trunk/ConsoleDataMigration/sources/tools/CmacAdder/main.cpp b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/main.cpp new file mode 100644 index 0000000..7193676 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tools/CmacAdder/main.cpp @@ -0,0 +1,290 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: main.cpp + + Copyright (C)2011 Nintendo Co., Ltd. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "Aes_define.h" +#include "FileTransfer.h" +#include "CommonLogger.h" + +#include "demo.h" + +#include +#include + +#include "DrawSystemState.h" +#include "FileName.h" +#include "SimplePlayer.h" +#include "CommonLogger.h" +#include "SDMountManager.h" +#include "HeapManager.h" +#include "common_Types.h" +#include "VersionDetect.h" +#include "Util.h" +#include "CommonLogger.h" +#include "SdReaderWriter.h" + +namespace +{ + +// グラフィックスに割り当てるメモリ +const size_t s_GxHeapSize = 0x800000; + +const u32 CONSOLE_WIDTH = 38; +const u32 CONSOLE_HEIGHT = 24; +const u32 CONSOLE_MAX_LINE = 1000; + +const size_t ADD_CMAC_THREAD_STACK_SIZE = 0x4000; +nn::os::Thread s_AddCmacThread; +nn::os::StackBuffer s_AddCmacThreadStack; + +u32 s_AddCmacSuccess = 0; +u32 s_AddCmacFail = 0; + +} + +namespace CmacAdder +{ + +// ディレクトリ間のコピー +// アーカイブ越しのコピーが可能 +// アーカイブにマウントした状態で呼び出す必要あり +// 書き込み先のディレクトリはあらかじめ消去しておくこと。 +// 引数はスラッシュ付き +// TODO:分割して短くする +bool AddCmac(const wchar_t * from_path, void* buf, const size_t bufSize) +{ + using namespace common; + + nn::fs::Directory from_dir; + nn::fs::DirectoryEntry entry; + s32 numread = 0; + std::wostringstream target_from; + std::wostringstream target_to; + bool ret_value = true; + + nn::Result result = from_dir.TryInitialize(from_path); + + if (result.IsFailure()) + { + COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); + return false; + } + + while (1) + { + result = from_dir.TryRead(&numread, &entry, 1); + if (result.IsFailure() || numread != 1) + { + break; + } + + if (std::wcscmp(entry.entryName, L".") == 0 || std::wcscmp(entry.entryName, L"..") == 0) + { + continue; + } + + target_from.str(L""); + target_from.clear(std::stringstream::goodbit); + target_from << from_path << entry.entryName; + + target_to.str(L""); + target_to.clear(std::stringstream::goodbit); + target_to << from_path << entry.entryName << L".cmac"; + + // ディレクトリの場合 + if (entry.attributes.isDirectory) + { + continue; + } + else if (std::wcscmp(entry.entryName, common::AP_SETTING_FILENAME) == 0) + { + continue; + } + // ファイルの場合 + // CMACが付いていないと考えてCMACを付加する + else + { + nn::fs::FileInputStream sdFile; + s64 filesize; + s32 readsize; + + // 読み込み対象ファイル開く + result = sdFile.TryInitialize(target_from.str().c_str()); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + + // 読み込み対象ファイルのサイズ取得 + result = sdFile.TryGetSize(&filesize); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + + result = sdFile.TryRead(&readsize, buf, bufSize); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + + common::SdReaderWriter writer; + result = writer.WriteBufWithCmac(target_to.str().c_str(), buf, readsize); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + sdFile.Finalize(); + s_AddCmacSuccess++; + } + } + from_dir.Finalize(); + return ret_value; +} + + +void AddCmacThreadFunc() +{ + nn::Result result; + + COMMON_LOGGER("AddCmacThreadFunc Start\n"); + s_AddCmacFail = 0; + s_AddCmacSuccess = 0; + + result = common::SdMountManager::Mount(); + + size_t bufSize = common::GetAllocatableSize(AES_BLOCK_SIZE * 2); + + common::HeapManager heap(bufSize, AES_BLOCK_SIZE * 2); + void* buf = heap.GetAddr(); + if (buf != NULL) + { + AddCmac((std::wstring(common::SDMC_ROOT_DIRECTORY_PATH).c_str()), + buf, bufSize); + } + + common::SdMountManager::Unmount(); + + COMMON_LOGGER("AddCmac Thread Finalize\n"); + + COMMON_LOGGER("\n\n"); + COMMON_LOGGER("AddCmac Finished, success = %d, fail = %d\n", s_AddCmacSuccess, s_AddCmacFail); +} + +extern "C" void nninitSetupDaemons(void) +{ +} + + +extern "C" void nnMain(void) +{ + nn::Result result; + + // os の初期化 + nn::os::Initialize(); + + // fs の初期化 + nn::fs::Initialize(); + + // appletの初期化 + nn::applet::Enable( false ); + + // hid の初期化 + result = nn::hid::Initialize(); + NN_ERR_THROW_FATAL_IF_FATAL_ONLY(result); + + // ヒープの確保 + common::InitializeHeap(); + + // RenderSystem の準備 + common::HeapManager gxHeap(s_GxHeapSize); + uptr heapForGx = reinterpret_cast(gxHeap.GetAddr()); + demo::RenderSystemDrawing s_RenderSystem; + s_RenderSystem.Initialize(heapForGx, s_GxHeapSize); + + // ログ描画の初期化 + common::Logger::GetLoggerInstance()->Initialize(CONSOLE_WIDTH, CONSOLE_HEIGHT, CONSOLE_MAX_LINE, &s_RenderSystem); + + // RenderSystemを作ってからログが出せる + common::Logger::InitializeEjectThread(); + + COMMON_LOGGER("AddCmac Start\n"); + + // ボタン入力 + nn::hid::PadReader s_PadReader; + nn::hid::PadStatus padStatus; + + for(;;) + { + s_PadReader.ReadLatest(&padStatus); + + if(padStatus.trigger & nn::hid::BUTTON_A) + { + if(s_AddCmacThread.IsValid() && !s_AddCmacThread.IsAlive()) + { + s_AddCmacThread.Join(); + s_AddCmacThread.Finalize(); + } + s_AddCmacThread.Start(AddCmacThreadFunc, s_AddCmacThreadStack); + } + + // コンソールスクロール + if(padStatus.hold & nn::hid::BUTTON_UP) + { + common::Logger::GetLoggerInstance()->ScrollUp(); + } + + // コンソールスクロール + if(padStatus.hold & nn::hid::BUTTON_DOWN) + { + common::Logger::GetLoggerInstance()->ScrollDown(); + } + + if(padStatus.hold & nn::hid::BUTTON_LEFT) + { + common::Logger::GetLoggerInstance()->ScrollToBegin(); + } + + if(padStatus.hold & nn::hid::BUTTON_RIGHT) + { + common::Logger::GetLoggerInstance()->ScrollToEnd(); + } + + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); + s_RenderSystem.Clear(); + s_RenderSystem.SetColor(1.f, 1.f, 1.f); + + common::Logger::GetLoggerInstance()->DrawConsole(); + s_RenderSystem.SwapBuffers(); + + s_RenderSystem.WaitVsync(NN_GX_DISPLAY_BOTH); + } +} + +}