From 1632d0b788fdbff07b312e83ce223493ea64e129 Mon Sep 17 00:00:00 2001 From: N2614 Date: Fri, 20 Jan 2012 02:49:56 +0000 Subject: [PATCH] =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E5=BF=98=E3=82=8C?= 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@585 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../ConsoleRestore/PreinstallImporter.cpp | 132 ++++++++++++++++++ .../ConsoleRestore/PreinstallImporter.h | 40 ++++++ 2 files changed, 172 insertions(+) create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleRestore/PreinstallImporter.cpp create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleRestore/PreinstallImporter.h diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/PreinstallImporter.cpp b/trunk/ConsoleDataMigration/sources/ConsoleRestore/PreinstallImporter.cpp new file mode 100644 index 0000000..16dbaa3 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/PreinstallImporter.cpp @@ -0,0 +1,132 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: PreinstallImporter.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 "CommonLogger.h" +#include "HeapManager.h" +#include "PreinstallImporter.h" +#include "XmlCreator.h" +#include "BgsCommunicator.h" +#include "SimpleXmlPreprocessor.h" +#include +#include + +namespace ConsoleRestore +{ + +PreinstallImporter::PreinstallImporter() +{ + // TODO 自動生成されたコンストラクター・スタブ + +} + +PreinstallImporter::~PreinstallImporter() +{ + // TODO Auto-generated destructor stub +} + +nn::Result PreinstallImporter::ListTitles(nn::ProgramId* list, size_t* num, bit64 deviceId, u8* serialNo) +{ + // 送信用のXMLデータを構築する + XmlCreator sendXml; + sendXml.Exec(deviceId, serialNo); + + // 構築したXMLデータを使ってBGSと通信する + BgsCommunicator comm; + if(!comm.Execute(sendXml.GetData().c_str(), sendXml.GetData().size())) + { + return comm.GetLastResult(); + } + + // 通信結果を取得する + size_t bodySize; + if(!comm.GetBodySize(&bodySize)) + { + return comm.GetLastResult(); + } + if(common::GetAllocatableSize() < bodySize) + { + // 巨大な通信結果のためFATAL。1回で受信しきれるはず + return nn::Result(nn::Result::LEVEL_FATAL, nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_COMMON, + nn::Result::DESCRIPTION_OUT_OF_MEMORY); + } + common::HeapManager heap(bodySize); + void* buf = heap.GetAddr(); + if(!comm.GetBody(reinterpret_cast(buf), bodySize)) + { + return comm.GetLastResult(); + } + + // 通信結果をパースする + // SimpleXmlParserに食わせるために変換する + SimpleXmlPreprocessor pp; + // システムヒープ(8MB)を超えたら正常に動かない + std::string xmlResult(reinterpret_cast(buf)); + pp.Canonicalize(xmlResult); + + // XMLをパースしてタイトルリストを取得する + nn::fnd::IAllocator* pAllocator = nn::init::GetAllocator(); + nn::xml::simple::SimpleXmlParser simpleXmlParser(pAllocator); + simpleXmlParser.parse(reinterpret_cast(const_cast(xmlResult.c_str())), xmlResult.size()); + + if(simpleXmlParser.isError()) + { + COMMON_LOGGER("invalid xml Data\n"); + return nn::Result(nn::Result::LEVEL_STATUS, nn::Result::SUMMARY_INVALID_STATE, nn::Result::MODULE_COMMON, + nn::Result::DESCRIPTION_INVALID_RESULT_VALUE); + } + + const nn::xml::simple::SimpleXmlParser::Node* pRootNode = simpleXmlParser.getRootNode(); + const nn::xml::simple::SimpleXmlParser::Node* pTargetNode = pRootNode->firstChild; + // 欲しい情報がある場所まで階層を掘り下げる + const nn::xml::simple::SimpleXmlParser::Node* pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode( + pTargetNode, "Body"); + pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild, + "GetPreInstalledInfoResponse"); + pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild, + "GetPreInstalledInfoResponse"); + pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild, "PreinstalledInfo"); + + const nn::xml::simple::SimpleXmlParser::Node* pTaskIdNode = nn::xml::simple::SimpleXmlParser::FindNextNode( + pPriorityNode->firstChild, "TitleIds"); + common::HeapManager xmlHeap(pTaskIdNode->contentSize); + void* titleIdBuffer = xmlHeap.GetAddr(); + std::memcpy(titleIdBuffer, pTaskIdNode->content, pTaskIdNode->contentSize); + + // 分割する + char* tok; + + tok = std::strtok(reinterpret_cast(titleIdBuffer), ","); + if(!tok) + { + return nn::ResultSuccess(); + } + + list[*num] = std::strtoll(tok, NULL, 16); + (*num)++; + + while( tok ) + { + tok = std::strtok(NULL, ","); + if(tok) + { + list[*num] = std::strtoll(tok, NULL, 16); + (*num)++; + } + } + + return nn::ResultSuccess(); +} + +} /* namespace ConsoleRestore */ diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/PreinstallImporter.h b/trunk/ConsoleDataMigration/sources/ConsoleRestore/PreinstallImporter.h new file mode 100644 index 0000000..966784d --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/PreinstallImporter.h @@ -0,0 +1,40 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: PreinstallImporter.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 PREINSTALLIMPORTER_H_ +#define PREINSTALLIMPORTER_H_ + +#include + +namespace ConsoleRestore +{ + +//! @brief プリインストールをSDカードに書き込むためのクラスです +class PreinstallImporter +{ +public: + PreinstallImporter(); + virtual ~PreinstallImporter(); + + //! @brief ダウンロードするプリインストールタイトルをBGS経由でリストアップする + //! @param[out] list    プリインストールタイトルの配列。十分に大きいものを渡すこと。 + //! @param[out] num プリインストールタイトルの数 + //! @param[in] deviceId デバイスID + //! @param[in] serialNo シリアルナンバー + nn::Result ListTitles(nn::ProgramId* list, size_t* num, bit64 deviceId, u8* serialNo); +}; + +} /* namespace ConsoleRestore */ +#endif /* PREINSTALLIMPORTER_H_ */