nfc_magic_app_i.h 4.4 KB

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