diff --git a/Makefile b/Makefile index b96efeb..c0a0745 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ include $(DEVKITARM)/ds_rules export TARGET := twlnf export TOPDIR := $(CURDIR) -export VERSION := 0.2.0 +export VERSION := 0.2.1 .PHONY: arm7/$(TARGET).elf arm9/$(TARGET).elf diff --git a/arm9/source/aes.c b/arm9/source/aes.c index 88e858a..c1dea3b 100644 --- a/arm9/source/aes.c +++ b/arm9/source/aes.c @@ -1,5 +1,6 @@ #include +#include #include "aes.h" /* AES 128 ECB dug out from mbed TLS 2.5.1 @@ -32,11 +33,15 @@ DTCM_BSS static uint32_t FT0[256]; DTCM_BSS static uint32_t FT1[256]; DTCM_BSS static uint32_t FT2[256]; DTCM_BSS static uint32_t FT3[256]; + +#define NO_R_TABLES +#ifndef NO_R_TABLES static unsigned char RSb[256]; static uint32_t RT0[256]; static uint32_t RT1[256]; static uint32_t RT2[256]; static uint32_t RT3[256]; +#endif static uint32_t RCON[256]; @@ -49,6 +54,14 @@ static uint32_t RCON[256]; void aes_gen_tables(void) { +#ifdef NO_R_TABLES + unsigned char *RSb = memalign(32, 256); + uint32_t *RT0 = memalign(32, 256 * sizeof(uint32_t)); + uint32_t *RT1 = memalign(32, 256 * sizeof(uint32_t)); + uint32_t *RT2 = memalign(32, 256 * sizeof(uint32_t)); + uint32_t *RT3 = memalign(32, 256 * sizeof(uint32_t)); +#endif + int i, x, y, z; int pow[256]; int log[256]; @@ -121,6 +134,13 @@ void aes_gen_tables(void) RT2[i] = ROTL8(RT1[i]); RT3[i] = ROTL8(RT2[i]); } +#ifdef NO_R_TABLES + free(RSb); + free(RT0); + free(RT1); + free(RT2); + free(RT3); +#endif } // did a little counting to understand why buf is [68] diff --git a/arm9/source/main.c b/arm9/source/main.c index a652503..3979b56 100644 --- a/arm9/source/main.c +++ b/arm9/source/main.c @@ -142,13 +142,30 @@ unsigned wait_keys(unsigned keys) { } } -void walk_cb_lst(const char *name, void *p_param) { +void walk_cb_lst_file(const char *name, int is_dir, void *p_param) { + if (is_dir) { + return; + } + name += sizeof(nand_root) - 1; + iprintf("%s\n", name); + fiprintf((FILE*)p_param, "%s\n", name); +} + +void walk_cb_lst_dir(const char *name, int is_dir, void *p_param) { + if (!is_dir) { + return; + } + name += sizeof(nand_root) - 1; iprintf("%s\n", name); fiprintf((FILE*)p_param, "%s\n", name); } -void walk_cb_sha1(const char *name, void *p_param) { - iprintf("%s", name); +void walk_cb_sha1(const char *name, int is_dir, void *p_param) { + if (is_dir) { + return; + } + const char *rname = name + sizeof(nand_root) - 1; + iprintf("%s", rname); unsigned char digest[SHA1_LEN]; int sha1_ret = sha1_file(digest, name); iprintf(" %d\n", sha1_ret); @@ -158,10 +175,10 @@ void walk_cb_sha1(const char *name, void *p_param) { for (unsigned i = 0; i < SHA1_LEN; ++i) { fiprintf((FILE*)p_param, "%02X", digest[i]); } - fiprintf((FILE*)p_param, " *%s\n", name); + fiprintf((FILE*)p_param, " *%s\n", rname); } -void walk_cb_dump(const char *name, void *_) { +void walk_cb_dump(const char *name, int is_dir, void *_) { } void menu_action(const char *name) { @@ -222,21 +239,23 @@ void menu() { } else if (keys & KEY_A) { menu_action(file_list[view_pos + cur_pos].name); } else if ((keys & KEY_L) && (keys & KEY_R)) { - iprintf("\t(A) list NAND files\n" - "\t(X) sha1 NAND files\n" - "\t(Y) walk NAND\n" + iprintf("\t(A) list NAND directories\n" + "\t(X) list NAND files\n" + "\t(Y) sha1 NAND files\n" "\t(B) cancel\n"); unsigned keys = wait_keys(KEY_A | KEY_B | KEY_X | KEY_Y); if (keys & KEY_A) { - FILE * f = fopen("nand_files.lst", "w"); - iprintf("walk returned %d\n", walk(nand_root, walk_cb_lst, f)); + FILE * f = fopen("nand_dirs.lst", "w"); + iprintf("walk returned %d\n", walk(nand_root, walk_cb_lst_dir, f)); fclose(f); } else if (keys & KEY_X) { + FILE * f = fopen("nand_files.lst", "w"); + iprintf("walk returned %d\n", walk(nand_root, walk_cb_lst_file, f)); + fclose(f); + } else if (keys & KEY_Y) { FILE * f = fopen("nand_files.sha1", "w"); iprintf("walk returned %d\n", walk(nand_root, walk_cb_sha1, f)); fclose(f); - } else if (keys & KEY_Y) { - iprintf("walk returned %d\n", walk(nand_root, 0, 0)); } } if (needs_redraw) { @@ -380,7 +399,7 @@ int main(int argc, const char * const argv[]) { exit_with_prompt(-1); } } - // either way, we should have a valid NAND image by now + // either way, we should have a valid native NAND image by now iprintf("mount image (A)? quit(B)?\n"); unsigned keys = wait_keys(KEY_A | KEY_B | KEY_X); if (keys & KEY_B) { diff --git a/arm9/source/walk.c b/arm9/source/walk.c index a918f09..36d62cd 100644 --- a/arm9/source/walk.c +++ b/arm9/source/walk.c @@ -63,7 +63,7 @@ static void s_deep_free() { free(base); } -int walk(const char *dir, void (*callback)(const char*, void*), void *p_cb_param) { +int walk(const char *dir, void (*callback)(const char*, int, void*), void *p_cb_param) { // init the stack stack_max_depth = 0; stack_usage = 0; @@ -106,12 +106,12 @@ int walk(const char *dir, void (*callback)(const char*, void*), void *p_cb_param } if ((s.st_mode & S_IFMT) == S_IFREG) { if (callback != 0) { - callback(fullname, p_cb_param); + callback(fullname, 0, p_cb_param); } free(fullname); } else if ((s.st_mode & S_IFMT) == S_IFDIR) { - if (callback == 0) { - iprintf("%s\n", fullname); + if (callback != 0) { + callback(fullname, 1, p_cb_param); } if (s_push(fullname) == 0) { free(fullname); @@ -150,7 +150,7 @@ void listdir(const char *dir, int want_full, void(*callback)(const char*, size_t if ((s.st_mode & S_IFMT) == S_IFREG) { callback(want_full ? name_buf : de->d_name, s.st_size, p_cb_param); } else if ((s.st_mode & S_IFMT) == S_IFDIR) { - // use INVALID_SIZE as indication + // use INVALID_SIZE as is_dir callback(want_full ? name_buf : de->d_name, INVALID_SIZE, p_cb_param); } } diff --git a/arm9/source/walk.h b/arm9/source/walk.h index 9c5402b..e8e84d7 100644 --- a/arm9/source/walk.h +++ b/arm9/source/walk.h @@ -4,6 +4,6 @@ #define INVALID_SIZE ((size_t)-1) -int walk(const char *dir, void(*callback)(const char*, void*), void *p_cb_param); +int walk(const char *dir, void(*callback)(const char*, int, void*), void *p_cb_param); void listdir(const char *dir, int want_full, void(*callback)(const char*, size_t, void*), void *p_cb_param);