Skip to content

Commit

Permalink
tools/cxbe: Handle invalid title id and remove redundant a region flag
Browse files Browse the repository at this point in the history
  • Loading branch information
PQCraft committed Jul 28, 2023
1 parent dab7981 commit 303a499
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions tools/cxbe/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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");
Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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])
Expand Down

0 comments on commit 303a499

Please sign in to comment.