mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
PreinstallImporterを分割
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@586 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
1632d0b788
commit
c367283c33
@ -17,7 +17,6 @@
|
|||||||
#include "HeapManager.h"
|
#include "HeapManager.h"
|
||||||
#include "PreinstallImporter.h"
|
#include "PreinstallImporter.h"
|
||||||
#include "XmlCreator.h"
|
#include "XmlCreator.h"
|
||||||
#include "BgsCommunicator.h"
|
|
||||||
#include "SimpleXmlPreprocessor.h"
|
#include "SimpleXmlPreprocessor.h"
|
||||||
#include <nn/xml/simple/xml_simple_SimpleXmlParser.h>
|
#include <nn/xml/simple/xml_simple_SimpleXmlParser.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -49,6 +48,14 @@ nn::Result PreinstallImporter::ListTitles(nn::ProgramId* list, size_t* num, bit6
|
|||||||
return comm.GetLastResult();
|
return comm.GetLastResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
GetHtmlBodyAndParseXmlData(comm, list, num)
|
||||||
|
);
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result PreinstallImporter::GetHtmlBodyAndParseXmlData(BgsCommunicator& comm, nn::ProgramId* list, size_t* num)
|
||||||
|
{
|
||||||
// 通信結果を取得する
|
// 通信結果を取得する
|
||||||
size_t bodySize;
|
size_t bodySize;
|
||||||
if(!comm.GetBodySize(&bodySize))
|
if(!comm.GetBodySize(&bodySize))
|
||||||
@ -68,6 +75,14 @@ nn::Result PreinstallImporter::ListTitles(nn::ProgramId* list, size_t* num, bit6
|
|||||||
return comm.GetLastResult();
|
return comm.GetLastResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XMLを解析してタイトルリストを設定する
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(ParseXmlData(buf, list, num));
|
||||||
|
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result PreinstallImporter::ParseXmlData(void* buf, nn::ProgramId* list, size_t* num)
|
||||||
|
{
|
||||||
// 通信結果をパースする
|
// 通信結果をパースする
|
||||||
// SimpleXmlParserに食わせるために変換する
|
// SimpleXmlParserに食わせるために変換する
|
||||||
SimpleXmlPreprocessor pp;
|
SimpleXmlPreprocessor pp;
|
||||||
@ -78,18 +93,59 @@ nn::Result PreinstallImporter::ListTitles(nn::ProgramId* list, size_t* num, bit6
|
|||||||
// XMLをパースしてタイトルリストを取得する
|
// XMLをパースしてタイトルリストを取得する
|
||||||
nn::fnd::IAllocator* pAllocator = nn::init::GetAllocator();
|
nn::fnd::IAllocator* pAllocator = nn::init::GetAllocator();
|
||||||
nn::xml::simple::SimpleXmlParser simpleXmlParser(pAllocator);
|
nn::xml::simple::SimpleXmlParser simpleXmlParser(pAllocator);
|
||||||
simpleXmlParser.parse(reinterpret_cast<u8*>(const_cast<char*>(xmlResult.c_str())), xmlResult.size());
|
const nn::xml::simple::SimpleXmlParser::Node* pTaskIdNode;
|
||||||
|
|
||||||
if(simpleXmlParser.isError())
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
SetNodetoTitleIds(simpleXmlParser, xmlResult, &pTaskIdNode)
|
||||||
|
);
|
||||||
|
|
||||||
|
// タイトルIDリストをコピーする
|
||||||
|
common::HeapManager xmlHeap(pTaskIdNode->contentSize);
|
||||||
|
void* titleIdBuffer = xmlHeap.GetAddr();
|
||||||
|
std::memcpy(titleIdBuffer, pTaskIdNode->content, pTaskIdNode->contentSize);
|
||||||
|
|
||||||
|
SplitTextAndSetupList(list, num, reinterpret_cast<char*>(titleIdBuffer));
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result PreinstallImporter::SetNodetoTitleIds(nn::xml::simple::SimpleXmlParser& parser, std::string& xmlData, const nn::xml::simple::SimpleXmlParser::Node** pNode)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* SimpleXmlPreprocessorを通したXMLデータはこんな形になっている
|
||||||
|
<Envelope>
|
||||||
|
<Body>
|
||||||
|
<GetPreInstalledInfoResponse>
|
||||||
|
<GetPreInstalledInfoResponse>
|
||||||
|
<Version></Version>
|
||||||
|
<MessageId></MessageId>
|
||||||
|
<TimeStamp>1326939225587</TimeStamp>
|
||||||
|
<ErrorCode>0</ErrorCode>
|
||||||
|
<ListResultTotalSize>1</ListResultTotalSize>
|
||||||
|
<PreinstalledInfo>
|
||||||
|
<DeviceId>17179924184</DeviceId>
|
||||||
|
<SerialNo>EJA20305940</SerialNo>
|
||||||
|
<Region>JPN</Region>
|
||||||
|
<ManufactureDate>1324339327000</ManufactureDate>
|
||||||
|
<TitleIds>000400000FEEB400,000400000FEEB000</TitleIds>
|
||||||
|
</PreinstalledInfo>
|
||||||
|
</GetPreInstalledInfoResponse>
|
||||||
|
</GetPreInstalledInfoResponse>
|
||||||
|
</Body>
|
||||||
|
</Envelope>
|
||||||
|
*/
|
||||||
|
|
||||||
|
parser.parse(reinterpret_cast<u8*>(const_cast<char*>(xmlData.c_str())), xmlData.size());
|
||||||
|
|
||||||
|
if(parser.isError())
|
||||||
{
|
{
|
||||||
COMMON_LOGGER("invalid xml Data\n");
|
COMMON_LOGGER("invalid xml Data\n");
|
||||||
return nn::Result(nn::Result::LEVEL_STATUS, nn::Result::SUMMARY_INVALID_STATE, nn::Result::MODULE_COMMON,
|
return nn::Result(nn::Result::LEVEL_STATUS, nn::Result::SUMMARY_INVALID_STATE, nn::Result::MODULE_COMMON,
|
||||||
nn::Result::DESCRIPTION_INVALID_RESULT_VALUE);
|
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* pRootNode = parser.getRootNode();
|
||||||
|
const nn::xml::simple::SimpleXmlParser::Node* pTargetNode = pRootNode->firstChild;
|
||||||
const nn::xml::simple::SimpleXmlParser::Node* pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(
|
const nn::xml::simple::SimpleXmlParser::Node* pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(
|
||||||
pTargetNode, "Body");
|
pTargetNode, "Body");
|
||||||
pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild,
|
pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild,
|
||||||
@ -98,35 +154,34 @@ nn::Result PreinstallImporter::ListTitles(nn::ProgramId* list, size_t* num, bit6
|
|||||||
"GetPreInstalledInfoResponse");
|
"GetPreInstalledInfoResponse");
|
||||||
pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild, "PreinstalledInfo");
|
pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild, "PreinstalledInfo");
|
||||||
|
|
||||||
const nn::xml::simple::SimpleXmlParser::Node* pTaskIdNode = nn::xml::simple::SimpleXmlParser::FindNextNode(
|
*pNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild, "TitleIds");
|
||||||
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();
|
return nn::ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreinstallImporter::SplitTextAndSetupList(nn::ProgramId* list, size_t* num, char* text)
|
||||||
|
{
|
||||||
|
const char* token = ",";
|
||||||
|
char* cutout;
|
||||||
|
|
||||||
|
cutout = std::strtok(text, token);
|
||||||
|
if(!cutout)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
list[*num] = std::strtoll(cutout, NULL, 16);
|
||||||
|
(*num)++;
|
||||||
|
|
||||||
|
while( cutout )
|
||||||
|
{
|
||||||
|
cutout = std::strtok(NULL, token);
|
||||||
|
if(cutout)
|
||||||
|
{
|
||||||
|
list[*num] = std::strtoll(cutout, NULL, 16);
|
||||||
|
(*num)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace ConsoleRestore */
|
} /* namespace ConsoleRestore */
|
||||||
|
|||||||
@ -17,6 +17,8 @@
|
|||||||
#define PREINSTALLIMPORTER_H_
|
#define PREINSTALLIMPORTER_H_
|
||||||
|
|
||||||
#include <nn.h>
|
#include <nn.h>
|
||||||
|
#include <nn/xml/simple/xml_simple_SimpleXmlParser.h>
|
||||||
|
#include "BgsCommunicator.h"
|
||||||
|
|
||||||
namespace ConsoleRestore
|
namespace ConsoleRestore
|
||||||
{
|
{
|
||||||
@ -34,6 +36,19 @@ public:
|
|||||||
//! @param[in] deviceId デバイスID
|
//! @param[in] deviceId デバイスID
|
||||||
//! @param[in] serialNo シリアルナンバー
|
//! @param[in] serialNo シリアルナンバー
|
||||||
nn::Result ListTitles(nn::ProgramId* list, size_t* num, bit64 deviceId, u8* serialNo);
|
nn::Result ListTitles(nn::ProgramId* list, size_t* num, bit64 deviceId, u8* serialNo);
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! @brief HTMLレスポンスを受信してXMLデータを解析します
|
||||||
|
nn::Result GetHtmlBodyAndParseXmlData(BgsCommunicator& comm, nn::ProgramId* list, size_t* num);
|
||||||
|
|
||||||
|
//! @brief 受信したXMLデータを解析してタイトルIDリストを設定します
|
||||||
|
nn::Result ParseXmlData(void* buf, nn::ProgramId* list, size_t* num);
|
||||||
|
|
||||||
|
//! @brief SimpleXmlパーサの解析をTitleIdノードまで進めます
|
||||||
|
nn::Result SetNodetoTitleIds(nn::xml::simple::SimpleXmlParser& parser, std::string& xmlData, const nn::xml::simple::SimpleXmlParser::Node** pNode);
|
||||||
|
|
||||||
|
//! @brief カンマ区切りのプログラムIDのリストを分割して出力用のリストに設定します
|
||||||
|
void SplitTextAndSetupList(nn::ProgramId* list, size_t* num, char* text);
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace ConsoleRestore */
|
} /* namespace ConsoleRestore */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user