nfc_magic_app_i.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #pragma once
  2. #include "nfc_magic_app.h"
  3. #include "helpers/nfc_magic_custom_events.h"
  4. #include <furi.h>
  5. #include <gui/gui.h>
  6. #include <gui/view_dispatcher.h>
  7. #include <gui/scene_manager.h>
  8. #include <notification/notification_messages.h>
  9. #include <gui/modules/submenu.h>
  10. #include <gui/modules/popup.h>
  11. #include <gui/modules/loading.h>
  12. #include <gui/modules/text_input.h>
  13. #include <gui/modules/byte_input.h>
  14. #include <gui/modules/widget.h>
  15. #include <views/dict_attack.h>
  16. #include <views/write_problems.h>
  17. #include <input/input.h>
  18. #include "scenes/nfc_magic_scene.h"
  19. #include <storage/storage.h>
  20. #include <dialogs/dialogs.h>
  21. #include <lib/toolbox/path.h>
  22. #include "nfc_magic_icons.h"
  23. #include <nfc/nfc.h>
  24. #include <nfc/nfc_device.h>
  25. #include <nfc/nfc_poller.h>
  26. #include <toolbox/keys_dict.h>
  27. #include "magic/nfc_magic_scanner.h"
  28. #include "magic/protocols/nfc_magic_protocols.h"
  29. #include "magic/protocols/gen1a/gen1a_poller.h"
  30. #include "magic/protocols/gen2/gen2_poller.h"
  31. #include "magic/protocols/gen4/gen4_poller.h"
  32. #include "lib/nfc/protocols/mf_classic/mf_classic_poller.h"
  33. #define NFC_APP_FOLDER ANY_PATH("nfc")
  34. #define NFC_APP_EXTENSION ".nfc"
  35. #define NFC_APP_SHADOW_EXTENSION ".shd"
  36. #define NFC_APP_MF_CLASSIC_DICT_USER_PATH (NFC_APP_FOLDER "/assets/mf_classic_dict_user.nfc")
  37. #define NFC_APP_MF_CLASSIC_DICT_SYSTEM_PATH (NFC_APP_FOLDER "/assets/mf_classic_dict.nfc")
  38. #define NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE (4)
  39. enum NfcMagicAppCustomEvent {
  40. // Reserve first 100 events for button types and indexes, starting from 0
  41. NfcMagicAppCustomEventReserved = 100,
  42. NfcMagicAppCustomEventViewExit,
  43. NfcMagicAppCustomEventWorkerExit,
  44. NfcMagicAppCustomEventByteInputDone,
  45. NfcMagicAppCustomEventTextInputDone,
  46. NfcMagicAppCustomEventCardDetected,
  47. NfcMagicAppCustomEventCardLost,
  48. NfcMagicAppCustomEventDictAttackDataUpdate,
  49. NfcMagicAppCustomEventDictAttackComplete,
  50. NfcMagicAppCustomEventDictAttackSkip,
  51. };
  52. typedef struct {
  53. KeysDict* dict;
  54. uint8_t sectors_total;
  55. uint8_t sectors_read;
  56. uint8_t current_sector;
  57. uint8_t keys_found;
  58. size_t dict_keys_total;
  59. size_t dict_keys_current;
  60. bool is_key_attack;
  61. uint8_t key_attack_current_sector;
  62. bool is_card_present;
  63. } NfcMagicAppMfClassicDictAttackContext;
  64. typedef struct {
  65. uint8_t problem_index;
  66. uint8_t problem_index_abs;
  67. uint8_t problems_total;
  68. Gen2PollerWriteProblems problems;
  69. } NfcMagicAppWriteProblemsContext;
  70. struct NfcMagicApp {
  71. ViewDispatcher* view_dispatcher;
  72. Gui* gui;
  73. NotificationApp* notifications;
  74. DialogsApp* dialogs;
  75. Storage* storage;
  76. SceneManager* scene_manager;
  77. NfcDevice* source_dev;
  78. NfcDevice* target_dev;
  79. FuriString* file_name;
  80. FuriString* file_path;
  81. Nfc* nfc;
  82. NfcMagicProtocol protocol;
  83. NfcMagicScanner* scanner;
  84. NfcPoller* poller;
  85. Gen1aPoller* gen1a_poller;
  86. Gen2Poller* gen2_poller;
  87. bool gen2_poller_is_wipe_mode;
  88. Gen4Poller* gen4_poller;
  89. Gen4* gen4_data;
  90. Gen4Password gen4_password;
  91. Gen4Password gen4_password_new;
  92. NfcMagicAppMfClassicDictAttackContext nfc_dict_context;
  93. DictAttack* dict_attack;
  94. NfcMagicAppWriteProblemsContext write_problems_context;
  95. WriteProblems* write_problems;
  96. FuriString* text_box_store;
  97. uint8_t byte_input_store[NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE];
  98. // Common Views
  99. Submenu* submenu;
  100. Popup* popup;
  101. Loading* loading;
  102. TextInput* text_input;
  103. ByteInput* byte_input;
  104. Widget* widget;
  105. };
  106. typedef enum {
  107. NfcMagicAppViewMenu,
  108. NfcMagicAppViewPopup,
  109. NfcMagicAppViewLoading,
  110. NfcMagicAppViewTextInput,
  111. NfcMagicAppViewByteInput,
  112. NfcMagicAppViewWidget,
  113. NfcMagicAppViewDictAttack,
  114. NfcMagicAppViewWriteProblems,
  115. } NfcMagicAppView;
  116. void nfc_magic_app_blink_start(NfcMagicApp* nfc_magic);
  117. void nfc_magic_app_blink_stop(NfcMagicApp* nfc_magic);
  118. void nfc_magic_app_show_loading_popup(void* context, bool show);
  119. bool nfc_magic_load_from_file_select(NfcMagicApp* instance);