mirror of
https://github.com/DarkStore-3DS/Project_CTR.git
synced 2026-07-05 16:59:02 +00:00
Fix UTF-16 to UTF-8 conversion on non-Windows
U+800 to U+FFFF encode as one UTF-16 code unit, but three byte in UTF-8. Filenames containing more characters in this range than the ASCII range would be cut off. This range includes all BMP Japanese characters.
This commit is contained in:
+4
-3
@@ -152,10 +152,11 @@ char* strcopy_UTF16toUTF8(const utf16char_t *src)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
src_len = utf16_strlen(src);
|
src_len = utf16_strlen(src);
|
||||||
dst_len = src_len * 2;
|
// UTF-8 can use up to 3 bytes per UTF-16 code unit, or four for a surrogate pair
|
||||||
|
dst_len = src_len * 3;
|
||||||
|
|
||||||
// Allocate memory for string
|
// Allocate memory for string
|
||||||
dst = calloc(dst_len, sizeof(char)); // twice the size, as UTF-8 will use up to two bytes for converted UTF16 chars afaik
|
dst = calloc(dst_len, sizeof(char));
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -206,4 +207,4 @@ oschar_t* os_AppendUTF16StrToPath(const oschar_t *src, const utf16char_t *add)
|
|||||||
|
|
||||||
free(_add);
|
free(_add);
|
||||||
return new_path;
|
return new_path;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -73,7 +73,7 @@ int LoadKeysFromResources(keys_struct *keys)
|
|||||||
/* AES Keys */
|
/* AES Keys */
|
||||||
// CIA
|
// CIA
|
||||||
//SetCommonKey(keys, zeros_aesKey,1);
|
//SetCommonKey(keys, zeros_aesKey,1);
|
||||||
if(keys->aes.currentCommonKey > 0xff)
|
if(keys->aes.currentCommonKey > MAX_CMN_KEY)
|
||||||
SetCurrentCommonKey(keys,0);
|
SetCurrentCommonKey(keys,0);
|
||||||
|
|
||||||
// NCCH
|
// NCCH
|
||||||
@@ -101,7 +101,7 @@ int LoadKeysFromResources(keys_struct *keys)
|
|||||||
for(int i = 0; i < 6; i++)
|
for(int i = 0; i < 6; i++)
|
||||||
SetCommonKey(keys, ctr_common_etd_key_dpki[i],i);
|
SetCommonKey(keys, ctr_common_etd_key_dpki[i],i);
|
||||||
|
|
||||||
if(keys->aes.currentCommonKey > 0xff)
|
if(keys->aes.currentCommonKey > MAX_CMN_KEY)
|
||||||
SetCurrentCommonKey(keys,0);
|
SetCurrentCommonKey(keys,0);
|
||||||
|
|
||||||
// NCCH
|
// NCCH
|
||||||
@@ -133,7 +133,7 @@ int LoadKeysFromResources(keys_struct *keys)
|
|||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
SetCommonKey(keys, ctr_common_etd_key_ppki[i], i);
|
SetCommonKey(keys, ctr_common_etd_key_ppki[i], i);
|
||||||
|
|
||||||
if(keys->aes.currentCommonKey > 0xff)
|
if(keys->aes.currentCommonKey > MAX_CMN_KEY)
|
||||||
SetCurrentCommonKey(keys,0);
|
SetCurrentCommonKey(keys,0);
|
||||||
|
|
||||||
// NCCH
|
// NCCH
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
AES_128_KEY_SIZE = 16,
|
AES_128_KEY_SIZE = 16,
|
||||||
MAX_CMN_KEY = MAX_U8,
|
MAX_CMN_KEY = 0x05,
|
||||||
MAX_NCCH_KEYX = MAX_U8
|
MAX_NCCH_KEYX = MAX_U8
|
||||||
} keydata_limits;
|
} keydata_limits;
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -152,10 +152,11 @@ char* strcopy_UTF16toUTF8(const utf16char_t *src)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
src_len = utf16_strlen(src);
|
src_len = utf16_strlen(src);
|
||||||
dst_len = src_len * 2;
|
// UTF-8 can use up to 3 bytes per UTF-16 code unit, or four for a surrogate pair
|
||||||
|
dst_len = src_len * 3;
|
||||||
|
|
||||||
// Allocate memory for string
|
// Allocate memory for string
|
||||||
dst = calloc(dst_len, sizeof(char)); // twice the size, as UTF-8 will use up to two bytes for converted UTF16 chars afaik
|
dst = calloc(dst_len, sizeof(char));
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -206,4 +207,4 @@ oschar_t* os_AppendUTF16StrToPath(const oschar_t *src, const utf16char_t *add)
|
|||||||
|
|
||||||
free(_add);
|
free(_add);
|
||||||
return new_path;
|
return new_path;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-7
@@ -89,6 +89,7 @@ void SetDefaults(user_settings *set)
|
|||||||
|
|
||||||
// Build NCCH Info
|
// Build NCCH Info
|
||||||
set->ncch.useSecCrypto = true;
|
set->ncch.useSecCrypto = true;
|
||||||
|
set->ncch.keyXID = 0;
|
||||||
set->ncch.buildNcch0 = true;
|
set->ncch.buildNcch0 = true;
|
||||||
set->ncch.includeExefsLogo = false;
|
set->ncch.includeExefsLogo = false;
|
||||||
set->common.outFormat = NCCH;
|
set->common.outFormat = NCCH;
|
||||||
@@ -115,7 +116,7 @@ void SetDefaults(user_settings *set)
|
|||||||
set->cia.useDataTitleVer = false;
|
set->cia.useDataTitleVer = false;
|
||||||
set->cia.useFullTitleVer = false;
|
set->cia.useFullTitleVer = false;
|
||||||
set->cia.randomTitleKey = false;
|
set->cia.randomTitleKey = false;
|
||||||
set->common.keys.aes.currentCommonKey = MAX_U8 + 1; // invalid so changes can be detected
|
set->common.keys.aes.currentCommonKey = 0;
|
||||||
for (int i = 0; i < CIA_MAX_CONTENT; i++)
|
for (int i = 0; i < CIA_MAX_CONTENT; i++)
|
||||||
set->cia.contentId[i] = MAX_U32 + 1; // invalid so changes can be detected
|
set->cia.contentId[i] = MAX_U32 + 1; // invalid so changes can be detected
|
||||||
}
|
}
|
||||||
@@ -196,7 +197,6 @@ int SetArgument(int argc, int i, char *argv[], user_settings *set)
|
|||||||
}
|
}
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
else if (strcmp(argv[i], "-ckeyid") == 0) {
|
else if (strcmp(argv[i], "-ckeyid") == 0) {
|
||||||
if (ParamNum != 1) {
|
if (ParamNum != 1) {
|
||||||
PrintArgReqParam(argv[i], 1);
|
PrintArgReqParam(argv[i], 1);
|
||||||
@@ -224,7 +224,6 @@ int SetArgument(int argc, int i, char *argv[], user_settings *set)
|
|||||||
}
|
}
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
else if (strcmp(argv[i], "-showkeys") == 0) {
|
else if (strcmp(argv[i], "-showkeys") == 0) {
|
||||||
if (ParamNum) {
|
if (ParamNum) {
|
||||||
PrintNoNeedParam(argv[i]);
|
PrintNoNeedParam(argv[i]);
|
||||||
@@ -903,7 +902,7 @@ void PrintNoNeedParam(char *arg)
|
|||||||
|
|
||||||
void DisplayBanner(void)
|
void DisplayBanner(void)
|
||||||
{
|
{
|
||||||
printf("CTR MAKEROM v0.16 (C) 3DSGuy 2017\n");
|
printf("CTR MAKEROM v0.16.1 (C) 3DSGuy 2017\n");
|
||||||
printf("Built: %s %s\n\n", __TIME__, __DATE__);
|
printf("Built: %s %s\n\n", __TIME__, __DATE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -952,10 +951,16 @@ void DisplayExtendedHelp(char *app_name)
|
|||||||
printf(" 't' Test(false) Keys & prod Certs\n");
|
printf(" 't' Test(false) Keys & prod Certs\n");
|
||||||
printf(" 'd' Development Keys & Certs\n");
|
printf(" 'd' Development Keys & Certs\n");
|
||||||
printf(" 'p' Production Keys & Certs\n");
|
printf(" 'p' Production Keys & Certs\n");
|
||||||
//printf(" -ckeyid <index> Override the automatic common key selection\n");
|
printf(" -ckeyid <index> Ticket Common Key Index, defaults to 0x00\n");
|
||||||
//printf(" -ncchseckey <index> Ncch keyX index ('0'=1.0+, '1'=7.0+)\n");
|
printf(" 0x00 : Applications / eShop\n");
|
||||||
|
printf(" 0x01 : System Titles\n");
|
||||||
|
printf(" 0x02-0x05 : Unused\n");
|
||||||
|
printf(" -ncchseckey <index> NCCH KeyX index, defaults to 0x00\n");
|
||||||
|
printf(" 0x00 : FW 1.0.0+\n");
|
||||||
|
printf(" 0x01 : FW 7.0.0+\n");
|
||||||
|
printf(" 0x0a : FW 9.3.0+ (New3DS only)\n");
|
||||||
|
printf(" 0x0b : FW 9.6.0+ (New3DS only)\n");
|
||||||
printf(" -showkeys Display the loaded key chain\n");
|
printf(" -showkeys Display the loaded key chain\n");
|
||||||
//printf(" -fsign False sign digital signatures\n");
|
|
||||||
printf(" -ignoresign Ignore invalid signatures\n");
|
printf(" -ignoresign Ignore invalid signatures\n");
|
||||||
printf("NCCH OPTIONS:\n");
|
printf("NCCH OPTIONS:\n");
|
||||||
printf(" -elf <file> ELF file\n");
|
printf(" -elf <file> ELF file\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user