Skip to content

Commit dc16822

Browse files
committed
Fix potential case sensitivity issue and warnings on Linux
1 parent d986668 commit dc16822

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

aes.c

-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ int aes_setkey_enc(aes_context* ctx, const uint8_t* key, unsigned int keybits)
461461
{
462462
aes_gen_tables();
463463
aes_init_done = 1;
464-
465464
}
466465
#endif
467466

cdecrypt.c

+20-14
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ static bool extract_file_hash(FILE* src, uint64_t part_data_offset, uint64_t fil
238238
if (write_size > size)
239239
write_size = size;
240240

241-
fread(enc, sizeof(char), BLOCK_SIZE, src);
241+
if (fread(enc, sizeof(char), BLOCK_SIZE, src) != BLOCK_SIZE) {
242+
fprintf(stderr, "ERROR: Could not read %d bytes from '%s'\n", BLOCK_SIZE, path);
243+
goto out;
244+
}
242245

243246
memset(iv, 0, sizeof(iv));
244247
iv[1] = (uint8_t)content_id;
@@ -261,7 +264,7 @@ static bool extract_file_hash(FILE* src, uint64_t part_data_offset, uint64_t fil
261264
hexdump(hash, SHA_DIGEST_LENGTH);
262265
hexdump(hashes, 0x100);
263266
hexdump(dec, 0x100);
264-
fprintf(stderr, "ERROR: Failed to verify H0 hash\n");
267+
fprintf(stderr, "ERROR: Could not verify H0 hash\n");
265268
goto out;
266269
}
267270

@@ -324,7 +327,10 @@ static bool extract_file(FILE* src, uint64_t part_data_offset, uint64_t file_off
324327
if (write_size > size)
325328
write_size = size;
326329

327-
fread(enc, sizeof(char), BLOCK_SIZE, src);
330+
if (fread(enc, sizeof(char), BLOCK_SIZE, src) != BLOCK_SIZE) {
331+
fprintf(stderr, "ERROR: Could not read %d bytes from '%s'\n", BLOCK_SIZE, path);
332+
goto out;
333+
}
328334

329335
aes_crypt_cbc(&ctx, AES_DECRYPT, BLOCK_SIZE, iv, (const uint8_t*)(enc), (uint8_t*)dec);
330336

@@ -356,6 +362,7 @@ int main_utf8(int argc, char** argv)
356362
FILE* src = NULL;
357363
TitleMetaData* tmd = NULL;
358364
uint8_t *tik = NULL, *cnt = NULL;
365+
const char* pattern[] = { "%s%c%08x.app", "%s%c%08X.app", "%s%c%08x", "%s%c%08X" };
359366

360367
if (argc < 2) {
361368
printf("%s %s - Wii U NUS content file decrypter\n"
@@ -383,8 +390,7 @@ int main_utf8(int argc, char** argv)
383390
tik_path = strdup(argv[1]);
384391
tik_path[strlen(tik_path) - 2] = 'i';
385392
tik_path[strlen(tik_path) - 1] = 'k';
386-
}
387-
else {
393+
} else {
388394
tik_path = strdup(argv[2]);
389395
}
390396
} else if (magic == TIK_MAGIC) {
@@ -393,8 +399,7 @@ int main_utf8(int argc, char** argv)
393399
tmd_path = strdup(argv[1]);
394400
tmd_path[strlen(tik_path) - 2] = 'm';
395401
tmd_path[strlen(tik_path) - 1] = 'd';
396-
}
397-
else {
402+
} else {
398403
tmd_path = strdup(argv[2]);
399404
}
400405
}
@@ -543,17 +548,18 @@ int main_utf8(int argc, char** argv)
543548
cnt_offset, getbe16(&fe[i].ContentID), getbe16(&fe[i].Flags), &path[short_path]);
544549

545550
uint32_t cnt_file_id = getbe32(&tmd->Contents[getbe16(&fe[i].ContentID)].ID);
546-
sprintf(str, "%s%c%08X.app", argv[1], PATH_SEP, cnt_file_id);
547551

548552
if (!(fe[i].Type & 0x80)) {
553+
// Handle upper/lowercase for target as well as files without extension
554+
for (uint32_t k = 0; k < array_size(pattern); k++) {
555+
sprintf(str, pattern[k], argv[1], PATH_SEP, cnt_file_id);
556+
if (is_file(str))
557+
break;
558+
}
549559
src = fopen_utf8(str, "rb");
550560
if (src == NULL) {
551-
sprintf(str, "%s%c%08X", argv[1], PATH_SEP, cnt_file_id);
552-
src = fopen_utf8(str, "rb");
553-
if (src == NULL) {
554-
fprintf(stderr, "ERROR: Could not open: '%s'\n", str);
555-
goto out;
556-
}
561+
fprintf(stderr, "ERROR: Could not open: '%s'\n", str);
562+
goto out;
557563
}
558564
if ((getbe16(&fe[i].Flags) & 0x440)) {
559565
if (!extract_file_hash(src, 0, cnt_offset, getbe32(&fe[i].FileLength), path, getbe16(&fe[i].ContentID)))

0 commit comments

Comments
 (0)