nfc_magic_app_i.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 <assets_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 "lib/magic/nfc_magic_scanner.h"
  29. #include "lib/magic/protocols/nfc_magic_protocols.h"
  30. #include "lib/magic/protocols/gen1a/gen1a_poller.h"
  31. #include "lib/magic/protocols/gen2/gen2_poller.h"
  32. #include "lib/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_BYTE_INPUT_STORE_SIZE (4)
  40. enum NfcMagicAppCustomEvent {
  41. // Reserve first 100 events for button types and indexes, starting from 0
  42. NfcMagicAppCustomEventReserved = 100,
  43. NfcMagicAppCustomEventViewExit,
  44. NfcMagicAppCustomEventWorkerExit,
  45. NfcMagicAppCustomEventByteInputDone,
  46. NfcMagicAppCustomEventTextInputDone,
  47. NfcMagicAppCustomEventCardDetected,
  48. NfcMagicAppCustomEventCardLost,
  49. NfcMagicAppCustomEventDictAttackDataUpdate,
  50. NfcMagicAppCustomEventDictAttackComplete,
  51. NfcMagicAppCustomEventDictAttackSkip,
  52. };
  53. typedef struct {
  54. KeysDict* dict;
  55. uint8_t sectors_total;
  56. uint8_t sectors_read;
  57. uint8_t current_sector;
  58. uint8_t keys_found;
  59. size_t dict_keys_total;
  60. size_t dict_keys_current;
  61. bool is_key_attack;
  62. uint8_t key_attack_current_sector;
  63. bool is_card_present;
  64. } NfcMagicAppMfClassicDictAttackContext;
  65. typedef struct {
  66. uint8_t problem_index;
  67. uint8_t problem_index_abs;
  68. uint8_t problems_total;
  69. Gen2PollerWriteProblems problems;
  70. } NfcMagicAppWriteProblemsContext;
  71. struct NfcMagicApp {
  72. ViewDispatcher* view_dispatcher;
  73. Gui* gui;
  74. NotificationApp* notifications;
  75. DialogsApp* dialogs;
  76. Storage* storage;
  77. SceneManager* scene_manager;
  78. NfcDevice* source_dev;
  79. NfcDevice* target_dev;
  80. FuriString* file_name;
  81. FuriString* file_path;
  82. Nfc* nfc;
  83. NfcMagicProtocol protocol;
  84. NfcMagicScanner* scanner;
  85. NfcPoller* poller;
  86. Gen1aPoller* gen1a_poller;
  87. Gen2Poller* gen2_poller;
  88. bool gen2_poller_is_wipe_mode;
  89. Gen4Poller* gen4_poller;
  90. NfcMagicAppMfClassicDictAttackContext nfc_dict_context;
  91. DictAttack* dict_attack;
  92. NfcMagicAppWriteProblemsContext write_problems_context;
  93. WriteProblems* write_problems;
  94. uint32_t gen4_password;
  95. uint32_t gen4_password_new;
  96. uint8_t gen4_config[32];
  97. uint8_t gen4_revision[5];
  98. FuriString* text_box_store;
  99. uint8_t byte_input_store[NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE];
  100. // Common Views
  101. Submenu* submenu;
  102. Popup* popup;
  103. Loading* loading;
  104. TextInput* text_input;
  105. ByteInput* byte_input;
  106. Widget* widget;
  107. };
  108. typedef enum {
  109. NfcMagicAppViewMenu,
  110. NfcMagicAppViewPopup,
  111. NfcMagicAppViewLoading,
  112. NfcMagicAppViewTextInput,
  113. NfcMagicAppViewByteInput,
  114. NfcMagicAppViewWidget,
  115. NfcMagicAppViewDictAttack,
  116. NfcMagicAppViewWriteProblems,
  117. } NfcMagicAppView;
  118. void nfc_magic_app_blink_start(NfcMagicApp* nfc_magic);
  119. void nfc_magic_app_blink_stop(NfcMagicApp* nfc_magic);
  120. void nfc_magic_app_show_loading_popup(void* context, bool show);
  121. bool nfc_magic_load_from_file_select(NfcMagicApp* instance);