Remove illegal fat32 chars in badge dump

This commit is contained in:
2024-06-17 14:10:14 -04:00
parent 7182fd9078
commit 11113bbc07
4 changed files with 16 additions and 1 deletions

View File

@@ -32,7 +32,7 @@
#include <jansson.h> #include <jansson.h>
typedef struct { typedef struct {
u32 background_color; u32 background_color;
u32 accent_color; u32 accent_color;
u32 red_color; u32 red_color;
u32 yellow_color; u32 yellow_color;

View File

@@ -29,6 +29,7 @@
#include "common.h" #include "common.h"
void replace_chars(u16 *input, char *remove, u16 with);
size_t strulen(const u16 *, ssize_t); size_t strulen(const u16 *, ssize_t);
void struacat(u16 * input, const char * addition); void struacat(u16 * input, const char * addition);
void printu(u16 * input); void printu(u16 * input);

View File

@@ -353,6 +353,7 @@ SetNode * extract_sets(char *badgeMngBuffer, Handle backupDataHandle)
DEBUG("Processing icon for set %lu at index %lu\n", cursor->set_id, cursor->set_index); DEBUG("Processing icon for set %lu at index %lu\n", cursor->set_id, cursor->set_index);
u16 utf16SetName[0x46] = {0}; u16 utf16SetName[0x46] = {0};
FSFILE_Read(backupDataHandle, NULL, cursor->set_index * 16 * 0x8A, utf16SetName, 0x8A); FSFILE_Read(backupDataHandle, NULL, cursor->set_index * 16 * 0x8A, utf16SetName, 0x8A);
replace_chars(utf16SetName, ILLEGAL_CHARS, u'-');
u16 set_path[256] = {0}; u16 set_path[256] = {0};
struacat(set_path, "/3ds/" APP_TITLE "/BadgeBackups/"); struacat(set_path, "/3ds/" APP_TITLE "/BadgeBackups/");
size_t set_name_len = strucat(set_path, utf16SetName); size_t set_name_len = strucat(set_path, utf16SetName);
@@ -431,6 +432,7 @@ Result extract_badges(void)
u16 utf16Name[0x46] = {0}; u16 utf16Name[0x46] = {0};
FSFILE_Read(backupDataHandle, NULL, 0x35E80 + i * 16 * 0x8A, utf16Name, 0x8A); FSFILE_Read(backupDataHandle, NULL, 0x35E80 + i * 16 * 0x8A, utf16Name, 0x8A);
replace_chars(utf16Name, ILLEGAL_CHARS, u'-');
char utf8Name[256] = {0}; char utf8Name[256] = {0};
res = utf16_to_utf8((u8 *) utf8Name, utf16Name, 256); res = utf16_to_utf8((u8 *) utf8Name, utf16Name, 256);
@@ -444,6 +446,7 @@ Result extract_badges(void)
{ {
u16 utf16SetName[0x46] = {0}; u16 utf16SetName[0x46] = {0};
FSFILE_Read(backupDataHandle, NULL, set_index * 16 * 0x8A, utf16SetName, 0x8A); FSFILE_Read(backupDataHandle, NULL, set_index * 16 * 0x8A, utf16SetName, 0x8A);
replace_chars(utf16SetName, ILLEGAL_CHARS, u'-');
char utf8SetName[128] = {0}; char utf8SetName[128] = {0};
res = utf16_to_utf8((u8 *) utf8SetName, utf16SetName, 128); res = utf16_to_utf8((u8 *) utf8SetName, utf16SetName, 128);
if (!res) if (!res)

View File

@@ -26,6 +26,17 @@
#include "unicode.h" #include "unicode.h"
void replace_chars(u16 *input, char *remove, u16 with)
{
for (u16 *cursor = input; *cursor != '\0'; cursor++)
{
if (strchr(remove, (char) (*cursor & 0xFF)))
{
*cursor = with;
}
}
}
size_t strulen(const u16 * input, ssize_t max_len) size_t strulen(const u16 * input, ssize_t max_len)
{ {
for (int i = 0; i < max_len; i++) if (input[i] == 0) return i; for (int i = 0; i < max_len; i++) if (input[i] == 0) return i;