nfc_mf_classic_dict.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "nfc_mf_classic_dict.h"
  2. #include <flipper_format/flipper_format.h>
  3. #include <lib/toolbox/args.h>
  4. #define NFC_MF_CLASSIC_DICT_PATH "/ext/nfc/assets/mf_classic_dict.nfc"
  5. #define NFC_MF_CLASSIC_KEY_LEN (13)
  6. bool nfc_mf_classic_dict_check_presence(Storage* storage) {
  7. furi_assert(storage);
  8. return storage_common_stat(storage, NFC_MF_CLASSIC_DICT_PATH, NULL) == FSE_OK;
  9. }
  10. bool nfc_mf_classic_dict_open_file(Stream* stream) {
  11. furi_assert(stream);
  12. return file_stream_open(stream, NFC_MF_CLASSIC_DICT_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
  13. }
  14. void nfc_mf_classic_dict_close_file(Stream* stream) {
  15. furi_assert(stream);
  16. file_stream_close(stream);
  17. }
  18. bool nfc_mf_classic_dict_get_next_key(Stream* stream, uint64_t* key) {
  19. furi_assert(stream);
  20. furi_assert(key);
  21. uint8_t key_byte_tmp = 0;
  22. string_t next_line;
  23. string_init(next_line);
  24. *key = 0;
  25. bool next_key_read = false;
  26. while(!next_key_read) {
  27. if(!stream_read_line(stream, next_line)) break;
  28. if(string_get_char(next_line, 0) == '#') continue;
  29. if(string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
  30. for(uint8_t i = 0; i < 12; i += 2) {
  31. args_char_to_hex(
  32. string_get_char(next_line, i), string_get_char(next_line, i + 1), &key_byte_tmp);
  33. *key |= (uint64_t)key_byte_tmp << 8 * (5 - i / 2);
  34. }
  35. next_key_read = true;
  36. }
  37. string_clear(next_line);
  38. return next_key_read;
  39. }
  40. void nfc_mf_classic_dict_reset(Stream* stream) {
  41. furi_assert(stream);
  42. stream_rewind(stream);
  43. }