flipperzero-firmware/applications/nfc/helpers/nfc_mf_classic_dict.c
hedger 056446dfed
[FL-2675] /int space reservation (#1448)
* storage: added global #defines for /int, /ext & /any
* storage: introduced PATH_EXT, PATH_INT& PATH_ANY macros
* core apps: moved hardcoded config files names to separate headers; prefixed them with "."; updater: added file name migration to new naming convention on backup extraction
* storage: fixed storage_merge_recursive handling of complex directory structures; storage_move_to_sd: changed data migration logic to all non-dot files & all folders
* core: added macro aliases for core record names
* Bumped protobuf commit pointer
* storage: reserved 5 pages in /int; denying write&creation of non-dot files when running out of free space

Co-authored-by: あく <alleteam@gmail.com>
2022-07-26 21:21:51 +09:00

54 lines
1.5 KiB
C

#include "nfc_mf_classic_dict.h"
#include <flipper_format/flipper_format.h>
#include <lib/toolbox/args.h>
#define NFC_MF_CLASSIC_DICT_PATH EXT_PATH("nfc/assets/mf_classic_dict.nfc")
#define NFC_MF_CLASSIC_KEY_LEN (13)
bool nfc_mf_classic_dict_check_presence(Storage* storage) {
furi_assert(storage);
return storage_common_stat(storage, NFC_MF_CLASSIC_DICT_PATH, NULL) == FSE_OK;
}
bool nfc_mf_classic_dict_open_file(Stream* stream) {
furi_assert(stream);
return file_stream_open(stream, NFC_MF_CLASSIC_DICT_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
}
void nfc_mf_classic_dict_close_file(Stream* stream) {
furi_assert(stream);
file_stream_close(stream);
}
bool nfc_mf_classic_dict_get_next_key(Stream* stream, uint64_t* key) {
furi_assert(stream);
furi_assert(key);
uint8_t key_byte_tmp = 0;
string_t next_line;
string_init(next_line);
*key = 0;
bool next_key_read = false;
while(!next_key_read) {
if(!stream_read_line(stream, next_line)) break;
if(string_get_char(next_line, 0) == '#') continue;
if(string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
for(uint8_t i = 0; i < 12; i += 2) {
args_char_to_hex(
string_get_char(next_line, i), string_get_char(next_line, i + 1), &key_byte_tmp);
*key |= (uint64_t)key_byte_tmp << 8 * (5 - i / 2);
}
next_key_read = true;
}
string_clear(next_line);
return next_key_read;
}
void nfc_mf_classic_dict_reset(Stream* stream) {
furi_assert(stream);
stream_rewind(stream);
}