diff --git a/armsrc/spiffs.c b/armsrc/spiffs.c index 8242df9fc..d200eafc7 100644 --- a/armsrc/spiffs.c +++ b/armsrc/spiffs.c @@ -549,17 +549,13 @@ void rdv40_spiffs_safe_print_fsinfo(void) { rdv40_spiffs_fsinfo fsinfo; rdv40_spiffs_getfsinfo(&fsinfo, RDV40_SPIFFS_SAFETY_SAFE); - DbpString(_CYAN_("Flash Memory FileSystem Info (SPIFFS)")); - - - Dbprintf(" Logical Block Size........." _YELLOW_("%d")" bytes", fsinfo.blockSize); - Dbprintf(" Logical Page Size.........." _YELLOW_("%d")" bytes", fsinfo.pageSize); - Dbprintf(""); - Dbprintf(" Max Open Files............." _YELLOW_("%d")" file descriptors", fsinfo.maxOpenFiles); - Dbprintf(" Max Path Length............" _YELLOW_("%d")" chars", fsinfo.maxPathLength); + Dbprintf(" Logical block size......... " _YELLOW_("%d")" bytes", fsinfo.blockSize); + Dbprintf(" Logical page size.......... " _YELLOW_("%d")" bytes", fsinfo.pageSize); + Dbprintf(" Max open files............. " _YELLOW_("%d")" file descriptors", fsinfo.maxOpenFiles); + Dbprintf(" Max path length............ " _YELLOW_("%d")" chars", fsinfo.maxPathLength); DbpString(""); - Dbprintf(" filesystem size used available use% mounted"); - Dbprintf(" spiffs %6d B %6d B %6d B " _YELLOW_("%2d%")" /" + Dbprintf(" Filesystem size used available use% mounted"); + Dbprintf(" spiffs %6d B %6d B %6d B " _YELLOW_("%2d%")" /" , fsinfo.totalBytes , fsinfo.usedBytes , fsinfo.freeBytes @@ -574,20 +570,13 @@ void rdv40_spiffs_safe_print_fsinfo(void) { // maintaining prefix list sorting, unique_checking, THEN outputing precomputed // tree Other solutio nwould be to add directory support to SPIFFS, but that we // dont want, as prefix are way easier and lighter in every aspect. -void rdv40_spiffs_safe_print_tree(uint8_t banner) { - - if (banner) { - DbpString(_CYAN_("Flash Memory FileSystem tree (SPIFFS)")); - Dbprintf("-------------------------------------"); - } - +void rdv40_spiffs_safe_print_tree(void) { int changed = rdv40_spiffs_lazy_mount(); spiffs_DIR d; struct spiffs_dirent e; struct spiffs_dirent *pe = &e; SPIFFS_opendir(&fs, "/", &d); - Dbprintf(" \t \t/"); while ((pe = SPIFFS_readdir(&d, pe))) { char resolvedlink[11 + SPIFFS_OBJ_NAME_LEN]; @@ -601,10 +590,9 @@ void rdv40_spiffs_safe_print_tree(uint8_t banner) { memset(resolvedlink, 0, sizeof(resolvedlink)); } - Dbprintf("[%04x]\t %ibytes \t|-- %s%s", pe->obj_id, pe->size, pe->name, resolvedlink); + Dbprintf("[%04x]\t " _YELLOW_("%i") " B |-- %s%s", pe->obj_id, pe->size, pe->name, resolvedlink); } SPIFFS_closedir(&d); - rdv40_spiffs_lazy_mount_rollback(changed); } @@ -651,7 +639,7 @@ void test_spiffs(void) { int changed = rdv40_spiffs_lazy_mount(); Dbprintf(" Printing tree.............."); - rdv40_spiffs_safe_print_tree(false); + rdv40_spiffs_safe_print_tree(); Dbprintf(" Writing 'I love Proxmark3 RDV4' in a testspiffs.txt"); @@ -660,13 +648,13 @@ void test_spiffs(void) { rdv40_spiffs_write((char *)"testspiffs.txt", (uint8_t *)"I love Proxmark3 RDV4", 21, RDV40_SPIFFS_SAFETY_SAFE); Dbprintf(" Printing tree again......."); - rdv40_spiffs_safe_print_tree(false); + rdv40_spiffs_safe_print_tree(); Dbprintf(" Making a symlink to testspiffs.txt"); rdv40_spiffs_make_symlink((char *)"testspiffs.txt", (char *)"linktotestspiffs.txt", RDV40_SPIFFS_SAFETY_SAFE); Dbprintf(" Printing tree again......."); - rdv40_spiffs_safe_print_tree(false); + rdv40_spiffs_safe_print_tree(); // TODO READBACK, rename,print tree read back, remove, print tree; Dbprintf(" Rollbacking The mount status IF things have changed"); diff --git a/armsrc/spiffs.h b/armsrc/spiffs.h index 8754cb432..520ff8809 100644 --- a/armsrc/spiffs.h +++ b/armsrc/spiffs.h @@ -45,7 +45,7 @@ int rdv40_spiffs_read_as_symlink(char *filename, uint8_t *dst, uint32_t size, RD void write_to_spiffs(const char *filename, uint8_t *src, uint32_t size); void read_from_spiffs(const char *filename, uint8_t *dst, uint32_t size); void test_spiffs(void); -void rdv40_spiffs_safe_print_tree(uint8_t banner); +void rdv40_spiffs_safe_print_tree(void); int rdv40_spiffs_unmount(void); int rdv40_spiffs_mount(void); int rdv40_spiffs_is_symlink(const char *s); diff --git a/client/src/cmdflashmemspiffs.c b/client/src/cmdflashmemspiffs.c index 9409e52ee..3b9214e95 100644 --- a/client/src/cmdflashmemspiffs.c +++ b/client/src/cmdflashmemspiffs.c @@ -39,8 +39,11 @@ int flashmem_spiffs_load(char *destfn, uint8_t *data, size_t datalen) { flashmem_write_t *payload = calloc(1, sizeof(flashmem_write_t) + bytes_in_packet); payload->append = (bytes_sent > 0); - payload->fnlen = strlen(destfn); - memcpy(payload->fn, destfn, strlen(destfn)); + + uint8_t fnlen = MIN(sizeof(payload->fn), strlen(destfn)); + + payload->fnlen = fnlen; + memcpy(payload->fn, destfn, fnlen); payload->bytes_in_packet = bytes_in_packet; memset(payload->data, 0, bytes_in_packet); @@ -158,6 +161,8 @@ static int CmdFlashMemSpiFFSTree(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); + + PrintAndLogEx(INFO, "--- " _CYAN_("Flash Memory tree (SPIFFS)") " -----------------"); clearCommandBuffer(); SendCommandNG(CMD_SPIFFS_PRINT_TREE, NULL, 0); return PM3_SUCCESS; @@ -175,6 +180,8 @@ static int CmdFlashMemSpiFFSInfo(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, true); CLIParserFree(ctx); + + PrintAndLogEx(INFO, "--- " _CYAN_("Flash Memory info (SPIFFS)") " -----------------"); clearCommandBuffer(); SendCommandNG(CMD_SPIFFS_PRINT_FSINFO, NULL, 0); return PM3_SUCCESS;