Change hf mf fchk --mem to read dictionary from spiffs file

This commit is contained in:
Piotr Rzeszut 2024-12-25 19:14:05 +01:00
commit d7ab949d1f

View file

@ -38,6 +38,8 @@
#include "spiffs.h" // spiffs #include "spiffs.h" // spiffs
#include "appmain.h" // print_stack_usage #include "appmain.h" // print_stack_usage
#define MF_KEYS_FILE "dict_mf.bin"
#ifndef HARDNESTED_AUTHENTICATION_TIMEOUT #ifndef HARDNESTED_AUTHENTICATION_TIMEOUT
# define HARDNESTED_AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation) # define HARDNESTED_AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation)
#endif #endif
@ -1900,13 +1902,12 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
#ifdef WITH_FLASH #ifdef WITH_FLASH
if (use_flashmem) { if (use_flashmem) {
BigBuf_free(); BigBuf_free();
uint16_t isok = 0; uint32_t size = 0;
uint8_t size[2] = {0x00, 0x00}; size = size_in_spiffs(MF_KEYS_FILE);
isok = Flash_ReadData(DEFAULT_MF_KEYS_OFFSET_P(spi_flash_pages64k), size, 2); if (size <= 0)
if (isok != 2)
goto OUT; goto OUT;
keyCount = size[1] << 8 | size[0]; keyCount = size / 6;
if (keyCount == 0) if (keyCount == 0)
goto OUT; goto OUT;
@ -1921,10 +1922,8 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
if (datain == NULL) if (datain == NULL)
goto OUT; goto OUT;
isok = Flash_ReadData(DEFAULT_MF_KEYS_OFFSET_P(spi_flash_pages64k) + 2, datain, key_mem_available); rdv40_spiffs_read_as_filetype(MF_KEYS_FILE, datain, keyCount * 6, RDV40_SPIFFS_SAFETY_SAFE);
if (isok != key_mem_available) if (g_dbglevel >= DBG_ERROR) Dbprintf("Loaded %u keys from spiffs file: %s", keyCount, MF_KEYS_FILE);
goto OUT;
} }
#endif #endif