ctr_Repair/trunk/BoxyardEraser/VersionDetect.cpp
N2614 5eb2259845 BOXYARD消去用ツールのプロトタイプ
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@179 385bec56-5757-e545-9c3a-d8741f4650f1
2011-04-06 08:00:08 +00:00

125 lines
4.0 KiB
C++

/*---------------------------------------------------------------------------*
Project: Horizon
File: VersionDetect.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 <nn.h>
#include <nn/fs.h>
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
#include "VersionDetect.h"
#include "HeapManager.h"
namespace common
{
nn::Result GetCupVersion(nn::pl::CTR::CardUpdateVersion* cup, nn::cfg::CTR::CfgRegionCode region)
{
nn::Result result;
const size_t BUF_SIZE = 1024;
u8 buf[BUF_SIZE];
// CUPバージョン
{
result = nn::fs::MountContent("cver:", nn::fs::MEDIA_TYPE_NAND, common::cCupVerId[region], 0, 1, 1, buf,
BUF_SIZE);
NN_UTIL_RETURN_IF_FAILED(result);
nn::fs::FileInputStream fis;
result = fis.TryInitialize(L"cver:/version.bin");
NN_UTIL_RETURN_IF_FAILED(result);
if (result.IsSuccess())
{
s64 fileSize = fis.GetSize();
NN_LOG("version.bin size = %lld\n", fileSize);
s32 ret;
void* addr = NULL;
addr = common::HeapManager::GetHeap()->Allocate(fileSize);
if (addr != NULL)
{
result = fis.TryRead(&ret, addr, fileSize);
NN_UTIL_RETURN_IF_FAILED(result);
if (result.IsSuccess())
{
nn::pl::CTR::CardUpdateVersion* ver_buf = reinterpret_cast<nn::pl::CTR::CardUpdateVersion*> (addr);
std::memcpy(cup, ver_buf, sizeof(nn::pl::CTR::CardUpdateVersion));
}
common::HeapManager::GetHeap()->Free(addr);
}
}
fis.Finalize();
nn::fs::Unmount("cver:");
}
return result;
}
nn::Result GetNupVersion(nn::pl::CTR::NetworkUpdateVersion* nup, nn::cfg::CTR::CfgRegionCode region)
{
nn::Result result;
const size_t BUF_SIZE = 1024;
u8 buf[BUF_SIZE];
// NUPバージョン
{
result = nn::fs::MountContent("nver:", nn::fs::MEDIA_TYPE_NAND, common::cNupVerId[region], 0, 1, 1, buf,
BUF_SIZE);
NN_UTIL_RETURN_IF_FAILED(result);
nn::fs::FileInputStream fis;
result = fis.TryInitialize(L"nver:/version.bin");
NN_UTIL_RETURN_IF_FAILED(result);
if (result.IsSuccess())
{
s64 fileSize = fis.GetSize();
NN_LOG("version.bin size = %lld\n", fileSize);
s32 ret;
void* addr = NULL;
addr = common::HeapManager::GetHeap()->Allocate(fileSize);
if (addr != NULL)
{
result = fis.TryRead(&ret, addr, fileSize);
NN_UTIL_RETURN_IF_FAILED(result);
if (result.IsSuccess())
{
nn::pl::CTR::NetworkUpdateVersion* ver_buf =
reinterpret_cast<nn::pl::CTR::NetworkUpdateVersion*> (addr);
std::memcpy(nup, ver_buf, sizeof(nn::pl::CTR::NetworkUpdateVersion));
}
common::HeapManager::GetHeap()->Free(addr);
}
}
fis.Finalize();
nn::fs::Unmount("nver:");
}
return result;
}
nn::Result GetSystemVersion(common::VerDef* mVerData, nn::cfg::CTR::CfgRegionCode region)
{
nn::Result result;
result = GetCupVersion(&mVerData->cup, region);
NN_UTIL_RETURN_IF_FAILED(result);
result = GetNupVersion(&mVerData->nup, region);
NN_UTIL_RETURN_IF_FAILED(result);
}
}