From baba3783f451c3d82df82a8fc2a077779a73a0cd Mon Sep 17 00:00:00 2001 From: Pk11 Date: Tue, 18 Jan 2022 22:52:02 -0600 Subject: [PATCH] Fix homebrew banner padding --- arm9/src/install.c | 12 ++++++------ arm9/src/storage.c | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arm9/src/install.c b/arm9/src/install.c index 1d382d2..f643b57 100644 --- a/arm9/src/install.c +++ b/arm9/src/install.c @@ -487,11 +487,11 @@ bool install(char* fpath, bool systemTitle) swiWaitForVBlank(); u32 clusterSize = getDsiClusterSize(); - unsigned long long fileSize = getRomSize(fpath); - if ((fileSize % clusterSize) != 0) - fileSize += clusterSize - (fileSize % clusterSize); + unsigned long long fileSize = getRomSize(fpath), fileSizeOnDisk = fileSize; + if ((fileSizeOnDisk % clusterSize) != 0) + fileSizeOnDisk = clusterSize - (fileSizeOnDisk % clusterSize); //file + saves + TMD (rounded up to cluster size) - unsigned long long installSize = fileSize + _getSaveDataSize(h) + clusterSize; + unsigned long long installSize = fileSizeOnDisk + _getSaveDataSize(h) + clusterSize; if (tmdFound) installSize += clusterSize; //ticket, rounded up to cluster size printBytes(installSize); @@ -661,12 +661,12 @@ bool install(char* fpath, bool systemTitle) //pad out banner if it is the last part of the file { - if (h->ndshdr.bannerOffset == fileSize - 0x1C00) + if (h->ndshdr.bannerOffset > (fileSize - 0x23C0)) { iprintf("Padding banner..."); swiWaitForVBlank(); - if (padFile(appPath, 0x7C0) == false) + if (padFile(appPath, h->ndshdr.bannerOffset + 0x23C0 - fileSize) == false) { iprintf("\x1B[31m"); //red iprintf("Failed\n"); diff --git a/arm9/src/storage.c b/arm9/src/storage.c index f6631e1..a15a31d 100644 --- a/arm9/src/storage.c +++ b/arm9/src/storage.c @@ -186,8 +186,8 @@ bool padFile(char const* path, int size) } else { - char zero = 0; - fwrite(&zero, size, 1, f); + for (int i = 0; i < size; i++) + fputc('\0', f); } fclose(f);