From 06738e071a5cdfdbcb8d8f1627a5b25d0565d864 Mon Sep 17 00:00:00 2001 From: Lectem Date: Sun, 10 May 2015 08:56:13 +0200 Subject: [PATCH 1/2] Fix problem on windows MAX_PATH is defined in stdlib as 260 on windows. As some source files included stdlib and some not, it made the program crash because of different sizes of the filepath structure. You can check it with sizeof(filepath) in romfs.c and settings.h. Tested on MinGW latest update. --- ctrtool/utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctrtool/utils.h b/ctrtool/utils.h index 31a06fb..8e8f543 100644 --- a/ctrtool/utils.h +++ b/ctrtool/utils.h @@ -10,7 +10,7 @@ #endif #ifndef MAX_PATH - #define MAX_PATH 255 + #define MAX_PATH 260 #endif #ifdef __cplusplus From bf77d99a4e7dc90f6dafe88b88aa7c7950753356 Mon Sep 17 00:00:00 2001 From: Lectem Date: Fri, 15 May 2015 00:32:59 +0200 Subject: [PATCH 2/2] dont blow the stack ! --- ctrtool/romfs.c | 19 +++++++++++-------- ctrtool/romfs.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ctrtool/romfs.c b/ctrtool/romfs.c index af58d74..27667e0 100644 --- a/ctrtool/romfs.c +++ b/ctrtool/romfs.c @@ -6,6 +6,7 @@ #include "types.h" #include "romfs.h" #include "utils.h" +#include "filepath.h" void romfs_init(romfs_context* ctx) { @@ -86,12 +87,14 @@ void romfs_process(romfs_context* ctx, u32 actions) fseek(ctx->file, dirblockoffset, SEEK_SET); fread(ctx->dirblock, 1, dirblocksize, ctx->file); } + else perror("ctx->dirblock\n"); if (ctx->fileblock) { fseek(ctx->file, fileblockoffset, SEEK_SET); fread(ctx->fileblock, 1, fileblocksize, ctx->file); } + else perror("ctx->fileblock\n"); if (actions & InfoFlag) romfs_print(ctx); @@ -223,8 +226,10 @@ void romfs_visit_dir(romfs_context* ctx, u32 diroffset, u32 depth, u32 actions, childoffset = getle32(entry->childoffset); fileoffset = getle32(entry->fileoffset); - if (fileoffset != (~0)) - romfs_visit_file(ctx, fileoffset, depth+1, actions, ¤tpath); + while(fileoffset != (~0)) + { + fileoffset=romfs_visit_file(ctx, fileoffset, depth+1, actions, ¤tpath); + } if (childoffset != (~0)) romfs_visit_dir(ctx, childoffset, depth+1, actions, ¤tpath); @@ -234,7 +239,7 @@ void romfs_visit_dir(romfs_context* ctx, u32 diroffset, u32 depth, u32 actions, } -void romfs_visit_file(romfs_context* ctx, u32 fileoffset, u32 depth, u32 actions, filepath* rootpath) +u32 romfs_visit_file(romfs_context *ctx, u32 fileoffset, u32 depth, u32 actions, filepath *rootpath) { u32 siblingoffset = 0; filepath currentpath; @@ -242,7 +247,7 @@ void romfs_visit_file(romfs_context* ctx, u32 fileoffset, u32 depth, u32 actions if (!romfs_fileblock_readentry(ctx, fileoffset, entry)) - return; + return 0; // fprintf(stdout, "%08X %08X %016llX %016llX %08X ", @@ -262,7 +267,7 @@ void romfs_visit_file(romfs_context* ctx, u32 fileoffset, u32 depth, u32 actions else { fprintf(stderr, "Error creating directory in root %s\n", rootpath->pathname); - return; + return 0; } } else @@ -279,9 +284,7 @@ void romfs_visit_file(romfs_context* ctx, u32 fileoffset, u32 depth, u32 actions } siblingoffset = getle32(entry->siblingoffset); - - if (siblingoffset != (~0)) - romfs_visit_file(ctx, siblingoffset, depth, actions, rootpath); + return siblingoffset; } void romfs_extract_datafile(romfs_context* ctx, u64 offset, u64 size, filepath* path) diff --git a/ctrtool/romfs.h b/ctrtool/romfs.h index 892e9ac..cfb68fe 100644 --- a/ctrtool/romfs.h +++ b/ctrtool/romfs.h @@ -82,7 +82,7 @@ int romfs_dirblock_readentry(romfs_context* ctx, u32 diroffset, romfs_direntry* int romfs_fileblock_read(romfs_context* ctx, u32 fileoffset, u32 filesize, void* buffer); int romfs_fileblock_readentry(romfs_context* ctx, u32 fileoffset, romfs_fileentry* entry); void romfs_visit_dir(romfs_context* ctx, u32 diroffset, u32 depth, u32 actions, filepath* rootpath); -void romfs_visit_file(romfs_context* ctx, u32 fileoffset, u32 depth, u32 actions, filepath* rootpath); +u32 romfs_visit_file(romfs_context *ctx, u32 fileoffset, u32 depth, u32 actions, filepath *rootpath); void romfs_extract_datafile(romfs_context* ctx, u64 offset, u64 size, filepath* path); void romfs_process(romfs_context* ctx, u32 actions); void romfs_print(romfs_context* ctx);