From 45b7a75af057ac59f7fd1e529891ee7d16d92727 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Fri, 17 Nov 2017 16:25:30 +0100 Subject: [PATCH] Simplified TAR code --- arm9/source/crypto/keydb.c | 2 +- arm9/source/godmode.c | 10 +++++----- arm9/source/system/tar.c | 8 ++++---- arm9/source/system/tar.h | 2 +- arm9/source/system/vram0.h | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/arm9/source/crypto/keydb.c b/arm9/source/crypto/keydb.c index c7c9bf7..1fef802 100644 --- a/arm9/source/crypto/keydb.c +++ b/arm9/source/crypto/keydb.c @@ -123,7 +123,7 @@ u32 LoadKeyDb(const char* path_db, AesKeyInfo* keydb, u32 bsize) { } else { // check for hardcoded key database u64 aeskeydb_bin_size = 0; - void* aeskeydb_bin = FindVTarFileInfo(VRAM0_AESKEY_DB, &aeskeydb_bin_size, NULL); + void* aeskeydb_bin = FindVTarFileInfo(VRAM0_AESKEY_DB, &aeskeydb_bin_size); fsize = (aeskeydb_bin_size <= bsize) ? aeskeydb_bin_size : 0; if (fsize) memcpy(keydb, aeskeydb_bin, aeskeydb_bin_size); diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index 372e4d3..f26497b 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -1589,7 +1589,7 @@ u32 HomeMoreMenu(char* current_path) { int hsrestore = ((CheckHealthAndSafetyInject("1:") == 0) || (CheckHealthAndSafetyInject("4:") == 0)) ? (int) ++n_opt : -1; int clock = ++n_opt; int sysinfo = ++n_opt; - int readme = (FindVTarFileInfo(VRAM0_README_MD, NULL, NULL)) ? (int) ++n_opt : -1; + int readme = (FindVTarFileInfo(VRAM0_README_MD, NULL)) ? (int) ++n_opt : -1; if (sdformat > 0) optionstr[sdformat - 1] = "SD format menu"; if (bonus > 0) optionstr[bonus - 1] = "Bonus drive setup"; @@ -1704,7 +1704,7 @@ u32 HomeMoreMenu(char* current_path) { } else if (user_select == readme) { // Display GodMode9 readme u64 README_md_size; - char* README_md = FindVTarFileInfo(VRAM0_README_MD, &README_md_size, NULL); + char* README_md = FindVTarFileInfo(VRAM0_README_MD, &README_md_size); MemToCViewer(README_md, README_md_size, "GodMode9 ReadMe Table of Contents"); return 0; } else return 1; @@ -1713,7 +1713,7 @@ u32 HomeMoreMenu(char* current_path) { } u32 SplashInit(const char* modestr) { - void* splash = FindVTarFileInfo(VRAM0_SPLASH_QLZ, NULL, NULL); + void* splash = FindVTarFileInfo(VRAM0_SPLASH_QLZ, NULL); const char* namestr = FLAVOR " " VERSION; const char* loadstr = "booting..."; const u32 pos_xb = 10; @@ -1723,7 +1723,7 @@ u32 SplashInit(const char* modestr) { ClearScreenF(true, true, COLOR_STD_BG); if (splash) QlzDecompress(TOP_SCREEN, splash, 0); - else DrawStringF(TOP_SCREEN, 10, 10, COLOR_STD_FONT, COLOR_TRANSPARENT, "(splash not found)"); + else DrawStringF(TOP_SCREEN, 10, 10, COLOR_STD_FONT, COLOR_TRANSPARENT, "(" VRAM0_SPLASH_QLZ " not found)"); if (modestr) DrawStringF(TOP_SCREEN, SCREEN_WIDTH_TOP - 10 - GetDrawStringWidth(modestr), SCREEN_HEIGHT - 10 - GetDrawStringHeight(modestr), COLOR_STD_FONT, COLOR_TRANSPARENT, modestr); @@ -2309,7 +2309,7 @@ u32 ScriptRunner(int entrypoint) { // get script from VRAM0 TAR u64 autorun_gm9_size = 0; - void* autorun_gm9 = FindVTarFileInfo(VRAM0_AUTORUN_GM9, &autorun_gm9_size, NULL); + void* autorun_gm9 = FindVTarFileInfo(VRAM0_AUTORUN_GM9, &autorun_gm9_size); if (autorun_gm9 && autorun_gm9_size) { // copy script to script buffer and run it diff --git a/arm9/source/system/tar.c b/arm9/source/system/tar.c index 25c1a57..d580a0a 100644 --- a/arm9/source/system/tar.c +++ b/arm9/source/system/tar.c @@ -32,7 +32,7 @@ u32 ValidateTarHeader(void* tardata, void* tardata_end) { return 1; // type can only be standard file or dir - if ((tar->ftype != '0') && (tar->ftype != '5')) + if (tar->ftype && (tar->ftype != '0') && (tar->ftype != '5')) return 1; // checksum @@ -70,13 +70,13 @@ void* NextTarEntry(void* tardata, void* tardata_end) { return data; } -void* FindTarFileInfo(void* tardata, void* tardata_end, const char* fname, u64* fsize, bool* is_dir) { +void* FindTarFileInfo(void* tardata, void* tardata_end, const char* fname, u64* fsize) { while (tardata && (tardata < tardata_end)) { TarHeader* tar = tardata; if (ValidateTarHeader(tardata, tardata_end) != 0) break; - if ((strncasecmp(tar->fname, fname, 100) == 0) && (tar->ftype == '0')) - return GetTarFileInfo(tardata, NULL, fsize, is_dir); + if ((strncasecmp(tar->fname, fname, 100) == 0) && (!tar->ftype || (tar->ftype == '0'))) + return GetTarFileInfo(tardata, NULL, fsize, NULL); tardata = ((u8*) tardata) + sizeof(TarHeader) + align(ReadAsciiOctal(tar->fsize, 12), 512); } diff --git a/arm9/source/system/tar.h b/arm9/source/system/tar.h index 740801c..b014e96 100644 --- a/arm9/source/system/tar.h +++ b/arm9/source/system/tar.h @@ -32,4 +32,4 @@ typedef struct { u32 ValidateTarHeader(void* tardata, void* tardata_end); void* GetTarFileInfo(void* tardata, char* fname, u64* fsize, bool* is_dir); void* NextTarEntry(void* tardata, void* tardata_end); -void* FindTarFileInfo(void* tardata, void* tardata_end, const char* fname, u64* fsize, bool* is_dir); +void* FindTarFileInfo(void* tardata, void* tardata_end, const char* fname, u64* fsize); diff --git a/arm9/source/system/vram0.h b/arm9/source/system/vram0.h index a295773..b927ea4 100644 --- a/arm9/source/system/vram0.h +++ b/arm9/source/system/vram0.h @@ -34,5 +34,5 @@ #define GetVTarFileInfo(tardata, fname, fsize, is_dir) \ GetTarFileInfo(tardata, fname, fsize, is_dir) -#define FindVTarFileInfo(fname, fsize, is_dir) \ - FindTarFileInfo(TARDATA, TARDATA_END, fname, fsize, is_dir) +#define FindVTarFileInfo(fname, fsize) \ + FindTarFileInfo(TARDATA, TARDATA_END, fname, fsize)