From c6a700bf51b36175bbe643ede86976de53fadfee Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 14 Feb 2022 19:35:01 +0100 Subject: [PATCH] Make sure the iconCache is aligned properly --- src/RPXLoading.cpp | 6 +++--- src/globals.h | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/RPXLoading.cpp b/src/RPXLoading.cpp index 13eaad5..b9e6590 100644 --- a/src/RPXLoading.cpp +++ b/src/RPXLoading.cpp @@ -42,7 +42,7 @@ DECL_FUNCTION(int, RPX_FSOpenFile, FSClient *client, FSCmdBlock *block, char *pa if (StringTools::EndsWith(path, iconTex)) { if (gReplacementInfo.rpxReplacementInfo.isRPXReplaced) { if (StringTools::EndsWith(path, iconTex)) { - auto *reader = new FileReader(reinterpret_cast(gReplacementInfo.rpxReplacementInfo.iconCache), sizeof(gReplacementInfo.rpxReplacementInfo.iconCache)); + auto *reader = new FileReader(reinterpret_cast(gReplacementInfo.rpxReplacementInfo.iconCache), ICON_SIZE); *handle = (uint32_t) reader; return FS_STATUS_OK; } @@ -144,7 +144,7 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) { } if (reader) { uint32_t alreadyRead = 0; - uint32_t toRead = sizeof(gReplacementInfo.rpxReplacementInfo.iconCache); + uint32_t toRead = ICON_SIZE; do { int read = reader->read(reinterpret_cast(&gReplacementInfo.rpxReplacementInfo.iconCache[alreadyRead]), toRead); if (read <= 0) { @@ -152,7 +152,7 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) { } alreadyRead += read; toRead -= read; - } while (alreadyRead < sizeof(gReplacementInfo.rpxReplacementInfo.iconCache)); + } while (alreadyRead < ICON_SIZE); delete reader; } else { memset(gReplacementInfo.rpxReplacementInfo.iconCache, 0, sizeof(gReplacementInfo.rpxReplacementInfo.iconCache)); diff --git a/src/globals.h b/src/globals.h index 24db43d..5cf3a1c 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,12 +1,15 @@ +#include "utils/utils.h" #include #include #include +#include -typedef struct MetaInformation_t { +typedef struct WUT_PACKED MetaInformation_t { char shortname[64]; char longname[64]; char author[64]; } MetaInformation; +WUT_CHECK_SIZE(MetaInformation_t, 0xC0); typedef struct BundleMountInformation_t { bool isMounted; @@ -14,12 +17,18 @@ typedef struct BundleMountInformation_t { char mountedPath[255]; } BundleMountInformation; -typedef struct RPXReplacementInfo_t { +#define ICON_SIZE 65580 + +typedef struct WUT_PACKED RPXReplacementInfo_t { bool willRPXBeReplaced; bool isRPXReplaced; MetaInformation metaInformation; - char iconCache[65580]; + WUT_UNKNOWN_BYTES(0x3E); + char iconCache[ROUNDUP(ICON_SIZE, 0x040)]; } RPXReplacementInfo; +// make sure the iconCache is aligned to 0x40 +WUT_CHECK_OFFSET(RPXReplacementInfo, 0x100, iconCache); + typedef enum ContentRedirect_Mode { CONTENTREDIRECT_NONE,