Skip to content

Commit

Permalink
Add a block if the backup persistent ID differs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightkingale committed Jul 31, 2024
1 parent 97edbc9 commit 8137beb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TOPDIR ?= $(CURDIR)
APP_NAME := Wii U Account Swap
APP_SHORTNAME := Wii U Account Swap
APP_AUTHOR := Nightkingale
APP_VERSION := v2.0.3
APP_VERSION := v2.0.4

include $(DEVKITPRO)/wut/share/wut_rules

Expand Down
46 changes: 46 additions & 0 deletions source/swap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,45 @@ handle_cleanup(FILE* backup, account account_type, char* buffer, bool is_error =
}
}

bool
user_check(FILE* backup, account account_type)
{
char *buffer = (char *)malloc(BUFFER_SIZE);
size_t bytes_read = 0;
if (buffer == NULL) {
draw_error_menu("Error allocating memory!");
handle_cleanup(backup, account_type, buffer, true);
return false;
}

// Prepare the search string, including the user's persistent ID.
char persistent_id_hex[9];
sprintf(persistent_id_hex, "%08x", PERSISTENT_ID);
std::string search_string = "PersistentId=" + std::string(persistent_id_hex);
bool found = false;
rewind(backup);

while ((bytes_read = fread(buffer, 1, BUFFER_SIZE, backup)) > 0) {
if (ferror(backup)) {
draw_error_menu("Error reading from backup account.dat file!");
handle_cleanup(backup, account_type, buffer, true);
return false;
}

if (strstr(buffer, search_string.c_str()) != NULL) {
found = true; // The user's persistent ID was found.
break;
}
}

if (!found) {
// The persistent ID probably does not match the user's, so block the swap.
// This means that the end-user probably tried moving backups around.
draw_error_menu("The account.dat does not match the current user!");
handle_cleanup(backup, account_type, buffer, true);
}
return found;
}

bool
swap_account(const char* backup_file, account account_type)
Expand All @@ -60,7 +99,14 @@ swap_account(const char* backup_file, account account_type)
return false;
}

// This is a fix to prevent users from using account.dat files that aren't made for it.
// Moving around backups was an oversight people abused, which led to broken users and bricks.
if (!user_check(backup, account_type)) {
return false;
}

// Open the account.dat file for writing.
rewind(backup); // Maybe not necessary but just in case?
char *buffer = (char *)malloc(BUFFER_SIZE);
if (buffer == NULL) {
draw_error_menu("Error allocating memory!");
Expand Down

0 comments on commit 8137beb

Please sign in to comment.