From 1cf7485274dac2b67ffcbc14a4abfb7c27357acd Mon Sep 17 00:00:00 2001 From: sbJFn5r Date: Sun, 31 Aug 2014 22:24:09 -0400 Subject: [PATCH 1/5] Update ctr.h --- ctrtool/ctr.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ctrtool/ctr.h b/ctrtool/ctr.h index 724f4c0..9321051 100644 --- a/ctrtool/ctr.h +++ b/ctrtool/ctr.h @@ -26,6 +26,7 @@ typedef enum FILETYPE_LZSS, FILETYPE_FIRM, FILETYPE_CWAV, + FILETYPE_EXEFS, FILETYPE_ROMFS } ctr_filetypes; From 7210dbc7d8af454485b269579dbcf4cde83734f3 Mon Sep 17 00:00:00 2001 From: sbJFn5r Date: Sun, 31 Aug 2014 22:24:56 -0400 Subject: [PATCH 2/5] Update types.h --- ctrtool/types.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ctrtool/types.h b/ctrtool/types.h index 0ec1442..bade7f1 100644 --- a/ctrtool/types.h +++ b/ctrtool/types.h @@ -21,7 +21,8 @@ enum flags VerboseFlag = (1<<3), VerifyFlag = (1<<4), RawFlag = (1<<5), - ShowKeysFlag = (1<<6) + ShowKeysFlag = (1<<6), + DecompressCodeFlag = (1<<7) }; enum validstate From ea2dbc023bf30f381d0242b199dd5c5d67d5dce9 Mon Sep 17 00:00:00 2001 From: sbJFn5r Date: Sun, 31 Aug 2014 22:26:38 -0400 Subject: [PATCH 3/5] Update main.c --- ctrtool/main.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ctrtool/main.c b/ctrtool/main.c index 2f837f0..5846fa2 100644 --- a/ctrtool/main.c +++ b/ctrtool/main.c @@ -78,6 +78,9 @@ static void usage(const char *argv0) "CWAV options:\n" " --wav=file Specify wav output file.\n" " --wavloops=count Specify wav loop count, default 0.\n" + "EXEFS options:\n" + " --decompresscode Decompress .code section\n" + " (only needed when using raw EXEFS file)\n" "ROMFS options:\n" " --romfsdir=dir Specify RomFS directory path.\n" " --listromfs List files in RomFS.\n" @@ -142,6 +145,7 @@ int main(int argc, char* argv[]) {"listromfs", 0, NULL, 18}, {"wavloops", 1, NULL, 19}, {"logo", 1, NULL, 20}, + {"decompresscode", 0, NULL, 21}, {NULL}, }; @@ -201,6 +205,8 @@ int main(int argc, char* argv[]) ctx.filetype = FILETYPE_FIRM; else if (!strcmp(optarg, "cwav")) ctx.filetype = FILETYPE_CWAV; + else if (!strcmp(optarg, "exefs")) + ctx.filetype = FILETYPE_EXEFS; else if (!strcmp(optarg, "romfs")) ctx.filetype = FILETYPE_ROMFS; break; @@ -226,6 +232,7 @@ int main(int argc, char* argv[]) case 18: settings_set_list_romfs_files(&ctx.usersettings, 1); break; case 19: settings_set_cwav_loopcount(&ctx.usersettings, strtoul(optarg, 0, 0)); break; case 20: settings_set_logo_path(&ctx.usersettings, optarg); break; + case 21: ctx.actions |= DecompressCodeFlag; break; default: usage(argv[0]); @@ -424,6 +431,19 @@ int main(int argc, char* argv[]) break; } + + case FILETYPE_EXEFS: + { + exefs_context exefsctx; + + exefs_init(&exefsctx); + exefs_set_file(&exefsctx, ctx.infile); + exefs_set_size(&exefsctx, ctx.infilesize); + exefs_set_usersettings(&exefsctx, &ctx.usersettings); + exefs_process(&exefsctx, ctx.actions); + + break; + } case FILETYPE_ROMFS: { From 2b4a79f517606a2ff334e6d7d8a99d0fd69c26e7 Mon Sep 17 00:00:00 2001 From: sbJFn5r Date: Sun, 31 Aug 2014 22:27:36 -0400 Subject: [PATCH 4/5] Update exefs.c --- ctrtool/exefs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ctrtool/exefs.c b/ctrtool/exefs.c index a4dce90..7807071 100644 --- a/ctrtool/exefs.c +++ b/ctrtool/exefs.c @@ -129,7 +129,7 @@ void exefs_save(exefs_context* ctx, u32 index, u32 flags) ctr_init_counter(&ctx->aes, ctx->key, ctx->counter); ctr_add_counter(&ctx->aes, offset / 0x10); - if (index == 0 && ctx->compressedflag && ((flags & RawFlag) == 0)) + if (index == 0 && (ctx->compressedflag || (flags & DecompressCodeFlag)) && ((flags & RawFlag) == 0)) { fprintf(stdout, "Decompressing section %s to %s...\n", name, outfname); @@ -200,6 +200,8 @@ void exefs_save(exefs_context* ctx, u32 index, u32 flags) } clean: + if (fout) + fclose(fout); free(compressedbuffer); free(decompressedbuffer); return; From 2e6341ac0da493ed8537adff6f1e27b664167ab2 Mon Sep 17 00:00:00 2001 From: sbJFn5r Date: Mon, 1 Sep 2014 14:09:28 -0400 Subject: [PATCH 5/5] Forgot to add 'exefs' to the '-t' options display --- ctrtool/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctrtool/main.c b/ctrtool/main.c index 5846fa2..f80823a 100644 --- a/ctrtool/main.c +++ b/ctrtool/main.c @@ -57,7 +57,7 @@ static void usage(const char *argv0) " --ncchsyskey=key Set ncch fixed system key.\n" " --showkeys Show the keys being used.\n" " -t, --intype=type Specify input file type [ncsd, ncch, exheader, cia, tmd, lzss,\n" - " firm, cwav, romfs]\n" + " firm, cwav, exefs, romfs]\n" "LZSS options:\n" " --lzssout=file Specify lzss output file\n" "CXI/CCI options:\n"