Format the code via clang-format

This commit is contained in:
Maschell 2022-07-26 08:16:27 +02:00
parent 8d0f3825f6
commit 990c67d481
109 changed files with 643 additions and 608 deletions

67
.clang-format Normal file
View File

@ -0,0 +1,67 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 8
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never

View File

@ -6,9 +6,16 @@ on:
- main - main
jobs: jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
build-binary: build-binary:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
needs: clang-format
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Checkout submodules using a PAT - name: Checkout submodules using a PAT

View File

@ -3,8 +3,16 @@ name: CI-PR
on: [pull_request] on: [pull_request]
jobs: jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
build-binary: build-binary:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
needs: clang-format
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Checkout submodules using a PAT - name: Checkout submodules using a PAT

View File

@ -28,11 +28,15 @@ It's possible to use a docker image for building. This way you don't need anythi
``` ```
# Build docker image (only needed once) # Build docker image (only needed once)
docker build . -t WUDD-builder docker build . -t wudd-builder
# make # make
docker run -it --rm -v ${PWD}:/project WUDD-builder make docker run -it --rm -v ${PWD}:/project wudd-builder make
# make clean # make clean
docker run -it --rm -v ${PWD}:/project WUDD-builder make clean docker run -it --rm -v ${PWD}:/project wudd-builder make clean
``` ```
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i`

View File

@ -1,8 +1,9 @@
#pragma once #pragma once
#include "input/Input.h"
#include <utils/WiiUScreen.h> #include "utils/ScreenUtils.h"
#include <utils/ScreenUtils.h> #include "utils/WiiUScreen.h"
#include <stdint.h>
class ApplicationState { class ApplicationState {
public: public:

View File

@ -14,22 +14,22 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include "GMPartitionsDumperState.h"
#include <WUD/DiscReaderDiscDrive.h>
#include <WUD/NUSTitle.h>
#include <WUD/content/partitions/WiiUGMPartition.h>
#include <WUD/header/WiiUDiscHeader.h>
#include <common/common.h> #include <common/common.h>
#include <fs/FSUtils.h>
#include <iosuhax.h> #include <iosuhax.h>
#include <memory> #include <memory>
#include <WUD/DiscReaderDiscDrive.h>
#include <WUD/header/WiiUDiscHeader.h>
#include <fs/FSUtils.h>
#include <WUD/content/partitions/WiiUGMPartition.h>
#include <WUD/NUSTitle.h>
#include "GMPartitionsDumperState.h"
#include <utils/StringTools.h> #include <utils/StringTools.h>
#define READ_BUFFER_SIZE (SECTOR_SIZE * 128) #define READ_BUFFER_SIZE (SECTOR_SIZE * 128)
GMPartitionsDumperState::GMPartitionsDumperState(eDumpTarget pTargetDevice) : targetDevice(pTargetDevice) { GMPartitionsDumperState::GMPartitionsDumperState(eDumpTarget pTargetDevice) : targetDevice(pTargetDevice) {
this->sectorBufSize = SECTOR_SIZE; this->sectorBufSize = SECTOR_SIZE;
this->state = STATE_OPEN_ODD1; this->state = STATE_OPEN_ODD1;
} }
GMPartitionsDumperState::~GMPartitionsDumperState() { GMPartitionsDumperState::~GMPartitionsDumperState() {
@ -72,9 +72,9 @@ void GMPartitionsDumperState::render() {
WiiUScreen::drawLine("This disc has no dumpable GM partitions "); WiiUScreen::drawLine("This disc has no dumpable GM partitions ");
} else { } else {
uint32_t index = 0; uint32_t index = 0;
for (auto &partitionPair: gmPartitionPairs) { for (auto &partitionPair : gmPartitionPairs) {
uint32_t size = 0; uint32_t size = 0;
for (auto &content: partitionPair.second->tmd->contentList) { for (auto &content : partitionPair.second->tmd->contentList) {
size += ROUNDUP(content->encryptedFileSize, 16); size += ROUNDUP(content->encryptedFileSize, 16);
} }
WiiUScreen::drawLinef("%s %s (~%0.2f MiB)", index == (uint32_t) selectedOptionY ? ">" : " ", partitionPair.first->getVolumeId().c_str(), (float) size / 1024.0f / 1024.0f); WiiUScreen::drawLinef("%s %s (~%0.2f MiB)", index == (uint32_t) selectedOptionY ? ">" : " ", partitionPair.first->getVolumeId().c_str(), (float) size / 1024.0f / 1024.0f);
@ -98,10 +98,10 @@ void GMPartitionsDumperState::render() {
WiiUScreen::drawLine("Dumping Partition"); WiiUScreen::drawLine("Dumping Partition");
} }
uint64_t partitionSize = 0; uint64_t partitionSize = 0;
uint64_t partitionOffset = curOffsetInContent; uint64_t partitionOffset = curOffsetInContent;
if (curNUSTitle != nullptr) { if (curNUSTitle != nullptr) {
for (auto &content: curNUSTitle->tmd->contentList) { for (auto &content : curNUSTitle->tmd->contentList) {
partitionSize += ROUNDUP(content->encryptedFileSize, 16); partitionSize += ROUNDUP(content->encryptedFileSize, 16);
if (content->index < curContentIndex) { if (content->index < curContentIndex) {
partitionOffset += ROUNDUP(content->encryptedFileSize, 16); partitionOffset += ROUNDUP(content->encryptedFileSize, 16);
@ -122,7 +122,7 @@ void GMPartitionsDumperState::render() {
} }
auto offset = curOffsetInContent; auto offset = curOffsetInContent;
auto size = curContent != nullptr ? ROUNDUP(curContent->encryptedFileSize, 16) : 0; auto size = curContent != nullptr ? ROUNDUP(curContent->encryptedFileSize, 16) : 0;
if (size > 0) { if (size > 0) {
WiiUScreen::drawLinef("Progress: %.2f MiB / %.2f MiB (%0.2f%%)", offset / 1024.0f / 1024.0f, WiiUScreen::drawLinef("Progress: %.2f MiB / %.2f MiB (%0.2f%%)", offset / 1024.0f / 1024.0f,
@ -205,10 +205,10 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
return SUBSTATE_RUNNING; return SUBSTATE_RUNNING;
} }
this->discHeader = std::move(discHeaderOpt.value()); this->discHeader = std::move(discHeaderOpt.value());
this->state = STATE_PROCESS_GM_PARTITIONS; this->state = STATE_PROCESS_GM_PARTITIONS;
} else if (this->state == STATE_PROCESS_GM_PARTITIONS) { } else if (this->state == STATE_PROCESS_GM_PARTITIONS) {
this->gmPartitionPairs.clear(); this->gmPartitionPairs.clear();
for (auto &partition: discHeader->wiiUContentsInformation->partitions->partitions) { for (auto &partition : discHeader->wiiUContentsInformation->partitions->partitions) {
auto gmPartition = std::dynamic_pointer_cast<WiiUGMPartition>(partition); auto gmPartition = std::dynamic_pointer_cast<WiiUGMPartition>(partition);
if (gmPartition != nullptr) { if (gmPartition != nullptr) {
auto nusTitleOpt = NUSTitle::loadTitleFromGMPartition(gmPartition, discReader, cKey); auto nusTitleOpt = NUSTitle::loadTitleFromGMPartition(gmPartition, discReader, cKey);
@ -235,7 +235,7 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
auto gmPartitionPair = gmPartitionPairs[selectedOptionY]; auto gmPartitionPair = gmPartitionPairs[selectedOptionY];
if (gmPartitionPair.first != nullptr) { if (gmPartitionPair.first != nullptr) {
this->curPartition = gmPartitionPair.first; this->curPartition = gmPartitionPair.first;
this->curNUSTitle = gmPartitionPair.second; this->curNUSTitle = gmPartitionPair.second;
this->dataProvider = this->curNUSTitle->dataProcessor->getDataProvider(); this->dataProvider = this->curNUSTitle->dataProcessor->getDataProvider();
} else { } else {
DEBUG_FUNCTION_LINE("Failed to find a GM partition"); DEBUG_FUNCTION_LINE("Failed to find a GM partition");
@ -290,7 +290,7 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
return SUBSTATE_RUNNING; return SUBSTATE_RUNNING;
} }
this->curContentIndex = 0; this->curContentIndex = 0;
this->state = STATE_DUMP_PARTITION_CONTENTS; this->state = STATE_DUMP_PARTITION_CONTENTS;
} else if (this->state == STATE_DUMP_PARTITION_CONTENTS) { } else if (this->state == STATE_DUMP_PARTITION_CONTENTS) {
// Get current content by index. // Get current content by index.
if (curContent == nullptr) { if (curContent == nullptr) {
@ -386,13 +386,13 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
} }
void GMPartitionsDumperState::setError(GMPartitionsDumperState::eErrorState err) { void GMPartitionsDumperState::setError(GMPartitionsDumperState::eErrorState err) {
this->state = STATE_ERROR; this->state = STATE_ERROR;
this->errorState = err; this->errorState = err;
//OSEnableHomeButtonMenu(true); //OSEnableHomeButtonMenu(true);
} }
std::string GMPartitionsDumperState::getPathForDevice(eDumpTarget target) const { std::string GMPartitionsDumperState::getPathForDevice(eDumpTarget target) const {
if (target == TARGET_NTFS){ if (target == TARGET_NTFS) {
return "ntfs0:/"; return "ntfs0:/";
} }
return "fs:/vol/external01/"; return "fs:/vol/external01/";
@ -504,5 +504,3 @@ std::string GMPartitionsDumperState::ErrorDescription() const {
} }
return "UNKNOWN_ERROR"; return "UNKNOWN_ERROR";
} }

View File

@ -16,17 +16,18 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "ApplicationState.h"
#include "common/common.h"
#include "fs/WUXFileWriter.h"
#include "fs/WriteOnlyFileWithCache.h"
#include <WUD/NUSTitle.h>
#include <WUD/entities/TMD/Content.h>
#include <WUD/header/WiiUDiscHeader.h>
#include <input/Input.h>
#include <map> #include <map>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
#include <input/Input.h>
#include "ApplicationState.h"
#include "fs/WriteOnlyFileWithCache.h"
#include "fs/WUXFileWriter.h"
#include <WUD/entities/TMD/Content.h>
#include <WUD/NUSTitle.h>
#include <WUD/header/WiiUDiscHeader.h>
class GMPartitionsDumperState : public ApplicationState { class GMPartitionsDumperState : public ApplicationState {
public: public:
@ -88,22 +89,22 @@ public:
std::array<uint8_t, 11> discId{}; std::array<uint8_t, 11> discId{};
std::array<uint8_t, 0x10> cKey{}; std::array<uint8_t, 0x10> cKey{};
int32_t oddFd = -1; int32_t oddFd = -1;
void *sectorBuf = nullptr; void *sectorBuf = nullptr;
uint32_t sectorBufSize; uint32_t sectorBufSize;
std::shared_ptr<DiscReaderDiscDrive> discReader = nullptr; std::shared_ptr<DiscReaderDiscDrive> discReader = nullptr;
std::unique_ptr<WiiUDiscHeader> discHeader = nullptr; std::unique_ptr<WiiUDiscHeader> discHeader = nullptr;
std::shared_ptr<WiiUGMPartition> curPartition = nullptr; std::shared_ptr<WiiUGMPartition> curPartition = nullptr;
std::shared_ptr<NUSDataProvider> dataProvider = nullptr; std::shared_ptr<NUSDataProvider> dataProvider = nullptr;
std::string targetPath; std::string targetPath;
std::shared_ptr<NUSTitle> curNUSTitle = nullptr; std::shared_ptr<NUSTitle> curNUSTitle = nullptr;
uint16_t curContentIndex = 0; uint16_t curContentIndex = 0;
std::unique_ptr<CFile> contentFile = nullptr; std::unique_ptr<CFile> contentFile = nullptr;
std::shared_ptr<Content> curContent = nullptr; std::shared_ptr<Content> curContent = nullptr;
uint8_t *readBuffer = nullptr; uint8_t *readBuffer = nullptr;
uint32_t curOffsetInContent = 0; uint32_t curOffsetInContent = 0;
[[nodiscard]] std::string ErrorMessage() const; [[nodiscard]] std::string ErrorMessage() const;

View File

@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include "MainApplicationState.h" #include "MainApplicationState.h"
#include "WUDDumperState.h"
#include "GMPartitionsDumperState.h" #include "GMPartitionsDumperState.h"
#include "WUDDumperState.h"
#include <sysapp/launch.h> #include <sysapp/launch.h>
MainApplicationState::MainApplicationState() { MainApplicationState::MainApplicationState() {
@ -24,7 +24,8 @@ MainApplicationState::MainApplicationState() {
this->state = STATE_WELCOME_SCREEN; this->state = STATE_WELCOME_SCREEN;
} }
MainApplicationState::~MainApplicationState() = default;; MainApplicationState::~MainApplicationState() = default;
;
void MainApplicationState::render() { void MainApplicationState::render() {
if (this->state == STATE_DO_SUBSTATE) { if (this->state == STATE_DO_SUBSTATE) {
@ -73,13 +74,13 @@ ApplicationState::eSubState MainApplicationState::update(Input *input) {
} }
if (entrySelected(input)) { if (entrySelected(input)) {
if (this->selectedOptionY == 0) { if (this->selectedOptionY == 0) {
this->state = STATE_DO_SUBSTATE; this->state = STATE_DO_SUBSTATE;
this->subState = std::make_unique<WUDDumperState>(WUDDumperState::DUMP_AS_WUX, dumpTarget); this->subState = std::make_unique<WUDDumperState>(WUDDumperState::DUMP_AS_WUX, dumpTarget);
} else if (this->selectedOptionY == 1) { } else if (this->selectedOptionY == 1) {
this->state = STATE_DO_SUBSTATE; this->state = STATE_DO_SUBSTATE;
this->subState = std::make_unique<WUDDumperState>(WUDDumperState::DUMP_AS_WUD, dumpTarget); this->subState = std::make_unique<WUDDumperState>(WUDDumperState::DUMP_AS_WUD, dumpTarget);
} else if (this->selectedOptionY == 2) { } else if (this->selectedOptionY == 2) {
this->state = STATE_DO_SUBSTATE; this->state = STATE_DO_SUBSTATE;
this->subState = std::make_unique<GMPartitionsDumperState>(dumpTarget); this->subState = std::make_unique<GMPartitionsDumperState>(dumpTarget);
} else if (this->selectedOptionY == 3) { } else if (this->selectedOptionY == 3) {
// //

View File

@ -16,16 +16,16 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "ApplicationState.h"
#include "fs/CFile.hpp"
#include "input/Input.h"
#include <common/common.h>
#include <ctime>
#include <map> #include <map>
#include <memory> #include <memory>
#include <string>
#include <optional> #include <optional>
#include <queue> #include <queue>
#include <ctime> #include <string>
#include <common/common.h>
#include "input/Input.h"
#include "fs/CFile.hpp"
#include "ApplicationState.h"
class MainApplicationState : public ApplicationState { class MainApplicationState : public ApplicationState {

View File

@ -53,7 +53,6 @@ std::shared_ptr<NUSDataProvider> DefaultNUSDataProcessor::getDataProvider() {
DefaultNUSDataProcessor::DefaultNUSDataProcessor( DefaultNUSDataProcessor::DefaultNUSDataProcessor(
std::shared_ptr<NUSDataProvider> pDataProvider, std::shared_ptr<NUSDataProvider> pDataProvider,
std::shared_ptr<NUSDecryption> pNUSDecryption) : std::shared_ptr<NUSDecryption> pNUSDecryption) : dataProvider(std::move(pDataProvider)),
dataProvider(std::move(pDataProvider)), nusDecryption(std::move(pNUSDecryption)) {
nusDecryption(std::move(pNUSDecryption)) {
} }

View File

@ -16,8 +16,8 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <utils/utils.h>
#include "NUSDataProcessor.h" #include "NUSDataProcessor.h"
#include <utils/utils.h>
class DefaultNUSDataProcessor : public NUSDataProcessor { class DefaultNUSDataProcessor : public NUSDataProcessor {
public: public:

View File

@ -15,11 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <WUD/content/WiiUDiscContentsHeader.h>
#include <MainApplicationState.h> #include <MainApplicationState.h>
#include <utils/rijndael.h> #include <WUD/content/WiiUDiscContentsHeader.h>
#include <coreinit/debug.h>
#include <common/common.h> #include <common/common.h>
#include <coreinit/debug.h>
#include <utils/rijndael.h>
bool DiscReader::readDecryptedChunk(uint64_t readOffset, uint8_t *out_buffer, uint8_t *key, uint8_t *IV) const { bool DiscReader::readDecryptedChunk(uint64_t readOffset, uint8_t *out_buffer, uint8_t *key, uint8_t *IV) const {
int CHUNK_SIZE = 0x10000; int CHUNK_SIZE = 0x10000;
@ -59,9 +59,9 @@ bool DiscReader::readDecrypted(uint8_t *out_buffer, uint64_t clusterOffset, uint
int BLOCK_SIZE = 0x10000; int BLOCK_SIZE = 0x10000;
uint32_t usedSize = size; uint32_t usedSize = size;
uint64_t usedFileOffset = fileOffset; uint64_t usedFileOffset = fileOffset;
auto *buffer = (uint8_t *) malloc(BLOCK_SIZE); auto *buffer = (uint8_t *) malloc(BLOCK_SIZE);
if (buffer == nullptr) { if (buffer == nullptr) {
return false; return false;
} }
@ -92,7 +92,7 @@ bool DiscReader::readDecrypted(uint8_t *out_buffer, uint64_t clusterOffset, uint
break; break;
} }
maxCopySize = BLOCK_SIZE - blockOffset; maxCopySize = BLOCK_SIZE - blockOffset;
copySize = (usedSize > maxCopySize) ? maxCopySize : usedSize; copySize = (usedSize > maxCopySize) ? maxCopySize : usedSize;
memcpy(out_buffer + totalread, buffer + blockOffset, copySize); memcpy(out_buffer + totalread, buffer + blockOffset, copySize);
@ -133,9 +133,9 @@ bool DiscReader::readEncrypted(uint8_t *buf, uint64_t offset, uint32_t size) {
return true; return true;
} }
uint32_t missingFromPrevSector = offset % SECTOR_SIZE; uint32_t missingFromPrevSector = offset % SECTOR_SIZE;
auto curOffset = offset; auto curOffset = offset;
uint32_t offsetInBuf = 0; uint32_t offsetInBuf = 0;
uint32_t totalRead = 0; uint32_t totalRead = 0;
if (missingFromPrevSector > 0) { if (missingFromPrevSector > 0) {
auto offset_in_sectors = offset / SECTOR_SIZE; auto offset_in_sectors = offset / SECTOR_SIZE;
if (!readEncryptedSector(sector_buf, 1, offset_in_sectors)) { if (!readEncryptedSector(sector_buf, 1, offset_in_sectors)) {
@ -149,7 +149,6 @@ bool DiscReader::readEncrypted(uint8_t *buf, uint64_t offset, uint32_t size) {
totalRead += toCopy; totalRead += toCopy;
curOffset += missingFromPrevSector; curOffset += missingFromPrevSector;
offsetInBuf += missingFromPrevSector; offsetInBuf += missingFromPrevSector;
} }
if (totalRead >= size) { if (totalRead >= size) {

View File

@ -38,6 +38,7 @@ public:
uint8_t discKey[16]{}; uint8_t discKey[16]{};
bool hasDiscKey = false; bool hasDiscKey = false;
private: private:
uint8_t *sector_buf; uint8_t *sector_buf;
}; };

View File

@ -14,13 +14,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include "DiscReaderDiscDrive.h"
#include <MainApplicationState.h>
#include <WUD/content/WiiUDiscContentsHeader.h> #include <WUD/content/WiiUDiscContentsHeader.h>
#include <common/common.h> #include <common/common.h>
#include <MainApplicationState.h>
#include <iosuhax.h> #include <iosuhax.h>
#include <utils/rijndael.h>
#include <utils/logger.h> #include <utils/logger.h>
#include "DiscReaderDiscDrive.h" #include <utils/rijndael.h>
DiscReaderDiscDrive::DiscReaderDiscDrive() : DiscReader() { DiscReaderDiscDrive::DiscReaderDiscDrive() : DiscReader() {
@ -43,7 +43,7 @@ DiscReaderDiscDrive::DiscReaderDiscDrive() : DiscReader() {
auto discKeyRes = IOSUHAX_ODM_GetDiscKey(discKey); auto discKeyRes = IOSUHAX_ODM_GetDiscKey(discKey);
if (discKeyRes >= 0) { if (discKeyRes >= 0) {
hasDiscKey = true; hasDiscKey = true;
auto sector_buf_decrypted = (uint8_t *) malloc(READ_SECTOR_SIZE); auto sector_buf_decrypted = (uint8_t *) malloc(READ_SECTOR_SIZE);
if (sector_buf_decrypted != nullptr) { if (sector_buf_decrypted != nullptr) {
aes_set_key((uint8_t *) discKey); aes_set_key((uint8_t *) discKey);
@ -87,7 +87,7 @@ bool DiscReaderDiscDrive::readEncrypted(uint8_t *buf, uint64_t offset, uint32_t
if ((offset & 0x7FFF) != 0 || (size & 0x7FFF) != 0) { if ((offset & 0x7FFF) != 0 || (size & 0x7FFF) != 0) {
return DiscReader::readEncrypted(buf, offset, size); return DiscReader::readEncrypted(buf, offset, size);
} }
uint32_t block_cnt = size >> 15; uint32_t block_cnt = size >> 15;
uint32_t offset_in_sectors = offset >> 15; uint32_t offset_in_sectors = offset >> 15;
if (IOSUHAX_FSA_RawRead(gFSAfd, buf, 0x8000, block_cnt, offset_in_sectors, device_handle) < 0) { if (IOSUHAX_FSA_RawRead(gFSAfd, buf, 0x8000, block_cnt, offset_in_sectors, device_handle) < 0) {
DEBUG_FUNCTION_LINE("Failed to read from Disc"); DEBUG_FUNCTION_LINE("Failed to read from Disc");

View File

@ -16,9 +16,9 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "DiscReader.h"
#include <cstdint> #include <cstdint>
#include <optional> #include <optional>
#include "DiscReader.h"
class DiscReaderDiscDrive : public DiscReader { class DiscReaderDiscDrive : public DiscReader {
public: public:
@ -35,6 +35,6 @@ public:
bool readEncrypted(uint8_t *buf, uint64_t offset, uint32_t size) override; bool readEncrypted(uint8_t *buf, uint64_t offset, uint32_t size) override;
private: private:
bool init_done = false; bool init_done = false;
int32_t device_handle = -1; int32_t device_handle = -1;
}; };

View File

@ -16,9 +16,9 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <cstdint>
#include <WUD/entities/TMD/Content.h>
#include <WUD/entities/FST/FST.h> #include <WUD/entities/FST/FST.h>
#include <WUD/entities/TMD/Content.h>
#include <cstdint>
class NUSDataProvider { class NUSDataProvider {
@ -36,6 +36,5 @@ public:
virtual bool getRawCert(std::vector<uint8_t> &out_data) = 0; virtual bool getRawCert(std::vector<uint8_t> &out_data) = 0;
virtual void setFST(const std::shared_ptr<FST> &fst) { virtual void setFST(const std::shared_ptr<FST> &fst) {
} }
}; };

View File

@ -18,7 +18,7 @@
NUSDataProviderWUD::NUSDataProviderWUD(const std::shared_ptr<WiiUGMPartition> &pGamePartition, const std::shared_ptr<DiscReader> &pDiscReader) { NUSDataProviderWUD::NUSDataProviderWUD(const std::shared_ptr<WiiUGMPartition> &pGamePartition, const std::shared_ptr<DiscReader> &pDiscReader) {
gamePartition = pGamePartition; gamePartition = pGamePartition;
discReader = pDiscReader; discReader = pDiscReader;
} }
NUSDataProviderWUD::~NUSDataProviderWUD() = default; NUSDataProviderWUD::~NUSDataProviderWUD() = default;
@ -48,9 +48,9 @@ bool NUSDataProviderWUD::getContentH3Hash(const std::shared_ptr<Content> &conten
void NUSDataProviderWUD::setFST(const std::shared_ptr<FST> &pFST) { void NUSDataProviderWUD::setFST(const std::shared_ptr<FST> &pFST) {
// We need to set the correct blocksizes // We need to set the correct blocksizes
auto blockSize = gamePartition->getVolumes().begin()->second->blockSize; auto blockSize = gamePartition->getVolumes().begin()->second->blockSize;
for (const auto &e: pFST->sectionEntries->getSections()) { for (const auto &e : pFST->sectionEntries->getSections()) {
e->address = AddressInVolumeBlocks(blockSize, e->address.value); e->address = AddressInVolumeBlocks(blockSize, e->address.value);
e->size = SizeInVolumeBlocks(blockSize, e->size.value); e->size = SizeInVolumeBlocks(blockSize, e->size.value);
} }
fst = pFST; fst = pFST;
} }

View File

@ -16,11 +16,11 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <WUD/content/partitions/WiiUGMPartition.h>
#include "NUSDataProvider.h"
#include "DiscReader.h" #include "DiscReader.h"
#include <utils/FSTUtils.h> #include "NUSDataProvider.h"
#include <WUD/content/partitions/WiiUGMPartition.h>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <utils/FSTUtils.h>
class NUSDataProviderWUD : public NUSDataProvider { class NUSDataProviderWUD : public NUSDataProvider {

View File

@ -45,7 +45,7 @@ std::optional<std::shared_ptr<NUSTitle>> NUSTitle::loadTitle(const std::shared_p
dataBuffer.clear(); dataBuffer.clear();
auto decryption = std::make_shared<NUSDecryption>(std::move(ticketOpt.value())); auto decryption = std::make_shared<NUSDecryption>(std::move(ticketOpt.value()));
auto dpp = std::shared_ptr<NUSDataProcessor>(new DefaultNUSDataProcessor(dataProvider, decryption)); auto dpp = std::shared_ptr<NUSDataProcessor>(new DefaultNUSDataProcessor(dataProvider, decryption));
// If we have more than one content, the index 0 is the FST. // If we have more than one content, the index 0 is the FST.
auto fstContentOpt = tmdOpt.value()->getContentByIndex(0); auto fstContentOpt = tmdOpt.value()->getContentByIndex(0);
@ -78,13 +78,12 @@ NUSTitle::NUSTitle(std::shared_ptr<TitleMetaData> pTMD,
std::shared_ptr<Ticket> pTicket, std::shared_ptr<Ticket> pTicket,
std::shared_ptr<FST> pFST) : std::shared_ptr<FST> pFST) :
dataProcessor(std::move(pProcessor)), dataProcessor(std::move(pProcessor)),
tmd(std::move(pTMD)), tmd(std::move(pTMD)),
ticket(std::move(pTicket)), ticket(std::move(pTicket)),
fst(std::move(pFST)), fst(std::move(pFST)),
decryption(std::move(pDecryption)), decryption(std::move(pDecryption)),
dataProvider(std::move(pDataProvider)) { dataProvider(std::move(pDataProvider)) {
} }
std::optional<std::shared_ptr<NUSTitle>> std::optional<std::shared_ptr<NUSTitle>>

View File

@ -16,15 +16,15 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <WUD/NUSDataProvider.h>
#include <WUD/entities/TMD/TitleMetaData.h>
#include <WUD/content/partitions/WiiUGMPartition.h>
#include "Ticket.h"
#include "NUSDataProcessor.h"
#include "NUSDecryption.h"
#include "DefaultNUSDataProcessor.h" #include "DefaultNUSDataProcessor.h"
#include "DiscReaderDiscDrive.h" #include "DiscReaderDiscDrive.h"
#include "NUSDataProcessor.h"
#include "NUSDataProviderWUD.h" #include "NUSDataProviderWUD.h"
#include "NUSDecryption.h"
#include "Ticket.h"
#include <WUD/NUSDataProvider.h>
#include <WUD/content/partitions/WiiUGMPartition.h>
#include <WUD/entities/TMD/TitleMetaData.h>
class NUSTitle { class NUSTitle {
@ -52,5 +52,4 @@ private:
std::shared_ptr<NUSDecryption> pDecryption, std::shared_ptr<NUSDecryption> pDecryption,
std::shared_ptr<Ticket> pTicket, std::shared_ptr<Ticket> pTicket,
std::shared_ptr<FST> pFST); std::shared_ptr<FST> pFST);
}; };

View File

@ -18,9 +18,8 @@
#include <algorithm> #include <algorithm>
#include <utils/logger.h> #include <utils/logger.h>
Ticket::Ticket(const std::array<uint8_t, 16> &pEncryptedKey, const std::array<uint8_t, 16> &pDecryptedKey) : Ticket::Ticket(const std::array<uint8_t, 16> &pEncryptedKey, const std::array<uint8_t, 16> &pDecryptedKey) : ticketKeyEnc(pEncryptedKey),
ticketKeyEnc(pEncryptedKey), ticketKeyDec(pDecryptedKey) {
ticketKeyDec(pDecryptedKey) {
} }
std::optional<std::shared_ptr<Ticket>> Ticket::make_shared(const std::vector<uint8_t> &data, std::optional<const std::array<uint8_t, 16>> commonKey) { std::optional<std::shared_ptr<Ticket>> Ticket::make_shared(const std::vector<uint8_t> &data, std::optional<const std::array<uint8_t, 16>> commonKey) {
@ -39,7 +38,7 @@ std::optional<std::shared_ptr<Ticket>> Ticket::make_shared(const std::vector<uin
uint8_t IV[0x10]; uint8_t IV[0x10];
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
IV[i] = title_id[i]; IV[i] = title_id[i];
IV[i + 8] = 0x00; IV[i + 8] = 0x00;
} }

View File

@ -17,10 +17,10 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <utils/rijndael.h>
#include <cstring> #include <cstring>
#include <optional>
#include <memory> #include <memory>
#include <optional>
#include <utils/rijndael.h>
#include <vector> #include <vector>
class Ticket { class Ticket {

View File

@ -14,13 +14,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <coreinit/debug.h>
#include "WiiUContentsInformation.h" #include "WiiUContentsInformation.h"
#include <coreinit/debug.h>
uint32_t WiiUContentsInformation::LENGTH = 32768; uint32_t WiiUContentsInformation::LENGTH = 32768;
std::optional<std::unique_ptr<WiiUContentsInformation>> WiiUContentsInformation::make_unique(const std::shared_ptr<DiscReader> &discReader, uint32_t offset) { std::optional<std::unique_ptr<WiiUContentsInformation>> WiiUContentsInformation::make_unique(const std::shared_ptr<DiscReader> &discReader, uint32_t offset) {
uint32_t curOffset = offset; uint32_t curOffset = offset;
auto discContentHeaderOpt = WiiUDiscContentsHeader::make_unique(discReader, curOffset); auto discContentHeaderOpt = WiiUDiscContentsHeader::make_unique(discReader, curOffset);
if (!discContentHeaderOpt.has_value()) { if (!discContentHeaderOpt.has_value()) {
DEBUG_FUNCTION_LINE("Failed to read WiiUDiscContentsHeader"); DEBUG_FUNCTION_LINE("Failed to read WiiUDiscContentsHeader");
@ -47,9 +47,7 @@ std::optional<std::unique_ptr<WiiUContentsInformation>> WiiUContentsInformation:
WiiUContentsInformation::WiiUContentsInformation(std::unique_ptr<WiiUDiscContentsHeader> pDiscContentHeader, WiiUContentsInformation::WiiUContentsInformation(std::unique_ptr<WiiUDiscContentsHeader> pDiscContentHeader,
std::unique_ptr<WiiUPartitions> pPartitions) : std::unique_ptr<WiiUPartitions> pPartitions) : discContentHeader(std::move(pDiscContentHeader)),
discContentHeader(std::move(pDiscContentHeader)), partitions(std::move(pPartitions)){
partitions(std::move(pPartitions)) {
};
};

View File

@ -16,10 +16,10 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <memory>
#include <WUD/DiscReader.h>
#include "WiiUDiscContentsHeader.h" #include "WiiUDiscContentsHeader.h"
#include "partitions/WiiUPartitions.h" #include "partitions/WiiUPartitions.h"
#include <WUD/DiscReader.h>
#include <memory>
class WiiUContentsInformation { class WiiUContentsInformation {

View File

@ -14,9 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <utils/blocksize/DiscBlockSize.h>
#include <coreinit/debug.h>
#include "WiiUDiscContentsHeader.h" #include "WiiUDiscContentsHeader.h"
#include <coreinit/debug.h>
#include <utils/blocksize/DiscBlockSize.h>
std::optional<std::unique_ptr<WiiUDiscContentsHeader>> WiiUDiscContentsHeader::make_unique(const std::shared_ptr<DiscReader> &discReader, uint32_t offset) { std::optional<std::unique_ptr<WiiUDiscContentsHeader>> WiiUDiscContentsHeader::make_unique(const std::shared_ptr<DiscReader> &discReader, uint32_t offset) {
auto *buffer = (uint8_t *) malloc(LENGTH); auto *buffer = (uint8_t *) malloc(LENGTH);
@ -49,10 +49,7 @@ std::optional<std::unique_ptr<WiiUDiscContentsHeader>> WiiUDiscContentsHeader::m
return std::unique_ptr<WiiUDiscContentsHeader>(new WiiUDiscContentsHeader(blockSize, tocHash, numberOfPartition)); return std::unique_ptr<WiiUDiscContentsHeader>(new WiiUDiscContentsHeader(blockSize, tocHash, numberOfPartition));
} }
WiiUDiscContentsHeader::WiiUDiscContentsHeader(DiscBlockSize pSize, const std::array<uint8_t, 20> &pTocHash, uint32_t pNumberOfPartitions) : WiiUDiscContentsHeader::WiiUDiscContentsHeader(DiscBlockSize pSize, const std::array<uint8_t, 20> &pTocHash, uint32_t pNumberOfPartitions) : blockSize(pSize),
blockSize(pSize), numberOfPartition(pNumberOfPartitions),
numberOfPartition(pNumberOfPartitions), tocHash(pTocHash) {
tocHash(pTocHash) {
} }

View File

@ -16,11 +16,11 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <WUD/DiscReader.h>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <WUD/DiscReader.h>
#include <utils/blocksize/DiscBlockSize.h>
#include <optional> #include <optional>
#include <utils/blocksize/DiscBlockSize.h>
class WiiUDiscContentsHeader { class WiiUDiscContentsHeader {
@ -30,7 +30,7 @@ public:
std::array<uint8_t, 20> tocHash; std::array<uint8_t, 20> tocHash;
static constexpr uint32_t LENGTH = 2048; static constexpr uint32_t LENGTH = 2048;
static constexpr uint32_t MAGIC = 0xCCA6E67B; static constexpr uint32_t MAGIC = 0xCCA6E67B;
static std::optional<std::unique_ptr<WiiUDiscContentsHeader>> make_unique(const std::shared_ptr<DiscReader> &discReader, uint32_t offset); static std::optional<std::unique_ptr<WiiUDiscContentsHeader>> make_unique(const std::shared_ptr<DiscReader> &discReader, uint32_t offset);

View File

@ -22,17 +22,15 @@ WiiUDataPartition::~WiiUDataPartition() = default;
WiiUDataPartition::WiiUDataPartition( WiiUDataPartition::WiiUDataPartition(
std::shared_ptr<WiiUPartition> pPartition, std::shared_ptr<WiiUPartition> pPartition,
std::shared_ptr<FST> pFST) : std::shared_ptr<FST> pFST) : fst(std::move(pFST)),
fst(std::move(pFST)), basePartition(std::move(pPartition)) {
basePartition(std::move(pPartition)) {
} }
std::string WiiUDataPartition::getVolumeId() const &{ std::string WiiUDataPartition::getVolumeId() const & {
return basePartition->getVolumeId(); return basePartition->getVolumeId();
} }
std::map<AddressInDiscBlocks, std::shared_ptr<VolumeHeader>> WiiUDataPartition::getVolumes() const &{ std::map<AddressInDiscBlocks, std::shared_ptr<VolumeHeader>> WiiUDataPartition::getVolumes() const & {
return basePartition->getVolumes(); return basePartition->getVolumes();
} }

View File

@ -16,11 +16,11 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "WiiUPartition.h"
#include <WUD/entities/FST/FST.h>
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <WUD/entities/FST/FST.h>
#include <utils/blocksize/AddressInDiscBlocks.h> #include <utils/blocksize/AddressInDiscBlocks.h>
#include "WiiUPartition.h"
class WiiUDataPartition : public WiiUPartition { class WiiUDataPartition : public WiiUPartition {
@ -43,4 +43,3 @@ public:
private: private:
std::shared_ptr<WiiUPartition> basePartition; std::shared_ptr<WiiUPartition> basePartition;
}; };

View File

@ -20,18 +20,18 @@ WiiUGMPartition::WiiUGMPartition(std::shared_ptr<WiiUPartition> partition,
std::vector<uint8_t> pRawTicket, std::vector<uint8_t> pRawTicket,
std::vector<uint8_t> pRawTMD, std::vector<uint8_t> pRawTMD,
std::vector<uint8_t> pRawCert) std::vector<uint8_t> pRawCert)
: WiiUPartition(), : WiiUPartition(),
rawTicket(std::move(pRawTicket)), rawTicket(std::move(pRawTicket)),
rawTMD(std::move(pRawTMD)), rawTMD(std::move(pRawTMD)),
rawCert(std::move(pRawCert)), rawCert(std::move(pRawCert)),
basePartition(std::move(partition)) { basePartition(std::move(partition)) {
} }
std::string WiiUGMPartition::getVolumeId() const &{ std::string WiiUGMPartition::getVolumeId() const & {
return basePartition->getVolumeId(); return basePartition->getVolumeId();
} }
std::map<AddressInDiscBlocks, std::shared_ptr<VolumeHeader>> WiiUGMPartition::getVolumes() const &{ std::map<AddressInDiscBlocks, std::shared_ptr<VolumeHeader>> WiiUGMPartition::getVolumes() const & {
return basePartition->getVolumes(); return basePartition->getVolumes();
} }

View File

@ -16,10 +16,10 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <memory> #include "WiiUPartition.h"
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include "WiiUPartition.h" #include <memory>
class WiiUGMPartition : public WiiUPartition { class WiiUGMPartition : public WiiUPartition {
public: public:
@ -43,4 +43,3 @@ public:
private: private:
std::shared_ptr<WiiUPartition> basePartition; std::shared_ptr<WiiUPartition> basePartition;
}; };

View File

@ -14,9 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <memory>
#include <coreinit/debug.h>
#include "WiiUPartition.h" #include "WiiUPartition.h"
#include <coreinit/debug.h>
#include <memory>
uint64_t WiiUPartition::getSectionOffsetOnDefaultPartition() { uint64_t WiiUPartition::getSectionOffsetOnDefaultPartition() {
if (volumes.size() != 1) { if (volumes.size() != 1) {
@ -52,14 +52,14 @@ std::optional<std::shared_ptr<WiiUPartition>> WiiUPartition::make_shared(const s
memset(name, 0, sizeof(name)); memset(name, 0, sizeof(name));
memcpy(name, buffer, 31); memcpy(name, buffer, 31);
auto volumeId = name; auto volumeId = name;
uint8_t num = buffer[31]; uint8_t num = buffer[31];
std::map<AddressInDiscBlocks, std::shared_ptr<VolumeHeader>> volumes; std::map<AddressInDiscBlocks, std::shared_ptr<VolumeHeader>> volumes;
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
auto address = *((uint32_t *) &buffer[32 + (i * 4)]); auto address = *((uint32_t *) &buffer[32 + (i * 4)]);
AddressInDiscBlocks discLbaAddress = AddressInDiscBlocks(blockSize, address); AddressInDiscBlocks discLbaAddress = AddressInDiscBlocks(blockSize, address);
auto vh = VolumeHeader::make_shared(discReader, discLbaAddress.getAddressInBytes()); auto vh = VolumeHeader::make_shared(discReader, discLbaAddress.getAddressInBytes());
if (!vh.has_value()) { if (!vh.has_value()) {
free(buffer); free(buffer);
return {}; return {};
@ -77,11 +77,11 @@ std::optional<std::shared_ptr<WiiUPartition>> WiiUPartition::make_shared(const s
fileSystemDescriptor)); fileSystemDescriptor));
} }
std::string WiiUPartition::getVolumeId() const &{ std::string WiiUPartition::getVolumeId() const & {
return volumeId; return volumeId;
} }
std::map<AddressInDiscBlocks, std::shared_ptr<VolumeHeader>> WiiUPartition::getVolumes() const &{ std::map<AddressInDiscBlocks, std::shared_ptr<VolumeHeader>> WiiUPartition::getVolumes() const & {
return volumes; return volumes;
} }
@ -90,7 +90,3 @@ uint16_t WiiUPartition::getFileSystemDescriptor() const {
} }
WiiUPartition::~WiiUPartition() = default; WiiUPartition::~WiiUPartition() = default;

View File

@ -16,11 +16,12 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <map>
#include <utility>
#include <utils/blocksize/DiscBlockSize.h>
#include <utils/blocksize/AddressInDiscBlocks.h>
#include "volumes/VolumeHeader.h" #include "volumes/VolumeHeader.h"
#include <map>
#include <memory>
#include <utility>
#include <utils/blocksize/AddressInDiscBlocks.h>
#include <utils/blocksize/DiscBlockSize.h>
class WiiUPartition { class WiiUPartition {
@ -44,7 +45,7 @@ protected:
private: private:
WiiUPartition(char *pVolumeId, std::map<AddressInDiscBlocks, std::shared_ptr<VolumeHeader>> pVolumes, uint16_t pFileSystemDescriptor) WiiUPartition(char *pVolumeId, std::map<AddressInDiscBlocks, std::shared_ptr<VolumeHeader>> pVolumes, uint16_t pFileSystemDescriptor)
: volumeId(pVolumeId), volumes(std::move(pVolumes)), fileSystemDescriptor(pFileSystemDescriptor) { : volumeId(pVolumeId), volumes(std::move(pVolumes)), fileSystemDescriptor(pFileSystemDescriptor) {
} }
std::string volumeId; std::string volumeId;

View File

@ -14,13 +14,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <utils/FSTUtils.h>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <utils/FSTUtils.h>
#include <utility>
#include "WiiUPartitions.h"
#include "WiiUGMPartition.h"
#include "WiiUDataPartition.h" #include "WiiUDataPartition.h"
#include "WiiUGMPartition.h"
#include "WiiUPartitions.h"
#include <utility>
bool WiiUPartitions::getFSTEntryAsByte(std::string &filePath, bool WiiUPartitions::getFSTEntryAsByte(std::string &filePath,
const std::shared_ptr<FST> &fst, const std::shared_ptr<FST> &fst,
@ -37,7 +37,7 @@ bool WiiUPartitions::getFSTEntryAsByte(std::string &filePath,
return false; return false;
} }
auto info = asFileEntry->getSectionEntry(); auto info = asFileEntry->getSectionEntry();
uint64_t sectionOffsetOnDisc = volumeAddress.getAddressInBytes() + info->address.getAddressInBytes(); uint64_t sectionOffsetOnDisc = volumeAddress.getAddressInBytes() + info->address.getAddressInBytes();
out_data.resize(asFileEntry->getSize()); out_data.resize(asFileEntry->getSize());
@ -70,7 +70,7 @@ WiiUPartitions::make_unique(const std::shared_ptr<DiscReader> &discReader, uint3
tmp.push_back(partitionOpt.value()); tmp.push_back(partitionOpt.value());
} }
std::optional<std::shared_ptr<WiiUPartition>> SIPartition; std::optional<std::shared_ptr<WiiUPartition>> SIPartition;
for (auto &partition: tmp) { for (auto &partition : tmp) {
if (partition->getVolumeId().starts_with("SI")) { if (partition->getVolumeId().starts_with("SI")) {
SIPartition = partition; SIPartition = partition;
break; break;
@ -78,10 +78,10 @@ WiiUPartitions::make_unique(const std::shared_ptr<DiscReader> &discReader, uint3
} }
if (SIPartition.has_value()) { if (SIPartition.has_value()) {
for (auto const&[key, val]: SIPartition.value()->getVolumes()) { for (auto const &[key, val] : SIPartition.value()->getVolumes()) {
auto volumeAddress = key; auto volumeAddress = key;
auto volumeAddressInBytes = volumeAddress.getAddressInBytes(); auto volumeAddressInBytes = volumeAddress.getAddressInBytes();
auto volumeHeader = val; auto volumeHeader = val;
std::vector<uint8_t> fstData; std::vector<uint8_t> fstData;
fstData.resize(volumeHeader->FSTSize); fstData.resize(volumeHeader->FSTSize);
@ -106,7 +106,7 @@ WiiUPartitions::make_unique(const std::shared_ptr<DiscReader> &discReader, uint3
return {}; return {};
} }
for (auto &child: siFST.value()->getRootEntry()->getDirChildren()) { for (auto &child : siFST.value()->getRootEntry()->getDirChildren()) {
std::vector<uint8_t> bufferTicket; std::vector<uint8_t> bufferTicket;
std::string tikFilePath = std::string(child->getFullPath() + '/' + WUD_TICKET_FILENAME); std::string tikFilePath = std::string(child->getFullPath() + '/' + WUD_TICKET_FILENAME);
if (!getFSTEntryAsByte(tikFilePath, siFST.value(), volumeAddress, discReader, bufferTicket)) { if (!getFSTEntryAsByte(tikFilePath, siFST.value(), volumeAddress, discReader, bufferTicket)) {
@ -135,7 +135,7 @@ WiiUPartitions::make_unique(const std::shared_ptr<DiscReader> &discReader, uint3
std::string partitionName = std::string("GM") + partitionNameRaw; std::string partitionName = std::string("GM") + partitionNameRaw;
std::optional<std::shared_ptr<WiiUPartition>> curPartition; std::optional<std::shared_ptr<WiiUPartition>> curPartition;
for (auto &partition: tmp) { for (auto &partition : tmp) {
if (partition->getVolumeId().starts_with(partitionName)) { if (partition->getVolumeId().starts_with(partitionName)) {
curPartition = partition; curPartition = partition;
break; break;
@ -151,10 +151,9 @@ WiiUPartitions::make_unique(const std::shared_ptr<DiscReader> &discReader, uint3
partitions.push_back(gmPartition); partitions.push_back(gmPartition);
} }
} }
} }
for (auto &partition: tmp) { for (auto &partition : tmp) {
if (partition->getVolumeId().starts_with("GM")) { if (partition->getVolumeId().starts_with("GM")) {
continue; continue;
} }
@ -162,7 +161,7 @@ WiiUPartitions::make_unique(const std::shared_ptr<DiscReader> &discReader, uint3
OSFatal("We can't handle more or less than one partion address yet."); OSFatal("We can't handle more or less than one partion address yet.");
} }
auto volumeAddress = partition->getVolumes().begin()->first; auto volumeAddress = partition->getVolumes().begin()->first;
auto vh = partition->getVolumes().begin()->second; auto vh = partition->getVolumes().begin()->second;
std::vector<uint8_t> fstData; std::vector<uint8_t> fstData;
fstData.resize(vh->FSTSize); fstData.resize(vh->FSTSize);
@ -190,4 +189,3 @@ WiiUPartitions::make_unique(const std::shared_ptr<DiscReader> &discReader, uint3
WiiUPartitions::WiiUPartitions(std::vector<std::shared_ptr<WiiUPartition>> pPartitions) : partitions(std::move(pPartitions)) { WiiUPartitions::WiiUPartitions(std::vector<std::shared_ptr<WiiUPartition>> pPartitions) : partitions(std::move(pPartitions)) {
} }

View File

@ -16,17 +16,17 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <memory>
#include <cstdint>
#include <utils/blocksize/DiscBlockSize.h>
#include <utils/blocksize/AddressInDiscBlocks.h>
#include <WUD/entities/FST/FST.h>
#include <WUD/DiscReader.h>
#include "WiiUPartition.h" #include "WiiUPartition.h"
#include <WUD/DiscReader.h>
#include <WUD/entities/FST/FST.h>
#include <cstdint>
#include <memory>
#include <utils/blocksize/AddressInDiscBlocks.h>
#include <utils/blocksize/DiscBlockSize.h>
#define WUD_TMD_FILENAME "title.tmd" #define WUD_TMD_FILENAME "title.tmd"
#define WUD_TICKET_FILENAME "title.tik" #define WUD_TICKET_FILENAME "title.tik"
#define WUD_CERT_FILENAME "title.cert" #define WUD_CERT_FILENAME "title.cert"
class WiiUPartitions { class WiiUPartitions {

View File

@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include "H3HashArray.h" #include "H3HashArray.h"
#include <cstring>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <cstring>
H3HashArray::H3HashArray(uint8_t *pData, uint32_t pSize) { H3HashArray::H3HashArray(uint8_t *pData, uint32_t pSize) {
size = pSize; size = pSize;

View File

@ -15,12 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <memory>
#include "VolumeHeader.h" #include "VolumeHeader.h"
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <memory>
#include <utils/logger.h> #include <utils/logger.h>
uint32_t VolumeHeader::MAGIC = 0xCC93A4F5; uint32_t VolumeHeader::MAGIC = 0xCC93A4F5;
std::vector<std::shared_ptr<H3HashArray>> VolumeHeader::getH3HashArray(uint8_t *h3Data, uint32_t pNumberOfH3HashArray, uint32_t pH3HashArrayListSize) { std::vector<std::shared_ptr<H3HashArray>> VolumeHeader::getH3HashArray(uint8_t *h3Data, uint32_t pNumberOfH3HashArray, uint32_t pH3HashArrayListSize) {
std::vector<std::shared_ptr<H3HashArray>> arrayList; std::vector<std::shared_ptr<H3HashArray>> arrayList;
@ -29,9 +29,9 @@ std::vector<std::shared_ptr<H3HashArray>> VolumeHeader::getH3HashArray(uint8_t *
} }
for (uint32_t i = 1; i < pNumberOfH3HashArray; i++) { for (uint32_t i = 1; i < pNumberOfH3HashArray; i++) {
auto *offsetPtr = (uint32_t *) &h3Data[i * 4]; auto *offsetPtr = (uint32_t *) &h3Data[i * 4];
uint32_t curOffset = offsetPtr[0]; uint32_t curOffset = offsetPtr[0];
uint32_t curEnd = pH3HashArrayListSize; uint32_t curEnd = pH3HashArrayListSize;
if (i < pNumberOfH3HashArray - 1) { if (i < pNumberOfH3HashArray - 1) {
// If it's not the last element, the end of our .h3 is the start of the next .h3 // If it's not the last element, the end of our .h3 is the start of the next .h3
curEnd = offsetPtr[1]; curEnd = offsetPtr[1];
@ -64,16 +64,16 @@ std::optional<std::shared_ptr<VolumeHeader>> VolumeHeader::make_shared(const std
return {}; return {};
} }
auto blockSize = VolumeBlockSize(bufferUint[1]); auto blockSize = VolumeBlockSize(bufferUint[1]);
auto volumeSize = SizeInVolumeBlocks(blockSize, bufferUint[2]); auto volumeSize = SizeInVolumeBlocks(blockSize, bufferUint[2]);
auto h3HashArrayListSize = bufferUint[3]; auto h3HashArrayListSize = bufferUint[3];
auto numberOfH3HashArray = bufferUint[4]; auto numberOfH3HashArray = bufferUint[4];
auto FSTSize = bufferUint[5]; auto FSTSize = bufferUint[5];
auto FSTAddress = AddressInVolumeBlocks(blockSize, bufferUint[6]); auto FSTAddress = AddressInVolumeBlocks(blockSize, bufferUint[6]);
auto FSTHashMode = buffer[36]; auto FSTHashMode = buffer[36];
auto encryptType = buffer[37]; auto encryptType = buffer[37];
auto majorVersion = buffer[38]; auto majorVersion = buffer[38];
auto minorVersion = buffer[39]; auto minorVersion = buffer[39];
auto expiringMajorVersion = buffer[40]; auto expiringMajorVersion = buffer[40];
free(buffer); free(buffer);
@ -123,5 +123,3 @@ VolumeHeader::VolumeHeader(const VolumeBlockSize &pBlockSize,
h3HashArrayListSize(pH3HashArrayListSize), h3HashArrayListSize(pH3HashArrayListSize),
numberOfH3HashArray(pNumberOfH3HashArray) { numberOfH3HashArray(pNumberOfH3HashArray) {
} }

View File

@ -16,16 +16,17 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <utility> #include "H3HashArray.h"
#include <vector>
#include <cstdint>
#include <WUD/DiscReader.h> #include <WUD/DiscReader.h>
#include <utils/blocksize/VolumeBlockSize.h> #include <cstdint>
#include <memory>
#include <optional>
#include <utility>
#include <utils/blocksize/AddressInVolumeBlocks.h> #include <utils/blocksize/AddressInVolumeBlocks.h>
#include <utils/blocksize/SizeInVolumeBlocks.h> #include <utils/blocksize/SizeInVolumeBlocks.h>
#include <optional> #include <utils/blocksize/VolumeBlockSize.h>
#include <utils/utils.h> #include <utils/utils.h>
#include "H3HashArray.h" #include <vector>
class VolumeHeader { class VolumeHeader {
@ -63,5 +64,4 @@ private:
std::vector<std::shared_ptr<H3HashArray>> pH3HashArrayList, std::vector<std::shared_ptr<H3HashArray>> pH3HashArrayList,
uint32_t pH3HashArrayListSize, uint32_t pH3HashArrayListSize,
uint32_t pNumberOfH3HashArray); uint32_t pNumberOfH3HashArray);
}; };

View File

@ -85,10 +85,8 @@ std::optional<std::shared_ptr<FST>> FST::make_shared(const std::vector<uint8_t>
FST::FST(std::unique_ptr<FSTHeader> pHeader, FST::FST(std::unique_ptr<FSTHeader> pHeader,
std::shared_ptr<SectionEntries> pSectionEntries, std::shared_ptr<SectionEntries> pSectionEntries,
std::shared_ptr<StringTable> pStringTable, std::shared_ptr<StringTable> pStringTable,
std::unique_ptr<NodeEntries> pNodeEntries) : std::unique_ptr<NodeEntries> pNodeEntries) : sectionEntries(std::move(pSectionEntries)),
sectionEntries(std::move(pSectionEntries)), stringTable(std::move(pStringTable)),
stringTable(std::move(pStringTable)), nodeEntries(std::move(pNodeEntries)),
nodeEntries(std::move(pNodeEntries)), header(std::move(pHeader)) {
header(std::move(pHeader)) {
} }

View File

@ -16,15 +16,15 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <optional>
#include <memory>
#include <cstdint>
#include <utility>
#include <WUD/entities/FST/header/FSTHeader.h> #include <WUD/entities/FST/header/FSTHeader.h>
#include <WUD/entities/FST/sectionentry/SectionEntries.h>
#include <WUD/entities/FST/stringtable/StringTable.h>
#include <WUD/entities/FST/nodeentry/NodeEntries.h> #include <WUD/entities/FST/nodeentry/NodeEntries.h>
#include <WUD/entities/FST/nodeentry/RootEntry.h> #include <WUD/entities/FST/nodeentry/RootEntry.h>
#include <WUD/entities/FST/sectionentry/SectionEntries.h>
#include <WUD/entities/FST/stringtable/StringTable.h>
#include <cstdint>
#include <memory>
#include <optional>
#include <utility>
class FST { class FST {
public: public:
@ -33,12 +33,12 @@ public:
static std::optional<std::shared_ptr<FST>> make_shared(const std::vector<uint8_t> &data, uint32_t offset, const VolumeBlockSize &blockSize); static std::optional<std::shared_ptr<FST>> make_shared(const std::vector<uint8_t> &data, uint32_t offset, const VolumeBlockSize &blockSize);
std::shared_ptr<SectionEntries> sectionEntries; std::shared_ptr<SectionEntries> sectionEntries;
private: private:
FST(std::unique_ptr<FSTHeader> pHeader, FST(std::unique_ptr<FSTHeader> pHeader,
std::shared_ptr<SectionEntries> pSectionEntries, std::shared_ptr<SectionEntries> pSectionEntries,
std::shared_ptr<StringTable> pStringTable, std::shared_ptr<StringTable> pStringTable,
std::unique_ptr<NodeEntries> pNodeEntries std::unique_ptr<NodeEntries> pNodeEntries);
);
std::shared_ptr<StringTable> stringTable; std::shared_ptr<StringTable> stringTable;
std::unique_ptr<NodeEntries> nodeEntries; std::unique_ptr<NodeEntries> nodeEntries;

View File

@ -14,9 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include "FSTHeader.h"
#include <utils/blocksize/SectionBlockSize.h> #include <utils/blocksize/SectionBlockSize.h>
#include <utils/logger.h> #include <utils/logger.h>
#include "FSTHeader.h"
std::optional<std::unique_ptr<FSTHeader>> FSTHeader::make_unique(const std::array<uint8_t, FSTHeader::LENGTH> &data) { std::optional<std::unique_ptr<FSTHeader>> FSTHeader::make_unique(const std::array<uint8_t, FSTHeader::LENGTH> &data) {
auto *dataAsUint = (uint32_t *) data.data(); auto *dataAsUint = (uint32_t *) data.data();
@ -24,22 +24,20 @@ std::optional<std::unique_ptr<FSTHeader>> FSTHeader::make_unique(const std::arra
DEBUG_FUNCTION_LINE("FST Header magic was wrong"); DEBUG_FUNCTION_LINE("FST Header magic was wrong");
return {}; return {};
} }
auto FSTVersion = data[3]; auto FSTVersion = data[3];
auto blockSize = SectionBlockSize(dataAsUint[1]); auto blockSize = SectionBlockSize(dataAsUint[1]);
auto numberOfSections = dataAsUint[2]; auto numberOfSections = dataAsUint[2];
auto hashDisabled = data[12]; auto hashDisabled = data[12];
return std::unique_ptr<FSTHeader>(new FSTHeader( return std::unique_ptr<FSTHeader>(new FSTHeader(
FSTVersion, FSTVersion,
blockSize, blockSize,
numberOfSections, numberOfSections,
hashDisabled hashDisabled));
));
} }
FSTHeader::FSTHeader(uint8_t pFSTVersion, SectionBlockSize pBlockSize, uint32_t pNumberOfSections, uint8_t pHashDisabled) : FSTVersion(pFSTVersion), FSTHeader::FSTHeader(uint8_t pFSTVersion, SectionBlockSize pBlockSize, uint32_t pNumberOfSections, uint8_t pHashDisabled) : FSTVersion(pFSTVersion),
blockSize(pBlockSize), blockSize(pBlockSize),
numberOfSections(pNumberOfSections), numberOfSections(pNumberOfSections),
hashDisabled(pHashDisabled) { hashDisabled(pHashDisabled) {
} }

View File

@ -16,9 +16,9 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <optional>
#include <memory>
#include <cstdint> #include <cstdint>
#include <memory>
#include <optional>
#include <utils/blocksize/SectionBlockSize.h> #include <utils/blocksize/SectionBlockSize.h>
class FSTHeader { class FSTHeader {
@ -35,5 +35,4 @@ public:
private: private:
FSTHeader(uint8_t pFSTVersion, SectionBlockSize pBlockSize, uint32_t pNumberOfSections, uint8_t pHashDisabled); FSTHeader(uint8_t pFSTVersion, SectionBlockSize pBlockSize, uint32_t pNumberOfSections, uint8_t pHashDisabled);
}; };

View File

@ -14,15 +14,15 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <coreinit/debug.h>
#include "DirectoryEntry.h" #include "DirectoryEntry.h"
#include <coreinit/debug.h>
std::optional<std::shared_ptr<DirectoryEntry>> std::optional<std::shared_ptr<DirectoryEntry>>
DirectoryEntry::parseData(const std::array<uint8_t, NodeEntry::LENGTH> &data, const NodeEntryParam &param, const std::shared_ptr<SectionEntries> &sectionEntries, DirectoryEntry::parseData(const std::array<uint8_t, NodeEntry::LENGTH> &data, const NodeEntryParam &param, const std::shared_ptr<SectionEntries> &sectionEntries,
const std::shared_ptr<StringTable> &stringTable) { const std::shared_ptr<StringTable> &stringTable) {
auto parentEntryNumber = ((uint32_t *) &data[4])[0]; auto parentEntryNumber = ((uint32_t *) &data[4])[0];
auto lastEntryNumber = ((uint32_t *) &data[8])[0]; auto lastEntryNumber = ((uint32_t *) &data[8])[0];
auto stringNameOpt = stringTable->getStringEntry(param.uint24); auto stringNameOpt = stringTable->getStringEntry(param.uint24);
if (!stringNameOpt.has_value()) { if (!stringNameOpt.has_value()) {
DEBUG_FUNCTION_LINE("Failed to get string name"); DEBUG_FUNCTION_LINE("Failed to get string name");
return {}; return {};
@ -40,7 +40,7 @@ DirectoryEntry::parseData(const std::array<uint8_t, NodeEntry::LENGTH> &data, co
std::vector<std::shared_ptr<DirectoryEntry>> DirectoryEntry::getDirChildren() const { std::vector<std::shared_ptr<DirectoryEntry>> DirectoryEntry::getDirChildren() const {
std::vector<std::shared_ptr<DirectoryEntry>> res; std::vector<std::shared_ptr<DirectoryEntry>> res;
for (auto &cur: children) { for (auto &cur : children) {
if (cur->isDirectory()) { if (cur->isDirectory()) {
res.push_back(std::dynamic_pointer_cast<DirectoryEntry>(cur)); res.push_back(std::dynamic_pointer_cast<DirectoryEntry>(cur));
} }
@ -50,7 +50,7 @@ std::vector<std::shared_ptr<DirectoryEntry>> DirectoryEntry::getDirChildren() co
std::vector<std::shared_ptr<FileEntry>> DirectoryEntry::getFileChildren() const { std::vector<std::shared_ptr<FileEntry>> DirectoryEntry::getFileChildren() const {
std::vector<std::shared_ptr<FileEntry>> res; std::vector<std::shared_ptr<FileEntry>> res;
for (auto &cur: children) { for (auto &cur : children) {
if (cur->isFile()) { if (cur->isFile()) {
res.push_back(std::dynamic_pointer_cast<FileEntry>(cur)); res.push_back(std::dynamic_pointer_cast<FileEntry>(cur));
} }
@ -64,7 +64,7 @@ std::vector<std::shared_ptr<NodeEntry>> DirectoryEntry::getChildren() const {
void DirectoryEntry::printPathRecursive() { void DirectoryEntry::printPathRecursive() {
DEBUG_FUNCTION_LINE("%s", getFullPath().c_str()); DEBUG_FUNCTION_LINE("%s", getFullPath().c_str());
for (auto &child: children) { for (auto &child : children) {
child->printPathRecursive(); child->printPathRecursive();
} }
} }
@ -77,25 +77,22 @@ DirectoryEntry::DirectoryEntry(const NodeEntryParam &param,
const std::shared_ptr<StringEntry> &pStringEntry, const std::shared_ptr<StringEntry> &pStringEntry,
const std::shared_ptr<SectionEntry> &pSectionEntry, const std::shared_ptr<SectionEntry> &pSectionEntry,
uint32_t pParentEntryNumber, uint32_t pParentEntryNumber,
uint32_t pLastEntryNumber) : uint32_t pLastEntryNumber) : NodeEntry(param.permission,
NodeEntry(param.permission, pStringEntry,
pStringEntry, pSectionEntry,
pSectionEntry, param.parent,
param.parent, param.type,
param.type, param.entryNumber),
param.entryNumber), parentEntryNumber(pParentEntryNumber),
parentEntryNumber(pParentEntryNumber), lastEntryNumber(pLastEntryNumber) {
lastEntryNumber(pLastEntryNumber) {
} }
DirectoryEntry::DirectoryEntry(const std::shared_ptr<DirectoryEntry> &input) : DirectoryEntry::DirectoryEntry(const std::shared_ptr<DirectoryEntry> &input) : NodeEntry(input->permission,
NodeEntry(input->permission, input->nameString,
input->nameString, input->sectionEntry,
input->sectionEntry, input->parent,
input->parent, input->entryType,
input->entryType, input->entryNumber),
input->entryNumber), parentEntryNumber(input->parentEntryNumber),
parentEntryNumber(input->parentEntryNumber), lastEntryNumber(input->lastEntryNumber) {
lastEntryNumber(input->lastEntryNumber) {
} }

View File

@ -16,11 +16,11 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "FileEntry.h"
#include "NodeEntry.h"
#include "NodeEntryParam.h"
#include <WUD/entities/FST/sectionentry/SectionEntries.h> #include <WUD/entities/FST/sectionentry/SectionEntries.h>
#include <WUD/entities/FST/stringtable/StringTable.h> #include <WUD/entities/FST/stringtable/StringTable.h>
#include "NodeEntryParam.h"
#include "NodeEntry.h"
#include "FileEntry.h"
class DirectoryEntry : public NodeEntry { class DirectoryEntry : public NodeEntry {
public: public:

View File

@ -27,7 +27,7 @@ FileEntry::parseData(const std::array<uint8_t, NodeEntry::LENGTH> &data,
const std::shared_ptr<SectionEntries> &sectionEntries, const std::shared_ptr<SectionEntries> &sectionEntries,
const std::shared_ptr<StringTable> &stringTable, const std::shared_ptr<StringTable> &stringTable,
const SectionBlockSize &blockSize) { const SectionBlockSize &blockSize) {
auto size = ((uint32_t *) &data[8])[0]; auto size = ((uint32_t *) &data[8])[0];
auto offset = SectionAddress(blockSize, ((uint32_t *) &data[4])[0]); auto offset = SectionAddress(blockSize, ((uint32_t *) &data[4])[0]);
auto stringNameOpt = stringTable->getStringEntry(param.uint24); auto stringNameOpt = stringTable->getStringEntry(param.uint24);
@ -61,14 +61,12 @@ FileEntry::FileEntry(
const NodeEntryParam &param, const NodeEntryParam &param,
const std::shared_ptr<StringEntry> &pStringEntry, const std::shared_ptr<StringEntry> &pStringEntry,
const std::shared_ptr<SectionEntry> &pSectionEntry, const std::shared_ptr<SectionEntry> &pSectionEntry,
uint32_t pSize, SectionAddress pAddress) : uint32_t pSize, SectionAddress pAddress) : NodeEntry(param.permission,
NodeEntry(param.permission, pStringEntry,
pStringEntry, pSectionEntry,
pSectionEntry, param.parent,
param.parent, param.type,
param.type, param.entryNumber),
param.entryNumber), address(std::move(pAddress)),
address(std::move(pAddress)), size(pSize) {
size(pSize) {
} }

View File

@ -23,7 +23,6 @@
class FileEntry : public NodeEntry { class FileEntry : public NodeEntry {
public: public:
static std::optional<std::shared_ptr<NodeEntry>> static std::optional<std::shared_ptr<NodeEntry>>
parseData(const std::array<uint8_t, NodeEntry::LENGTH> &data, parseData(const std::array<uint8_t, NodeEntry::LENGTH> &data,
const NodeEntryParam &param, const NodeEntryParam &param,

View File

@ -14,8 +14,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <coreinit/debug.h>
#include "NodeEntries.h" #include "NodeEntries.h"
#include <coreinit/debug.h>
std::optional<std::shared_ptr<NodeEntry>> NodeEntries::DeserializeImpl(const std::vector<uint8_t> &pData, std::optional<std::shared_ptr<NodeEntry>> NodeEntries::DeserializeImpl(const std::vector<uint8_t> &pData,
uint32_t pOffset, uint32_t pOffset,

View File

@ -16,15 +16,15 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <WUD/entities/FST/sectionentry/SectionEntries.h>
#include <WUD/entities/FST/stringtable/StringTable.h> #include <WUD/entities/FST/stringtable/StringTable.h>
#include <utils/blocksize/SectionBlockSize.h> #include <utils/blocksize/SectionBlockSize.h>
#include <WUD/entities/FST/sectionentry/SectionEntries.h>
#include <utility>
#include "DirectoryEntry.h" #include "DirectoryEntry.h"
#include "RootEntry.h"
#include "NodeEntry.h"
#include "NodeEntries.h" #include "NodeEntries.h"
#include "NodeEntry.h"
#include "RootEntry.h"
#include <utility>
class NodeEntries { class NodeEntries {

View File

@ -14,15 +14,15 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <utils/blocksize/SectionBlockSize.h>
#include <WUD/entities/FST/stringtable/StringTable.h>
#include <WUD/entities/FST/sectionentry/SectionEntries.h> #include <WUD/entities/FST/sectionentry/SectionEntries.h>
#include <WUD/entities/FST/stringtable/StringTable.h>
#include <utils/blocksize/SectionBlockSize.h>
#include "DirectoryEntry.h"
#include "NodeEntry.h"
#include "RootEntry.h"
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include "NodeEntry.h"
#include "DirectoryEntry.h"
#include "RootEntry.h"
std::optional<std::shared_ptr<NodeEntry>> std::optional<std::shared_ptr<NodeEntry>>
NodeEntry::AutoDeserialize(const std::vector<uint8_t> &data, NodeEntry::AutoDeserialize(const std::vector<uint8_t> &data,
@ -39,12 +39,12 @@ NodeEntry::AutoDeserialize(const std::vector<uint8_t> &data,
std::copy_n(data.begin() + (int) offset, NodeEntry::LENGTH, curEntryData.begin()); std::copy_n(data.begin() + (int) offset, NodeEntry::LENGTH, curEntryData.begin());
NodeEntryParam param{}; NodeEntryParam param{};
param.permission = ((uint16_t *) &curEntryData[12])[0]; param.permission = ((uint16_t *) &curEntryData[12])[0];
param.sectionNumber = ((uint16_t *) &curEntryData[14])[0]; param.sectionNumber = ((uint16_t *) &curEntryData[14])[0];
param.entryNumber = eEntryNumber; param.entryNumber = eEntryNumber;
param.parent = pParent; param.parent = pParent;
param.type = curEntryData[0]; param.type = curEntryData[0];
param.uint24 = ((uint32_t *) &curEntryData[0])[0] & 0x00FFFFFF; param.uint24 = ((uint32_t *) &curEntryData[0])[0] & 0x00FFFFFF;
if ((param.type & ENTRY_TYPE_Directory) == ENTRY_TYPE_Directory && param.uint24 == 0) { // Root if ((param.type & ENTRY_TYPE_Directory) == ENTRY_TYPE_Directory && param.uint24 == 0) { // Root
auto res = RootEntry::parseData(curEntryData, param, sectionEntries, stringTable); auto res = RootEntry::parseData(curEntryData, param, sectionEntries, stringTable);
@ -123,17 +123,14 @@ NodeEntry::NodeEntry(const uint16_t pPermission,
std::shared_ptr<StringEntry> pNameString, std::shared_ptr<StringEntry> pNameString,
std::shared_ptr<SectionEntry> pSectionEntry, std::shared_ptr<SectionEntry> pSectionEntry,
std::optional<std::shared_ptr<DirectoryEntry>> pParent, std::optional<std::shared_ptr<DirectoryEntry>> pParent,
const uint8_t pType, const uint32_t pEntryNumber) : const uint8_t pType, const uint32_t pEntryNumber) : permission(pPermission),
permission(pPermission), nameString(std::move(pNameString)),
nameString(std::move(pNameString)), sectionEntry(std::move(pSectionEntry)),
sectionEntry(std::move(pSectionEntry)), parent(std::move(pParent)),
parent(std::move(pParent)), entryType(pType),
entryType(pType), entryNumber(pEntryNumber) {
entryNumber(pEntryNumber) {
} }
void NodeEntry::printPathRecursive() { void NodeEntry::printPathRecursive() {
DEBUG_FUNCTION_LINE("%s", getFullPath().c_str()); DEBUG_FUNCTION_LINE("%s", getFullPath().c_str());
} }

View File

@ -16,17 +16,17 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "NodeEntryParam.h"
#include <WUD/entities/FST/sectionentry/SectionEntries.h>
#include <WUD/entities/FST/sectionentry/SectionEntry.h>
#include <WUD/entities/FST/stringtable/StringEntry.h>
#include <cstdint> #include <cstdint>
#include <utils/blocksize/SectionBlockSize.h> #include <utils/blocksize/SectionBlockSize.h>
#include <WUD/entities/FST/stringtable/StringEntry.h>
#include <WUD/entities/FST/sectionentry/SectionEntry.h>
#include <WUD/entities/FST/sectionentry/SectionEntries.h>
#include <utils/logger.h> #include <utils/logger.h>
#include "NodeEntryParam.h"
#define ENTRY_TYPE_File 0 #define ENTRY_TYPE_File 0
#define ENTRY_TYPE_Directory 1 #define ENTRY_TYPE_Directory 1
#define ENTRY_TYPE_Link 0x80 #define ENTRY_TYPE_Link 0x80
class DirectoryEntry; class DirectoryEntry;

View File

@ -17,6 +17,8 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <memory>
#include <optional>
class DirectoryEntry; class DirectoryEntry;

View File

@ -14,11 +14,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <coreinit/debug.h>
#include "RootEntry.h" #include "RootEntry.h"
#include <coreinit/debug.h>
RootEntry::RootEntry(const std::shared_ptr<DirectoryEntry> &input) : DirectoryEntry(input) { RootEntry::RootEntry(const std::shared_ptr<DirectoryEntry> &input) : DirectoryEntry(input) {
} }
uint32_t RootEntry::parseLastEntryNumber(const std::array<uint8_t, NodeEntry::LENGTH> &data) { uint32_t RootEntry::parseLastEntryNumber(const std::array<uint8_t, NodeEntry::LENGTH> &data) {
@ -26,11 +25,10 @@ uint32_t RootEntry::parseLastEntryNumber(const std::array<uint8_t, NodeEntry::LE
} }
std::optional<std::shared_ptr<NodeEntry>> std::optional<std::shared_ptr<NodeEntry>>
RootEntry::parseData RootEntry::parseData(const std::array<uint8_t, NodeEntry::LENGTH> &data,
(const std::array<uint8_t, NodeEntry::LENGTH> &data, const NodeEntryParam &param,
const NodeEntryParam &param, const std::shared_ptr<SectionEntries> &sectionEntries,
const std::shared_ptr<SectionEntries> &sectionEntries, const std::shared_ptr<StringTable> &stringTable) {
const std::shared_ptr<StringTable> &stringTable) {
auto dir = DirectoryEntry::parseData(data, param, sectionEntries, stringTable); auto dir = DirectoryEntry::parseData(data, param, sectionEntries, stringTable);
if (dir.has_value()) { if (dir.has_value()) {
if ((dir.value()->entryType & ENTRY_TYPE_Directory) != ENTRY_TYPE_Directory || dir.value()->entryNumber != 0) { if ((dir.value()->entryType & ENTRY_TYPE_Directory) != ENTRY_TYPE_Directory || dir.value()->entryNumber != 0) {

View File

@ -16,11 +16,11 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <cstdint>
#include <WUD/entities/FST/stringtable/StringTable.h>
#include <utils/blocksize/SectionBlockSize.h>
#include <WUD/entities/FST/sectionentry/SectionEntries.h>
#include "DirectoryEntry.h" #include "DirectoryEntry.h"
#include <WUD/entities/FST/sectionentry/SectionEntries.h>
#include <WUD/entities/FST/stringtable/StringTable.h>
#include <cstdint>
#include <utils/blocksize/SectionBlockSize.h>
class RootEntry : public DirectoryEntry { class RootEntry : public DirectoryEntry {

View File

@ -17,7 +17,7 @@
#include "SectionEntries.h" #include "SectionEntries.h"
std::optional<std::shared_ptr<SectionEntry>> SectionEntries::getSection(uint16_t sectionNumber) const { std::optional<std::shared_ptr<SectionEntry>> SectionEntries::getSection(uint16_t sectionNumber) const {
for (auto const &e: list) { for (auto const &e : list) {
if (e->sectionNumber == sectionNumber) { if (e->sectionNumber == sectionNumber) {
return e; return e;
} }
@ -42,15 +42,15 @@ std::optional<std::shared_ptr<SectionEntries>> SectionEntries::make_shared(const
} }
std::array<uint8_t, SectionEntry::LENGTH> sectionEntryData{}; std::array<uint8_t, SectionEntry::LENGTH> sectionEntryData{};
memcpy(sectionEntryData.data(), data.data() + (i * SectionEntry::LENGTH), SectionEntry::LENGTH); memcpy(sectionEntryData.data(), data.data() + (i * SectionEntry::LENGTH), SectionEntry::LENGTH);
list.push_back(std::make_shared<SectionEntry>(sectionEntryData, i, pBlockSize));; list.push_back(std::make_shared<SectionEntry>(sectionEntryData, i, pBlockSize));
;
} }
return std::shared_ptr<SectionEntries>(new SectionEntries(list)); return std::shared_ptr<SectionEntries>(new SectionEntries(list));
} }
std::vector<std::shared_ptr<SectionEntry>> SectionEntries::getSections() const &{ std::vector<std::shared_ptr<SectionEntry>> SectionEntries::getSections() const & {
return list; return list;
} }
SectionEntries::SectionEntries(std::vector<std::shared_ptr<SectionEntry>> pList) : list(std::move(pList)) { SectionEntries::SectionEntries(std::vector<std::shared_ptr<SectionEntry>> pList) : list(std::move(pList)) {
} }

View File

@ -16,14 +16,14 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <optional> #include "SectionEntry.h"
#include <memory>
#include <cstdint> #include <cstdint>
#include <memory>
#include <optional>
#include <utility> #include <utility>
#include <vector>
#include <utils/blocksize/VolumeBlockSize.h> #include <utils/blocksize/VolumeBlockSize.h>
#include <utils/logger.h> #include <utils/logger.h>
#include "SectionEntry.h" #include <vector>
class SectionEntries { class SectionEntries {

View File

@ -18,15 +18,15 @@
SectionEntry::SectionEntry(const std::array<uint8_t, SectionEntry::LENGTH> &data, uint32_t pSectionNumber, const VolumeBlockSize &pBlockSize) { SectionEntry::SectionEntry(const std::array<uint8_t, SectionEntry::LENGTH> &data, uint32_t pSectionNumber, const VolumeBlockSize &pBlockSize) {
auto *dataAsUint = (uint32_t *) data.data(); auto *dataAsUint = (uint32_t *) data.data();
address = AddressInVolumeBlocks(pBlockSize, dataAsUint[0]); address = AddressInVolumeBlocks(pBlockSize, dataAsUint[0]);
size = SizeInVolumeBlocks(pBlockSize, dataAsUint[1]); size = SizeInVolumeBlocks(pBlockSize, dataAsUint[1]);
ownerID = ((uint64_t *) (&data[8]))[0]; ownerID = ((uint64_t *) (&data[8]))[0];
groupID = ((uint64_t *) (&data[16]))[0]; groupID = ((uint64_t *) (&data[16]))[0];
hashMode = data[20]; hashMode = data[20];
char buff[32]; char buff[32];
snprintf(buff, sizeof(buff), "Section: %d", pSectionNumber); snprintf(buff, sizeof(buff), "Section: %d", pSectionNumber);
name = std::string(buff); name = std::string(buff);
sectionNumber = pSectionNumber; sectionNumber = pSectionNumber;
} }

View File

@ -16,9 +16,9 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <array>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <array>
#include <utils/blocksize/AddressInVolumeBlocks.h> #include <utils/blocksize/AddressInVolumeBlocks.h>
#include <utils/blocksize/SizeInVolumeBlocks.h> #include <utils/blocksize/SizeInVolumeBlocks.h>

View File

@ -16,9 +16,9 @@
****************************************************************************/ ****************************************************************************/
#include "StringEntry.h" #include "StringEntry.h"
#include "StringTable.h"
#include <utility> #include <utility>
#include <utils/logger.h> #include <utils/logger.h>
#include "StringTable.h"
std::optional<std::string> StringEntry::toString() const { std::optional<std::string> StringEntry::toString() const {
return stringTable->getByAddress(offset); return stringTable->getByAddress(offset);

View File

@ -17,9 +17,9 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <string>
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <string>
class StringTable; class StringTable;

View File

@ -14,10 +14,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <cstring>
#include <coreinit/debug.h>
#include <utils/logger.h>
#include "StringTable.h" #include "StringTable.h"
#include <coreinit/debug.h>
#include <cstring>
#include <utils/logger.h>
std::optional<std::shared_ptr<StringTable>> StringTable::make_shared(const std::vector<uint8_t> &data, uint32_t offset, uint32_t stringCount) { std::optional<std::shared_ptr<StringTable>> StringTable::make_shared(const std::vector<uint8_t> &data, uint32_t offset, uint32_t stringCount) {
@ -25,7 +25,7 @@ std::optional<std::shared_ptr<StringTable>> StringTable::make_shared(const std::
DEBUG_FUNCTION_LINE("Invalid offset for reading StringTable"); DEBUG_FUNCTION_LINE("Invalid offset for reading StringTable");
return {}; return {};
} }
auto stringTable = std::shared_ptr<StringTable>(new StringTable()); auto stringTable = std::shared_ptr<StringTable>(new StringTable());
uint32_t curOffset = 0; uint32_t curOffset = 0;
uint32_t i; uint32_t i;
for (i = 0; curOffset < data.size() && i < stringCount; ++curOffset) { for (i = 0; curOffset < data.size() && i < stringCount; ++curOffset) {
@ -41,9 +41,9 @@ std::optional<std::shared_ptr<StringTable>> StringTable::make_shared(const std::
uint32_t curLength = 0; uint32_t curLength = 0;
for (i = 0; i < stringCount; ++i) { for (i = 0; i < stringCount; ++i) {
curOffset = offset + curLength; curOffset = offset + curLength;
stringTable->stringMap[curLength] = std::make_shared<StringEntry>(stringTable, curLength); stringTable->stringMap[curLength] = std::make_shared<StringEntry>(stringTable, curLength);
stringTable->strings[curLength] = (char *) &data[curOffset]; stringTable->strings[curLength] = (char *) &data[curOffset];
curLength += strlen((char *) &data[curOffset]) + 1; curLength += strlen((char *) &data[curOffset]) + 1;
} }
@ -67,14 +67,14 @@ std::optional<std::shared_ptr<StringEntry>> StringTable::getStringEntry(uint32_t
uint32_t StringTable::getSize() { uint32_t StringTable::getSize() {
uint32_t capacity = 1; // root entry uint32_t capacity = 1; // root entry
for (auto &cur: strings) { for (auto &cur : strings) {
capacity += cur.second.length() + 1; capacity += cur.second.length() + 1;
} }
return capacity; return capacity;
} }
std::optional<std::shared_ptr<StringEntry>> StringTable::getEntry(std::string &str) { std::optional<std::shared_ptr<StringEntry>> StringTable::getEntry(std::string &str) {
for (auto &cur: strings) { for (auto &cur : strings) {
if (cur.second == str) { if (cur.second == str) {
return stringMap[cur.first]; return stringMap[cur.first];
} }

View File

@ -16,12 +16,12 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <optional>
#include <memory>
#include <vector>
#include <string>
#include <map>
#include "StringEntry.h" #include "StringEntry.h"
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>
class StringTable { class StringTable {

View File

@ -14,21 +14,20 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <cstring>
#include "Content.h" #include "Content.h"
#include <cstring>
Content::Content(uint32_t pId, uint16_t pIndex, uint16_t pType, uint64_t pEncryptedFileSize, const std::array<uint8_t, 0x14> &pHash) : Content::Content(uint32_t pId, uint16_t pIndex, uint16_t pType, uint64_t pEncryptedFileSize, const std::array<uint8_t, 0x14> &pHash) : ID(pId),
ID(pId), index(pIndex),
index(pIndex), type(pType),
type(pType), encryptedFileSize(pEncryptedFileSize),
encryptedFileSize(pEncryptedFileSize), hash(pHash) {
hash(pHash) {
} }
std::optional<std::shared_ptr<Content>> Content::make_shared(const std::array<uint8_t, 0x30> &data) { std::optional<std::shared_ptr<Content>> Content::make_shared(const std::array<uint8_t, 0x30> &data) {
auto id = ((uint32_t *) &data[0x00])[0]; auto id = ((uint32_t *) &data[0x00])[0];
auto index = ((uint16_t *) &data[0x04])[0]; auto index = ((uint16_t *) &data[0x04])[0];
auto type = ((uint16_t *) &data[0x06])[0]; auto type = ((uint16_t *) &data[0x06])[0];
auto encryptedFileSize = ((uint64_t *) &data[0x08])[0]; auto encryptedFileSize = ((uint64_t *) &data[0x08])[0];
std::array<uint8_t, 0x14> hash{}; std::array<uint8_t, 0x14> hash{};
memcpy(hash.data(), &data[0x10], 0x14); memcpy(hash.data(), &data[0x10], 0x14);

View File

@ -17,8 +17,8 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <optional>
#include <memory> #include <memory>
#include <optional>
class Content { class Content {
public: public:

View File

@ -22,11 +22,10 @@
TitleMetaData::TitleMetaData(std::vector<std::shared_ptr<Content>> pContentList) : contentList(std::move(pContentList)) { TitleMetaData::TitleMetaData(std::vector<std::shared_ptr<Content>> pContentList) : contentList(std::move(pContentList)) {
// Get Contents // Get Contents
} }
std::optional<std::shared_ptr<Content>> TitleMetaData::getContentByIndex(uint16_t i) { std::optional<std::shared_ptr<Content>> TitleMetaData::getContentByIndex(uint16_t i) {
for (auto &content: contentList) { for (auto &content : contentList) {
if (content->index == i) { if (content->index == i) {
return content; return content;
} }

View File

@ -16,11 +16,11 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <optional>
#include <memory>
#include <cstdint>
#include <vector>
#include "Content.h" #include "Content.h"
#include <cstdint>
#include <memory>
#include <optional>
#include <vector>
class TitleMetaData { class TitleMetaData {
public: public:

View File

@ -21,10 +21,9 @@ uint32_t WiiUDiscHeader::LENGTH = 131072L;
WiiUDiscHeader::WiiUDiscHeader(std::unique_ptr<WiiUManufactorDiscId> pManufactorDiscId, WiiUDiscHeader::WiiUDiscHeader(std::unique_ptr<WiiUManufactorDiscId> pManufactorDiscId,
std::unique_ptr<WiiUDiscId> pDiscId, std::unique_ptr<WiiUDiscId> pDiscId,
std::unique_ptr<WiiUContentsInformation> pWiiUContentsInformation) : std::unique_ptr<WiiUContentsInformation> pWiiUContentsInformation) : manufactorDiscId(std::move(pManufactorDiscId)),
manufactorDiscId(std::move(pManufactorDiscId)), discId(std::move(pDiscId)),
discId(std::move(pDiscId)), wiiUContentsInformation(std::move(pWiiUContentsInformation)) {
wiiUContentsInformation(std::move(pWiiUContentsInformation)) {
} }
std::optional<std::unique_ptr<WiiUDiscHeader>> WiiUDiscHeader::make_unique(const std::shared_ptr<DiscReader> &discReader) { std::optional<std::unique_ptr<WiiUDiscHeader>> WiiUDiscHeader::make_unique(const std::shared_ptr<DiscReader> &discReader) {
@ -32,8 +31,8 @@ std::optional<std::unique_ptr<WiiUDiscHeader>> WiiUDiscHeader::make_unique(const
DEBUG_FUNCTION_LINE("DiscReader is not ready"); DEBUG_FUNCTION_LINE("DiscReader is not ready");
return {}; return {};
} }
uint32_t offset = 0; uint32_t offset = 0;
uint32_t curOffset = offset; uint32_t curOffset = offset;
auto manufactorDiscIDOpt = WiiUManufactorDiscId::make_unique(discReader); auto manufactorDiscIDOpt = WiiUManufactorDiscId::make_unique(discReader);
if (!manufactorDiscIDOpt.has_value()) { if (!manufactorDiscIDOpt.has_value()) {
DEBUG_FUNCTION_LINE("Failed to read ManufactorDiscId"); DEBUG_FUNCTION_LINE("Failed to read ManufactorDiscId");

View File

@ -16,17 +16,16 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <cstdint>
#include <WUD/DiscReader.h>
#include <WUD/content/WiiUContentsInformation.h>
#include <WUD/DiscReaderDiscDrive.h>
#include <memory>
#include "WiiUManufactorDiscId.h"
#include "WiiUDiscId.h" #include "WiiUDiscId.h"
#include "WiiUManufactorDiscId.h"
#include <WUD/DiscReader.h>
#include <WUD/DiscReaderDiscDrive.h>
#include <WUD/content/WiiUContentsInformation.h>
#include <cstdint>
#include <memory>
class WiiUDiscHeader { class WiiUDiscHeader {
public: public:
static std::optional<std::unique_ptr<WiiUDiscHeader>> make_unique(const std::shared_ptr<DiscReader> &discReader); static std::optional<std::unique_ptr<WiiUDiscHeader>> make_unique(const std::shared_ptr<DiscReader> &discReader);
std::unique_ptr<WiiUManufactorDiscId> manufactorDiscId; std::unique_ptr<WiiUManufactorDiscId> manufactorDiscId;
@ -39,6 +38,5 @@ private:
explicit WiiUDiscHeader( explicit WiiUDiscHeader(
std::unique_ptr<WiiUManufactorDiscId> pManufactorDiscId, std::unique_ptr<WiiUManufactorDiscId> pManufactorDiscId,
std::unique_ptr<WiiUDiscId> pDiscId, std::unique_ptr<WiiUDiscId> pDiscId,
std::unique_ptr<WiiUContentsInformation> pWiiUContentsInformation std::unique_ptr<WiiUContentsInformation> pWiiUContentsInformation);
);
}; };

View File

@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include "WiiUDiscId.h" #include "WiiUDiscId.h"
#include <memory>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <memory>
#include <utils/logger.h> #include <utils/logger.h>
std::optional<std::unique_ptr<WiiUDiscId>> WiiUDiscId::make_unique(const std::shared_ptr<DiscReader> &discReader, uint32_t offset) { std::optional<std::unique_ptr<WiiUDiscId>> WiiUDiscId::make_unique(const std::shared_ptr<DiscReader> &discReader, uint32_t offset) {
@ -46,9 +46,7 @@ std::optional<std::unique_ptr<WiiUDiscId>> WiiUDiscId::make_unique(const std::sh
return std::unique_ptr<WiiUDiscId>(new WiiUDiscId(minorVersion, majorVersion, footprint)); return std::unique_ptr<WiiUDiscId>(new WiiUDiscId(minorVersion, majorVersion, footprint));
} }
WiiUDiscId::WiiUDiscId(uint8_t pMinorVersion, uint8_t pMajorVersion, const std::string &pFootprint) : WiiUDiscId::WiiUDiscId(uint8_t pMinorVersion, uint8_t pMajorVersion, const std::string &pFootprint) : minorVersion(pMinorVersion),
minorVersion(pMinorVersion), majorVersion(pMajorVersion),
majorVersion(pMajorVersion), footprint(pFootprint) {
footprint(pFootprint) {
} }

View File

@ -16,17 +16,17 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <memory>
#include <string>
#include <WUD/DiscReader.h> #include <WUD/DiscReader.h>
#include <memory>
#include <optional> #include <optional>
#include <string>
#include <utility> #include <utility>
class WiiUDiscId { class WiiUDiscId {
public: public:
static constexpr uint32_t LENGTH = 32768; static constexpr uint32_t LENGTH = 32768;
static constexpr uint32_t MAGIC = 0xCC549EB9; static constexpr uint32_t MAGIC = 0xCC549EB9;
uint8_t minorVersion; uint8_t minorVersion;
uint8_t majorVersion; uint8_t majorVersion;
std::string footprint; std::string footprint;

View File

@ -16,9 +16,9 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <memory>
#include <cstdint>
#include <WUD/DiscReader.h> #include <WUD/DiscReader.h>
#include <cstdint>
#include <memory>
#include <optional> #include <optional>
class WiiUManufactorDiscId { class WiiUManufactorDiscId {

View File

@ -14,20 +14,20 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <malloc.h>
#include <utils/WiiUScreen.h>
#include <common/common.h>
#include <iosuhax.h>
#include <fs/FSUtils.h>
#include <utils/StringTools.h>
#include <utils/utils.h>
#include <WUD/content/WiiUDiscContentsHeader.h>
#include "WUDDumperState.h" #include "WUDDumperState.h"
#include <WUD/content/WiiUDiscContentsHeader.h>
#include <common/common.h>
#include <fs/FSUtils.h>
#include <iosuhax.h>
#include <malloc.h>
#include <utils/StringTools.h>
#include <utils/WiiUScreen.h>
#include <utils/utils.h>
WUDDumperState::WUDDumperState(WUDDumperState::eDumpTargetFormat pTargetFormat, eDumpTarget pTargetDevice) WUDDumperState::WUDDumperState(WUDDumperState::eDumpTargetFormat pTargetFormat, eDumpTarget pTargetDevice)
: targetFormat(pTargetFormat), targetDevice(pTargetDevice) { : targetFormat(pTargetFormat), targetDevice(pTargetDevice) {
this->sectorBufSize = READ_SECTOR_SIZE * READ_NUM_SECTORS; this->sectorBufSize = READ_SECTOR_SIZE * READ_NUM_SECTORS;
this->state = STATE_OPEN_ODD1; this->state = STATE_OPEN_ODD1;
} }
WUDDumperState::~WUDDumperState() { WUDDumperState::~WUDDumperState() {
@ -139,11 +139,11 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
this->startTime = OSGetTime(); this->startTime = OSGetTime();
this->state = STATE_DUMP_DISC; this->state = STATE_DUMP_DISC;
this->totalSectorCount = (WUD_FILE_SIZE / SECTOR_SIZE); this->totalSectorCount = (WUD_FILE_SIZE / SECTOR_SIZE);
this->currentSector = 0; this->currentSector = 0;
this->writtenSectors = 0; this->writtenSectors = 0;
this->retryCount = 10; this->retryCount = 10;
} else if (this->state == STATE_DUMP_DISC) { } else if (this->state == STATE_DUMP_DISC) {
size_t numSectors = this->currentSector + READ_NUM_SECTORS > this->totalSectorCount ? this->totalSectorCount - this->currentSector : READ_NUM_SECTORS; size_t numSectors = this->currentSector + READ_NUM_SECTORS > this->totalSectorCount ? this->totalSectorCount - this->currentSector : READ_NUM_SECTORS;
if ((this->readResult = IOSUHAX_FSA_RawRead(gFSAfd, sectorBuf, READ_SECTOR_SIZE, numSectors, this->currentSector, this->oddFd)) >= 0) { if ((this->readResult = IOSUHAX_FSA_RawRead(gFSAfd, sectorBuf, READ_SECTOR_SIZE, numSectors, this->currentSector, this->oddFd)) >= 0) {
@ -207,7 +207,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
this->writtenSectors += curWrittenSectors; this->writtenSectors += curWrittenSectors;
this->readResult = 0; this->readResult = 0;
} else if (input->data.buttons_d & Input::BUTTON_B) { } else if (input->data.buttons_d & Input::BUTTON_B) {
this->state = STATE_OPEN_ODD1; this->state = STATE_OPEN_ODD1;
this->readResult = 0; this->readResult = 0;
} else if (input->data.buttons_d & Input::BUTTON_Y) { } else if (input->data.buttons_d & Input::BUTTON_Y) {
this->autoSkipOnError = true; this->autoSkipOnError = true;
@ -264,13 +264,13 @@ void WUDDumperState::render() {
WiiUScreen::drawLine("Press A to skip this sector (will be replaced by 0's)"); WiiUScreen::drawLine("Press A to skip this sector (will be replaced by 0's)");
WiiUScreen::drawLine("Press B to try again"); WiiUScreen::drawLine("Press B to try again");
} else { } else {
OSTime curTime = OSGetTime(); OSTime curTime = OSGetTime();
float remaining = (WUD_FILE_SIZE - (READ_SECTOR_SIZE * this->currentSector)) / 1024.0f / 1024.0f; float remaining = (WUD_FILE_SIZE - (READ_SECTOR_SIZE * this->currentSector)) / 1024.0f / 1024.0f;
float curSpeed = READ_SECTOR_SIZE * ((this->currentSector / 1000.0f) / OSTicksToMilliseconds(curTime - startTime)); float curSpeed = READ_SECTOR_SIZE * ((this->currentSector / 1000.0f) / OSTicksToMilliseconds(curTime - startTime));
int32_t remainingSec = remaining / curSpeed; int32_t remainingSec = remaining / curSpeed;
int32_t minutes = (remainingSec / 60) % 60; int32_t minutes = (remainingSec / 60) % 60;
int32_t seconds = remainingSec % 60; int32_t seconds = remainingSec % 60;
int32_t hours = remainingSec / 3600; int32_t hours = remainingSec / 3600;
WiiUScreen::drawLinef("Speed: %.2f MiB/s ETA: %02dh %02dm %02ds", curSpeed, remaining, hours, minutes, seconds); WiiUScreen::drawLinef("Speed: %.2f MiB/s ETA: %02dh %02dm %02ds", curSpeed, remaining, hours, minutes, seconds);
} }
@ -288,7 +288,7 @@ void WUDDumperState::render() {
} }
void WUDDumperState::setError(WUDDumperState::eErrorState err) { void WUDDumperState::setError(WUDDumperState::eErrorState err) {
this->state = STATE_ERROR; this->state = STATE_ERROR;
this->errorState = err; this->errorState = err;
//OSEnableHomeButtonMenu(true); //OSEnableHomeButtonMenu(true);
} }

View File

@ -16,23 +16,22 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "ApplicationState.h"
#include "fs/WUXFileWriter.h"
#include "fs/WriteOnlyFileWithCache.h"
#include <common/common.h>
#include <input/Input.h>
#include <map> #include <map>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
#include <input/Input.h>
#include <common/common.h>
#include "ApplicationState.h"
#include "fs/WriteOnlyFileWithCache.h"
#include "fs/WUXFileWriter.h"
#define READ_NUM_SECTORS 128 #define READ_NUM_SECTORS 128
#define WRITE_BUFFER_NUM_SECTORS 128 #define WRITE_BUFFER_NUM_SECTORS 128
#define WUD_FILE_SIZE 0x5D3A00000L #define WUD_FILE_SIZE 0x5D3A00000L
class WUDDumperState : public ApplicationState { class WUDDumperState : public ApplicationState {
public: public:
enum eDumpTargetFormat { enum eDumpTargetFormat {
DUMP_AS_WUX, DUMP_AS_WUX,
DUMP_AS_WUD, DUMP_AS_WUD,
@ -86,7 +85,7 @@ public:
void *sectorBuf = nullptr; void *sectorBuf = nullptr;
int readResult = 0; int readResult = 0;
int oddFd = -1; int oddFd = -1;
int retryCount = 10; int retryCount = 10;
OSTime startTime{}; OSTime startTime{};
@ -109,5 +108,4 @@ public:
int32_t writtenSectors{}; int32_t writtenSectors{};
void *emptySector = nullptr; void *emptySector = nullptr;
}; };

View File

@ -5,7 +5,7 @@
extern int32_t gFSAfd; extern int32_t gFSAfd;
#define SECTOR_SIZE 0x8000 #define SECTOR_SIZE 0x8000
#define READ_SECTOR_SIZE SECTOR_SIZE #define READ_SECTOR_SIZE SECTOR_SIZE
extern ntfs_md *ntfs_mounts; extern ntfs_md *ntfs_mounts;

View File

@ -1,14 +1,14 @@
#include "CFile.hpp"
#include <cstdarg> #include <cstdarg>
#include <cstdio> #include <cstdio>
#include <strings.h> #include <strings.h>
#include <utils/logger.h> #include <utils/logger.h>
#include "CFile.hpp"
CFile::CFile() { CFile::CFile() {
iFd = -1; iFd = -1;
mem_file = nullptr; mem_file = nullptr;
filesize = 0; filesize = 0;
pos = 0; pos = 0;
} }
CFile::CFile(const std::string &filepath, eOpenTypes mode) { CFile::CFile(const std::string &filepath, eOpenTypes mode) {
@ -34,7 +34,7 @@ int32_t CFile::open(const std::string &filepath, eOpenTypes mode) {
switch (mode) { switch (mode) {
default: default:
case ReadOnly: // file must exist case ReadOnly: // file must exist
openMode = O_RDONLY; openMode = O_RDONLY;
break; break;
case WriteOnly: // file will be created / zerod case WriteOnly: // file will be created / zerod
@ -76,10 +76,10 @@ void CFile::close() {
if (iFd >= 0) if (iFd >= 0)
::close(iFd); ::close(iFd);
iFd = -1; iFd = -1;
mem_file = nullptr; mem_file = nullptr;
filesize = 0; filesize = 0;
pos = 0; pos = 0;
} }
int32_t CFile::read(uint8_t *ptr, size_t size) { int32_t CFile::read(uint8_t *ptr, size_t size) {
@ -129,7 +129,7 @@ int32_t CFile::write(const uint8_t *ptr, size_t size) {
} }
int32_t CFile::seek(int64_t offset, int32_t origin) { int32_t CFile::seek(int64_t offset, int32_t origin) {
int32_t ret = 0; int32_t ret = 0;
int64_t newPos = pos; int64_t newPos = pos;
if (origin == SEEK_SET) { if (origin == SEEK_SET) {
@ -160,7 +160,7 @@ int32_t CFile::seek(int64_t offset, int32_t origin) {
int32_t CFile::fwrite(const char *format, ...) { int32_t CFile::fwrite(const char *format, ...) {
char tmp[512]; char tmp[512];
tmp[0] = 0; tmp[0] = 0;
int32_t result = -1; int32_t result = -1;
va_list va; va_list va;
@ -173,5 +173,3 @@ int32_t CFile::fwrite(const char *format, ...) {
return result; return result;
} }

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#include <cstdio> #include <cstdio>
#include <string>
#include <cstring> #include <cstring>
#include <fcntl.h> #include <fcntl.h>
#include <string>
#include <unistd.h> #include <unistd.h>
#include <wut_types.h>
#include <utils/logger.h> #include <utils/logger.h>
#include <wut_types.h>
class CFile { class CFile {
public: public:

View File

@ -1,11 +1,11 @@
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include "FSUtils.h" #include "FSUtils.h"
#include "CFile.hpp" #include "CFile.hpp"
#include "utils/logger.h" #include "utils/logger.h"
#include <fcntl.h>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) { int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
//! always initialze input //! always initialze input
@ -27,8 +27,8 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
} }
uint32_t blocksize = 0x4000; uint32_t blocksize = 0x4000;
uint32_t done = 0; uint32_t done = 0;
int32_t readBytes = 0; int32_t readBytes = 0;
while (done < filesize) { while (done < filesize) {
if (done + blocksize > filesize) { if (done + blocksize > filesize) {
@ -136,7 +136,7 @@ bool FSUtils::copyFile(const std::string &in, const std::string &out) {
size_t size; size_t size;
int source = open(in.c_str(), O_RDONLY, 0); int source = open(in.c_str(), O_RDONLY, 0);
int dest = open(out.c_str(), 0x602, 0644); int dest = open(out.c_str(), 0x602, 0644);
if (source < 0) { if (source < 0) {
return false; return false;
} }
@ -146,7 +146,7 @@ bool FSUtils::copyFile(const std::string &in, const std::string &out) {
} }
auto bufferSize = 1024 * 1024; auto bufferSize = 1024 * 1024;
char *buf = (char *) malloc(bufferSize); char *buf = (char *) malloc(bufferSize);
if (buf == NULL) { if (buf == NULL) {
return false; return false;
} }
@ -171,4 +171,3 @@ int32_t FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size)
file.close(); file.close();
return written; return written;
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <wut_types.h>
#include <string> #include <string>
#include <wut_types.h>
class FSUtils { class FSUtils {
public: public:

View File

@ -14,12 +14,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <utils/logger.h>
#include "WUDFileWriter.h" #include "WUDFileWriter.h"
#include <utils/logger.h>
WUDFileWriter::WUDFileWriter(const char *path, int32_t cacheSize, int32_t pSectorSize, bool split) : WUDFileWriter::WUDFileWriter(const char *path, int32_t cacheSize, int32_t pSectorSize, bool split) : WriteOnlyFileWithCache(path, cacheSize, split),
WriteOnlyFileWithCache(path, cacheSize, split), sectorSize(pSectorSize) {
sectorSize(pSectorSize) {
} }
int32_t WUDFileWriter::writeSector(const uint8_t *buffer, uint32_t numberOfSectors) { int32_t WUDFileWriter::writeSector(const uint8_t *buffer, uint32_t numberOfSectors) {
@ -31,5 +30,4 @@ int32_t WUDFileWriter::writeSector(const uint8_t *buffer, uint32_t numberOfSecto
} }
void WUDFileWriter::finalize() { void WUDFileWriter::finalize() {
} }

View File

@ -25,6 +25,7 @@ public:
virtual int32_t writeSector(const uint8_t *buffer, uint32_t numberOfSectors); virtual int32_t writeSector(const uint8_t *buffer, uint32_t numberOfSectors);
virtual void finalize(); virtual void finalize();
protected: protected:
int32_t sectorSize; int32_t sectorSize;
}; };

View File

@ -14,18 +14,17 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <utils/logger.h>
#include "WUXFileWriter.h" #include "WUXFileWriter.h"
#include "WUDDumperState.h" #include "WUDDumperState.h"
#include <utils/logger.h>
WUXFileWriter::WUXFileWriter(const char *path, int32_t cacheSize, int32_t sectorSize, bool split) : WUXFileWriter::WUXFileWriter(const char *path, int32_t cacheSize, int32_t sectorSize, bool split) : WUDFileWriter(path, cacheSize, sectorSize, split) {
WUDFileWriter(path, cacheSize, sectorSize, split) { wuxHeader_t wuxHeader = {0};
wuxHeader_t wuxHeader = {0}; wuxHeader.magic0 = WUX_MAGIC_0;
wuxHeader.magic0 = WUX_MAGIC_0; wuxHeader.magic1 = WUX_MAGIC_1;
wuxHeader.magic1 = WUX_MAGIC_1; wuxHeader.sectorSize = swap_uint32(this->sectorSize);
wuxHeader.sectorSize = swap_uint32(this->sectorSize);
wuxHeader.uncompressedSize = swap_uint64(WUD_FILE_SIZE); wuxHeader.uncompressedSize = swap_uint64(WUD_FILE_SIZE);
wuxHeader.flags = 0; wuxHeader.flags = 0;
this->write((uint8_t *) &wuxHeader, sizeof(wuxHeader_t)); this->write((uint8_t *) &wuxHeader, sizeof(wuxHeader_t));
this->sectorTableStart = this->tell(); this->sectorTableStart = this->tell();
@ -45,12 +44,12 @@ WUXFileWriter::WUXFileWriter(const char *path, int32_t cacheSize, int32_t sector
} }
this->sectorTableEnd = this->tell(); this->sectorTableEnd = this->tell();
uint64_t tableEnd = this->sectorTableEnd; uint64_t tableEnd = this->sectorTableEnd;
this->sectorTableEnd += this->sectorSize - 1; this->sectorTableEnd += this->sectorSize - 1;
this->sectorTableEnd -= (this->sectorTableEnd % this->sectorSize); this->sectorTableEnd -= (this->sectorTableEnd % this->sectorSize);
uint64_t padding = this->sectorTableEnd - tableEnd; uint64_t padding = this->sectorTableEnd - tableEnd;
auto *paddingData = (uint8_t *) malloc(padding); auto *paddingData = (uint8_t *) malloc(padding);
memset(paddingData, 0, padding); memset(paddingData, 0, padding);
this->write(reinterpret_cast<const uint8_t *>(paddingData), padding); this->write(reinterpret_cast<const uint8_t *>(paddingData), padding);
@ -77,7 +76,7 @@ int32_t WUXFileWriter::writeSector(const uint8_t *buffer, uint32_t numberOfSecto
indexTable[this->currentSector] = swap_uint32(this->hashMap[hash]); indexTable[this->currentSector] = swap_uint32(this->hashMap[hash]);
} else { } else {
indexTable[this->currentSector] = swap_uint32(this->writtenSector); indexTable[this->currentSector] = swap_uint32(this->writtenSector);
hashMap[hash] = writtenSector; hashMap[hash] = writtenSector;
if (isOpen()) { if (isOpen()) {
if (!write((uint8_t *) addr, this->sectorSize)) { if (!write((uint8_t *) addr, this->sectorSize)) {
DEBUG_FUNCTION_LINE("Write failed"); DEBUG_FUNCTION_LINE("Write failed");
@ -111,5 +110,4 @@ void WUXFileWriter::finalize() {
WUDFileWriter::finalize(); WUDFileWriter::finalize();
writeSectorIndexTable(); writeSectorIndexTable();
WUXFileWriter::close(); WUXFileWriter::close();
} }

View File

@ -16,8 +16,8 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "utils/utils.h"
#include "WUDFileWriter.h" #include "WUDFileWriter.h"
#include "utils/utils.h"
#include <map> #include <map>
typedef struct { typedef struct {
@ -28,8 +28,8 @@ typedef struct {
unsigned int flags; unsigned int flags;
} wuxHeader_t; } wuxHeader_t;
#define WUX_MAGIC_0 0x57555830 #define WUX_MAGIC_0 0x57555830
#define WUX_MAGIC_1 swap_uint32(0x1099d02e) #define WUX_MAGIC_1 swap_uint32(0x1099d02e)
class WUXFileWriter : public WUDFileWriter { class WUXFileWriter : public WUDFileWriter {
public: public:

View File

@ -14,11 +14,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <malloc.h>
#include <coreinit/memory.h>
#include <utils/logger.h>
#include <utils/StringTools.h>
#include "WriteOnlyFileWithCache.h" #include "WriteOnlyFileWithCache.h"
#include <coreinit/memory.h>
#include <malloc.h>
#include <utils/StringTools.h>
#include <utils/logger.h>
#define SPLIT_SIZE (0x80000000) #define SPLIT_SIZE (0x80000000)
@ -29,7 +29,7 @@ WriteOnlyFileWithCache::WriteOnlyFileWithCache(const char *path, int32_t cacheSi
return; return;
} }
this->writeBufferSize = cacheSize; this->writeBufferSize = cacheSize;
this->writeBuffer = (void *) memalign(0x1000, this->writeBufferSize); this->writeBuffer = (void *) memalign(0x1000, this->writeBufferSize);
if (this->writeBuffer == nullptr) { if (this->writeBuffer == nullptr) {
this->close(); this->close();
return; return;
@ -55,7 +55,7 @@ bool WriteOnlyFileWithCache::flush() {
} }
int32_t WriteOnlyFileWithCache::write(const uint8_t *addr, size_t writeSize) { int32_t WriteOnlyFileWithCache::write(const uint8_t *addr, size_t writeSize) {
auto finalAddr = addr; auto finalAddr = addr;
size_t finalWriteSize = writeSize; size_t finalWriteSize = writeSize;
if (splitFile) { if (splitFile) {
if (pos + writeBufferPos + finalWriteSize >= SPLIT_SIZE) { if (pos + writeBufferPos + finalWriteSize >= SPLIT_SIZE) {
@ -73,7 +73,7 @@ int32_t WriteOnlyFileWithCache::write(const uint8_t *addr, size_t writeSize) {
} }
} }
finalWriteSize = writeSize - realWriteSize; finalWriteSize = writeSize - realWriteSize;
finalAddr = (uint8_t *) ((uint32_t) addr + realWriteSize); finalAddr = (uint8_t *) ((uint32_t) addr + realWriteSize);
part++; part++;
if (!flush()) { if (!flush()) {
return -2; return -2;

View File

@ -43,6 +43,6 @@ public:
size_t writeBufferPos; size_t writeBufferPos;
bool splitFile = false; bool splitFile = false;
int32_t part = 1; int32_t part = 1;
std::string originalPath; std::string originalPath;
}; };

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "Input.h"
class CombinedInput : public Input { class CombinedInput : public Input {
public: public:
void combine(const Input &b) { void combine(const Input &b) {

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <cstring>
#include <cstdint> #include <cstdint>
#include <cstring>
class Input { class Input {
public: public:
@ -12,36 +12,36 @@ public:
virtual ~Input() = default; virtual ~Input() = default;
enum eButtons { enum eButtons {
BUTTON_NONE = 0x0000, BUTTON_NONE = 0x0000,
VPAD_TOUCH = 0x80000000, VPAD_TOUCH = 0x80000000,
BUTTON_Z = 0x20000, BUTTON_Z = 0x20000,
BUTTON_C = 0x10000, BUTTON_C = 0x10000,
BUTTON_A = 0x8000, BUTTON_A = 0x8000,
BUTTON_B = 0x4000, BUTTON_B = 0x4000,
BUTTON_X = 0x2000, BUTTON_X = 0x2000,
BUTTON_Y = 0x1000, BUTTON_Y = 0x1000,
BUTTON_1 = BUTTON_Y, BUTTON_1 = BUTTON_Y,
BUTTON_2 = BUTTON_X, BUTTON_2 = BUTTON_X,
BUTTON_LEFT = 0x0800, BUTTON_LEFT = 0x0800,
BUTTON_RIGHT = 0x0400, BUTTON_RIGHT = 0x0400,
BUTTON_UP = 0x0200, BUTTON_UP = 0x0200,
BUTTON_DOWN = 0x0100, BUTTON_DOWN = 0x0100,
BUTTON_ZL = 0x0080, BUTTON_ZL = 0x0080,
BUTTON_ZR = 0x0040, BUTTON_ZR = 0x0040,
BUTTON_L = 0x0020, BUTTON_L = 0x0020,
BUTTON_R = 0x0010, BUTTON_R = 0x0010,
BUTTON_PLUS = 0x0008, BUTTON_PLUS = 0x0008,
BUTTON_MINUS = 0x0004, BUTTON_MINUS = 0x0004,
BUTTON_HOME = 0x0002, BUTTON_HOME = 0x0002,
BUTTON_SYNC = 0x0001, BUTTON_SYNC = 0x0001,
STICK_R_LEFT = 0x04000000, STICK_R_LEFT = 0x04000000,
STICK_R_RIGHT = 0x02000000, STICK_R_RIGHT = 0x02000000,
STICK_R_UP = 0x01000000, STICK_R_UP = 0x01000000,
STICK_R_DOWN = 0x00800000, STICK_R_DOWN = 0x00800000,
STICK_L_LEFT = 0x40000000, STICK_L_LEFT = 0x40000000,
STICK_L_RIGHT = 0x20000000, STICK_L_RIGHT = 0x20000000,
STICK_L_UP = 0x10000000, STICK_L_UP = 0x10000000,
STICK_L_DOWN = 0x08000000 STICK_L_DOWN = 0x08000000
}; };
typedef struct { typedef struct {
@ -57,5 +57,4 @@ public:
PadData data{}; PadData data{};
PadData lastData{}; PadData lastData{};
}; };

View File

@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <vpad/input.h>
#include "Input.h" #include "Input.h"
#include <vpad/input.h>
class VPadInput : public Input { class VPadInput : public Input {
public: public:
@ -36,11 +36,11 @@ public:
VPADRead(VPAD_CHAN_0, &vpad, 1, &vpadError); VPADRead(VPAD_CHAN_0, &vpad, 1, &vpadError);
if (vpadError == VPAD_READ_SUCCESS) { if (vpadError == VPAD_READ_SUCCESS) {
data.buttons_r = vpad.release; data.buttons_r = vpad.release;
data.buttons_h = vpad.hold; data.buttons_h = vpad.hold;
data.buttons_d = vpad.trigger; data.buttons_d = vpad.trigger;
data.validPointer = !vpad.tpNormal.validity; data.validPointer = !vpad.tpNormal.validity;
data.touched = vpad.tpNormal.touched; data.touched = vpad.tpNormal.touched;
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpCalib, &vpad.tpFiltered1); VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpCalib, &vpad.tpFiltered1);

View File

@ -16,9 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include "Input.h"
#include <padscore/kpad.h> #include <padscore/kpad.h>
#include <padscore/wpad.h> #include <padscore/wpad.h>
#include "Input.h"
class WPADInput : public Input { class WPADInput : public Input {
public: public:

View File

@ -1,21 +1,21 @@
#include <whb/proc.h>
#include <whb/log.h> #include <whb/log.h>
#include <whb/log_udp.h> #include <whb/log_udp.h>
#include <whb/proc.h>
#include <thread> #include <thread>
#include <iosuhax.h>
#include <ntfs.h>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <coreinit/energysaver.h> #include <coreinit/energysaver.h>
#include <padscore/kpad.h>
#include <input/WPADInput.h>
#include <input/CombinedInput.h> #include <input/CombinedInput.h>
#include <input/WPADInput.h>
#include <iosuhax.h>
#include <ntfs.h>
#include <padscore/kpad.h>
#include "utils/logger.h"
#include "utils/WiiUScreen.h"
#include "input/VPADInput.h"
#include "MainApplicationState.h" #include "MainApplicationState.h"
#include "input/VPADInput.h"
#include "utils/WiiUScreen.h"
#include "utils/logger.h"
void initIOSUHax(); void initIOSUHax();
@ -84,8 +84,7 @@ void main_loop() {
WPAD_CHAN_0, WPAD_CHAN_0,
WPAD_CHAN_1, WPAD_CHAN_1,
WPAD_CHAN_2, WPAD_CHAN_2,
WPAD_CHAN_3 WPAD_CHAN_3};
};
if (gFSAfd < 0 || !sIosuhaxMount) { if (gFSAfd < 0 || !sIosuhaxMount) {
// state.setError(MainApplicationState::eErrorState::ERROR_IOSUHAX_FAILED); // state.setError(MainApplicationState::eErrorState::ERROR_IOSUHAX_FAILED);
@ -98,8 +97,8 @@ void main_loop() {
if (vpadInput.update(1280, 720)) { if (vpadInput.update(1280, 720)) {
baseInput.combine(vpadInput); baseInput.combine(vpadInput);
} }
for (auto &wpadInput: wpadInputs) { for (auto &wpadInput : wpadInputs) {
if(wpadInput.update(1280, 720)){ if (wpadInput.update(1280, 720)) {
baseInput.combine(wpadInput); baseInput.combine(wpadInput);
} }
} }
@ -111,12 +110,12 @@ void main_loop() {
void initIOSUHax() { void initIOSUHax() {
sIosuhaxMount = false; sIosuhaxMount = false;
int res = IOSUHAX_Open(nullptr); int res = IOSUHAX_Open(nullptr);
if (res < 0) { if (res < 0) {
DEBUG_FUNCTION_LINE("IOSUHAX_open failed"); DEBUG_FUNCTION_LINE("IOSUHAX_open failed");
} else { } else {
sIosuhaxMount = true; sIosuhaxMount = true;
gFSAfd = IOSUHAX_FSA_Open(); gFSAfd = IOSUHAX_FSA_Open();
if (gFSAfd < 0) { if (gFSAfd < 0) {
DEBUG_FUNCTION_LINE("IOSUHAX_FSA_Open failed"); DEBUG_FUNCTION_LINE("IOSUHAX_FSA_Open failed");
} else { } else {

View File

@ -25,16 +25,16 @@ std::optional<std::shared_ptr<NodeEntry>> FSTUtils::getFSTEntryByFullPath(const
fullPath = "/" + fullPath; fullPath = "/" + fullPath;
} }
auto pathOpt = std::optional(root); auto pathOpt = std::optional(root);
std::filesystem::path asPath = fullPath; std::filesystem::path asPath = fullPath;
std::string dirPath = asPath.parent_path().string(); std::string dirPath = asPath.parent_path().string();
if (dirPath != "/") { if (dirPath != "/") {
pathOpt = getFileEntryDir(root, dirPath); pathOpt = getFileEntryDir(root, dirPath);
} }
if (!pathOpt.has_value()) { if (!pathOpt.has_value()) {
return {}; return {};
} }
for (auto &child: pathOpt.value()->getChildren()) { for (auto &child : pathOpt.value()->getChildren()) {
if (child->getFullPath() == fullPath) { if (child->getFullPath() == fullPath) {
return child; return child;
} }
@ -48,7 +48,7 @@ std::optional<std::shared_ptr<DirectoryEntry>> FSTUtils::getFileEntryDir(const s
if (!string.ends_with("/")) { if (!string.ends_with("/")) {
string += "/"; string += "/";
} }
for (auto &curChild: curEntry->getDirChildren()) { for (auto &curChild : curEntry->getDirChildren()) {
std::string compareTo = curChild->getFullPath(); std::string compareTo = curChild->getFullPath();
if (!compareTo.ends_with("/")) { if (!compareTo.ends_with("/")) {
compareTo += "/"; compareTo += "/";
@ -64,7 +64,7 @@ std::optional<std::shared_ptr<DirectoryEntry>> FSTUtils::getFileEntryDir(const s
} }
std::optional<std::shared_ptr<SectionEntry>> FSTUtils::getSectionEntryForIndex(const std::shared_ptr<FST> &pFst, uint16_t index) { std::optional<std::shared_ptr<SectionEntry>> FSTUtils::getSectionEntryForIndex(const std::shared_ptr<FST> &pFst, uint16_t index) {
for (const auto &entry: pFst->sectionEntries->getSections()) { for (const auto &entry : pFst->sectionEntries->getSections()) {
if (entry->sectionNumber == index) { if (entry->sectionNumber == index) {
return entry; return entry;
} }

View File

@ -16,10 +16,10 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <string>
#include <WUD/entities/FST/nodeentry/NodeEntry.h>
#include <WUD/entities/FST/nodeentry/DirectoryEntry.h>
#include <WUD/entities/FST/FST.h> #include <WUD/entities/FST/FST.h>
#include <WUD/entities/FST/nodeentry/DirectoryEntry.h>
#include <WUD/entities/FST/nodeentry/NodeEntry.h>
#include <string>
class FSTUtils { class FSTUtils {
public: public:
@ -29,4 +29,3 @@ public:
static std::optional<std::shared_ptr<SectionEntry>> getSectionEntryForIndex(const std::shared_ptr<FST> &pFst, uint16_t index); static std::optional<std::shared_ptr<SectionEntry>> getSectionEntryForIndex(const std::shared_ptr<FST> &pFst, uint16_t index);
}; };

View File

@ -14,8 +14,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <coreinit/screen.h>
#include "ScreenUtils.h" #include "ScreenUtils.h"
#include <coreinit/screen.h>
void ScreenUtils::printTextOnScreen(ConsoleScreenID screen, int x, int y, const char *msg) { void ScreenUtils::printTextOnScreen(ConsoleScreenID screen, int x, int y, const char *msg) {
if (!msg) { if (!msg) {

View File

@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <stdint.h>
//! Defines the ID of a display usable with OSScreen. //! Defines the ID of a display usable with OSScreen.
typedef enum ConsoleScreenID { typedef enum ConsoleScreenID {

View File

@ -23,17 +23,16 @@
* *
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <vector>
#include <string>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <strings.h>
#include <wut_types.h>
#include <stdio.h>
#include "StringTools.h" #include "StringTools.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <strings.h>
#include <vector>
#include <wchar.h>
#include <wut_types.h>
BOOL StringTools::EndsWith(const std::string &a, const std::string &b) { BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {
@ -85,7 +84,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
static char tmp[512]; static char tmp[512];
static wchar_t strWChar[512]; static wchar_t strWChar[512];
strWChar[0] = 0; strWChar[0] = 0;
tmp[0] = 0; tmp[0] = 0;
if (!format) if (!format)
return (const wchar_t *) strWChar; return (const wchar_t *) strWChar;
@ -98,7 +97,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
if ((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
int32_t bt; int32_t bt;
int32_t strlength = strlen(tmp); int32_t strlength = strlen(tmp);
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512); bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);
if (bt > 0) { if (bt > 0) {
strWChar[bt] = 0; strWChar[bt] = 0;
@ -112,13 +111,13 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
int32_t StringTools::strprintf(std::string &str, const char *format, ...) { int32_t StringTools::strprintf(std::string &str, const char *format, ...) {
static char tmp[512]; static char tmp[512];
tmp[0] = 0; tmp[0] = 0;
int32_t result = 0; int32_t result = 0;
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if ((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
str = tmp; str = tmp;
result = str.size(); result = str.size();
} }
va_end(va); va_end(va);
@ -214,8 +213,7 @@ bool StringTools::findStringIC(const std::string &strHaystack, const std::string
auto it = std::search( auto it = std::search(
strHaystack.begin(), strHaystack.end(), strHaystack.begin(), strHaystack.end(),
strNeedle.begin(), strNeedle.end(), strNeedle.begin(), strNeedle.end(),
[](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); } [](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); });
);
return (it != strHaystack.end()); return (it != strHaystack.end());
} }

View File

@ -25,11 +25,11 @@
***************************************************************************/ ***************************************************************************/
#pragma once #pragma once
#include <vector>
#include <string>
#include <wut_types.h>
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <string>
#include <vector>
#include <wut_types.h>
class StringTools { class StringTools {
public: public:
@ -57,7 +57,7 @@ public:
if (!path) if (!path)
return path; return path;
const char *ptr = path; const char *ptr = path;
const char *Filename = ptr; const char *Filename = ptr;
while (*ptr != '\0') { while (*ptr != '\0') {

View File

@ -1,3 +1,4 @@
// clang-format off
/* /*
* *
* TinySHA1 - a header only implementation of the SHA1 algorithm in C++. Based * TinySHA1 - a header only implementation of the SHA1 algorithm in C++. Based

View File

@ -4,13 +4,13 @@
#include <cstdarg> #include <cstdarg>
#include <cstdio> #include <cstdio>
void *WiiUScreen::sBufferTV = nullptr; void *WiiUScreen::sBufferTV = nullptr;
void *WiiUScreen::sBufferDRC = nullptr; void *WiiUScreen::sBufferDRC = nullptr;
uint32_t WiiUScreen::sBufferSizeTV = 0; uint32_t WiiUScreen::sBufferSizeTV = 0;
uint32_t WiiUScreen::sBufferSizeDRC = 0; uint32_t WiiUScreen::sBufferSizeDRC = 0;
bool WiiUScreen::sConsoleHasForeground = true; bool WiiUScreen::sConsoleHasForeground = true;
uint32_t WiiUScreen::consoleColor = 0x041F60FF; uint32_t WiiUScreen::consoleColor = 0x041F60FF;
uint32_t WiiUScreen::consoleCursorY = 0; uint32_t WiiUScreen::consoleCursorY = 0;
uint32_t WiiUScreen::ProcCallbackAcquired(void *context) { uint32_t WiiUScreen::ProcCallbackAcquired(void *context) {
@ -38,7 +38,7 @@ uint32_t WiiUScreen::ProcCallbackReleased(void *context) {
bool WiiUScreen::Init() { bool WiiUScreen::Init() {
OSScreenInit(); OSScreenInit();
sBufferSizeTV = OSScreenGetBufferSizeEx(SCREEN_TV); sBufferSizeTV = OSScreenGetBufferSizeEx(SCREEN_TV);
sBufferSizeDRC = OSScreenGetBufferSizeEx(SCREEN_DRC); sBufferSizeDRC = OSScreenGetBufferSizeEx(SCREEN_DRC);
WiiUScreen::ProcCallbackAcquired(nullptr); WiiUScreen::ProcCallbackAcquired(nullptr);

View File

@ -3,23 +3,24 @@
#include <whb/log.h> #include <whb/log.h>
#include <whb/log_console.h> #include <whb/log_console.h>
#include <coreinit/memheap.h> #include "utils/logger.h"
#include <coreinit/cache.h> #include <coreinit/cache.h>
#include <coreinit/memfrmheap.h> #include <coreinit/memfrmheap.h>
#include <coreinit/memheap.h>
#include <coreinit/memory.h> #include <coreinit/memory.h>
#include <coreinit/screen.h> #include <coreinit/screen.h>
#include <proc_ui/procui.h>
#include <cstring> #include <cstring>
#include "utils/logger.h" #include <proc_ui/procui.h>
#define NUM_LINES (16) #define NUM_LINES (16)
#define LINE_LENGTH (128) #define LINE_LENGTH (128)
#define CONSOLE_FRAME_HEAP_TAG (0x000DECAF) #define CONSOLE_FRAME_HEAP_TAG (0x000DECAF)
#define PRINTF_BUFFER_LENGTH 2048 #define PRINTF_BUFFER_LENGTH 2048
#define DEBUG_CONSOLE_LOG(FMT, ARGS...)do { \ #define DEBUG_CONSOLE_LOG(FMT, ARGS...) \
DEBUG_FUNCTION_LINE(FMT, ## ARGS); \ do { \
WiiUScreen::drawLinef(FMT, ## ARGS); \ DEBUG_FUNCTION_LINE(FMT, ##ARGS); \
WiiUScreen::drawLinef(FMT, ##ARGS); \
} while (0) } while (0)

View File

@ -16,13 +16,12 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <cstdint>
#include "BlockSize.h" #include "BlockSize.h"
#include <cstdint>
class AddressInBlocks { class AddressInBlocks {
public: public:
explicit AddressInBlocks(const BlockSize &pBlockSize, uint32_t pValue) : blockSize(pBlockSize), value(pValue) { explicit AddressInBlocks(const BlockSize &pBlockSize, uint32_t pValue) : blockSize(pBlockSize), value(pValue) {
} }
AddressInBlocks() = default; AddressInBlocks() = default;

View File

@ -38,4 +38,4 @@ namespace std {
return lhs.getAddressInBytes() < rhs.getAddressInBytes(); return lhs.getAddressInBytes() < rhs.getAddressInBytes();
} }
}; };
} } // namespace std

View File

@ -16,8 +16,8 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "VolumeBlockSize.h"
#include "AddressInBlocks.h" #include "AddressInBlocks.h"
#include "VolumeBlockSize.h"
class AddressInVolumeBlocks : public AddressInBlocks { class AddressInVolumeBlocks : public AddressInBlocks {

View File

@ -16,8 +16,8 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "utils/logger.h"
#include "BlockSize.h" #include "BlockSize.h"
#include "utils/logger.h"
class DiscBlockSize : public BlockSize { class DiscBlockSize : public BlockSize {
@ -25,6 +25,5 @@ public:
DiscBlockSize() = default; DiscBlockSize() = default;
explicit DiscBlockSize(uint32_t blockSize) : BlockSize(blockSize) { explicit DiscBlockSize(uint32_t blockSize) : BlockSize(blockSize) {
} }
}; };

Some files were not shown because too many files have changed in this diff Show More