From 8eb4e2e21267915558f79be0f675abd84697872d Mon Sep 17 00:00:00 2001 From: N2614 Date: Wed, 18 Mar 2015 04:25:14 +0000 Subject: [PATCH] =?UTF-8?q?Ninja=E3=81=A8=E3=81=AE=E9=80=9A=E4=BF=A1?= =?UTF-8?q?=E3=80=81XML=E3=82=92=E3=83=91=E3=83=BC=E3=82=B9=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=AF=E3=83=A9=E3=82=B9=E3=81=AE=E8=BF=BD=E5=8A=A0?= 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@834 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../ConsoleRestore/NinjaCommunicator.cpp | 160 ++++++++++++++++ .../ConsoleRestore/NinjaCommunicator.h | 55 ++++++ .../sources/ConsoleRestore/OMakefile | 6 + .../ConsoleRestore/SimpleXmlPreprocessor.cpp | 180 ++++++++++++++++++ .../ConsoleRestore/SimpleXmlPreprocessor.h | 52 +++++ .../sources/common/HeapManager.cpp | 7 + .../sources/common/HeapManager.h | 3 + .../NinjaCommunicator/OMakefile | 69 +++++++ .../test_NinjaCommunicator.cpp | 151 +++++++++++++++ .../ConsoleRestore/NinjaXmlReader/OMakefile | 71 +++++++ .../NinjaXmlReader/test_NinjaXmlReader.cpp | 157 +++++++++++++++ 11 files changed, 911 insertions(+) create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleRestore/NinjaCommunicator.cpp create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleRestore/NinjaCommunicator.h create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.cpp create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.h create mode 100644 trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaCommunicator/OMakefile create mode 100644 trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaCommunicator/test_NinjaCommunicator.cpp create mode 100644 trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaXmlReader/OMakefile create mode 100644 trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaXmlReader/test_NinjaXmlReader.cpp diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/NinjaCommunicator.cpp b/trunk/ConsoleDataMigration/sources/ConsoleRestore/NinjaCommunicator.cpp new file mode 100644 index 0000000..16ba285 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/NinjaCommunicator.cpp @@ -0,0 +1,160 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: NinjaCommunicator.cpp + + Copyright 2009-2011 Nintendo. 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 "NinjaCommunicator.h" +#include "Util.h" +#include "CommonLogger.h" + +#include +#include +#include +#include +#include + +namespace ConsoleRestore +{ + +namespace +{ +static unsigned char s_Buffer[4096] NN_ATTRIBUTE_ALIGN(4096); +} + +NinjaCommunicator::NinjaCommunicator() +{ +} + +NinjaCommunicator::~NinjaCommunicator() +{ + // TODO Auto-generated destructor stub +} + +nn::Result NinjaCommunicator::GetNsUid(const char* baseUrl, nn::ProgramId programId) +{ + if(!nn::ac::IsConnected()) + { + COMMON_LOGGER_RETURN_RESULT_IF_FAILED( + common::InitializeNetwork()); + } + + std::string url(baseUrl); + GenerateUrlForNsUid(url, programId); + + return HttpCommunicationCore(url); +} + +nn::Result NinjaCommunicator::GetExternalKeyInfo(const char* baseUrl, const char* nsUid, const char* countryCode) +{ + if(!nn::ac::IsConnected()) + { + COMMON_LOGGER_RESULT_IF_FAILED( + common::InitializeNetwork()); + } + + std::string url(baseUrl); + GenerateUrlForGetExternalKeyInfo(url, nsUid, countryCode); + + return HttpCommunicationCore(url); +} + +nn::Result NinjaCommunicator::HttpCommunicationCore(std::string url) +{ + /* ------------------------------------------------------------------------ + ライブラリの初期化(HTTPライブラリ使用前に、各プロセスで一度だけ実行する。) + ------------------------------------------------------------------------ */ + COMMON_LOGGER_RESULT_IF_FAILED( + nn::http::Initialize(reinterpret_cast(s_Buffer), sizeof(s_Buffer))); + + /* ------------------------------------------------------------------------ + 通信準備 + ------------------------------------------------------------------------ */ + + //通信先の設定 + //<>URLの先頭文字はhttpsとなります + COMMON_LOGGER_RESULT_IF_FAILED( + m_HttpCon.Initialize(url.c_str())); + + /* ------------------------------------------------------------------------ + <>SSL処理用設定 + ------------------------------------------------------------------------ */ + //ルート証明書の設定 + COMMON_LOGGER_RESULT_IF_FAILED( + m_HttpCon.SetRootCa(NNSSL_CACERT_PUBLIC_CA_1)); + COMMON_LOGGER_RESULT_IF_FAILED( + m_HttpCon.SetRootCa(NNSSL_CACERT_PUBLIC_CA_2)); + COMMON_LOGGER_RESULT_IF_FAILED( + m_HttpCon.SetRootCa(NNSSL_CACERT_PUBLIC_CA_3)); + COMMON_LOGGER_RESULT_IF_FAILED( + m_HttpCon.SetRootCa(NNSSL_CACERT_PUBLIC_CA_4)); + +#ifndef USE_PROD_KEY + // 開発用サーバは自己署名証明書なので検証項目を減らす + COMMON_LOGGER_RESULT_IF_FAILED( + m_HttpCon.DisableVerifyOptionForDebug( + nn::ssl::VERIFY_COMMON_NAME | nn::ssl::VERIFY_SUBJECT_ALT_NAME | nn::ssl::VERIFY_ROOT_CA)); +#endif + + /* ------------------------------------------------------------------------ + 通信実行 + ------------------------------------------------------------------------ */ + //通信の開始 + COMMON_LOGGER_RESULT_IF_FAILED( + m_HttpCon.Connect()); //リクエストの送信を開始する。機器が同時実行可能な最大個数のHTTP通信がすでに実行中の場合は、空きができるまでブロック + + return nn::ResultSuccess(); +} + +void NinjaCommunicator::GenerateUrlForNsUid(std::string& url, nn::ProgramId programId) +{ + url.append("titles/id_pair?title_id%5B%5D="); + char programIdStr[32]; + std::snprintf(programIdStr, sizeof(programIdStr), "%016llX", programId); + url.append(programIdStr); + NN_LOG("URL=%s\n", url.c_str()); +} + +void NinjaCommunicator::GenerateUrlForGetExternalKeyInfo(std::string& url, const char* nsUid, const char* countryCode) +{ + url.append(countryCode); + url.append("/title/"); + url.append(nsUid); + url.append("/ec_info?countryCode="); + url.append(countryCode); + NN_LOG("URL=%s\n", url.c_str()); +} + +nn::Result NinjaCommunicator::GetBody(u8 *buf, size_t size) +{ + //HTTPレスポンスの取得 + nn::fnd::TimeSpan timeOut = nn::fnd::TimeSpan::FromSeconds(90); + std::memset(buf, 0, size); + //読み取りが完了するまでブロック。Bodyの最後までの読み込みが成功した場合は、Successを表すResultが返る。バッファサイズが足りない場合は、エラー(Description==ER_RES_BODYBUF_SHORTAGEのResult)が返る*/ + COMMON_LOGGER_RETURN_RESULT_IF_FAILED( + m_HttpCon.Read(buf, size, timeOut)); + + return nn::ResultSuccess(); +} + +nn::Result NinjaCommunicator::Finalize() +{ + COMMON_LOGGER_RETURN_RESULT_IF_FAILED( + m_HttpCon.Finalize()); + + COMMON_LOGGER_RETURN_RESULT_IF_FAILED( + nn::http::Finalize()); + + return nn::ResultSuccess(); +} + +} /* namespace ConsoleRestore */ diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/NinjaCommunicator.h b/trunk/ConsoleDataMigration/sources/ConsoleRestore/NinjaCommunicator.h new file mode 100644 index 0000000..c613d34 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/NinjaCommunicator.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: NinjaCommunicator.h + + Copyright 2009-2011 Nintendo. 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$ + *---------------------------------------------------------------------------*/ + +#ifndef BGSCOMMUNICATOR_H_ +#define BGSCOMMUNICATOR_H_ + +#include +#include +#include +namespace ConsoleRestore +{ + +class NinjaCommunicator +{ +public: + NinjaCommunicator(); + virtual ~NinjaCommunicator(); + + //! @Ninjaと通信してns_uidを取得します + //! @param[in] url 接続先URL + nn::Result GetNsUid(const char* baseUrl, nn::ProgramId programId); + + //! @Ninjaと通信して外部鍵情報を取得します + nn::Result GetExternalKeyInfo(const char* baseUrl, const char* nsUid, const char* countryCode); + + //! @brief 通信結果をバッファに書き込みます。 + //! @param[out] buf 通信結果を書き込むバッファ + //! @param[in] size バッファサイズ + nn::Result GetBody(u8* buf, size_t size); + + nn::Result Finalize(); + +private: + nn::Result HttpCommunicationCore(std::string url); + void GenerateUrlForNsUid(std::string& url, nn::ProgramId programId); + void GenerateUrlForGetExternalKeyInfo(std::string& url, const char* nsUid, const char* countryCode); + + //Connectionインスタンス + nn::http::Connection m_HttpCon; +}; + +} /* namespace ConsoleRestore */ +#endif /* BGSCOMMUNICATOR_H_ */ diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile b/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile index cce927a..79d2708 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/OMakefile @@ -35,6 +35,10 @@ SOURCES[] = PreinstallImporter.cpp ActCompleter.cpp AgeChecker.cpp + NinjaCommunicator.cpp + SimpleXmlPreprocessor.cpp + PreorderTitleRestorer.cpp + NinjaXmlReader.cpp ../common/Util.cpp ../common/DrawSystemState.cpp ../common/FileTransfer.cpp @@ -68,6 +72,8 @@ SHADER_PATH = $(ROMFS_ROOT)/$(SHADER_BIN) ROMFS_DEPENDENCIES = $(SHADER_PATH) +EXCLUDE_LIBS += libnn_olv + LIBS += libnn_cfg \ libnn_crypto \ libnn_mcu \ diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.cpp b/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.cpp new file mode 100644 index 0000000..25f3d43 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.cpp @@ -0,0 +1,180 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: SimpleXmlPreprocessor.cpp + + Copyright 2009-2011 Nintendo. 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 "SimpleXmlPreprocessor.h" +#if defined(__ARMCC_VERSION) +#include +#else +#include "test_common.h" +#endif + +namespace ConsoleRestore +{ + +bool SimpleXmlPreprocessor::Canonicalize(std::string& str) +{ + if(!EraseXmlDeclaration(str)) + { + NN_LOG("invalid xml!\n"); + return false; + } + + if(!EraseEmptyTag(str)) + { + NN_LOG("can't erase empty tag"); + return false; + } + + if(!EraseAttribute(str)) + { + NN_LOG("can't erase attribute\n"); + return false; + } + + if(!EraseNsTagEnd(str)) + { + NN_LOG("can't erase ns end\n"); + return false; + } + + if(!EraseNsTagStart(str)) + { + NN_LOG("can't erase ns start\n"); + return false; + } + + return true; +} + +bool SimpleXmlPreprocessor::EraseXmlDeclaration(std::string& str) +{ + std::string::size_type start = str.find(""); + if (end == std::string::npos) + { + return false; + } + + str.erase(start, end + 1 - start); + + return true; +} + +bool SimpleXmlPreprocessor::EraseEmptyTag(std::string& str) +{ + // XMLとしては正しい前提 + std::string::size_type end = str.find("/>"); + if (end == std::string::npos) + { + return true; + } + + std::string::size_type start = str.rfind("<", end); + if (start == std::string::npos) + { + return false; + } + + str.erase(start, end + 2 - start); + + return true; +} + +bool SimpleXmlPreprocessor::EraseNsTagEnd(std::string& str) +{ + std::string::size_type start = str.rfind("", start); + if (end == std::string::npos) + { + // 不正なXML + return false; + } + + std::string::size_type colon = str.substr(start, end - start).find(":"); + if (colon == std::string::npos) + { + // 名前空間無し + start = str.rfind("", start); + if (end == std::string::npos) + { + // 不正なXML + return false; + } + + std::string::size_type colon = str.substr(start, end - start).find(":"); + if (colon == std::string::npos) + { + // 名前空間無し + start = str.find("<", end); + continue; + } + + str.erase(start + 1, colon); + start = str.find("<", end - colon); + } + + return true; +} + +bool SimpleXmlPreprocessor::EraseAttribute(std::string& str) +{ + std::string::size_type start = str.find("<"); + while (start != std::string::npos) + { + std::string::size_type end = str.find(">", start); + if (end == std::string::npos) + { + // 不正なXML + return false; + } + + std::string::size_type space = str.substr(start, end - start).find(" "); + if (space == std::string::npos) + { + // 属性なし + start = str.find("<", end); + continue; + } + + str.erase(start + space, end - (start + space)); + start = str.find("<", start + space); + } + + return true; +} + +} /* namespace ConsoleRestore */ diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.h b/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.h new file mode 100644 index 0000000..7cf549b --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/SimpleXmlPreprocessor.h @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: SimpleXmlPreprocessor.h + + Copyright 2009-2011 Nintendo. 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$ + *---------------------------------------------------------------------------*/ + +#ifndef SIMPLEXMLPREPROCESSOR_H_ +#define SIMPLEXMLPREPROCESSOR_H_ + +#include + +namespace ConsoleRestore +{ + +class SimpleXmlPreprocessor +{ +public: + SimpleXmlPreprocessor() {}; + ~SimpleXmlPreprocessor() {}; + + // SimpleXmlParserで読めるように変換します + static bool Canonicalize(std::string& str); + +private: + // の除去 + static bool EraseXmlDeclaration(std::string& str); + + // 空タグの除去 + static bool EraseEmptyTag(std::string& str); + + // 属性の削除 + static bool EraseAttribute(std::string& str); + + // 終了タグの名前空間の削除 + static bool EraseNsTagEnd(std::string& str); + + // 開始タグの名前空間の削除 + static bool EraseNsTagStart(std::string& str); + +}; + +} /* namespace ConsoleRestore */ +#endif /* SIMPLEXMLPREPROCESSOR_H_ */ diff --git a/trunk/ConsoleDataMigration/sources/common/HeapManager.cpp b/trunk/ConsoleDataMigration/sources/common/HeapManager.cpp index 401b1a6..f76d493 100644 --- a/trunk/ConsoleDataMigration/sources/common/HeapManager.cpp +++ b/trunk/ConsoleDataMigration/sources/common/HeapManager.cpp @@ -19,6 +19,7 @@ namespace common { nn::fnd::ThreadSafeExpHeap s_AppHeap; +nn::fnd::ThreadSafeExpHeap::Allocator s_Allocator(s_AppHeap); HeapManager::HeapManager(size_t byteSize, s32 alignment, bit8 groupId, nn::fnd::ExpHeapBase::AllocationMode mode, bool reuse) @@ -61,4 +62,10 @@ void ForceFree(void* ptr) } } +// アロケータを渡す場合 +nn::fnd::ThreadSafeExpHeap::Allocator* GetAllocator() +{ + return &s_Allocator; +} + } diff --git a/trunk/ConsoleDataMigration/sources/common/HeapManager.h b/trunk/ConsoleDataMigration/sources/common/HeapManager.h index 0579abd..62e3b24 100644 --- a/trunk/ConsoleDataMigration/sources/common/HeapManager.h +++ b/trunk/ConsoleDataMigration/sources/common/HeapManager.h @@ -46,6 +46,9 @@ void* ForceAllocate(size_t byteSize, s32 alignment = nn::fnd::ExpHeapBase::DEFAU // HeapManagerを使わず解放する場合のみ void ForceFree(void* ptr); +// アロケータを渡す場合 +nn::fnd::ThreadSafeExpHeap::Allocator* GetAllocator(); + } // namespace common #endif /* HEAPMANAGER_H_ */ diff --git a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaCommunicator/OMakefile b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaCommunicator/OMakefile new file mode 100644 index 0000000..ea8c6dc --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaCommunicator/OMakefile @@ -0,0 +1,69 @@ +#!/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-*.Process.MPCore.* + +include $(makePlatformDefsPath tests) + +SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include) +INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \ + ../../../common \ + ../../../ConsoleRestore \ + + + +TEST_COMMON_SOURCES[] = + ../../../ConsoleRestore/TitleDownloader.cpp + ../../../ConsoleRestore/Shop.cpp + ../../../ConsoleRestore/PreinstallImporter.cpp + ../../../ConsoleRestore/NinjaCommunicator.cpp + ../../../common/Util.cpp + ../../../common/HeapManager.cpp + ../../../common/SdLogger.cpp + ../../../common/LogConsole.cpp + ../../../common/CommonLogger.cpp + ../../../common/SdMountManager.cpp + ../../../common/VersionDetect.cpp + ../../../common/HardwareStateManager.cpp + ../../../common/FileTransfer.cpp + ../../../common/SdReaderWriter.cpp + +CCFLAGS += -DCOMMON_LOGGER_DETAIL_ENABLE +include $(ROOT)/common/BuildSwitch.om + +SOURCES_TEST[] = test_NinjaCommunicator.cpp + +ROMFS_ROOT = ../../../common/romfiles + +TEST_ENVIRONMENT_PROCESSLIST = true +TEST_ENVIRONMENT_EMUMEM = true + +LIBS += libnn_test \ + libnn_mcu \ + libnn_ps \ + libnn_am \ + lib_demo \ + libnn_nim \ + libnn_xml_simple \ + + +ROM_SPEC_FILE = ../../../ConsoleRestore/ConsoleRestore.rsf +DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/tools/RepairTool.desc + + +include $(makePlatformDefsPath build.tests) + + +tests: $(TEST_TARGETS) diff --git a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaCommunicator/test_NinjaCommunicator.cpp b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaCommunicator/test_NinjaCommunicator.cpp new file mode 100644 index 0000000..da0edf1 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaCommunicator/test_NinjaCommunicator.cpp @@ -0,0 +1,151 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: test_NinjaCommunicator.cpp + + Copyright 2009 Nintendo. 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 "demo.h" + +#include "common_Types.h" +#include "CommonLogger.h" +#include "HeapManager.h" +#include "NinjaCommunicator.h" + +using namespace nn::test; + +class TestNinjaCommunicator : public Suite { +public: + virtual bool InitializeSuite(); + virtual void FinalizeSuite(); + + TestNinjaCommunicator() { + SUITE_NAME("Test"); + TEST_ADD(TestNinjaCommunicator::GetNsUid); + TEST_ADD(TestNinjaCommunicator::GetExternalKeyInfo); + } +private: + void GetNsUid(); + void GetExternalKeyInfo(); +}; + +namespace +{ + +const size_t s_GxHeapSize = 0x800000; + +} + +//------------------------------------------------------------------ +// Initialize/Finalize +//------------------------------------------------------------------ + +bool TestNinjaCommunicator::InitializeSuite() +{ + // os の初期化 + nn::fs::Initialize(); + nn::cfg::CTR::init::Initialize(); + nn::cfg::CTR::system::Initialize(); + + // amの初期化 + nn::am::InitializeForLocalImporter(); + + // ヒープの確保 + common::InitializeHeap(); + common::HeapManager gxHeap(s_GxHeapSize); + + // RenderSystem の準備 + uptr heapForGx = reinterpret_cast(gxHeap.GetAddr()); + demo::RenderSystemDrawing renderSystem; + renderSystem.Initialize(heapForGx, s_GxHeapSize); + + // ログ描画の初期化 + common::Logger::GetLoggerInstance()->Initialize(common::CONSOLE_WIDTH, common::CONSOLE_HEIGHT, + common::CONSOLE_MAX_LINE, &renderSystem); + + return true; + +} + +void TestNinjaCommunicator::FinalizeSuite() +{ +} + +//------------------------------------------------------------------ +// Test Util +//------------------------------------------------------------------ + + +//------------------------------------------------------------------ +// Test Functions +//------------------------------------------------------------------ + +void TestNinjaCommunicator::GetNsUid() +{ + NN_LOG("GetNsUid\n"); + ConsoleRestore::NinjaCommunicator ninja; + + NN_TEST_ASSERT( + ninja.GetNsUid("https://10.12.6.122/ninja/ws/", 0x000400000FECD000).IsSuccess()); + + size_t bufSize = 1024 * 1024; // 1MB + common::HeapManager heap(bufSize); + NN_TEST_ASSERT( + heap.GetAddr()); + + void* buf = heap.GetAddr(); + NN_TEST_ASSERT( + ninja.GetBody(reinterpret_cast(buf), bufSize).IsSuccess()); + + NN_LOG("%s\n", buf); + + NN_TEST_ASSERT( + ninja.Finalize().IsSuccess()); +} + +void TestNinjaCommunicator::GetExternalKeyInfo() +{ + NN_LOG("GetExternalKeyInfo\n"); + ConsoleRestore::NinjaCommunicator ninja; + + NN_TEST_ASSERT( + ninja.GetExternalKeyInfo("https://10.12.6.122/ninja/ws/", "50010000041101", "JP").IsSuccess()); + + size_t bufSize = 1024 * 1024; // 1MB + common::HeapManager heap(bufSize); + NN_TEST_ASSERT( + heap.GetAddr()); + + void* buf = heap.GetAddr(); + NN_TEST_ASSERT( + ninja.GetBody(reinterpret_cast(buf), bufSize).IsSuccess()); + + NN_LOG("%s\n", buf); + + NN_TEST_ASSERT( + ninja.Finalize().IsSuccess()); +} + +NN_TEST_DEFINE_MAIN(TestNinjaCommunicator) + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaXmlReader/OMakefile b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaXmlReader/OMakefile new file mode 100644 index 0000000..12543e8 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaXmlReader/OMakefile @@ -0,0 +1,71 @@ +#!/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-*.Process.MPCore.* + +include $(makePlatformDefsPath tests) + +SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include) +INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \ + ../../../common \ + ../../../ConsoleRestore \ + + + +TEST_COMMON_SOURCES[] = + ../../../ConsoleRestore/TitleDownloader.cpp + ../../../ConsoleRestore/Shop.cpp + ../../../ConsoleRestore/PreinstallImporter.cpp + ../../../ConsoleRestore/SimpleXmlPreprocessor.cpp + ../../../ConsoleRestore/NinjaXmlReader.cpp + ../../../common/Util.cpp + ../../../common/HeapManager.cpp + ../../../common/SdLogger.cpp + ../../../common/LogConsole.cpp + ../../../common/CommonLogger.cpp + ../../../common/SdMountManager.cpp + ../../../common/VersionDetect.cpp + ../../../common/HardwareStateManager.cpp + ../../../common/FileTransfer.cpp + ../../../common/SdReaderWriter.cpp + +CCFLAGS += -DCOMMON_LOGGER_DETAIL_ENABLE +include $(ROOT)/common/BuildSwitch.om + +SOURCES_TEST[] = test_NinjaXmlReader.cpp + +ROMFS_ROOT = ../../../common/romfiles + +TEST_ENVIRONMENT_PROCESSLIST = true +TEST_ENVIRONMENT_EMUMEM = true + +EXCLUDE_LIBS += libnn_olv + +LIBS += libnn_test \ + libnn_mcu \ + libnn_ps \ + libnn_am \ + lib_demo \ + libnn_xml_simple \ + + +ROM_SPEC_FILE = ../../../ConsoleRestore/ConsoleRestore.rsf +DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/tools/RepairTool.desc + + +include $(makePlatformDefsPath build.tests) + + +tests: $(TEST_TARGETS) diff --git a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaXmlReader/test_NinjaXmlReader.cpp b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaXmlReader/test_NinjaXmlReader.cpp new file mode 100644 index 0000000..8bcb2ea --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/NinjaXmlReader/test_NinjaXmlReader.cpp @@ -0,0 +1,157 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: test_NinjaCommunicator.cpp + + Copyright 2009 Nintendo. 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 "demo.h" + +#include "common_Types.h" +#include "CommonLogger.h" +#include "HeapManager.h" +#include "NinjaXmlReader.h" + +using namespace nn::test; + +class TestNinjaXmlReader : public Suite { +public: + virtual bool InitializeSuite(); + virtual void FinalizeSuite(); + + TestNinjaXmlReader() { + SUITE_NAME("Test"); + TEST_ADD(TestNinjaXmlReader::GetNsUid); + TEST_ADD(TestNinjaXmlReader::HasContentLock); + TEST_ADD(TestNinjaXmlReader::GetPlayableDate); + TEST_ADD(TestNinjaXmlReader::HasExternalSeed); + } +private: + void GetNsUid(); + void HasContentLock(); + void GetPlayableDate(); + void HasExternalSeed(); +}; + +namespace +{ + +const size_t s_GxHeapSize = 0x800000; + +} + +//------------------------------------------------------------------ +// Initialize/Finalize +//------------------------------------------------------------------ + +bool TestNinjaXmlReader::InitializeSuite() +{ + nn::fs::Initialize(); + nn::cfg::CTR::init::Initialize(); + nn::cfg::CTR::system::Initialize(); + + // ヒープの確保 + common::InitializeHeap(); + common::HeapManager gxHeap(s_GxHeapSize); + + return true; +} + +void TestNinjaXmlReader::FinalizeSuite() +{ +} + +//------------------------------------------------------------------ +// Test Util +//------------------------------------------------------------------ + + +//------------------------------------------------------------------ +// Test Functions +//------------------------------------------------------------------ + +void TestNinjaXmlReader::GetNsUid() +{ + char nsUid[32]; + ConsoleRestore::NinjaXmlReader reader; + std::string xml("50010000041101000400000FECD000T"); + reader.GetNsUid(nsUid, sizeof(nsUid) / sizeof(nsUid[0]), xml); + NN_TEST_ASSERT( + !std::strcmp(nsUid, "50010000041101")); + NN_LOG("ns_uid = %s\n", nsUid); +} + +void TestNinjaXmlReader::HasContentLock() +{ + { + ConsoleRestore::NinjaXmlReader reader; + std::string xml("000400000FECD0004002281024falsetruefalse2024-02-02"); + NN_TEST_ASSERT( + reader.HasContentLock(xml)); + } + + { + ConsoleRestore::NinjaXmlReader reader; + std::string xml("0004000001800A003489800false"); + NN_TEST_ASSERT( + !reader.HasContentLock(xml)); + } +} + +void TestNinjaXmlReader::GetPlayableDate() +{ + { + ConsoleRestore::NinjaXmlReader reader; + std::string xml("000400000FECD0004002281024falsetruefalse2024-02-02"); + nn::fnd::DateTime date = nn::fnd::DateTime::FromParameters(2024, 2, 2); + NN_TEST_ASSERT_EQUAL(date, reader.GetPlayableDate(xml)); + } + + { + ConsoleRestore::NinjaXmlReader reader; + std::string xml("000400000FECD0004002281024falsetruefalse2015-12-31"); + nn::fnd::DateTime date = nn::fnd::DateTime::FromParameters(2015, 12, 31); + NN_TEST_ASSERT_EQUAL(date, reader.GetPlayableDate(xml)); + } +} + +void TestNinjaXmlReader::HasExternalSeed() +{ + { + ConsoleRestore::NinjaXmlReader reader; + std::string xml("000400000FECAF003505160falsetrueab9d62312e43836bd73048c8b61e89e1"); + NN_TEST_ASSERT( + reader.HasExternalSeed(xml)); + } + + { + ConsoleRestore::NinjaXmlReader reader; + std::string xml("000400000FECD0004002281024falsetruefalse2015-12-31"); + NN_TEST_ASSERT( + !reader.HasExternalSeed(xml)); + } +} + +NN_TEST_DEFINE_MAIN(TestNinjaXmlReader) + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/