From 303a4999e2c4a3a2b611adedaef63dd32f22cafd Mon Sep 17 00:00:00 2001 From: PQCraft <0456523@gmail.com> Date: Thu, 20 Jul 2023 18:13:36 -0400 Subject: [PATCH] tools/cxbe: Handle invalid title id and remove redundant a region flag --- tools/cxbe/Main.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tools/cxbe/Main.cpp b/tools/cxbe/Main.cpp index 5d6f4b49a..a144dab6d 100644 --- a/tools/cxbe/Main.cpp +++ b/tools/cxbe/Main.cpp @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) bool bRetail; uint32 dwTitleId = 0xFFFF0002; - uint32 dwRegions; + uint32 dwRegions = XBEIMAGE_GAME_REGION_NA | XBEIMAGE_GAME_REGION_JAPAN | XBEIMAGE_GAME_REGION_RESTOFWORLD | XBEIMAGE_GAME_REGION_MANUFACTURING;; uint32 dwVersion; const char *program = argv[0]; @@ -89,9 +89,13 @@ int main(int argc, char *argv[]) } else { - char titlechar[2] = { (char)0xFF, (char)0xFF }; - unsigned titleno = 0x0002; - sscanf(szXbeTitleID, "%c%c-%u", &titlechar[0], &titlechar[1], &titleno); + char titlechar[2]; + unsigned titleno; + if (sscanf(szXbeTitleID, "%c%c-%u", &titlechar[0], &titlechar[1], &titleno) != 3) + { + strncpy(szErrorMessage, "invalid TITLEID", ERROR_LEN); + goto cleanup; + } if(titleno > 0xFFFF) { printf("WARNING: Title ID number too high (max is 65535)\n"); @@ -104,6 +108,7 @@ int main(int argc, char *argv[]) // interpret region flags if(szXbeRegions[0]) { + dwRegions = 0; char c; for(int i = 0; (c = szXbeRegions[i]); ++i) { @@ -112,11 +117,6 @@ int main(int argc, char *argv[]) case '-':; dwRegions = 0; goto breakfor; - case 'a':; - dwRegions = XBEIMAGE_GAME_REGION_NA | XBEIMAGE_GAME_REGION_JAPAN | - XBEIMAGE_GAME_REGION_RESTOFWORLD | - XBEIMAGE_GAME_REGION_MANUFACTURING; - goto breakfor; case 'n':; dwRegions |= XBEIMAGE_GAME_REGION_NA; break; @@ -136,11 +136,6 @@ int main(int argc, char *argv[]) } breakfor:; } - else - { - dwRegions = XBEIMAGE_GAME_REGION_NA | XBEIMAGE_GAME_REGION_JAPAN | - XBEIMAGE_GAME_REGION_RESTOFWORLD | XBEIMAGE_GAME_REGION_MANUFACTURING; - } // interpret version if(szXbeVersion[0])