From 990c67d481f2f9bf9b89bdb78cdb456c4df3d1cc Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 26 Jul 2022 08:16:27 +0200 Subject: [PATCH] Format the code via clang-format --- .clang-format | 67 +++++++++++++++++++ .github/workflows/ci.yml | 9 ++- .github/workflows/pr.yml | 8 +++ README.md | 12 ++-- source/ApplicationState.h | 7 +- source/GMPartitionsDumperState.cpp | 38 +++++------ source/GMPartitionsDumperState.h | 29 ++++---- source/MainApplicationState.cpp | 11 +-- source/MainApplicationState.h | 12 ++-- source/WUD/DefaultNUSDataProcessor.cpp | 5 +- source/WUD/DefaultNUSDataProcessor.h | 2 +- source/WUD/DiscReader.cpp | 19 +++--- source/WUD/DiscReader.h | 1 + source/WUD/DiscReaderDiscDrive.cpp | 10 +-- source/WUD/DiscReaderDiscDrive.h | 4 +- source/WUD/NUSDataProvider.h | 5 +- source/WUD/NUSDataProviderWUD.cpp | 6 +- source/WUD/NUSDataProviderWUD.h | 6 +- source/WUD/NUSTitle.cpp | 15 ++--- source/WUD/NUSTitle.h | 13 ++-- source/WUD/Ticket.cpp | 7 +- source/WUD/Ticket.h | 4 +- .../WUD/content/WiiUContentsInformation.cpp | 14 ++-- source/WUD/content/WiiUContentsInformation.h | 4 +- source/WUD/content/WiiUDiscContentsHeader.cpp | 13 ++-- source/WUD/content/WiiUDiscContentsHeader.h | 6 +- .../content/partitions/WiiUDataPartition.cpp | 10 ++- .../content/partitions/WiiUDataPartition.h | 5 +- .../content/partitions/WiiUGMPartition.cpp | 14 ++-- .../WUD/content/partitions/WiiUGMPartition.h | 5 +- .../WUD/content/partitions/WiiUPartition.cpp | 18 ++--- source/WUD/content/partitions/WiiUPartition.h | 11 +-- .../WUD/content/partitions/WiiUPartitions.cpp | 28 ++++---- .../WUD/content/partitions/WiiUPartitions.h | 18 ++--- .../partitions/volumes/H3HashArray.cpp | 2 +- .../partitions/volumes/VolumeHeader.cpp | 30 ++++----- .../content/partitions/volumes/VolumeHeader.h | 14 ++-- source/WUD/entities/FST/FST.cpp | 10 ++- source/WUD/entities/FST/FST.h | 16 ++--- source/WUD/entities/FST/header/FSTHeader.cpp | 12 ++-- source/WUD/entities/FST/header/FSTHeader.h | 5 +- .../entities/FST/nodeentry/DirectoryEntry.cpp | 47 ++++++------- .../entities/FST/nodeentry/DirectoryEntry.h | 6 +- .../WUD/entities/FST/nodeentry/FileEntry.cpp | 20 +++--- source/WUD/entities/FST/nodeentry/FileEntry.h | 1 - .../entities/FST/nodeentry/NodeEntries.cpp | 2 +- .../WUD/entities/FST/nodeentry/NodeEntries.h | 8 +-- .../WUD/entities/FST/nodeentry/NodeEntry.cpp | 35 +++++----- source/WUD/entities/FST/nodeentry/NodeEntry.h | 14 ++-- .../entities/FST/nodeentry/NodeEntryParam.h | 2 + .../WUD/entities/FST/nodeentry/RootEntry.cpp | 12 ++-- source/WUD/entities/FST/nodeentry/RootEntry.h | 8 +-- .../FST/sectionentry/SectionEntries.cpp | 8 +-- .../FST/sectionentry/SectionEntries.h | 8 +-- .../FST/sectionentry/SectionEntry.cpp | 10 +-- .../entities/FST/sectionentry/SectionEntry.h | 2 +- .../entities/FST/stringtable/StringEntry.cpp | 2 +- .../entities/FST/stringtable/StringEntry.h | 2 +- .../entities/FST/stringtable/StringTable.cpp | 16 ++--- .../entities/FST/stringtable/StringTable.h | 10 +-- source/WUD/entities/TMD/Content.cpp | 19 +++--- source/WUD/entities/TMD/Content.h | 2 +- source/WUD/entities/TMD/TitleMetaData.cpp | 3 +- source/WUD/entities/TMD/TitleMetaData.h | 8 +-- source/WUD/header/WiiUDiscHeader.cpp | 11 ++- source/WUD/header/WiiUDiscHeader.h | 16 ++--- source/WUD/header/WiiUDiscId.cpp | 10 ++- source/WUD/header/WiiUDiscId.h | 6 +- source/WUD/header/WiiUManufactorDiscId.h | 4 +- source/WUDDumperState.cpp | 44 ++++++------ source/WUDDumperState.h | 20 +++--- source/common/common.h | 2 +- source/fs/CFile.cpp | 18 +++-- source/fs/CFile.hpp | 4 +- source/fs/FSUtils.cpp | 19 +++--- source/fs/FSUtils.h | 2 +- source/fs/WUDFileWriter.cpp | 8 +-- source/fs/WUDFileWriter.h | 1 + source/fs/WUXFileWriter.cpp | 22 +++--- source/fs/WUXFileWriter.h | 6 +- source/fs/WriteOnlyFileWithCache.cpp | 14 ++-- source/fs/WriteOnlyFileWithCache.h | 2 +- source/input/CombinedInput.h | 2 +- source/input/Input.h | 63 +++++++++-------- source/input/VPADInput.h | 10 +-- source/input/WPADInput.h | 2 +- source/main.cpp | 27 ++++---- source/utils/FSTUtils.cpp | 10 +-- source/utils/FSTUtils.h | 7 +- source/utils/ScreenUtils.cpp | 2 +- source/utils/ScreenUtils.h | 1 + source/utils/StringTools.cpp | 30 ++++----- source/utils/StringTools.h | 8 +-- source/utils/TinySHA1.hpp | 1 + source/utils/WiiUScreen.cpp | 14 ++-- source/utils/WiiUScreen.h | 19 +++--- source/utils/blocksize/AddressInBlocks.h | 3 +- source/utils/blocksize/AddressInDiscBlocks.h | 2 +- .../utils/blocksize/AddressInVolumeBlocks.h | 2 +- source/utils/blocksize/DiscBlockSize.h | 3 +- source/utils/blocksize/SectionBlockSize.h | 2 +- source/utils/blocksize/SizeInBlocks.h | 2 +- source/utils/blocksize/SizeInVolumeBlocks.h | 3 +- source/utils/blocksize/VolumeBlockSize.h | 2 +- source/utils/logger.h | 12 ++-- source/utils/rijndael.c | 1 + source/utils/rijndael.h | 1 - source/utils/utils.cpp | 10 +-- source/utils/utils.h | 33 ++++----- 109 files changed, 643 insertions(+), 608 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..56cc685 --- /dev/null +++ b/.clang-format @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f967825..04f3223 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,9 +6,16 @@ on: - main 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: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: Checkout submodules using a PAT diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8e28a5f..73bee41 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -3,8 +3,16 @@ name: CI-PR on: [pull_request] 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: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: Checkout submodules using a PAT diff --git a/README.md b/README.md index 900f5bf..d14c4de 100644 --- a/README.md +++ b/README.md @@ -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) -docker build . -t WUDD-builder +docker build . -t wudd-builder # make -docker run -it --rm -v ${PWD}:/project WUDD-builder make +docker run -it --rm -v ${PWD}:/project wudd-builder make # make clean -docker run -it --rm -v ${PWD}:/project WUDD-builder make clean -``` \ No newline at end of file +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` \ No newline at end of file diff --git a/source/ApplicationState.h b/source/ApplicationState.h index fd7f047..51772db 100644 --- a/source/ApplicationState.h +++ b/source/ApplicationState.h @@ -1,8 +1,9 @@ #pragma once - -#include -#include +#include "input/Input.h" +#include "utils/ScreenUtils.h" +#include "utils/WiiUScreen.h" +#include class ApplicationState { public: diff --git a/source/GMPartitionsDumperState.cpp b/source/GMPartitionsDumperState.cpp index 4316057..7cbcafb 100644 --- a/source/GMPartitionsDumperState.cpp +++ b/source/GMPartitionsDumperState.cpp @@ -14,22 +14,22 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ +#include "GMPartitionsDumperState.h" +#include +#include +#include +#include #include +#include #include #include -#include -#include -#include -#include -#include -#include "GMPartitionsDumperState.h" #include #define READ_BUFFER_SIZE (SECTOR_SIZE * 128) GMPartitionsDumperState::GMPartitionsDumperState(eDumpTarget pTargetDevice) : targetDevice(pTargetDevice) { this->sectorBufSize = SECTOR_SIZE; - this->state = STATE_OPEN_ODD1; + this->state = STATE_OPEN_ODD1; } GMPartitionsDumperState::~GMPartitionsDumperState() { @@ -72,9 +72,9 @@ void GMPartitionsDumperState::render() { WiiUScreen::drawLine("This disc has no dumpable GM partitions "); } else { uint32_t index = 0; - for (auto &partitionPair: gmPartitionPairs) { + for (auto &partitionPair : gmPartitionPairs) { uint32_t size = 0; - for (auto &content: partitionPair.second->tmd->contentList) { + for (auto &content : partitionPair.second->tmd->contentList) { 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); @@ -98,10 +98,10 @@ void GMPartitionsDumperState::render() { WiiUScreen::drawLine("Dumping Partition"); } - uint64_t partitionSize = 0; + uint64_t partitionSize = 0; uint64_t partitionOffset = curOffsetInContent; if (curNUSTitle != nullptr) { - for (auto &content: curNUSTitle->tmd->contentList) { + for (auto &content : curNUSTitle->tmd->contentList) { partitionSize += ROUNDUP(content->encryptedFileSize, 16); if (content->index < curContentIndex) { partitionOffset += ROUNDUP(content->encryptedFileSize, 16); @@ -122,7 +122,7 @@ void GMPartitionsDumperState::render() { } auto offset = curOffsetInContent; - auto size = curContent != nullptr ? ROUNDUP(curContent->encryptedFileSize, 16) : 0; + auto size = curContent != nullptr ? ROUNDUP(curContent->encryptedFileSize, 16) : 0; if (size > 0) { 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; } 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) { this->gmPartitionPairs.clear(); - for (auto &partition: discHeader->wiiUContentsInformation->partitions->partitions) { + for (auto &partition : discHeader->wiiUContentsInformation->partitions->partitions) { auto gmPartition = std::dynamic_pointer_cast(partition); if (gmPartition != nullptr) { auto nusTitleOpt = NUSTitle::loadTitleFromGMPartition(gmPartition, discReader, cKey); @@ -235,7 +235,7 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) { auto gmPartitionPair = gmPartitionPairs[selectedOptionY]; if (gmPartitionPair.first != nullptr) { this->curPartition = gmPartitionPair.first; - this->curNUSTitle = gmPartitionPair.second; + this->curNUSTitle = gmPartitionPair.second; this->dataProvider = this->curNUSTitle->dataProcessor->getDataProvider(); } else { DEBUG_FUNCTION_LINE("Failed to find a GM partition"); @@ -290,7 +290,7 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) { return SUBSTATE_RUNNING; } this->curContentIndex = 0; - this->state = STATE_DUMP_PARTITION_CONTENTS; + this->state = STATE_DUMP_PARTITION_CONTENTS; } else if (this->state == STATE_DUMP_PARTITION_CONTENTS) { // Get current content by index. if (curContent == nullptr) { @@ -386,13 +386,13 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) { } void GMPartitionsDumperState::setError(GMPartitionsDumperState::eErrorState err) { - this->state = STATE_ERROR; + this->state = STATE_ERROR; this->errorState = err; //OSEnableHomeButtonMenu(true); } std::string GMPartitionsDumperState::getPathForDevice(eDumpTarget target) const { - if (target == TARGET_NTFS){ + if (target == TARGET_NTFS) { return "ntfs0:/"; } return "fs:/vol/external01/"; @@ -504,5 +504,3 @@ std::string GMPartitionsDumperState::ErrorDescription() const { } return "UNKNOWN_ERROR"; } - - diff --git a/source/GMPartitionsDumperState.h b/source/GMPartitionsDumperState.h index 2a2bd49..3fcd671 100644 --- a/source/GMPartitionsDumperState.h +++ b/source/GMPartitionsDumperState.h @@ -16,17 +16,18 @@ ****************************************************************************/ #pragma once +#include "ApplicationState.h" +#include "common/common.h" +#include "fs/WUXFileWriter.h" +#include "fs/WriteOnlyFileWithCache.h" +#include +#include +#include +#include #include +#include #include #include -#include -#include -#include "ApplicationState.h" -#include "fs/WriteOnlyFileWithCache.h" -#include "fs/WUXFileWriter.h" -#include -#include -#include class GMPartitionsDumperState : public ApplicationState { public: @@ -88,22 +89,22 @@ public: std::array discId{}; std::array cKey{}; - int32_t oddFd = -1; + int32_t oddFd = -1; void *sectorBuf = nullptr; uint32_t sectorBufSize; std::shared_ptr discReader = nullptr; - std::unique_ptr discHeader = nullptr; + std::unique_ptr discHeader = nullptr; std::shared_ptr curPartition = nullptr; std::shared_ptr dataProvider = nullptr; std::string targetPath; std::shared_ptr curNUSTitle = nullptr; - uint16_t curContentIndex = 0; - std::unique_ptr contentFile = nullptr; + uint16_t curContentIndex = 0; + std::unique_ptr contentFile = nullptr; std::shared_ptr curContent = nullptr; - uint8_t *readBuffer = nullptr; - uint32_t curOffsetInContent = 0; + uint8_t *readBuffer = nullptr; + uint32_t curOffsetInContent = 0; [[nodiscard]] std::string ErrorMessage() const; diff --git a/source/MainApplicationState.cpp b/source/MainApplicationState.cpp index 69d5e67..58147a9 100644 --- a/source/MainApplicationState.cpp +++ b/source/MainApplicationState.cpp @@ -15,8 +15,8 @@ * along with this program. If not, see . ****************************************************************************/ #include "MainApplicationState.h" -#include "WUDDumperState.h" #include "GMPartitionsDumperState.h" +#include "WUDDumperState.h" #include MainApplicationState::MainApplicationState() { @@ -24,7 +24,8 @@ MainApplicationState::MainApplicationState() { this->state = STATE_WELCOME_SCREEN; } -MainApplicationState::~MainApplicationState() = default;; +MainApplicationState::~MainApplicationState() = default; +; void MainApplicationState::render() { if (this->state == STATE_DO_SUBSTATE) { @@ -73,13 +74,13 @@ ApplicationState::eSubState MainApplicationState::update(Input *input) { } if (entrySelected(input)) { if (this->selectedOptionY == 0) { - this->state = STATE_DO_SUBSTATE; + this->state = STATE_DO_SUBSTATE; this->subState = std::make_unique(WUDDumperState::DUMP_AS_WUX, dumpTarget); } else if (this->selectedOptionY == 1) { - this->state = STATE_DO_SUBSTATE; + this->state = STATE_DO_SUBSTATE; this->subState = std::make_unique(WUDDumperState::DUMP_AS_WUD, dumpTarget); } else if (this->selectedOptionY == 2) { - this->state = STATE_DO_SUBSTATE; + this->state = STATE_DO_SUBSTATE; this->subState = std::make_unique(dumpTarget); } else if (this->selectedOptionY == 3) { // diff --git a/source/MainApplicationState.h b/source/MainApplicationState.h index 57de14d..28ac0e8 100644 --- a/source/MainApplicationState.h +++ b/source/MainApplicationState.h @@ -16,16 +16,16 @@ ****************************************************************************/ #pragma once +#include "ApplicationState.h" +#include "fs/CFile.hpp" +#include "input/Input.h" +#include +#include #include #include -#include #include #include -#include -#include -#include "input/Input.h" -#include "fs/CFile.hpp" -#include "ApplicationState.h" +#include class MainApplicationState : public ApplicationState { diff --git a/source/WUD/DefaultNUSDataProcessor.cpp b/source/WUD/DefaultNUSDataProcessor.cpp index a1d495f..889c31c 100644 --- a/source/WUD/DefaultNUSDataProcessor.cpp +++ b/source/WUD/DefaultNUSDataProcessor.cpp @@ -53,7 +53,6 @@ std::shared_ptr DefaultNUSDataProcessor::getDataProvider() { DefaultNUSDataProcessor::DefaultNUSDataProcessor( std::shared_ptr pDataProvider, - std::shared_ptr pNUSDecryption) : - dataProvider(std::move(pDataProvider)), - nusDecryption(std::move(pNUSDecryption)) { + std::shared_ptr pNUSDecryption) : dataProvider(std::move(pDataProvider)), + nusDecryption(std::move(pNUSDecryption)) { } diff --git a/source/WUD/DefaultNUSDataProcessor.h b/source/WUD/DefaultNUSDataProcessor.h index 94b9ff8..f728d9c 100644 --- a/source/WUD/DefaultNUSDataProcessor.h +++ b/source/WUD/DefaultNUSDataProcessor.h @@ -16,8 +16,8 @@ ****************************************************************************/ #pragma once -#include #include "NUSDataProcessor.h" +#include class DefaultNUSDataProcessor : public NUSDataProcessor { public: diff --git a/source/WUD/DiscReader.cpp b/source/WUD/DiscReader.cpp index 57576aa..585ad0b 100644 --- a/source/WUD/DiscReader.cpp +++ b/source/WUD/DiscReader.cpp @@ -15,11 +15,11 @@ * along with this program. If not, see . ****************************************************************************/ -#include #include -#include -#include +#include #include +#include +#include bool DiscReader::readDecryptedChunk(uint64_t readOffset, uint8_t *out_buffer, uint8_t *key, uint8_t *IV) const { int CHUNK_SIZE = 0x10000; @@ -59,9 +59,9 @@ bool DiscReader::readDecrypted(uint8_t *out_buffer, uint64_t clusterOffset, uint int BLOCK_SIZE = 0x10000; - uint32_t usedSize = size; + uint32_t usedSize = size; uint64_t usedFileOffset = fileOffset; - auto *buffer = (uint8_t *) malloc(BLOCK_SIZE); + auto *buffer = (uint8_t *) malloc(BLOCK_SIZE); if (buffer == nullptr) { return false; } @@ -92,7 +92,7 @@ bool DiscReader::readDecrypted(uint8_t *out_buffer, uint64_t clusterOffset, uint break; } maxCopySize = BLOCK_SIZE - blockOffset; - copySize = (usedSize > maxCopySize) ? maxCopySize : usedSize; + copySize = (usedSize > maxCopySize) ? maxCopySize : usedSize; 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; } uint32_t missingFromPrevSector = offset % SECTOR_SIZE; - auto curOffset = offset; - uint32_t offsetInBuf = 0; - uint32_t totalRead = 0; + auto curOffset = offset; + uint32_t offsetInBuf = 0; + uint32_t totalRead = 0; if (missingFromPrevSector > 0) { auto offset_in_sectors = offset / SECTOR_SIZE; 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; curOffset += missingFromPrevSector; offsetInBuf += missingFromPrevSector; - } if (totalRead >= size) { diff --git a/source/WUD/DiscReader.h b/source/WUD/DiscReader.h index adef411..634609a 100644 --- a/source/WUD/DiscReader.h +++ b/source/WUD/DiscReader.h @@ -38,6 +38,7 @@ public: uint8_t discKey[16]{}; bool hasDiscKey = false; + private: uint8_t *sector_buf; }; \ No newline at end of file diff --git a/source/WUD/DiscReaderDiscDrive.cpp b/source/WUD/DiscReaderDiscDrive.cpp index 4a33ed6..ef9659f 100644 --- a/source/WUD/DiscReaderDiscDrive.cpp +++ b/source/WUD/DiscReaderDiscDrive.cpp @@ -14,13 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ +#include "DiscReaderDiscDrive.h" +#include #include #include -#include #include -#include #include -#include "DiscReaderDiscDrive.h" +#include DiscReaderDiscDrive::DiscReaderDiscDrive() : DiscReader() { @@ -43,7 +43,7 @@ DiscReaderDiscDrive::DiscReaderDiscDrive() : DiscReader() { auto discKeyRes = IOSUHAX_ODM_GetDiscKey(discKey); if (discKeyRes >= 0) { - hasDiscKey = true; + hasDiscKey = true; auto sector_buf_decrypted = (uint8_t *) malloc(READ_SECTOR_SIZE); if (sector_buf_decrypted != nullptr) { 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) { 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; if (IOSUHAX_FSA_RawRead(gFSAfd, buf, 0x8000, block_cnt, offset_in_sectors, device_handle) < 0) { DEBUG_FUNCTION_LINE("Failed to read from Disc"); diff --git a/source/WUD/DiscReaderDiscDrive.h b/source/WUD/DiscReaderDiscDrive.h index 04091f4..a5f90b6 100644 --- a/source/WUD/DiscReaderDiscDrive.h +++ b/source/WUD/DiscReaderDiscDrive.h @@ -16,9 +16,9 @@ ****************************************************************************/ #pragma once +#include "DiscReader.h" #include #include -#include "DiscReader.h" class DiscReaderDiscDrive : public DiscReader { public: @@ -35,6 +35,6 @@ public: bool readEncrypted(uint8_t *buf, uint64_t offset, uint32_t size) override; private: - bool init_done = false; + bool init_done = false; int32_t device_handle = -1; }; \ No newline at end of file diff --git a/source/WUD/NUSDataProvider.h b/source/WUD/NUSDataProvider.h index 2e2be7a..045974e 100644 --- a/source/WUD/NUSDataProvider.h +++ b/source/WUD/NUSDataProvider.h @@ -16,9 +16,9 @@ ****************************************************************************/ #pragma once -#include -#include #include +#include +#include class NUSDataProvider { @@ -36,6 +36,5 @@ public: virtual bool getRawCert(std::vector &out_data) = 0; virtual void setFST(const std::shared_ptr &fst) { - } }; \ No newline at end of file diff --git a/source/WUD/NUSDataProviderWUD.cpp b/source/WUD/NUSDataProviderWUD.cpp index 3bb9d00..4fc32bc 100644 --- a/source/WUD/NUSDataProviderWUD.cpp +++ b/source/WUD/NUSDataProviderWUD.cpp @@ -18,7 +18,7 @@ NUSDataProviderWUD::NUSDataProviderWUD(const std::shared_ptr &pGamePartition, const std::shared_ptr &pDiscReader) { gamePartition = pGamePartition; - discReader = pDiscReader; + discReader = pDiscReader; } NUSDataProviderWUD::~NUSDataProviderWUD() = default; @@ -48,9 +48,9 @@ bool NUSDataProviderWUD::getContentH3Hash(const std::shared_ptr &conten void NUSDataProviderWUD::setFST(const std::shared_ptr &pFST) { // We need to set the correct blocksizes 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->size = SizeInVolumeBlocks(blockSize, e->size.value); + e->size = SizeInVolumeBlocks(blockSize, e->size.value); } fst = pFST; } diff --git a/source/WUD/NUSDataProviderWUD.h b/source/WUD/NUSDataProviderWUD.h index d5dc49c..0f7620c 100644 --- a/source/WUD/NUSDataProviderWUD.h +++ b/source/WUD/NUSDataProviderWUD.h @@ -16,11 +16,11 @@ ****************************************************************************/ #pragma once -#include -#include "NUSDataProvider.h" #include "DiscReader.h" -#include +#include "NUSDataProvider.h" +#include #include +#include class NUSDataProviderWUD : public NUSDataProvider { diff --git a/source/WUD/NUSTitle.cpp b/source/WUD/NUSTitle.cpp index 07ceb8f..cdcdef7 100644 --- a/source/WUD/NUSTitle.cpp +++ b/source/WUD/NUSTitle.cpp @@ -45,7 +45,7 @@ std::optional> NUSTitle::loadTitle(const std::shared_p dataBuffer.clear(); auto decryption = std::make_shared(std::move(ticketOpt.value())); - auto dpp = std::shared_ptr(new DefaultNUSDataProcessor(dataProvider, decryption)); + auto dpp = std::shared_ptr(new DefaultNUSDataProcessor(dataProvider, decryption)); // If we have more than one content, the index 0 is the FST. auto fstContentOpt = tmdOpt.value()->getContentByIndex(0); @@ -78,13 +78,12 @@ NUSTitle::NUSTitle(std::shared_ptr pTMD, std::shared_ptr pTicket, std::shared_ptr pFST) : - dataProcessor(std::move(pProcessor)), - tmd(std::move(pTMD)), - ticket(std::move(pTicket)), - fst(std::move(pFST)), - decryption(std::move(pDecryption)), - dataProvider(std::move(pDataProvider)) { - + dataProcessor(std::move(pProcessor)), + tmd(std::move(pTMD)), + ticket(std::move(pTicket)), + fst(std::move(pFST)), + decryption(std::move(pDecryption)), + dataProvider(std::move(pDataProvider)) { } std::optional> diff --git a/source/WUD/NUSTitle.h b/source/WUD/NUSTitle.h index 43eef28..0ad5269 100644 --- a/source/WUD/NUSTitle.h +++ b/source/WUD/NUSTitle.h @@ -16,15 +16,15 @@ ****************************************************************************/ #pragma once -#include -#include -#include -#include "Ticket.h" -#include "NUSDataProcessor.h" -#include "NUSDecryption.h" #include "DefaultNUSDataProcessor.h" #include "DiscReaderDiscDrive.h" +#include "NUSDataProcessor.h" #include "NUSDataProviderWUD.h" +#include "NUSDecryption.h" +#include "Ticket.h" +#include +#include +#include class NUSTitle { @@ -52,5 +52,4 @@ private: std::shared_ptr pDecryption, std::shared_ptr pTicket, std::shared_ptr pFST); - }; \ No newline at end of file diff --git a/source/WUD/Ticket.cpp b/source/WUD/Ticket.cpp index f6f1022..ce1ce0a 100644 --- a/source/WUD/Ticket.cpp +++ b/source/WUD/Ticket.cpp @@ -18,9 +18,8 @@ #include #include -Ticket::Ticket(const std::array &pEncryptedKey, const std::array &pDecryptedKey) : - ticketKeyEnc(pEncryptedKey), - ticketKeyDec(pDecryptedKey) { +Ticket::Ticket(const std::array &pEncryptedKey, const std::array &pDecryptedKey) : ticketKeyEnc(pEncryptedKey), + ticketKeyDec(pDecryptedKey) { } std::optional> Ticket::make_shared(const std::vector &data, std::optional> commonKey) { @@ -39,7 +38,7 @@ std::optional> Ticket::make_shared(const std::vector -#include #include -#include #include +#include +#include #include class Ticket { diff --git a/source/WUD/content/WiiUContentsInformation.cpp b/source/WUD/content/WiiUContentsInformation.cpp index 26b1b6d..eaf2eea 100644 --- a/source/WUD/content/WiiUContentsInformation.cpp +++ b/source/WUD/content/WiiUContentsInformation.cpp @@ -14,13 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include "WiiUContentsInformation.h" +#include -uint32_t WiiUContentsInformation::LENGTH = 32768; +uint32_t WiiUContentsInformation::LENGTH = 32768; std::optional> WiiUContentsInformation::make_unique(const std::shared_ptr &discReader, uint32_t offset) { - uint32_t curOffset = offset; + uint32_t curOffset = offset; auto discContentHeaderOpt = WiiUDiscContentsHeader::make_unique(discReader, curOffset); if (!discContentHeaderOpt.has_value()) { DEBUG_FUNCTION_LINE("Failed to read WiiUDiscContentsHeader"); @@ -47,9 +47,7 @@ std::optional> WiiUContentsInformation: WiiUContentsInformation::WiiUContentsInformation(std::unique_ptr pDiscContentHeader, - std::unique_ptr pPartitions) : - discContentHeader(std::move(pDiscContentHeader)), - partitions(std::move(pPartitions)) { - -}; + std::unique_ptr pPartitions) : discContentHeader(std::move(pDiscContentHeader)), + partitions(std::move(pPartitions)){ + }; diff --git a/source/WUD/content/WiiUContentsInformation.h b/source/WUD/content/WiiUContentsInformation.h index 2e44bd8..79031d6 100644 --- a/source/WUD/content/WiiUContentsInformation.h +++ b/source/WUD/content/WiiUContentsInformation.h @@ -16,10 +16,10 @@ ****************************************************************************/ #pragma once -#include -#include #include "WiiUDiscContentsHeader.h" #include "partitions/WiiUPartitions.h" +#include +#include class WiiUContentsInformation { diff --git a/source/WUD/content/WiiUDiscContentsHeader.cpp b/source/WUD/content/WiiUDiscContentsHeader.cpp index 886a349..1eeaf73 100644 --- a/source/WUD/content/WiiUDiscContentsHeader.cpp +++ b/source/WUD/content/WiiUDiscContentsHeader.cpp @@ -14,9 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include -#include #include "WiiUDiscContentsHeader.h" +#include +#include std::optional> WiiUDiscContentsHeader::make_unique(const std::shared_ptr &discReader, uint32_t offset) { auto *buffer = (uint8_t *) malloc(LENGTH); @@ -49,10 +49,7 @@ std::optional> WiiUDiscContentsHeader::m return std::unique_ptr(new WiiUDiscContentsHeader(blockSize, tocHash, numberOfPartition)); } -WiiUDiscContentsHeader::WiiUDiscContentsHeader(DiscBlockSize pSize, const std::array &pTocHash, uint32_t pNumberOfPartitions) : - blockSize(pSize), - numberOfPartition(pNumberOfPartitions), - tocHash(pTocHash) { - +WiiUDiscContentsHeader::WiiUDiscContentsHeader(DiscBlockSize pSize, const std::array &pTocHash, uint32_t pNumberOfPartitions) : blockSize(pSize), + numberOfPartition(pNumberOfPartitions), + tocHash(pTocHash) { } - diff --git a/source/WUD/content/WiiUDiscContentsHeader.h b/source/WUD/content/WiiUDiscContentsHeader.h index 4eecef2..f5457a3 100644 --- a/source/WUD/content/WiiUDiscContentsHeader.h +++ b/source/WUD/content/WiiUDiscContentsHeader.h @@ -16,11 +16,11 @@ ****************************************************************************/ #pragma once +#include #include #include -#include -#include #include +#include class WiiUDiscContentsHeader { @@ -30,7 +30,7 @@ public: std::array tocHash; static constexpr uint32_t LENGTH = 2048; - static constexpr uint32_t MAGIC = 0xCCA6E67B; + static constexpr uint32_t MAGIC = 0xCCA6E67B; static std::optional> make_unique(const std::shared_ptr &discReader, uint32_t offset); diff --git a/source/WUD/content/partitions/WiiUDataPartition.cpp b/source/WUD/content/partitions/WiiUDataPartition.cpp index b507eb2..e9459a9 100644 --- a/source/WUD/content/partitions/WiiUDataPartition.cpp +++ b/source/WUD/content/partitions/WiiUDataPartition.cpp @@ -22,17 +22,15 @@ WiiUDataPartition::~WiiUDataPartition() = default; WiiUDataPartition::WiiUDataPartition( std::shared_ptr pPartition, - std::shared_ptr pFST) : - fst(std::move(pFST)), - basePartition(std::move(pPartition)) { - + std::shared_ptr pFST) : fst(std::move(pFST)), + basePartition(std::move(pPartition)) { } -std::string WiiUDataPartition::getVolumeId() const &{ +std::string WiiUDataPartition::getVolumeId() const & { return basePartition->getVolumeId(); } -std::map> WiiUDataPartition::getVolumes() const &{ +std::map> WiiUDataPartition::getVolumes() const & { return basePartition->getVolumes(); } diff --git a/source/WUD/content/partitions/WiiUDataPartition.h b/source/WUD/content/partitions/WiiUDataPartition.h index b4c9b8f..cfc9dfd 100644 --- a/source/WUD/content/partitions/WiiUDataPartition.h +++ b/source/WUD/content/partitions/WiiUDataPartition.h @@ -16,11 +16,11 @@ ****************************************************************************/ #pragma once +#include "WiiUPartition.h" +#include #include #include -#include #include -#include "WiiUPartition.h" class WiiUDataPartition : public WiiUPartition { @@ -43,4 +43,3 @@ public: private: std::shared_ptr basePartition; }; - diff --git a/source/WUD/content/partitions/WiiUGMPartition.cpp b/source/WUD/content/partitions/WiiUGMPartition.cpp index 5c46782..b8229f9 100644 --- a/source/WUD/content/partitions/WiiUGMPartition.cpp +++ b/source/WUD/content/partitions/WiiUGMPartition.cpp @@ -20,18 +20,18 @@ WiiUGMPartition::WiiUGMPartition(std::shared_ptr partition, std::vector pRawTicket, std::vector pRawTMD, std::vector pRawCert) - : WiiUPartition(), - rawTicket(std::move(pRawTicket)), - rawTMD(std::move(pRawTMD)), - rawCert(std::move(pRawCert)), - basePartition(std::move(partition)) { + : WiiUPartition(), + rawTicket(std::move(pRawTicket)), + rawTMD(std::move(pRawTMD)), + rawCert(std::move(pRawCert)), + basePartition(std::move(partition)) { } -std::string WiiUGMPartition::getVolumeId() const &{ +std::string WiiUGMPartition::getVolumeId() const & { return basePartition->getVolumeId(); } -std::map> WiiUGMPartition::getVolumes() const &{ +std::map> WiiUGMPartition::getVolumes() const & { return basePartition->getVolumes(); } diff --git a/source/WUD/content/partitions/WiiUGMPartition.h b/source/WUD/content/partitions/WiiUGMPartition.h index 307b948..a647619 100644 --- a/source/WUD/content/partitions/WiiUGMPartition.h +++ b/source/WUD/content/partitions/WiiUGMPartition.h @@ -16,10 +16,10 @@ ****************************************************************************/ #pragma once -#include +#include "WiiUPartition.h" #include #include -#include "WiiUPartition.h" +#include class WiiUGMPartition : public WiiUPartition { public: @@ -43,4 +43,3 @@ public: private: std::shared_ptr basePartition; }; - diff --git a/source/WUD/content/partitions/WiiUPartition.cpp b/source/WUD/content/partitions/WiiUPartition.cpp index a7206d3..b5a346b 100644 --- a/source/WUD/content/partitions/WiiUPartition.cpp +++ b/source/WUD/content/partitions/WiiUPartition.cpp @@ -14,9 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include -#include #include "WiiUPartition.h" +#include +#include uint64_t WiiUPartition::getSectionOffsetOnDefaultPartition() { if (volumes.size() != 1) { @@ -52,14 +52,14 @@ std::optional> WiiUPartition::make_shared(const s memset(name, 0, sizeof(name)); memcpy(name, buffer, 31); auto volumeId = name; - uint8_t num = buffer[31]; + uint8_t num = buffer[31]; std::map> volumes; 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); - auto vh = VolumeHeader::make_shared(discReader, discLbaAddress.getAddressInBytes()); + auto vh = VolumeHeader::make_shared(discReader, discLbaAddress.getAddressInBytes()); if (!vh.has_value()) { free(buffer); return {}; @@ -77,11 +77,11 @@ std::optional> WiiUPartition::make_shared(const s fileSystemDescriptor)); } -std::string WiiUPartition::getVolumeId() const &{ +std::string WiiUPartition::getVolumeId() const & { return volumeId; } -std::map> WiiUPartition::getVolumes() const &{ +std::map> WiiUPartition::getVolumes() const & { return volumes; } @@ -90,7 +90,3 @@ uint16_t WiiUPartition::getFileSystemDescriptor() const { } WiiUPartition::~WiiUPartition() = default; - - - - diff --git a/source/WUD/content/partitions/WiiUPartition.h b/source/WUD/content/partitions/WiiUPartition.h index 21240a4..5fe73a2 100644 --- a/source/WUD/content/partitions/WiiUPartition.h +++ b/source/WUD/content/partitions/WiiUPartition.h @@ -16,11 +16,12 @@ ****************************************************************************/ #pragma once -#include -#include -#include -#include #include "volumes/VolumeHeader.h" +#include +#include +#include +#include +#include class WiiUPartition { @@ -44,7 +45,7 @@ protected: private: WiiUPartition(char *pVolumeId, std::map> pVolumes, uint16_t pFileSystemDescriptor) - : volumeId(pVolumeId), volumes(std::move(pVolumes)), fileSystemDescriptor(pFileSystemDescriptor) { + : volumeId(pVolumeId), volumes(std::move(pVolumes)), fileSystemDescriptor(pFileSystemDescriptor) { } std::string volumeId; diff --git a/source/WUD/content/partitions/WiiUPartitions.cpp b/source/WUD/content/partitions/WiiUPartitions.cpp index 62375e1..8b16bba 100644 --- a/source/WUD/content/partitions/WiiUPartitions.cpp +++ b/source/WUD/content/partitions/WiiUPartitions.cpp @@ -14,13 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include +#include -#include -#include "WiiUPartitions.h" -#include "WiiUGMPartition.h" #include "WiiUDataPartition.h" +#include "WiiUGMPartition.h" +#include "WiiUPartitions.h" +#include bool WiiUPartitions::getFSTEntryAsByte(std::string &filePath, const std::shared_ptr &fst, @@ -37,7 +37,7 @@ bool WiiUPartitions::getFSTEntryAsByte(std::string &filePath, return false; } - auto info = asFileEntry->getSectionEntry(); + auto info = asFileEntry->getSectionEntry(); uint64_t sectionOffsetOnDisc = volumeAddress.getAddressInBytes() + info->address.getAddressInBytes(); out_data.resize(asFileEntry->getSize()); @@ -70,7 +70,7 @@ WiiUPartitions::make_unique(const std::shared_ptr &discReader, uint3 tmp.push_back(partitionOpt.value()); } std::optional> SIPartition; - for (auto &partition: tmp) { + for (auto &partition : tmp) { if (partition->getVolumeId().starts_with("SI")) { SIPartition = partition; break; @@ -78,10 +78,10 @@ WiiUPartitions::make_unique(const std::shared_ptr &discReader, uint3 } if (SIPartition.has_value()) { - for (auto const&[key, val]: SIPartition.value()->getVolumes()) { - auto volumeAddress = key; + for (auto const &[key, val] : SIPartition.value()->getVolumes()) { + auto volumeAddress = key; auto volumeAddressInBytes = volumeAddress.getAddressInBytes(); - auto volumeHeader = val; + auto volumeHeader = val; std::vector fstData; fstData.resize(volumeHeader->FSTSize); @@ -106,7 +106,7 @@ WiiUPartitions::make_unique(const std::shared_ptr &discReader, uint3 return {}; } - for (auto &child: siFST.value()->getRootEntry()->getDirChildren()) { + for (auto &child : siFST.value()->getRootEntry()->getDirChildren()) { std::vector bufferTicket; std::string tikFilePath = std::string(child->getFullPath() + '/' + WUD_TICKET_FILENAME); if (!getFSTEntryAsByte(tikFilePath, siFST.value(), volumeAddress, discReader, bufferTicket)) { @@ -135,7 +135,7 @@ WiiUPartitions::make_unique(const std::shared_ptr &discReader, uint3 std::string partitionName = std::string("GM") + partitionNameRaw; std::optional> curPartition; - for (auto &partition: tmp) { + for (auto &partition : tmp) { if (partition->getVolumeId().starts_with(partitionName)) { curPartition = partition; break; @@ -151,10 +151,9 @@ WiiUPartitions::make_unique(const std::shared_ptr &discReader, uint3 partitions.push_back(gmPartition); } } - } - for (auto &partition: tmp) { + for (auto &partition : tmp) { if (partition->getVolumeId().starts_with("GM")) { continue; } @@ -162,7 +161,7 @@ WiiUPartitions::make_unique(const std::shared_ptr &discReader, uint3 OSFatal("We can't handle more or less than one partion address yet."); } auto volumeAddress = partition->getVolumes().begin()->first; - auto vh = partition->getVolumes().begin()->second; + auto vh = partition->getVolumes().begin()->second; std::vector fstData; fstData.resize(vh->FSTSize); @@ -190,4 +189,3 @@ WiiUPartitions::make_unique(const std::shared_ptr &discReader, uint3 WiiUPartitions::WiiUPartitions(std::vector> pPartitions) : partitions(std::move(pPartitions)) { } - diff --git a/source/WUD/content/partitions/WiiUPartitions.h b/source/WUD/content/partitions/WiiUPartitions.h index 4137d17..92dbcd3 100644 --- a/source/WUD/content/partitions/WiiUPartitions.h +++ b/source/WUD/content/partitions/WiiUPartitions.h @@ -16,17 +16,17 @@ ****************************************************************************/ #pragma once -#include -#include -#include -#include -#include -#include #include "WiiUPartition.h" +#include +#include +#include +#include +#include +#include -#define WUD_TMD_FILENAME "title.tmd" -#define WUD_TICKET_FILENAME "title.tik" -#define WUD_CERT_FILENAME "title.cert" +#define WUD_TMD_FILENAME "title.tmd" +#define WUD_TICKET_FILENAME "title.tik" +#define WUD_CERT_FILENAME "title.cert" class WiiUPartitions { diff --git a/source/WUD/content/partitions/volumes/H3HashArray.cpp b/source/WUD/content/partitions/volumes/H3HashArray.cpp index 7a90924..80258b6 100644 --- a/source/WUD/content/partitions/volumes/H3HashArray.cpp +++ b/source/WUD/content/partitions/volumes/H3HashArray.cpp @@ -15,8 +15,8 @@ * along with this program. If not, see . ****************************************************************************/ #include "H3HashArray.h" -#include #include +#include H3HashArray::H3HashArray(uint8_t *pData, uint32_t pSize) { size = pSize; diff --git a/source/WUD/content/partitions/volumes/VolumeHeader.cpp b/source/WUD/content/partitions/volumes/VolumeHeader.cpp index 642d1a3..01b82a8 100644 --- a/source/WUD/content/partitions/volumes/VolumeHeader.cpp +++ b/source/WUD/content/partitions/volumes/VolumeHeader.cpp @@ -15,12 +15,12 @@ * along with this program. If not, see . ****************************************************************************/ -#include #include "VolumeHeader.h" #include +#include #include -uint32_t VolumeHeader::MAGIC = 0xCC93A4F5; +uint32_t VolumeHeader::MAGIC = 0xCC93A4F5; std::vector> VolumeHeader::getH3HashArray(uint8_t *h3Data, uint32_t pNumberOfH3HashArray, uint32_t pH3HashArrayListSize) { std::vector> arrayList; @@ -29,9 +29,9 @@ std::vector> VolumeHeader::getH3HashArray(uint8_t * } 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 curEnd = pH3HashArrayListSize; + uint32_t curEnd = pH3HashArrayListSize; if (i < pNumberOfH3HashArray - 1) { // If it's not the last element, the end of our .h3 is the start of the next .h3 curEnd = offsetPtr[1]; @@ -64,16 +64,16 @@ std::optional> VolumeHeader::make_shared(const std return {}; } - auto blockSize = VolumeBlockSize(bufferUint[1]); - auto volumeSize = SizeInVolumeBlocks(blockSize, bufferUint[2]); - auto h3HashArrayListSize = bufferUint[3]; - auto numberOfH3HashArray = bufferUint[4]; - auto FSTSize = bufferUint[5]; - auto FSTAddress = AddressInVolumeBlocks(blockSize, bufferUint[6]); - auto FSTHashMode = buffer[36]; - auto encryptType = buffer[37]; - auto majorVersion = buffer[38]; - auto minorVersion = buffer[39]; + auto blockSize = VolumeBlockSize(bufferUint[1]); + auto volumeSize = SizeInVolumeBlocks(blockSize, bufferUint[2]); + auto h3HashArrayListSize = bufferUint[3]; + auto numberOfH3HashArray = bufferUint[4]; + auto FSTSize = bufferUint[5]; + auto FSTAddress = AddressInVolumeBlocks(blockSize, bufferUint[6]); + auto FSTHashMode = buffer[36]; + auto encryptType = buffer[37]; + auto majorVersion = buffer[38]; + auto minorVersion = buffer[39]; auto expiringMajorVersion = buffer[40]; free(buffer); @@ -123,5 +123,3 @@ VolumeHeader::VolumeHeader(const VolumeBlockSize &pBlockSize, h3HashArrayListSize(pH3HashArrayListSize), numberOfH3HashArray(pNumberOfH3HashArray) { } - - diff --git a/source/WUD/content/partitions/volumes/VolumeHeader.h b/source/WUD/content/partitions/volumes/VolumeHeader.h index 907fa04..1b5cd82 100644 --- a/source/WUD/content/partitions/volumes/VolumeHeader.h +++ b/source/WUD/content/partitions/volumes/VolumeHeader.h @@ -16,16 +16,17 @@ ****************************************************************************/ #pragma once -#include -#include -#include +#include "H3HashArray.h" #include -#include +#include +#include +#include +#include #include #include -#include +#include #include -#include "H3HashArray.h" +#include class VolumeHeader { @@ -63,5 +64,4 @@ private: std::vector> pH3HashArrayList, uint32_t pH3HashArrayListSize, uint32_t pNumberOfH3HashArray); - }; \ No newline at end of file diff --git a/source/WUD/entities/FST/FST.cpp b/source/WUD/entities/FST/FST.cpp index 57a153a..02841fb 100644 --- a/source/WUD/entities/FST/FST.cpp +++ b/source/WUD/entities/FST/FST.cpp @@ -85,10 +85,8 @@ std::optional> FST::make_shared(const std::vector FST::FST(std::unique_ptr pHeader, std::shared_ptr pSectionEntries, std::shared_ptr pStringTable, - std::unique_ptr pNodeEntries) : - sectionEntries(std::move(pSectionEntries)), - stringTable(std::move(pStringTable)), - nodeEntries(std::move(pNodeEntries)), - header(std::move(pHeader)) { - + std::unique_ptr pNodeEntries) : sectionEntries(std::move(pSectionEntries)), + stringTable(std::move(pStringTable)), + nodeEntries(std::move(pNodeEntries)), + header(std::move(pHeader)) { } diff --git a/source/WUD/entities/FST/FST.h b/source/WUD/entities/FST/FST.h index 270a7f9..f16acc9 100644 --- a/source/WUD/entities/FST/FST.h +++ b/source/WUD/entities/FST/FST.h @@ -16,15 +16,15 @@ ****************************************************************************/ #pragma once -#include -#include -#include -#include #include -#include -#include #include #include +#include +#include +#include +#include +#include +#include class FST { public: @@ -33,12 +33,12 @@ public: static std::optional> make_shared(const std::vector &data, uint32_t offset, const VolumeBlockSize &blockSize); std::shared_ptr sectionEntries; + private: FST(std::unique_ptr pHeader, std::shared_ptr pSectionEntries, std::shared_ptr pStringTable, - std::unique_ptr pNodeEntries - ); + std::unique_ptr pNodeEntries); std::shared_ptr stringTable; std::unique_ptr nodeEntries; diff --git a/source/WUD/entities/FST/header/FSTHeader.cpp b/source/WUD/entities/FST/header/FSTHeader.cpp index e3b45d3..2a03da1 100644 --- a/source/WUD/entities/FST/header/FSTHeader.cpp +++ b/source/WUD/entities/FST/header/FSTHeader.cpp @@ -14,9 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ +#include "FSTHeader.h" #include #include -#include "FSTHeader.h" std::optional> FSTHeader::make_unique(const std::array &data) { auto *dataAsUint = (uint32_t *) data.data(); @@ -24,22 +24,20 @@ std::optional> FSTHeader::make_unique(const std::arra DEBUG_FUNCTION_LINE("FST Header magic was wrong"); return {}; } - auto FSTVersion = data[3]; - auto blockSize = SectionBlockSize(dataAsUint[1]); + auto FSTVersion = data[3]; + auto blockSize = SectionBlockSize(dataAsUint[1]); auto numberOfSections = dataAsUint[2]; - auto hashDisabled = data[12]; + auto hashDisabled = data[12]; return std::unique_ptr(new FSTHeader( FSTVersion, blockSize, numberOfSections, - hashDisabled - )); + hashDisabled)); } FSTHeader::FSTHeader(uint8_t pFSTVersion, SectionBlockSize pBlockSize, uint32_t pNumberOfSections, uint8_t pHashDisabled) : FSTVersion(pFSTVersion), blockSize(pBlockSize), numberOfSections(pNumberOfSections), hashDisabled(pHashDisabled) { - } diff --git a/source/WUD/entities/FST/header/FSTHeader.h b/source/WUD/entities/FST/header/FSTHeader.h index 3c6aa63..747023e 100644 --- a/source/WUD/entities/FST/header/FSTHeader.h +++ b/source/WUD/entities/FST/header/FSTHeader.h @@ -16,9 +16,9 @@ ****************************************************************************/ #pragma once -#include -#include #include +#include +#include #include class FSTHeader { @@ -35,5 +35,4 @@ public: private: FSTHeader(uint8_t pFSTVersion, SectionBlockSize pBlockSize, uint32_t pNumberOfSections, uint8_t pHashDisabled); - }; diff --git a/source/WUD/entities/FST/nodeentry/DirectoryEntry.cpp b/source/WUD/entities/FST/nodeentry/DirectoryEntry.cpp index b9135ea..17055f1 100644 --- a/source/WUD/entities/FST/nodeentry/DirectoryEntry.cpp +++ b/source/WUD/entities/FST/nodeentry/DirectoryEntry.cpp @@ -14,15 +14,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include "DirectoryEntry.h" +#include std::optional> DirectoryEntry::parseData(const std::array &data, const NodeEntryParam ¶m, const std::shared_ptr §ionEntries, const std::shared_ptr &stringTable) { auto parentEntryNumber = ((uint32_t *) &data[4])[0]; - auto lastEntryNumber = ((uint32_t *) &data[8])[0]; - auto stringNameOpt = stringTable->getStringEntry(param.uint24); + auto lastEntryNumber = ((uint32_t *) &data[8])[0]; + auto stringNameOpt = stringTable->getStringEntry(param.uint24); if (!stringNameOpt.has_value()) { DEBUG_FUNCTION_LINE("Failed to get string name"); return {}; @@ -40,7 +40,7 @@ DirectoryEntry::parseData(const std::array &data, co std::vector> DirectoryEntry::getDirChildren() const { std::vector> res; - for (auto &cur: children) { + for (auto &cur : children) { if (cur->isDirectory()) { res.push_back(std::dynamic_pointer_cast(cur)); } @@ -50,7 +50,7 @@ std::vector> DirectoryEntry::getDirChildren() co std::vector> DirectoryEntry::getFileChildren() const { std::vector> res; - for (auto &cur: children) { + for (auto &cur : children) { if (cur->isFile()) { res.push_back(std::dynamic_pointer_cast(cur)); } @@ -64,7 +64,7 @@ std::vector> DirectoryEntry::getChildren() const { void DirectoryEntry::printPathRecursive() { DEBUG_FUNCTION_LINE("%s", getFullPath().c_str()); - for (auto &child: children) { + for (auto &child : children) { child->printPathRecursive(); } } @@ -77,25 +77,22 @@ DirectoryEntry::DirectoryEntry(const NodeEntryParam ¶m, const std::shared_ptr &pStringEntry, const std::shared_ptr &pSectionEntry, uint32_t pParentEntryNumber, - uint32_t pLastEntryNumber) : - NodeEntry(param.permission, - pStringEntry, - pSectionEntry, - param.parent, - param.type, - param.entryNumber), - parentEntryNumber(pParentEntryNumber), - lastEntryNumber(pLastEntryNumber) { + uint32_t pLastEntryNumber) : NodeEntry(param.permission, + pStringEntry, + pSectionEntry, + param.parent, + param.type, + param.entryNumber), + parentEntryNumber(pParentEntryNumber), + lastEntryNumber(pLastEntryNumber) { } -DirectoryEntry::DirectoryEntry(const std::shared_ptr &input) : - NodeEntry(input->permission, - input->nameString, - input->sectionEntry, - input->parent, - input->entryType, - input->entryNumber), - parentEntryNumber(input->parentEntryNumber), - lastEntryNumber(input->lastEntryNumber) { - +DirectoryEntry::DirectoryEntry(const std::shared_ptr &input) : NodeEntry(input->permission, + input->nameString, + input->sectionEntry, + input->parent, + input->entryType, + input->entryNumber), + parentEntryNumber(input->parentEntryNumber), + lastEntryNumber(input->lastEntryNumber) { } diff --git a/source/WUD/entities/FST/nodeentry/DirectoryEntry.h b/source/WUD/entities/FST/nodeentry/DirectoryEntry.h index 38ad879..eadd313 100644 --- a/source/WUD/entities/FST/nodeentry/DirectoryEntry.h +++ b/source/WUD/entities/FST/nodeentry/DirectoryEntry.h @@ -16,11 +16,11 @@ ****************************************************************************/ #pragma once +#include "FileEntry.h" +#include "NodeEntry.h" +#include "NodeEntryParam.h" #include #include -#include "NodeEntryParam.h" -#include "NodeEntry.h" -#include "FileEntry.h" class DirectoryEntry : public NodeEntry { public: diff --git a/source/WUD/entities/FST/nodeentry/FileEntry.cpp b/source/WUD/entities/FST/nodeentry/FileEntry.cpp index 88f4413..8b1f2d5 100644 --- a/source/WUD/entities/FST/nodeentry/FileEntry.cpp +++ b/source/WUD/entities/FST/nodeentry/FileEntry.cpp @@ -27,7 +27,7 @@ FileEntry::parseData(const std::array &data, const std::shared_ptr §ionEntries, const std::shared_ptr &stringTable, 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 stringNameOpt = stringTable->getStringEntry(param.uint24); @@ -61,14 +61,12 @@ FileEntry::FileEntry( const NodeEntryParam ¶m, const std::shared_ptr &pStringEntry, const std::shared_ptr &pSectionEntry, - uint32_t pSize, SectionAddress pAddress) : - NodeEntry(param.permission, - pStringEntry, - pSectionEntry, - param.parent, - param.type, - param.entryNumber), - address(std::move(pAddress)), - size(pSize) { - + uint32_t pSize, SectionAddress pAddress) : NodeEntry(param.permission, + pStringEntry, + pSectionEntry, + param.parent, + param.type, + param.entryNumber), + address(std::move(pAddress)), + size(pSize) { } \ No newline at end of file diff --git a/source/WUD/entities/FST/nodeentry/FileEntry.h b/source/WUD/entities/FST/nodeentry/FileEntry.h index 656190c..48bfdb8 100644 --- a/source/WUD/entities/FST/nodeentry/FileEntry.h +++ b/source/WUD/entities/FST/nodeentry/FileEntry.h @@ -23,7 +23,6 @@ class FileEntry : public NodeEntry { public: - static std::optional> parseData(const std::array &data, const NodeEntryParam ¶m, diff --git a/source/WUD/entities/FST/nodeentry/NodeEntries.cpp b/source/WUD/entities/FST/nodeentry/NodeEntries.cpp index 69d0a3a..b74b326 100644 --- a/source/WUD/entities/FST/nodeentry/NodeEntries.cpp +++ b/source/WUD/entities/FST/nodeentry/NodeEntries.cpp @@ -14,8 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include "NodeEntries.h" +#include std::optional> NodeEntries::DeserializeImpl(const std::vector &pData, uint32_t pOffset, diff --git a/source/WUD/entities/FST/nodeentry/NodeEntries.h b/source/WUD/entities/FST/nodeentry/NodeEntries.h index 327297b..f12333b 100644 --- a/source/WUD/entities/FST/nodeentry/NodeEntries.h +++ b/source/WUD/entities/FST/nodeentry/NodeEntries.h @@ -16,15 +16,15 @@ ****************************************************************************/ #pragma once +#include #include #include -#include -#include #include "DirectoryEntry.h" -#include "RootEntry.h" -#include "NodeEntry.h" #include "NodeEntries.h" +#include "NodeEntry.h" +#include "RootEntry.h" +#include class NodeEntries { diff --git a/source/WUD/entities/FST/nodeentry/NodeEntry.cpp b/source/WUD/entities/FST/nodeentry/NodeEntry.cpp index 7a76bbc..10c2b0b 100644 --- a/source/WUD/entities/FST/nodeentry/NodeEntry.cpp +++ b/source/WUD/entities/FST/nodeentry/NodeEntry.cpp @@ -14,15 +14,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include -#include #include +#include +#include +#include "DirectoryEntry.h" +#include "NodeEntry.h" +#include "RootEntry.h" #include #include -#include "NodeEntry.h" -#include "DirectoryEntry.h" -#include "RootEntry.h" std::optional> NodeEntry::AutoDeserialize(const std::vector &data, @@ -39,12 +39,12 @@ NodeEntry::AutoDeserialize(const std::vector &data, std::copy_n(data.begin() + (int) offset, NodeEntry::LENGTH, curEntryData.begin()); NodeEntryParam param{}; - param.permission = ((uint16_t *) &curEntryData[12])[0]; + param.permission = ((uint16_t *) &curEntryData[12])[0]; param.sectionNumber = ((uint16_t *) &curEntryData[14])[0]; - param.entryNumber = eEntryNumber; - param.parent = pParent; - param.type = curEntryData[0]; - param.uint24 = ((uint32_t *) &curEntryData[0])[0] & 0x00FFFFFF; + param.entryNumber = eEntryNumber; + param.parent = pParent; + param.type = curEntryData[0]; + param.uint24 = ((uint32_t *) &curEntryData[0])[0] & 0x00FFFFFF; if ((param.type & ENTRY_TYPE_Directory) == ENTRY_TYPE_Directory && param.uint24 == 0) { // Root auto res = RootEntry::parseData(curEntryData, param, sectionEntries, stringTable); @@ -123,17 +123,14 @@ NodeEntry::NodeEntry(const uint16_t pPermission, std::shared_ptr pNameString, std::shared_ptr pSectionEntry, std::optional> pParent, - const uint8_t pType, const uint32_t pEntryNumber) : - permission(pPermission), - nameString(std::move(pNameString)), - sectionEntry(std::move(pSectionEntry)), - parent(std::move(pParent)), - entryType(pType), - entryNumber(pEntryNumber) { - + const uint8_t pType, const uint32_t pEntryNumber) : permission(pPermission), + nameString(std::move(pNameString)), + sectionEntry(std::move(pSectionEntry)), + parent(std::move(pParent)), + entryType(pType), + entryNumber(pEntryNumber) { } void NodeEntry::printPathRecursive() { DEBUG_FUNCTION_LINE("%s", getFullPath().c_str()); } - diff --git a/source/WUD/entities/FST/nodeentry/NodeEntry.h b/source/WUD/entities/FST/nodeentry/NodeEntry.h index 346a3ca..5959c9d 100644 --- a/source/WUD/entities/FST/nodeentry/NodeEntry.h +++ b/source/WUD/entities/FST/nodeentry/NodeEntry.h @@ -16,17 +16,17 @@ ****************************************************************************/ #pragma once +#include "NodeEntryParam.h" +#include +#include +#include #include #include -#include -#include -#include #include -#include "NodeEntryParam.h" -#define ENTRY_TYPE_File 0 -#define ENTRY_TYPE_Directory 1 -#define ENTRY_TYPE_Link 0x80 +#define ENTRY_TYPE_File 0 +#define ENTRY_TYPE_Directory 1 +#define ENTRY_TYPE_Link 0x80 class DirectoryEntry; diff --git a/source/WUD/entities/FST/nodeentry/NodeEntryParam.h b/source/WUD/entities/FST/nodeentry/NodeEntryParam.h index 8012e4d..958dc5a 100644 --- a/source/WUD/entities/FST/nodeentry/NodeEntryParam.h +++ b/source/WUD/entities/FST/nodeentry/NodeEntryParam.h @@ -17,6 +17,8 @@ #pragma once #include +#include +#include class DirectoryEntry; diff --git a/source/WUD/entities/FST/nodeentry/RootEntry.cpp b/source/WUD/entities/FST/nodeentry/RootEntry.cpp index 1d6594c..33ce44d 100644 --- a/source/WUD/entities/FST/nodeentry/RootEntry.cpp +++ b/source/WUD/entities/FST/nodeentry/RootEntry.cpp @@ -14,11 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include "RootEntry.h" +#include RootEntry::RootEntry(const std::shared_ptr &input) : DirectoryEntry(input) { - } uint32_t RootEntry::parseLastEntryNumber(const std::array &data) { @@ -26,11 +25,10 @@ uint32_t RootEntry::parseLastEntryNumber(const std::array> -RootEntry::parseData - (const std::array &data, - const NodeEntryParam ¶m, - const std::shared_ptr §ionEntries, - const std::shared_ptr &stringTable) { +RootEntry::parseData(const std::array &data, + const NodeEntryParam ¶m, + const std::shared_ptr §ionEntries, + const std::shared_ptr &stringTable) { auto dir = DirectoryEntry::parseData(data, param, sectionEntries, stringTable); if (dir.has_value()) { if ((dir.value()->entryType & ENTRY_TYPE_Directory) != ENTRY_TYPE_Directory || dir.value()->entryNumber != 0) { diff --git a/source/WUD/entities/FST/nodeentry/RootEntry.h b/source/WUD/entities/FST/nodeentry/RootEntry.h index eeafa4d..62f3785 100644 --- a/source/WUD/entities/FST/nodeentry/RootEntry.h +++ b/source/WUD/entities/FST/nodeentry/RootEntry.h @@ -16,11 +16,11 @@ ****************************************************************************/ #pragma once -#include -#include -#include -#include #include "DirectoryEntry.h" +#include +#include +#include +#include class RootEntry : public DirectoryEntry { diff --git a/source/WUD/entities/FST/sectionentry/SectionEntries.cpp b/source/WUD/entities/FST/sectionentry/SectionEntries.cpp index 2144062..178f121 100644 --- a/source/WUD/entities/FST/sectionentry/SectionEntries.cpp +++ b/source/WUD/entities/FST/sectionentry/SectionEntries.cpp @@ -17,7 +17,7 @@ #include "SectionEntries.h" std::optional> SectionEntries::getSection(uint16_t sectionNumber) const { - for (auto const &e: list) { + for (auto const &e : list) { if (e->sectionNumber == sectionNumber) { return e; } @@ -42,15 +42,15 @@ std::optional> SectionEntries::make_shared(const } std::array sectionEntryData{}; memcpy(sectionEntryData.data(), data.data() + (i * SectionEntry::LENGTH), SectionEntry::LENGTH); - list.push_back(std::make_shared(sectionEntryData, i, pBlockSize));; + list.push_back(std::make_shared(sectionEntryData, i, pBlockSize)); + ; } return std::shared_ptr(new SectionEntries(list)); } -std::vector> SectionEntries::getSections() const &{ +std::vector> SectionEntries::getSections() const & { return list; } SectionEntries::SectionEntries(std::vector> pList) : list(std::move(pList)) { - } diff --git a/source/WUD/entities/FST/sectionentry/SectionEntries.h b/source/WUD/entities/FST/sectionentry/SectionEntries.h index 91c2942..1e65118 100644 --- a/source/WUD/entities/FST/sectionentry/SectionEntries.h +++ b/source/WUD/entities/FST/sectionentry/SectionEntries.h @@ -16,14 +16,14 @@ ****************************************************************************/ #pragma once -#include -#include +#include "SectionEntry.h" #include +#include +#include #include -#include #include #include -#include "SectionEntry.h" +#include class SectionEntries { diff --git a/source/WUD/entities/FST/sectionentry/SectionEntry.cpp b/source/WUD/entities/FST/sectionentry/SectionEntry.cpp index 921e508..0d390b3 100644 --- a/source/WUD/entities/FST/sectionentry/SectionEntry.cpp +++ b/source/WUD/entities/FST/sectionentry/SectionEntry.cpp @@ -18,15 +18,15 @@ SectionEntry::SectionEntry(const std::array &data, uint32_t pSectionNumber, const VolumeBlockSize &pBlockSize) { auto *dataAsUint = (uint32_t *) data.data(); - address = AddressInVolumeBlocks(pBlockSize, dataAsUint[0]); - size = SizeInVolumeBlocks(pBlockSize, dataAsUint[1]); + address = AddressInVolumeBlocks(pBlockSize, dataAsUint[0]); + size = SizeInVolumeBlocks(pBlockSize, dataAsUint[1]); - ownerID = ((uint64_t *) (&data[8]))[0]; - groupID = ((uint64_t *) (&data[16]))[0]; + ownerID = ((uint64_t *) (&data[8]))[0]; + groupID = ((uint64_t *) (&data[16]))[0]; hashMode = data[20]; char buff[32]; snprintf(buff, sizeof(buff), "Section: %d", pSectionNumber); - name = std::string(buff); + name = std::string(buff); sectionNumber = pSectionNumber; } diff --git a/source/WUD/entities/FST/sectionentry/SectionEntry.h b/source/WUD/entities/FST/sectionentry/SectionEntry.h index b5a31b3..88131f8 100644 --- a/source/WUD/entities/FST/sectionentry/SectionEntry.h +++ b/source/WUD/entities/FST/sectionentry/SectionEntry.h @@ -16,9 +16,9 @@ ****************************************************************************/ #pragma once +#include #include #include -#include #include #include diff --git a/source/WUD/entities/FST/stringtable/StringEntry.cpp b/source/WUD/entities/FST/stringtable/StringEntry.cpp index 362bf64..ed06fc6 100644 --- a/source/WUD/entities/FST/stringtable/StringEntry.cpp +++ b/source/WUD/entities/FST/stringtable/StringEntry.cpp @@ -16,9 +16,9 @@ ****************************************************************************/ #include "StringEntry.h" +#include "StringTable.h" #include #include -#include "StringTable.h" std::optional StringEntry::toString() const { return stringTable->getByAddress(offset); diff --git a/source/WUD/entities/FST/stringtable/StringEntry.h b/source/WUD/entities/FST/stringtable/StringEntry.h index f6963dd..4d8391d 100644 --- a/source/WUD/entities/FST/stringtable/StringEntry.h +++ b/source/WUD/entities/FST/stringtable/StringEntry.h @@ -17,9 +17,9 @@ #pragma once #include -#include #include #include +#include class StringTable; diff --git a/source/WUD/entities/FST/stringtable/StringTable.cpp b/source/WUD/entities/FST/stringtable/StringTable.cpp index 633b5dd..83facbc 100644 --- a/source/WUD/entities/FST/stringtable/StringTable.cpp +++ b/source/WUD/entities/FST/stringtable/StringTable.cpp @@ -14,10 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include -#include -#include #include "StringTable.h" +#include +#include +#include std::optional> StringTable::make_shared(const std::vector &data, uint32_t offset, uint32_t stringCount) { @@ -25,7 +25,7 @@ std::optional> StringTable::make_shared(const std:: DEBUG_FUNCTION_LINE("Invalid offset for reading StringTable"); return {}; } - auto stringTable = std::shared_ptr(new StringTable()); + auto stringTable = std::shared_ptr(new StringTable()); uint32_t curOffset = 0; uint32_t i; for (i = 0; curOffset < data.size() && i < stringCount; ++curOffset) { @@ -41,9 +41,9 @@ std::optional> StringTable::make_shared(const std:: uint32_t curLength = 0; for (i = 0; i < stringCount; ++i) { - curOffset = offset + curLength; + curOffset = offset + curLength; stringTable->stringMap[curLength] = std::make_shared(stringTable, curLength); - stringTable->strings[curLength] = (char *) &data[curOffset]; + stringTable->strings[curLength] = (char *) &data[curOffset]; curLength += strlen((char *) &data[curOffset]) + 1; } @@ -67,14 +67,14 @@ std::optional> StringTable::getStringEntry(uint32_t uint32_t StringTable::getSize() { uint32_t capacity = 1; // root entry - for (auto &cur: strings) { + for (auto &cur : strings) { capacity += cur.second.length() + 1; } return capacity; } std::optional> StringTable::getEntry(std::string &str) { - for (auto &cur: strings) { + for (auto &cur : strings) { if (cur.second == str) { return stringMap[cur.first]; } diff --git a/source/WUD/entities/FST/stringtable/StringTable.h b/source/WUD/entities/FST/stringtable/StringTable.h index 7efc304..129ac2c 100644 --- a/source/WUD/entities/FST/stringtable/StringTable.h +++ b/source/WUD/entities/FST/stringtable/StringTable.h @@ -16,12 +16,12 @@ ****************************************************************************/ #pragma once -#include -#include -#include -#include -#include #include "StringEntry.h" +#include +#include +#include +#include +#include class StringTable { diff --git a/source/WUD/entities/TMD/Content.cpp b/source/WUD/entities/TMD/Content.cpp index 4584103..3b819a6 100644 --- a/source/WUD/entities/TMD/Content.cpp +++ b/source/WUD/entities/TMD/Content.cpp @@ -14,21 +14,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include "Content.h" +#include -Content::Content(uint32_t pId, uint16_t pIndex, uint16_t pType, uint64_t pEncryptedFileSize, const std::array &pHash) : - ID(pId), - index(pIndex), - type(pType), - encryptedFileSize(pEncryptedFileSize), - hash(pHash) { +Content::Content(uint32_t pId, uint16_t pIndex, uint16_t pType, uint64_t pEncryptedFileSize, const std::array &pHash) : ID(pId), + index(pIndex), + type(pType), + encryptedFileSize(pEncryptedFileSize), + hash(pHash) { } std::optional> Content::make_shared(const std::array &data) { - auto id = ((uint32_t *) &data[0x00])[0]; - auto index = ((uint16_t *) &data[0x04])[0]; - auto type = ((uint16_t *) &data[0x06])[0]; + auto id = ((uint32_t *) &data[0x00])[0]; + auto index = ((uint16_t *) &data[0x04])[0]; + auto type = ((uint16_t *) &data[0x06])[0]; auto encryptedFileSize = ((uint64_t *) &data[0x08])[0]; std::array hash{}; memcpy(hash.data(), &data[0x10], 0x14); diff --git a/source/WUD/entities/TMD/Content.h b/source/WUD/entities/TMD/Content.h index 16a7521..7644c12 100644 --- a/source/WUD/entities/TMD/Content.h +++ b/source/WUD/entities/TMD/Content.h @@ -17,8 +17,8 @@ #pragma once #include -#include #include +#include class Content { public: diff --git a/source/WUD/entities/TMD/TitleMetaData.cpp b/source/WUD/entities/TMD/TitleMetaData.cpp index 1e1e943..15ce3bc 100644 --- a/source/WUD/entities/TMD/TitleMetaData.cpp +++ b/source/WUD/entities/TMD/TitleMetaData.cpp @@ -22,11 +22,10 @@ TitleMetaData::TitleMetaData(std::vector> pContentList) : contentList(std::move(pContentList)) { // Get Contents - } std::optional> TitleMetaData::getContentByIndex(uint16_t i) { - for (auto &content: contentList) { + for (auto &content : contentList) { if (content->index == i) { return content; } diff --git a/source/WUD/entities/TMD/TitleMetaData.h b/source/WUD/entities/TMD/TitleMetaData.h index 2ecb926..552423a 100644 --- a/source/WUD/entities/TMD/TitleMetaData.h +++ b/source/WUD/entities/TMD/TitleMetaData.h @@ -16,11 +16,11 @@ ****************************************************************************/ #pragma once -#include -#include -#include -#include #include "Content.h" +#include +#include +#include +#include class TitleMetaData { public: diff --git a/source/WUD/header/WiiUDiscHeader.cpp b/source/WUD/header/WiiUDiscHeader.cpp index c288338..3025f7a 100644 --- a/source/WUD/header/WiiUDiscHeader.cpp +++ b/source/WUD/header/WiiUDiscHeader.cpp @@ -21,10 +21,9 @@ uint32_t WiiUDiscHeader::LENGTH = 131072L; WiiUDiscHeader::WiiUDiscHeader(std::unique_ptr pManufactorDiscId, std::unique_ptr pDiscId, - std::unique_ptr pWiiUContentsInformation) : - manufactorDiscId(std::move(pManufactorDiscId)), - discId(std::move(pDiscId)), - wiiUContentsInformation(std::move(pWiiUContentsInformation)) { + std::unique_ptr pWiiUContentsInformation) : manufactorDiscId(std::move(pManufactorDiscId)), + discId(std::move(pDiscId)), + wiiUContentsInformation(std::move(pWiiUContentsInformation)) { } std::optional> WiiUDiscHeader::make_unique(const std::shared_ptr &discReader) { @@ -32,8 +31,8 @@ std::optional> WiiUDiscHeader::make_unique(const DEBUG_FUNCTION_LINE("DiscReader is not ready"); return {}; } - uint32_t offset = 0; - uint32_t curOffset = offset; + uint32_t offset = 0; + uint32_t curOffset = offset; auto manufactorDiscIDOpt = WiiUManufactorDiscId::make_unique(discReader); if (!manufactorDiscIDOpt.has_value()) { DEBUG_FUNCTION_LINE("Failed to read ManufactorDiscId"); diff --git a/source/WUD/header/WiiUDiscHeader.h b/source/WUD/header/WiiUDiscHeader.h index dd4e56e..f3dcf0f 100644 --- a/source/WUD/header/WiiUDiscHeader.h +++ b/source/WUD/header/WiiUDiscHeader.h @@ -16,17 +16,16 @@ ****************************************************************************/ #pragma once -#include -#include -#include -#include -#include -#include "WiiUManufactorDiscId.h" #include "WiiUDiscId.h" +#include "WiiUManufactorDiscId.h" +#include +#include +#include +#include +#include class WiiUDiscHeader { public: - static std::optional> make_unique(const std::shared_ptr &discReader); std::unique_ptr manufactorDiscId; @@ -39,6 +38,5 @@ private: explicit WiiUDiscHeader( std::unique_ptr pManufactorDiscId, std::unique_ptr pDiscId, - std::unique_ptr pWiiUContentsInformation - ); + std::unique_ptr pWiiUContentsInformation); }; \ No newline at end of file diff --git a/source/WUD/header/WiiUDiscId.cpp b/source/WUD/header/WiiUDiscId.cpp index 052d4bf..2fce86e 100644 --- a/source/WUD/header/WiiUDiscId.cpp +++ b/source/WUD/header/WiiUDiscId.cpp @@ -15,8 +15,8 @@ * along with this program. If not, see . ****************************************************************************/ #include "WiiUDiscId.h" -#include #include +#include #include std::optional> WiiUDiscId::make_unique(const std::shared_ptr &discReader, uint32_t offset) { @@ -46,9 +46,7 @@ std::optional> WiiUDiscId::make_unique(const std::sh return std::unique_ptr(new WiiUDiscId(minorVersion, majorVersion, footprint)); } -WiiUDiscId::WiiUDiscId(uint8_t pMinorVersion, uint8_t pMajorVersion, const std::string &pFootprint) : - minorVersion(pMinorVersion), - majorVersion(pMajorVersion), - footprint(pFootprint) { - +WiiUDiscId::WiiUDiscId(uint8_t pMinorVersion, uint8_t pMajorVersion, const std::string &pFootprint) : minorVersion(pMinorVersion), + majorVersion(pMajorVersion), + footprint(pFootprint) { } diff --git a/source/WUD/header/WiiUDiscId.h b/source/WUD/header/WiiUDiscId.h index 57e5985..8e1a0b5 100644 --- a/source/WUD/header/WiiUDiscId.h +++ b/source/WUD/header/WiiUDiscId.h @@ -16,17 +16,17 @@ ****************************************************************************/ #pragma once -#include -#include #include +#include #include +#include #include class WiiUDiscId { public: static constexpr uint32_t LENGTH = 32768; - static constexpr uint32_t MAGIC = 0xCC549EB9; + static constexpr uint32_t MAGIC = 0xCC549EB9; uint8_t minorVersion; uint8_t majorVersion; std::string footprint; diff --git a/source/WUD/header/WiiUManufactorDiscId.h b/source/WUD/header/WiiUManufactorDiscId.h index c0d9338..dba1285 100644 --- a/source/WUD/header/WiiUManufactorDiscId.h +++ b/source/WUD/header/WiiUManufactorDiscId.h @@ -16,9 +16,9 @@ ****************************************************************************/ #pragma once -#include -#include #include +#include +#include #include class WiiUManufactorDiscId { diff --git a/source/WUDDumperState.cpp b/source/WUDDumperState.cpp index 16357c9..74d5d70 100644 --- a/source/WUDDumperState.cpp +++ b/source/WUDDumperState.cpp @@ -14,20 +14,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include #include "WUDDumperState.h" +#include +#include +#include +#include +#include +#include +#include +#include WUDDumperState::WUDDumperState(WUDDumperState::eDumpTargetFormat pTargetFormat, eDumpTarget pTargetDevice) - : targetFormat(pTargetFormat), targetDevice(pTargetDevice) { + : targetFormat(pTargetFormat), targetDevice(pTargetDevice) { this->sectorBufSize = READ_SECTOR_SIZE * READ_NUM_SECTORS; - this->state = STATE_OPEN_ODD1; + this->state = STATE_OPEN_ODD1; } WUDDumperState::~WUDDumperState() { @@ -139,11 +139,11 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) { this->startTime = OSGetTime(); - this->state = STATE_DUMP_DISC; + this->state = STATE_DUMP_DISC; this->totalSectorCount = (WUD_FILE_SIZE / SECTOR_SIZE); - this->currentSector = 0; - this->writtenSectors = 0; - this->retryCount = 10; + this->currentSector = 0; + this->writtenSectors = 0; + this->retryCount = 10; } else if (this->state == STATE_DUMP_DISC) { 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) { @@ -207,7 +207,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) { this->writtenSectors += curWrittenSectors; this->readResult = 0; } else if (input->data.buttons_d & Input::BUTTON_B) { - this->state = STATE_OPEN_ODD1; + this->state = STATE_OPEN_ODD1; this->readResult = 0; } else if (input->data.buttons_d & Input::BUTTON_Y) { 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 B to try again"); } else { - OSTime curTime = OSGetTime(); - 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)); + OSTime curTime = OSGetTime(); + 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)); int32_t remainingSec = remaining / curSpeed; - int32_t minutes = (remainingSec / 60) % 60; - int32_t seconds = remainingSec % 60; - int32_t hours = remainingSec / 3600; + int32_t minutes = (remainingSec / 60) % 60; + int32_t seconds = remainingSec % 60; + int32_t hours = remainingSec / 3600; 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) { - this->state = STATE_ERROR; + this->state = STATE_ERROR; this->errorState = err; //OSEnableHomeButtonMenu(true); } diff --git a/source/WUDDumperState.h b/source/WUDDumperState.h index 3d1346d..875b1d0 100644 --- a/source/WUDDumperState.h +++ b/source/WUDDumperState.h @@ -16,23 +16,22 @@ ****************************************************************************/ #pragma once +#include "ApplicationState.h" +#include "fs/WUXFileWriter.h" +#include "fs/WriteOnlyFileWithCache.h" +#include +#include #include +#include #include #include -#include -#include -#include -#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 WUD_FILE_SIZE 0x5D3A00000L +#define WUD_FILE_SIZE 0x5D3A00000L class WUDDumperState : public ApplicationState { public: - enum eDumpTargetFormat { DUMP_AS_WUX, DUMP_AS_WUD, @@ -86,7 +85,7 @@ public: void *sectorBuf = nullptr; int readResult = 0; - int oddFd = -1; + int oddFd = -1; int retryCount = 10; OSTime startTime{}; @@ -109,5 +108,4 @@ public: int32_t writtenSectors{}; void *emptySector = nullptr; - }; \ No newline at end of file diff --git a/source/common/common.h b/source/common/common.h index e758788..3a06d8e 100644 --- a/source/common/common.h +++ b/source/common/common.h @@ -5,7 +5,7 @@ extern int32_t gFSAfd; -#define SECTOR_SIZE 0x8000 +#define SECTOR_SIZE 0x8000 #define READ_SECTOR_SIZE SECTOR_SIZE extern ntfs_md *ntfs_mounts; diff --git a/source/fs/CFile.cpp b/source/fs/CFile.cpp index f3583a7..3dcedb6 100644 --- a/source/fs/CFile.cpp +++ b/source/fs/CFile.cpp @@ -1,14 +1,14 @@ +#include "CFile.hpp" #include #include #include #include -#include "CFile.hpp" CFile::CFile() { - iFd = -1; + iFd = -1; mem_file = nullptr; filesize = 0; - pos = 0; + pos = 0; } CFile::CFile(const std::string &filepath, eOpenTypes mode) { @@ -34,7 +34,7 @@ int32_t CFile::open(const std::string &filepath, eOpenTypes mode) { switch (mode) { default: - case ReadOnly: // file must exist + case ReadOnly: // file must exist openMode = O_RDONLY; break; case WriteOnly: // file will be created / zerod @@ -76,10 +76,10 @@ void CFile::close() { if (iFd >= 0) ::close(iFd); - iFd = -1; + iFd = -1; mem_file = nullptr; filesize = 0; - pos = 0; + pos = 0; } 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 ret = 0; + int32_t ret = 0; int64_t newPos = pos; 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, ...) { char tmp[512]; - tmp[0] = 0; + tmp[0] = 0; int32_t result = -1; va_list va; @@ -173,5 +173,3 @@ int32_t CFile::fwrite(const char *format, ...) { return result; } - - diff --git a/source/fs/CFile.hpp b/source/fs/CFile.hpp index 29a8869..304d66b 100644 --- a/source/fs/CFile.hpp +++ b/source/fs/CFile.hpp @@ -1,12 +1,12 @@ #pragma once #include -#include #include #include +#include #include -#include #include +#include class CFile { public: diff --git a/source/fs/FSUtils.cpp b/source/fs/FSUtils.cpp index 59c4efa..0faf2bd 100644 --- a/source/fs/FSUtils.cpp +++ b/source/fs/FSUtils.cpp @@ -1,11 +1,11 @@ -#include -#include -#include -#include -#include #include "FSUtils.h" #include "CFile.hpp" #include "utils/logger.h" +#include +#include +#include +#include +#include int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) { //! always initialze input @@ -27,8 +27,8 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_ } uint32_t blocksize = 0x4000; - uint32_t done = 0; - int32_t readBytes = 0; + uint32_t done = 0; + int32_t readBytes = 0; while (done < filesize) { if (done + blocksize > filesize) { @@ -136,7 +136,7 @@ bool FSUtils::copyFile(const std::string &in, const std::string &out) { size_t size; 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) { return false; } @@ -146,7 +146,7 @@ bool FSUtils::copyFile(const std::string &in, const std::string &out) { } auto bufferSize = 1024 * 1024; - char *buf = (char *) malloc(bufferSize); + char *buf = (char *) malloc(bufferSize); if (buf == NULL) { return false; } @@ -171,4 +171,3 @@ int32_t FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size) file.close(); return written; } - diff --git a/source/fs/FSUtils.h b/source/fs/FSUtils.h index 1e7160f..67dd76a 100644 --- a/source/fs/FSUtils.h +++ b/source/fs/FSUtils.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include class FSUtils { public: diff --git a/source/fs/WUDFileWriter.cpp b/source/fs/WUDFileWriter.cpp index b45039d..2b284c0 100644 --- a/source/fs/WUDFileWriter.cpp +++ b/source/fs/WUDFileWriter.cpp @@ -14,12 +14,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include "WUDFileWriter.h" +#include -WUDFileWriter::WUDFileWriter(const char *path, int32_t cacheSize, int32_t pSectorSize, bool split) : - WriteOnlyFileWithCache(path, cacheSize, split), - sectorSize(pSectorSize) { +WUDFileWriter::WUDFileWriter(const char *path, int32_t cacheSize, int32_t pSectorSize, bool split) : WriteOnlyFileWithCache(path, cacheSize, split), + sectorSize(pSectorSize) { } 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() { - } diff --git a/source/fs/WUDFileWriter.h b/source/fs/WUDFileWriter.h index 1cc59a3..17fc21a 100644 --- a/source/fs/WUDFileWriter.h +++ b/source/fs/WUDFileWriter.h @@ -25,6 +25,7 @@ public: virtual int32_t writeSector(const uint8_t *buffer, uint32_t numberOfSectors); virtual void finalize(); + protected: int32_t sectorSize; }; diff --git a/source/fs/WUXFileWriter.cpp b/source/fs/WUXFileWriter.cpp index 431af49..cedc5a2 100644 --- a/source/fs/WUXFileWriter.cpp +++ b/source/fs/WUXFileWriter.cpp @@ -14,18 +14,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include "WUXFileWriter.h" #include "WUDDumperState.h" +#include -WUXFileWriter::WUXFileWriter(const char *path, int32_t cacheSize, int32_t sectorSize, bool split) : - WUDFileWriter(path, cacheSize, sectorSize, split) { - wuxHeader_t wuxHeader = {0}; - wuxHeader.magic0 = WUX_MAGIC_0; - wuxHeader.magic1 = WUX_MAGIC_1; - wuxHeader.sectorSize = swap_uint32(this->sectorSize); +WUXFileWriter::WUXFileWriter(const char *path, int32_t cacheSize, int32_t sectorSize, bool split) : WUDFileWriter(path, cacheSize, sectorSize, split) { + wuxHeader_t wuxHeader = {0}; + wuxHeader.magic0 = WUX_MAGIC_0; + wuxHeader.magic1 = WUX_MAGIC_1; + wuxHeader.sectorSize = swap_uint32(this->sectorSize); wuxHeader.uncompressedSize = swap_uint64(WUD_FILE_SIZE); - wuxHeader.flags = 0; + wuxHeader.flags = 0; this->write((uint8_t *) &wuxHeader, sizeof(wuxHeader_t)); this->sectorTableStart = this->tell(); @@ -45,12 +44,12 @@ WUXFileWriter::WUXFileWriter(const char *path, int32_t cacheSize, int32_t sector } this->sectorTableEnd = this->tell(); - uint64_t tableEnd = this->sectorTableEnd; + uint64_t tableEnd = this->sectorTableEnd; this->sectorTableEnd += this->sectorSize - 1; this->sectorTableEnd -= (this->sectorTableEnd % this->sectorSize); - uint64_t padding = this->sectorTableEnd - tableEnd; + uint64_t padding = this->sectorTableEnd - tableEnd; auto *paddingData = (uint8_t *) malloc(padding); memset(paddingData, 0, padding); this->write(reinterpret_cast(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]); } else { indexTable[this->currentSector] = swap_uint32(this->writtenSector); - hashMap[hash] = writtenSector; + hashMap[hash] = writtenSector; if (isOpen()) { if (!write((uint8_t *) addr, this->sectorSize)) { DEBUG_FUNCTION_LINE("Write failed"); @@ -111,5 +110,4 @@ void WUXFileWriter::finalize() { WUDFileWriter::finalize(); writeSectorIndexTable(); WUXFileWriter::close(); - } diff --git a/source/fs/WUXFileWriter.h b/source/fs/WUXFileWriter.h index ad2b4d8..cb39cd5 100644 --- a/source/fs/WUXFileWriter.h +++ b/source/fs/WUXFileWriter.h @@ -16,8 +16,8 @@ ****************************************************************************/ #pragma once -#include "utils/utils.h" #include "WUDFileWriter.h" +#include "utils/utils.h" #include typedef struct { @@ -28,8 +28,8 @@ typedef struct { unsigned int flags; } wuxHeader_t; -#define WUX_MAGIC_0 0x57555830 -#define WUX_MAGIC_1 swap_uint32(0x1099d02e) +#define WUX_MAGIC_0 0x57555830 +#define WUX_MAGIC_1 swap_uint32(0x1099d02e) class WUXFileWriter : public WUDFileWriter { public: diff --git a/source/fs/WriteOnlyFileWithCache.cpp b/source/fs/WriteOnlyFileWithCache.cpp index 218a83f..e4afdd3 100644 --- a/source/fs/WriteOnlyFileWithCache.cpp +++ b/source/fs/WriteOnlyFileWithCache.cpp @@ -14,11 +14,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include -#include -#include -#include #include "WriteOnlyFileWithCache.h" +#include +#include +#include +#include #define SPLIT_SIZE (0x80000000) @@ -29,7 +29,7 @@ WriteOnlyFileWithCache::WriteOnlyFileWithCache(const char *path, int32_t cacheSi return; } this->writeBufferSize = cacheSize; - this->writeBuffer = (void *) memalign(0x1000, this->writeBufferSize); + this->writeBuffer = (void *) memalign(0x1000, this->writeBufferSize); if (this->writeBuffer == nullptr) { this->close(); return; @@ -55,7 +55,7 @@ bool WriteOnlyFileWithCache::flush() { } int32_t WriteOnlyFileWithCache::write(const uint8_t *addr, size_t writeSize) { - auto finalAddr = addr; + auto finalAddr = addr; size_t finalWriteSize = writeSize; if (splitFile) { if (pos + writeBufferPos + finalWriteSize >= SPLIT_SIZE) { @@ -73,7 +73,7 @@ int32_t WriteOnlyFileWithCache::write(const uint8_t *addr, size_t writeSize) { } } finalWriteSize = writeSize - realWriteSize; - finalAddr = (uint8_t *) ((uint32_t) addr + realWriteSize); + finalAddr = (uint8_t *) ((uint32_t) addr + realWriteSize); part++; if (!flush()) { return -2; diff --git a/source/fs/WriteOnlyFileWithCache.h b/source/fs/WriteOnlyFileWithCache.h index 1a51cef..e1ce5b8 100644 --- a/source/fs/WriteOnlyFileWithCache.h +++ b/source/fs/WriteOnlyFileWithCache.h @@ -43,6 +43,6 @@ public: size_t writeBufferPos; bool splitFile = false; - int32_t part = 1; + int32_t part = 1; std::string originalPath; }; diff --git a/source/input/CombinedInput.h b/source/input/CombinedInput.h index d06350b..cba7c32 100644 --- a/source/input/CombinedInput.h +++ b/source/input/CombinedInput.h @@ -1,5 +1,5 @@ #pragma once - +#include "Input.h" class CombinedInput : public Input { public: void combine(const Input &b) { diff --git a/source/input/Input.h b/source/input/Input.h index f5fc51e..2c6d88f 100644 --- a/source/input/Input.h +++ b/source/input/Input.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include class Input { public: @@ -12,36 +12,36 @@ public: virtual ~Input() = default; enum eButtons { - BUTTON_NONE = 0x0000, - VPAD_TOUCH = 0x80000000, - BUTTON_Z = 0x20000, - BUTTON_C = 0x10000, - BUTTON_A = 0x8000, - BUTTON_B = 0x4000, - BUTTON_X = 0x2000, - BUTTON_Y = 0x1000, - BUTTON_1 = BUTTON_Y, - BUTTON_2 = BUTTON_X, - BUTTON_LEFT = 0x0800, - BUTTON_RIGHT = 0x0400, - BUTTON_UP = 0x0200, - BUTTON_DOWN = 0x0100, - BUTTON_ZL = 0x0080, - BUTTON_ZR = 0x0040, - BUTTON_L = 0x0020, - BUTTON_R = 0x0010, - BUTTON_PLUS = 0x0008, - BUTTON_MINUS = 0x0004, - BUTTON_HOME = 0x0002, - BUTTON_SYNC = 0x0001, - STICK_R_LEFT = 0x04000000, - STICK_R_RIGHT = 0x02000000, - STICK_R_UP = 0x01000000, - STICK_R_DOWN = 0x00800000, - STICK_L_LEFT = 0x40000000, - STICK_L_RIGHT = 0x20000000, - STICK_L_UP = 0x10000000, - STICK_L_DOWN = 0x08000000 + BUTTON_NONE = 0x0000, + VPAD_TOUCH = 0x80000000, + BUTTON_Z = 0x20000, + BUTTON_C = 0x10000, + BUTTON_A = 0x8000, + BUTTON_B = 0x4000, + BUTTON_X = 0x2000, + BUTTON_Y = 0x1000, + BUTTON_1 = BUTTON_Y, + BUTTON_2 = BUTTON_X, + BUTTON_LEFT = 0x0800, + BUTTON_RIGHT = 0x0400, + BUTTON_UP = 0x0200, + BUTTON_DOWN = 0x0100, + BUTTON_ZL = 0x0080, + BUTTON_ZR = 0x0040, + BUTTON_L = 0x0020, + BUTTON_R = 0x0010, + BUTTON_PLUS = 0x0008, + BUTTON_MINUS = 0x0004, + BUTTON_HOME = 0x0002, + BUTTON_SYNC = 0x0001, + STICK_R_LEFT = 0x04000000, + STICK_R_RIGHT = 0x02000000, + STICK_R_UP = 0x01000000, + STICK_R_DOWN = 0x00800000, + STICK_L_LEFT = 0x40000000, + STICK_L_RIGHT = 0x20000000, + STICK_L_UP = 0x10000000, + STICK_L_DOWN = 0x08000000 }; typedef struct { @@ -57,5 +57,4 @@ public: PadData data{}; PadData lastData{}; - }; diff --git a/source/input/VPADInput.h b/source/input/VPADInput.h index c4c538f..663f7b0 100644 --- a/source/input/VPADInput.h +++ b/source/input/VPADInput.h @@ -16,8 +16,8 @@ * along with this program. If not, see . ****************************************************************************/ -#include #include "Input.h" +#include class VPadInput : public Input { public: @@ -36,11 +36,11 @@ public: VPADRead(VPAD_CHAN_0, &vpad, 1, &vpadError); if (vpadError == VPAD_READ_SUCCESS) { - data.buttons_r = vpad.release; - data.buttons_h = vpad.hold; - data.buttons_d = vpad.trigger; + data.buttons_r = vpad.release; + data.buttons_h = vpad.hold; + data.buttons_d = vpad.trigger; data.validPointer = !vpad.tpNormal.validity; - data.touched = vpad.tpNormal.touched; + data.touched = vpad.tpNormal.touched; VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpCalib, &vpad.tpFiltered1); diff --git a/source/input/WPADInput.h b/source/input/WPADInput.h index 5d10091..1594ba6 100644 --- a/source/input/WPADInput.h +++ b/source/input/WPADInput.h @@ -16,9 +16,9 @@ * along with this program. If not, see . ****************************************************************************/ +#include "Input.h" #include #include -#include "Input.h" class WPADInput : public Input { public: diff --git a/source/main.cpp b/source/main.cpp index b5d2e59..830b1d7 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,21 +1,21 @@ -#include #include #include +#include #include -#include -#include #include #include -#include -#include #include +#include +#include +#include +#include -#include "utils/logger.h" -#include "utils/WiiUScreen.h" -#include "input/VPADInput.h" #include "MainApplicationState.h" +#include "input/VPADInput.h" +#include "utils/WiiUScreen.h" +#include "utils/logger.h" void initIOSUHax(); @@ -84,8 +84,7 @@ void main_loop() { WPAD_CHAN_0, WPAD_CHAN_1, WPAD_CHAN_2, - WPAD_CHAN_3 - }; + WPAD_CHAN_3}; if (gFSAfd < 0 || !sIosuhaxMount) { // state.setError(MainApplicationState::eErrorState::ERROR_IOSUHAX_FAILED); @@ -98,8 +97,8 @@ void main_loop() { if (vpadInput.update(1280, 720)) { baseInput.combine(vpadInput); } - for (auto &wpadInput: wpadInputs) { - if(wpadInput.update(1280, 720)){ + for (auto &wpadInput : wpadInputs) { + if (wpadInput.update(1280, 720)) { baseInput.combine(wpadInput); } } @@ -111,12 +110,12 @@ void main_loop() { void initIOSUHax() { sIosuhaxMount = false; - int res = IOSUHAX_Open(nullptr); + int res = IOSUHAX_Open(nullptr); if (res < 0) { DEBUG_FUNCTION_LINE("IOSUHAX_open failed"); } else { sIosuhaxMount = true; - gFSAfd = IOSUHAX_FSA_Open(); + gFSAfd = IOSUHAX_FSA_Open(); if (gFSAfd < 0) { DEBUG_FUNCTION_LINE("IOSUHAX_FSA_Open failed"); } else { diff --git a/source/utils/FSTUtils.cpp b/source/utils/FSTUtils.cpp index 1eb48d1..6e6fd4f 100644 --- a/source/utils/FSTUtils.cpp +++ b/source/utils/FSTUtils.cpp @@ -25,16 +25,16 @@ std::optional> FSTUtils::getFSTEntryByFullPath(const fullPath = "/" + fullPath; } - auto pathOpt = std::optional(root); + auto pathOpt = std::optional(root); std::filesystem::path asPath = fullPath; - std::string dirPath = asPath.parent_path().string(); + std::string dirPath = asPath.parent_path().string(); if (dirPath != "/") { pathOpt = getFileEntryDir(root, dirPath); } if (!pathOpt.has_value()) { return {}; } - for (auto &child: pathOpt.value()->getChildren()) { + for (auto &child : pathOpt.value()->getChildren()) { if (child->getFullPath() == fullPath) { return child; } @@ -48,7 +48,7 @@ std::optional> FSTUtils::getFileEntryDir(const s if (!string.ends_with("/")) { string += "/"; } - for (auto &curChild: curEntry->getDirChildren()) { + for (auto &curChild : curEntry->getDirChildren()) { std::string compareTo = curChild->getFullPath(); if (!compareTo.ends_with("/")) { compareTo += "/"; @@ -64,7 +64,7 @@ std::optional> FSTUtils::getFileEntryDir(const s } std::optional> FSTUtils::getSectionEntryForIndex(const std::shared_ptr &pFst, uint16_t index) { - for (const auto &entry: pFst->sectionEntries->getSections()) { + for (const auto &entry : pFst->sectionEntries->getSections()) { if (entry->sectionNumber == index) { return entry; } diff --git a/source/utils/FSTUtils.h b/source/utils/FSTUtils.h index f459490..6df63f2 100644 --- a/source/utils/FSTUtils.h +++ b/source/utils/FSTUtils.h @@ -16,10 +16,10 @@ ****************************************************************************/ #pragma once -#include -#include -#include #include +#include +#include +#include class FSTUtils { public: @@ -29,4 +29,3 @@ public: static std::optional> getSectionEntryForIndex(const std::shared_ptr &pFst, uint16_t index); }; - diff --git a/source/utils/ScreenUtils.cpp b/source/utils/ScreenUtils.cpp index 3fe9090..8ffc8a6 100644 --- a/source/utils/ScreenUtils.cpp +++ b/source/utils/ScreenUtils.cpp @@ -14,8 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include "ScreenUtils.h" +#include void ScreenUtils::printTextOnScreen(ConsoleScreenID screen, int x, int y, const char *msg) { if (!msg) { diff --git a/source/utils/ScreenUtils.h b/source/utils/ScreenUtils.h index ff6676f..30af8ad 100644 --- a/source/utils/ScreenUtils.h +++ b/source/utils/ScreenUtils.h @@ -15,6 +15,7 @@ * along with this program. If not, see . ****************************************************************************/ #pragma once +#include //! Defines the ID of a display usable with OSScreen. typedef enum ConsoleScreenID { diff --git a/source/utils/StringTools.cpp b/source/utils/StringTools.cpp index f313e3e..14ffcfa 100644 --- a/source/utils/StringTools.cpp +++ b/source/utils/StringTools.cpp @@ -23,17 +23,16 @@ * * for WiiXplorer 2010 ***************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "StringTools.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include 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 wchar_t strWChar[512]; strWChar[0] = 0; - tmp[0] = 0; + tmp[0] = 0; if (!format) return (const wchar_t *) strWChar; @@ -98,7 +97,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) { if ((vsprintf(tmp, format, va) >= 0)) { int32_t bt; int32_t strlength = strlen(tmp); - bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512); + bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512); if (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, ...) { static char tmp[512]; - tmp[0] = 0; + tmp[0] = 0; int32_t result = 0; va_list va; va_start(va, format); if ((vsprintf(tmp, format, va) >= 0)) { - str = tmp; + str = tmp; result = str.size(); } va_end(va); @@ -214,8 +213,7 @@ bool StringTools::findStringIC(const std::string &strHaystack, const std::string auto it = std::search( strHaystack.begin(), strHaystack.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()); } diff --git a/source/utils/StringTools.h b/source/utils/StringTools.h index faf467a..d84f4ef 100644 --- a/source/utils/StringTools.h +++ b/source/utils/StringTools.h @@ -25,11 +25,11 @@ ***************************************************************************/ #pragma once -#include -#include -#include #include #include +#include +#include +#include class StringTools { public: @@ -57,7 +57,7 @@ public: if (!path) return path; - const char *ptr = path; + const char *ptr = path; const char *Filename = ptr; while (*ptr != '\0') { diff --git a/source/utils/TinySHA1.hpp b/source/utils/TinySHA1.hpp index 70af046..32ad0fa 100644 --- a/source/utils/TinySHA1.hpp +++ b/source/utils/TinySHA1.hpp @@ -1,3 +1,4 @@ +// clang-format off /* * * TinySHA1 - a header only implementation of the SHA1 algorithm in C++. Based diff --git a/source/utils/WiiUScreen.cpp b/source/utils/WiiUScreen.cpp index b6e9260..b42213c 100644 --- a/source/utils/WiiUScreen.cpp +++ b/source/utils/WiiUScreen.cpp @@ -4,13 +4,13 @@ #include #include -void *WiiUScreen::sBufferTV = nullptr; -void *WiiUScreen::sBufferDRC = nullptr; -uint32_t WiiUScreen::sBufferSizeTV = 0; -uint32_t WiiUScreen::sBufferSizeDRC = 0; +void *WiiUScreen::sBufferTV = nullptr; +void *WiiUScreen::sBufferDRC = nullptr; +uint32_t WiiUScreen::sBufferSizeTV = 0; +uint32_t WiiUScreen::sBufferSizeDRC = 0; bool WiiUScreen::sConsoleHasForeground = true; -uint32_t WiiUScreen::consoleColor = 0x041F60FF; -uint32_t WiiUScreen::consoleCursorY = 0; +uint32_t WiiUScreen::consoleColor = 0x041F60FF; +uint32_t WiiUScreen::consoleCursorY = 0; uint32_t WiiUScreen::ProcCallbackAcquired(void *context) { @@ -38,7 +38,7 @@ uint32_t WiiUScreen::ProcCallbackReleased(void *context) { bool WiiUScreen::Init() { OSScreenInit(); - sBufferSizeTV = OSScreenGetBufferSizeEx(SCREEN_TV); + sBufferSizeTV = OSScreenGetBufferSizeEx(SCREEN_TV); sBufferSizeDRC = OSScreenGetBufferSizeEx(SCREEN_DRC); WiiUScreen::ProcCallbackAcquired(nullptr); diff --git a/source/utils/WiiUScreen.h b/source/utils/WiiUScreen.h index 1b7dbe6..71819b9 100644 --- a/source/utils/WiiUScreen.h +++ b/source/utils/WiiUScreen.h @@ -3,23 +3,24 @@ #include #include -#include +#include "utils/logger.h" #include #include +#include #include #include -#include #include -#include "utils/logger.h" +#include -#define NUM_LINES (16) -#define LINE_LENGTH (128) +#define NUM_LINES (16) +#define LINE_LENGTH (128) #define CONSOLE_FRAME_HEAP_TAG (0x000DECAF) -#define PRINTF_BUFFER_LENGTH 2048 +#define PRINTF_BUFFER_LENGTH 2048 -#define DEBUG_CONSOLE_LOG(FMT, ARGS...)do { \ - DEBUG_FUNCTION_LINE(FMT, ## ARGS); \ - WiiUScreen::drawLinef(FMT, ## ARGS); \ +#define DEBUG_CONSOLE_LOG(FMT, ARGS...) \ + do { \ + DEBUG_FUNCTION_LINE(FMT, ##ARGS); \ + WiiUScreen::drawLinef(FMT, ##ARGS); \ } while (0) diff --git a/source/utils/blocksize/AddressInBlocks.h b/source/utils/blocksize/AddressInBlocks.h index f92c526..4116a09 100644 --- a/source/utils/blocksize/AddressInBlocks.h +++ b/source/utils/blocksize/AddressInBlocks.h @@ -16,13 +16,12 @@ ****************************************************************************/ #pragma once -#include #include "BlockSize.h" +#include class AddressInBlocks { public: explicit AddressInBlocks(const BlockSize &pBlockSize, uint32_t pValue) : blockSize(pBlockSize), value(pValue) { - } AddressInBlocks() = default; diff --git a/source/utils/blocksize/AddressInDiscBlocks.h b/source/utils/blocksize/AddressInDiscBlocks.h index b2b6d7d..59d93da 100644 --- a/source/utils/blocksize/AddressInDiscBlocks.h +++ b/source/utils/blocksize/AddressInDiscBlocks.h @@ -38,4 +38,4 @@ namespace std { return lhs.getAddressInBytes() < rhs.getAddressInBytes(); } }; -} +} // namespace std diff --git a/source/utils/blocksize/AddressInVolumeBlocks.h b/source/utils/blocksize/AddressInVolumeBlocks.h index d5dae4e..ee2083c 100644 --- a/source/utils/blocksize/AddressInVolumeBlocks.h +++ b/source/utils/blocksize/AddressInVolumeBlocks.h @@ -16,8 +16,8 @@ ****************************************************************************/ #pragma once -#include "VolumeBlockSize.h" #include "AddressInBlocks.h" +#include "VolumeBlockSize.h" class AddressInVolumeBlocks : public AddressInBlocks { diff --git a/source/utils/blocksize/DiscBlockSize.h b/source/utils/blocksize/DiscBlockSize.h index 76f6dfe..19c4e92 100644 --- a/source/utils/blocksize/DiscBlockSize.h +++ b/source/utils/blocksize/DiscBlockSize.h @@ -16,8 +16,8 @@ ****************************************************************************/ #pragma once -#include "utils/logger.h" #include "BlockSize.h" +#include "utils/logger.h" class DiscBlockSize : public BlockSize { @@ -25,6 +25,5 @@ public: DiscBlockSize() = default; explicit DiscBlockSize(uint32_t blockSize) : BlockSize(blockSize) { - } }; \ No newline at end of file diff --git a/source/utils/blocksize/SectionBlockSize.h b/source/utils/blocksize/SectionBlockSize.h index a6807d1..ea9a011 100644 --- a/source/utils/blocksize/SectionBlockSize.h +++ b/source/utils/blocksize/SectionBlockSize.h @@ -16,8 +16,8 @@ ****************************************************************************/ #pragma once -#include #include "BlockSize.h" +#include class SectionBlockSize : public BlockSize { diff --git a/source/utils/blocksize/SizeInBlocks.h b/source/utils/blocksize/SizeInBlocks.h index fd3dc69..0dbfb2e 100644 --- a/source/utils/blocksize/SizeInBlocks.h +++ b/source/utils/blocksize/SizeInBlocks.h @@ -16,9 +16,9 @@ ****************************************************************************/ #pragma once +#include "BlockSize.h" #include #include -#include "BlockSize.h" class SizeInBlocks { public: diff --git a/source/utils/blocksize/SizeInVolumeBlocks.h b/source/utils/blocksize/SizeInVolumeBlocks.h index 4a20023..8260b7e 100644 --- a/source/utils/blocksize/SizeInVolumeBlocks.h +++ b/source/utils/blocksize/SizeInVolumeBlocks.h @@ -1,7 +1,7 @@ #pragma once -#include "VolumeBlockSize.h" #include "SizeInBlocks.h" +#include "VolumeBlockSize.h" class SizeInVolumeBlocks : public SizeInBlocks { @@ -9,6 +9,5 @@ public: SizeInVolumeBlocks() = default; SizeInVolumeBlocks(const VolumeBlockSize &blockSize, uint32_t value) : SizeInBlocks(blockSize, value) { - } }; \ No newline at end of file diff --git a/source/utils/blocksize/VolumeBlockSize.h b/source/utils/blocksize/VolumeBlockSize.h index cd3b9cf..ca82b67 100644 --- a/source/utils/blocksize/VolumeBlockSize.h +++ b/source/utils/blocksize/VolumeBlockSize.h @@ -16,8 +16,8 @@ ****************************************************************************/ #pragma once -#include #include "BlockSize.h" +#include class VolumeBlockSize : public BlockSize { diff --git a/source/utils/logger.h b/source/utils/logger.h index 750c908..aabe62c 100644 --- a/source/utils/logger.h +++ b/source/utils/logger.h @@ -8,14 +8,16 @@ extern "C" { #include #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) -#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) -#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ - WHBLogPrintf("[%23s]%30s@L%04d: " FMT ,__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ +#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \ + do { \ + WHBLogPrintf("[%23s]%30s@L%04d: " FMT, __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ } while (0) -#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ - WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \ + do { \ + WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ } while (0) #ifdef __cplusplus diff --git a/source/utils/rijndael.c b/source/utils/rijndael.c index db48c10..0308842 100644 --- a/source/utils/rijndael.c +++ b/source/utils/rijndael.c @@ -1,3 +1,4 @@ +// clang-format off /* Rijndael Block Cipher - rijndael.c Written by Mike Scott 21st April 1999 diff --git a/source/utils/rijndael.h b/source/utils/rijndael.h index 8d9e9b4..3007902 100644 --- a/source/utils/rijndael.h +++ b/source/utils/rijndael.h @@ -4,5 +4,4 @@ extern "C" { void aes_set_key(unsigned char *key); void aes_decrypt(unsigned char *iv, unsigned char *inbuf, unsigned char *outbuf, unsigned long long len); void aes_encrypt(unsigned char *iv, unsigned char *inbuf, unsigned char *outbuf, unsigned long long len); - }; \ No newline at end of file diff --git a/source/utils/utils.cpp b/source/utils/utils.cpp index 7dbe340..12c4e19 100644 --- a/source/utils/utils.cpp +++ b/source/utils/utils.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include "logger.h" #include "utils.h" -#include "TinySHA1.hpp" #include "../fs/FSUtils.h" +#include "TinySHA1.hpp" +#include "logger.h" +#include +#include +#include // https://gist.github.com/ccbrown/9722406 void Utils::dumpHex(const void *data, size_t size) { diff --git a/source/utils/utils.h b/source/utils/utils.h index e63c4fe..0350a77 100644 --- a/source/utils/utils.h +++ b/source/utils/utils.h @@ -7,28 +7,29 @@ extern "C" { #endif -#define LIMIT(x, min, max) \ - ({ \ - typeof( x ) _x = x; \ - typeof( min ) _min = min; \ - typeof( max ) _max = max; \ - ( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ -}) +#define LIMIT(x, min, max) \ + ({ \ + typeof(x) _x = x; \ + typeof(min) _min = min; \ + typeof(max) _max = max; \ + (((_x) < (_min)) ? (_min) : ((_x) > (_max)) ? (_max) \ + : (_x)); \ + }) -#define DegToRad(a) ( (a) * 0.01745329252f ) -#define RadToDeg(a) ( (a) * 57.29577951f ) +#define DegToRad(a) ((a) *0.01745329252f) +#define RadToDeg(a) ((a) *57.29577951f) -#define ALIGN4(x) (((x) + 3) & ~3) -#define ALIGN32(x) (((x) + 31) & ~31) +#define ALIGN4(x) (((x) + 3) & ~3) +#define ALIGN32(x) (((x) + 31) & ~31) // those work only in powers of 2 -#define ROUNDDOWN(val, align) ((val) & ~(align-1)) -#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align-1)), align) +#define ROUNDDOWN(val, align) ((val) & ~(align - 1)) +#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align) -#define le16(i) ((((uint16_t) ((i) & 0xFF)) << 8) | ((uint16_t) (((i) & 0xFF00) >> 8))) -#define le32(i) ((((uint32_t)le16((i) & 0xFFFF)) << 16) | ((uint32_t)le16(((i) & 0xFFFF0000) >> 16))) -#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) +#define le16(i) ((((uint16_t) ((i) &0xFF)) << 8) | ((uint16_t) (((i) &0xFF00) >> 8))) +#define le32(i) ((((uint32_t) le16((i) &0xFFFF)) << 16) | ((uint32_t) le16(((i) &0xFFFF0000) >> 16))) +#define le64(i) ((((uint64_t) le32((i) &0xFFFFFFFFLL)) << 32) | ((uint64_t) le32(((i) &0xFFFFFFFF00000000LL) >> 32))) unsigned int swap_uint32(unsigned int val);