wudd/source/WUD/NUSDataProviderWUD.cpp

85 lines
3.4 KiB
C++
Raw Normal View History

2021-10-09 00:58:55 +02:00
/****************************************************************************
* Copyright (C) 2016-2021 Maschell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "NUSDataProviderWUD.h"
NUSDataProviderWUD::NUSDataProviderWUD(const std::shared_ptr<WiiUGMPartition> &pGamePartition, const std::shared_ptr<DiscReader> &pDiscReader) {
2021-10-09 00:58:55 +02:00
gamePartition = pGamePartition;
2022-07-26 08:16:27 +02:00
discReader = pDiscReader;
2021-10-09 00:58:55 +02:00
}
2021-10-11 22:43:04 +02:00
NUSDataProviderWUD::~NUSDataProviderWUD() = default;
2021-10-09 00:58:55 +02:00
bool NUSDataProviderWUD::readRawContent(const std::shared_ptr<Content> &content, uint8_t *buffer, uint64_t offset, uint32_t size) {
2021-10-09 00:58:55 +02:00
if (buffer == nullptr) {
return false;
}
auto offsetInWUDOpt = getOffsetInWUD(content);
if (!offsetInWUDOpt.has_value()) {
return false;
}
auto offsetInWUD = offsetInWUDOpt.value() + offset;
2021-10-09 00:58:55 +02:00
return discReader->readEncrypted(buffer, offsetInWUD, size);
}
bool NUSDataProviderWUD::getContentH3Hash(const std::shared_ptr<Content> &content, std::vector<uint8_t> &out_data) {
2021-10-09 00:58:55 +02:00
auto cur = gamePartition->getVolumes().begin()->second->h3HashArrayList[content->index];
if (cur == nullptr || cur->size == 0) {
return false;
}
out_data.resize(cur->size);
memcpy(out_data.data(), cur->data, cur->size);
2021-10-09 00:58:55 +02:00
return true;
}
void NUSDataProviderWUD::setFST(const std::shared_ptr<FST> &pFST) {
2021-10-09 00:58:55 +02:00
// We need to set the correct blocksizes
auto blockSize = gamePartition->getVolumes().begin()->second->blockSize;
2022-07-26 08:16:27 +02:00
for (const auto &e : pFST->sectionEntries->getSections()) {
2021-10-09 00:58:55 +02:00
e->address = AddressInVolumeBlocks(blockSize, e->address.value);
2022-07-26 08:16:27 +02:00
e->size = SizeInVolumeBlocks(blockSize, e->size.value);
2021-10-09 00:58:55 +02:00
}
fst = pFST;
}
bool NUSDataProviderWUD::getRawCert(std::vector<uint8_t> &out_data) {
out_data = gamePartition->rawCert;
2021-10-09 00:58:55 +02:00
return true;
}
bool NUSDataProviderWUD::getRawTicket(std::vector<uint8_t> &out_data) {
out_data = gamePartition->rawTicket;
2021-10-09 00:58:55 +02:00
return true;
}
bool NUSDataProviderWUD::getRawTMD(std::vector<uint8_t> &out_data) {
out_data = gamePartition->rawTMD;
2021-10-09 00:58:55 +02:00
return true;
}
std::optional<uint64_t> NUSDataProviderWUD::getOffsetInWUD(const std::shared_ptr<Content> &content) const {
2021-10-09 00:58:55 +02:00
if (content->index == 0) { // Index 0 is the FST which is at the beginning of the partition;
auto vh = gamePartition->getVolumes().begin()->second;
2021-10-09 00:58:55 +02:00
return gamePartition->getSectionOffsetOnDefaultPartition() + vh->FSTAddress.getAddressInBytes();
}
auto info = FSTUtils::getSectionEntryForIndex(fst, content->index);
if (!info.has_value()) {
DEBUG_FUNCTION_LINE("Failed to get section for Content");
return {};
2021-10-09 00:58:55 +02:00
}
return gamePartition->getSectionOffsetOnDefaultPartition() + info.value()->address.getAddressInBytes();
2021-10-09 00:58:55 +02:00
}