Formatting and minor clean ups

This commit is contained in:
Maschell 2021-10-09 01:24:12 +02:00
parent 648c0d0fd7
commit 6919bdb44f
30 changed files with 57 additions and 39 deletions

View File

@ -719,7 +719,7 @@ void ApplicationState::dumpAppFiles() {
return; return;
} }
DEBUG_FUNCTION_LINE("Read DiscHeader"); DEBUG_FUNCTION_LINE("Read DiscHeader");
auto *discHeader = new WiiUDiscHeader(discReader, 0); auto *discHeader = new WiiUDiscHeader(discReader);
bool forceExit = false; bool forceExit = false;
for (auto &partition: discHeader->wiiUContentsInformation->partitions->partitions) { for (auto &partition: discHeader->wiiUContentsInformation->partitions->partitions) {
auto gmPartition = dynamic_cast<WiiUGMPartition *>(partition); auto gmPartition = dynamic_cast<WiiUGMPartition *>(partition);

View File

@ -104,7 +104,7 @@ private:
std::vector<uint64_t> skippedSectors; std::vector<uint64_t> skippedSectors;
int readResult = 0; int readResult = 0;
[[nodiscard]] bool writeDataToFile(void* buffer, int numberOfSection); [[nodiscard]] bool writeDataToFile(void *buffer, int numberOfSection);
uint64_t totalSectorCount = 0; uint64_t totalSectorCount = 0;
@ -116,7 +116,8 @@ private:
uint32_t writeBufferSize = 0; uint32_t writeBufferSize = 0;
[[nodiscard]] bool writeCached(uint32_t addr, uint32_t writeSize); [[nodiscard]] bool writeCached(uint32_t addr, uint32_t writeSize);
void clearWriteCache();
void clearWriteCache();
[[nodiscard]] bool flushWriteCache(); [[nodiscard]] bool flushWriteCache();

View File

@ -27,7 +27,7 @@ public:
bool readPlainDecryptedContent(Content *pContent, uint8_t **data, uint32_t *length) override; bool readPlainDecryptedContent(Content *pContent, uint8_t **data, uint32_t *length) override;
NUSDataProvider* getDataProvider() override; NUSDataProvider *getDataProvider() override;
private: private:
NUSDataProvider *dataProvider; NUSDataProvider *dataProvider;

View File

@ -21,6 +21,7 @@
class DiscReader { class DiscReader {
public: public:
DiscReader(); DiscReader();
virtual ~DiscReader(); virtual ~DiscReader();
virtual bool IsReady() = 0; virtual bool IsReady() = 0;

View File

@ -19,11 +19,14 @@
#include <cstdint> #include <cstdint>
#include "DiscReader.h" #include "DiscReader.h"
class DiscReaderDiscDrive : public DiscReader{ class DiscReaderDiscDrive : public DiscReader {
public: public:
DiscReaderDiscDrive(); DiscReaderDiscDrive();
~DiscReaderDiscDrive() override; ~DiscReaderDiscDrive() override;
bool readEncryptedSector(uint8_t *buffer, uint32_t block_cnt, uint64_t offset_in_sector) const override; bool readEncryptedSector(uint8_t *buffer, uint32_t block_cnt, uint64_t offset_in_sector) const override;
bool IsReady() override; bool IsReady() override;
bool readEncrypted(uint8_t *buf, uint64_t offset, uint32_t size) override; bool readEncrypted(uint8_t *buf, uint64_t offset, uint32_t size) override;

View File

@ -22,7 +22,7 @@ class NUSDecryption {
public: public:
explicit NUSDecryption(Ticket *pTicket); explicit NUSDecryption(Ticket *pTicket);
void decryptData(uint8_t *IV, uint8_t *inData, uint8_t *outData, uint32_t size) const ; void decryptData(uint8_t *IV, uint8_t *inData, uint8_t *outData, uint32_t size) const;
Ticket *ticket; Ticket *ticket;
}; };

View File

@ -18,6 +18,7 @@
#include "WiiUContentsInformation.h" #include "WiiUContentsInformation.h"
uint32_t WiiUContentsInformation::LENGTH = 32768; uint32_t WiiUContentsInformation::LENGTH = 32768;
WiiUContentsInformation::WiiUContentsInformation(DiscReader *reader, uint32_t offset) { WiiUContentsInformation::WiiUContentsInformation(DiscReader *reader, uint32_t offset) {
uint32_t curOffset = offset; uint32_t curOffset = offset;
discContentHeader = new WiiUDiscContentsHeader(reader, curOffset); discContentHeader = new WiiUDiscContentsHeader(reader, curOffset);

View File

@ -25,11 +25,11 @@ uint32_t WiiUDiscContentsHeader::MAGIC = 0xCCA6E67B;
WiiUDiscContentsHeader::WiiUDiscContentsHeader(DiscReader *reader, uint32_t offset) { WiiUDiscContentsHeader::WiiUDiscContentsHeader(DiscReader *reader, uint32_t offset) {
auto *buffer = (uint8_t *) malloc(LENGTH); auto *buffer = (uint8_t *) malloc(LENGTH);
if (!reader->hasDiscKey) { if (!reader->hasDiscKey) {
if(!reader->readEncrypted(buffer, offset, LENGTH)){ if (!reader->readEncrypted(buffer, offset, LENGTH)) {
OSFatal("WiiUDiscContentsHeader: Failed to read encrypted"); OSFatal("WiiUDiscContentsHeader: Failed to read encrypted");
} }
} else { } else {
if(!reader->readDecrypted(buffer, offset, 0, LENGTH, reader->discKey, nullptr, true)){ if (!reader->readDecrypted(buffer, offset, 0, LENGTH, reader->discKey, nullptr, true)) {
OSFatal("WiiUDiscContentsHeader: Failed to read decrypted"); OSFatal("WiiUDiscContentsHeader: Failed to read decrypted");
} }
} }

View File

@ -25,6 +25,7 @@ class WiiUPartition {
public: public:
WiiUPartition(); WiiUPartition();
explicit WiiUPartition(DiscReader *reader, uint32_t offset, const DiscBlockSize &blockSize); explicit WiiUPartition(DiscReader *reader, uint32_t offset, const DiscBlockSize &blockSize);
virtual uint64_t getSectionOffsetOnDefaultPartition(); virtual uint64_t getSectionOffsetOnDefaultPartition();
@ -35,11 +36,11 @@ public:
return volumeId; return volumeId;
} }
[[nodiscard]] virtual std::map<AddressInDiscBlocks, VolumeHeader *> getVolumes() const&{ [[nodiscard]] virtual std::map<AddressInDiscBlocks, VolumeHeader *> getVolumes() const &{
return volumes; return volumes;
} }
[[nodiscard]] virtual uint16_t getFileSystemDescriptor() const{ [[nodiscard]] virtual uint16_t getFileSystemDescriptor() const {
return fileSystemDescriptor; return fileSystemDescriptor;
} }

View File

@ -30,9 +30,9 @@
class WiiUPartitions { class WiiUPartitions {
public: public:
static bool getFSTEntryAsByte(uint8_t **buffer_out, uint32_t *outSize, std::string &filePath, FST *fst, const AddressInDiscBlocks& volumeAddress, DiscReader* discReader); static bool getFSTEntryAsByte(uint8_t **buffer_out, uint32_t *outSize, std::string &filePath, FST *fst, const AddressInDiscBlocks &volumeAddress, DiscReader *discReader);
WiiUPartitions(DiscReader *reader, uint32_t offset, uint32_t numberOfPartitions, const DiscBlockSize& blockSize); WiiUPartitions(DiscReader *reader, uint32_t offset, uint32_t numberOfPartitions, const DiscBlockSize &blockSize);
~WiiUPartitions(); ~WiiUPartitions();

View File

@ -21,7 +21,7 @@
uint32_t VolumeHeader::MAGIC = 0xCC93A4F5; uint32_t VolumeHeader::MAGIC = 0xCC93A4F5;
VolumeHeader::VolumeHeader(DiscReader *reader, uint64_t offset) { VolumeHeader::VolumeHeader(DiscReader *reader, uint64_t offset) {
auto buffer = (uint8_t *) malloc(64); auto buffer = (uint8_t *) malloc(64);
if (buffer == nullptr) { if (buffer == nullptr) {
OSFatal("VolumeHeader: failed to alloc buffer"); OSFatal("VolumeHeader: failed to alloc buffer");
@ -51,12 +51,12 @@ VolumeHeader::VolumeHeader(DiscReader *reader, uint64_t offset) {
free(buffer); free(buffer);
auto bufferH3 = (uint8_t *) malloc(ROUNDUP(h3HashArrayListSize,16)); auto bufferH3 = (uint8_t *) malloc(ROUNDUP(h3HashArrayListSize, 16));
if (bufferH3 == nullptr) { if (bufferH3 == nullptr) {
OSFatal("VolumeHeader: failed to alloc h3 buffer"); OSFatal("VolumeHeader: failed to alloc h3 buffer");
} }
if (!reader->readEncrypted(bufferH3,offset + 64, ROUNDUP(h3HashArrayListSize,16))) { if (!reader->readEncrypted(bufferH3, offset + 64, ROUNDUP(h3HashArrayListSize, 16))) {
OSFatal("VolumeHeader: failed to read h3"); OSFatal("VolumeHeader: failed to read h3");
} }
@ -67,7 +67,7 @@ VolumeHeader::VolumeHeader(DiscReader *reader, uint64_t offset) {
std::vector<H3HashArray *> VolumeHeader::getH3HashArray(uint8_t *h3Data, uint32_t pNumberOfH3HashArray, uint32_t pH3HashArrayListSize) { std::vector<H3HashArray *> VolumeHeader::getH3HashArray(uint8_t *h3Data, uint32_t pNumberOfH3HashArray, uint32_t pH3HashArrayListSize) {
std::vector<H3HashArray *> arrayList; std::vector<H3HashArray *> arrayList;
if(pNumberOfH3HashArray == 0){ if (pNumberOfH3HashArray == 0) {
return arrayList; return arrayList;
} }

View File

@ -26,7 +26,7 @@
class FST { class FST {
public: public:
FST(uint8_t *data, uint32_t fstSize, uint32_t offset, const VolumeBlockSize& blockSize); FST(uint8_t *data, uint32_t fstSize, uint32_t offset, const VolumeBlockSize &blockSize);
~FST(); ~FST();
@ -35,5 +35,5 @@ public:
StringTable *stringTable; StringTable *stringTable;
NodeEntries *nodeEntries; NodeEntries *nodeEntries;
[[nodiscard]] RootEntry * getRootEntry() const; [[nodiscard]] RootEntry *getRootEntry() const;
}; };

View File

@ -22,9 +22,9 @@
class FSTHeader { class FSTHeader {
public: public:
explicit FSTHeader(uint8_t *data) ; explicit FSTHeader(uint8_t *data);
~FSTHeader()= default; ~FSTHeader() = default;
uint8_t FSTVersion; uint8_t FSTVersion;
SectionBlockSize blockSize; SectionBlockSize blockSize;

View File

@ -41,19 +41,19 @@ public:
uint32_t entryNumber{}; uint32_t entryNumber{};
static NodeEntry *AutoDeserialize(uint8_t *data, uint32_t offset, DirectoryEntry *pParent, uint32_t eEntryNumber, SectionEntries *sectionEntries, static NodeEntry *AutoDeserialize(uint8_t *data, uint32_t offset, DirectoryEntry *pParent, uint32_t eEntryNumber, SectionEntries *sectionEntries,
StringTable *stringTable, const SectionBlockSize& blockSize); StringTable *stringTable, const SectionBlockSize &blockSize);
virtual ~NodeEntry()= default; virtual ~NodeEntry() = default;
virtual void printPathRecursive() { virtual void printPathRecursive() {
DEBUG_FUNCTION_LINE("%s", getFullPath().c_str()); DEBUG_FUNCTION_LINE("%s", getFullPath().c_str());
} }
[[nodiscard]] std::string getFullPath() const&; [[nodiscard]] std::string getFullPath() const &;
[[nodiscard]] std::string getPath() const&; [[nodiscard]] std::string getPath() const &;
[[nodiscard]] std::string getName() const&; [[nodiscard]] std::string getName() const &;
[[nodiscard]] bool isDirectory() const; [[nodiscard]] bool isDirectory() const;

View File

@ -17,13 +17,14 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
class DirectoryEntry; class DirectoryEntry;
class NodeEntryParam { class NodeEntryParam {
public: public:
uint16_t sectionNumber; uint16_t sectionNumber;
uint32_t entryNumber; uint32_t entryNumber;
DirectoryEntry* parent; DirectoryEntry *parent;
uint16_t permission; uint16_t permission;
uint8_t type; uint8_t type;
uint32_t uint24; uint32_t uint24;

View File

@ -25,7 +25,7 @@ RootEntry::RootEntry(DirectoryEntry *input) {
entryNumber = input->entryNumber; entryNumber = input->entryNumber;
parent = input->parent; parent = input->parent;
nameString = input->nameString; nameString = input->nameString;
if(nameString == nullptr){ if (nameString == nullptr) {
OSFatal("nameString was null"); OSFatal("nameString was null");
} }
entryType = input->entryType; entryType = input->entryType;

View File

@ -16,7 +16,7 @@
****************************************************************************/ ****************************************************************************/
#include "SectionEntry.h" #include "SectionEntry.h"
SectionEntry::SectionEntry(uint8_t *data, uint32_t pSectionNumber, const VolumeBlockSize& pBlockSize) { SectionEntry::SectionEntry(uint8_t *data, uint32_t pSectionNumber, const VolumeBlockSize &pBlockSize) {
auto *dataAsUint = (uint32_t *) data; auto *dataAsUint = (uint32_t *) data;
address = AddressInVolumeBlocks(pBlockSize, dataAsUint[0]); address = AddressInVolumeBlocks(pBlockSize, dataAsUint[0]);
size = SizeInVolumeBlocks(pBlockSize, dataAsUint[1]); size = SizeInVolumeBlocks(pBlockSize, dataAsUint[1]);

View File

@ -17,7 +17,7 @@
#include "StringEntry.h" #include "StringEntry.h"
#include "StringTable.h" #include "StringTable.h"
std::string StringEntry::toString() const{ std::string StringEntry::toString() const {
return stringTable->getByAddress(offset); return stringTable->getByAddress(offset);
} }

View File

@ -32,9 +32,9 @@ TitleMetaData::~TitleMetaData() {
} }
} }
Content* TitleMetaData::getContentByIndex(uint16_t i) { Content *TitleMetaData::getContentByIndex(uint16_t i) {
for (auto &content: contentList) { for (auto &content: contentList) {
if(content->index == i){ if (content->index == i) {
return content; return content;
} }
} }

View File

@ -28,7 +28,7 @@ public:
std::vector<Content *> contentList; std::vector<Content *> contentList;
Content* getContentByIndex(uint16_t index); Content *getContentByIndex(uint16_t index);
private: private:
uint16_t contentCount; uint16_t contentCount;

View File

@ -38,3 +38,7 @@ WiiUDiscHeader::~WiiUDiscHeader() {
delete discId; delete discId;
delete wiiUContentsInformation; delete wiiUContentsInformation;
} }
WiiUDiscHeader::WiiUDiscHeader(DiscReaderDiscDrive *pDrive) : WiiUDiscHeader(pDrive, 0) {
}

View File

@ -19,19 +19,22 @@
#include <cstdint> #include <cstdint>
#include <WUD/DiscReader.h> #include <WUD/DiscReader.h>
#include <WUD/content/WiiUContentsInformation.h> #include <WUD/content/WiiUContentsInformation.h>
#include <WUD/DiscReaderDiscDrive.h>
#include "WiiUManufactorDiscID.h" #include "WiiUManufactorDiscID.h"
#include "WiiUDiscID.h" #include "WiiUDiscID.h"
class WiiUDiscHeader { class WiiUDiscHeader {
public: public:
static uint32_t LENGTH; explicit WiiUDiscHeader(DiscReaderDiscDrive *pDrive);
WiiUDiscHeader(DiscReader *reader, uint32_t offset); WiiUDiscHeader(DiscReader *reader, uint32_t offset);
~WiiUDiscHeader();
WiiUManufactorDiscID *manufactorDiscID = nullptr; WiiUManufactorDiscID *manufactorDiscID = nullptr;
WiiUDiscID *discId = nullptr; WiiUDiscID *discId = nullptr;
WiiUContentsInformation *wiiUContentsInformation = nullptr; WiiUContentsInformation *wiiUContentsInformation = nullptr;
~WiiUDiscHeader(); static uint32_t LENGTH;
}; };

View File

@ -20,7 +20,7 @@
uint32_t WiiUManufactorDiscID::LENGTH = 65536; uint32_t WiiUManufactorDiscID::LENGTH = 65536;
WiiUManufactorDiscID::WiiUManufactorDiscID(DiscReader *reader, uint32_t offset) { WiiUManufactorDiscID::WiiUManufactorDiscID(DiscReader *reader, uint32_t offset) {
if(!reader->readEncrypted(data, offset, LENGTH)){ if (!reader->readEncrypted(data, offset, LENGTH)) {
OSFatal("WiiUManufactorDiscID: read failed"); OSFatal("WiiUManufactorDiscID: read failed");
} }
} }

View File

@ -5,7 +5,7 @@
#include <WUD/entities/FST/nodeentry/DirectoryEntry.h> #include <WUD/entities/FST/nodeentry/DirectoryEntry.h>
#include <WUD/entities/FST/FST.h> #include <WUD/entities/FST/FST.h>
class FSTUtils{ class FSTUtils {
public: public:
static NodeEntry *getFSTEntryByFullPath(DirectoryEntry *root, std::string &givenFullPath); static NodeEntry *getFSTEntryByFullPath(DirectoryEntry *root, std::string &givenFullPath);

View File

@ -51,5 +51,6 @@ public:
private: private:
ScreenUtils() = default; ScreenUtils() = default;
~ScreenUtils() = default; ~ScreenUtils() = default;
}; };

View File

@ -89,7 +89,7 @@ public:
static bool findStringIC(const std::string &strHaystack, const std::string &strNeedle); static bool findStringIC(const std::string &strHaystack, const std::string &strNeedle);
// https://stackoverflow.com/a/3418285 // https://stackoverflow.com/a/3418285
static bool replace(std::string& str, const std::string& from, const std::string& to); static bool replace(std::string &str, const std::string &from, const std::string &to);
static bool strCompareIC(const std::string &str1, const std::string &str2); static bool strCompareIC(const std::string &str1, const std::string &str2);
}; };

View File

@ -23,6 +23,7 @@ class AddressInVolumeBlocks : public AddressInBlocks {
public: public:
AddressInVolumeBlocks() = default; AddressInVolumeBlocks() = default;
AddressInVolumeBlocks(const VolumeBlockSize &pBlockSize, uint32_t pValue) : AddressInBlocks(pBlockSize, pValue) { AddressInVolumeBlocks(const VolumeBlockSize &pBlockSize, uint32_t pValue) : AddressInBlocks(pBlockSize, pValue) {
} }
}; };

View File

@ -26,5 +26,5 @@ public:
this->blockSize = blockSize; this->blockSize = blockSize;
} }
uint32_t blockSize {}; uint32_t blockSize{};
}; };

View File

@ -23,6 +23,7 @@ class DiscBlockSize : public BlockSize {
public: public:
DiscBlockSize() = default; DiscBlockSize() = default;
explicit DiscBlockSize(uint32_t blockSize) : BlockSize(blockSize) { explicit DiscBlockSize(uint32_t blockSize) : BlockSize(blockSize) {
} }

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "AddressInBlocks.h" #include "AddressInBlocks.h"
#include "SectionBlockSize.h" #include "SectionBlockSize.h"