Skip to content

Commit

Permalink
walk polish
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyZ authored and JimmyZ committed Sep 22, 2017
1 parent b517192 commit 6710316
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions arm9/source/aes.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include <nds.h>
#include <malloc.h>
#include "aes.h"

/* AES 128 ECB dug out from mbed TLS 2.5.1
Expand Down Expand Up @@ -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];

Expand All @@ -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];
Expand Down Expand Up @@ -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]
Expand Down
45 changes: 32 additions & 13 deletions arm9/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions arm9/source/walk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion arm9/source/walk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 6710316

Please sign in to comment.