mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
追加忘れ
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
This commit is contained in:
parent
e3b63e777b
commit
1632d0b788
@ -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 <nn/xml/simple/xml_simple_SimpleXmlParser.h>
|
||||
#include <cstring>
|
||||
|
||||
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<u8*>(buf), bodySize))
|
||||
{
|
||||
return comm.GetLastResult();
|
||||
}
|
||||
|
||||
// 通信結果をパースする
|
||||
// SimpleXmlParserに食わせるために変換する
|
||||
SimpleXmlPreprocessor pp;
|
||||
// システムヒープ(8MB)を超えたら正常に動かない
|
||||
std::string xmlResult(reinterpret_cast<char*>(buf));
|
||||
pp.Canonicalize(xmlResult);
|
||||
|
||||
// XMLをパースしてタイトルリストを取得する
|
||||
nn::fnd::IAllocator* pAllocator = nn::init::GetAllocator();
|
||||
nn::xml::simple::SimpleXmlParser simpleXmlParser(pAllocator);
|
||||
simpleXmlParser.parse(reinterpret_cast<u8*>(const_cast<char*>(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<char*>(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 */
|
||||
@ -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 <nn.h>
|
||||
|
||||
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_ */
|
||||
Loading…
Reference in New Issue
Block a user