mifare_nested_i.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #pragma once
  2. #include "mifare_nested.h"
  3. #include "mifare_nested_worker.h"
  4. #include "lib/nested/nested.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/widget.h>
  14. #include <input/input.h>
  15. #include "scenes/mifare_nested_scene.h"
  16. #include <storage/storage.h>
  17. #include <lib/toolbox/path.h>
  18. #include <lib/toolbox/value_index.h>
  19. #include <gui/modules/variable_item_list.h>
  20. #include "lib/nfclegacy/nfc_device.h"
  21. #include "mifare_nested_icons.h"
  22. #define NESTED_VERSION_APP FAP_VERSION
  23. #define NESTED_GITHUB_LINK "https://github.com/AloneLiberty/FlipperNested"
  24. #define NESTED_RECOVER_KEYS_GITHUB_LINK "https://github.com/AloneLiberty/FlipperNestedRecovery"
  25. #define NESTED_NONCE_FORMAT_VERSION "3"
  26. #define NESTED_AUTHOR \
  27. "@AloneLiberty (t.me/libertydev)\nMade it work with latest firmware by @xMasterX"
  28. enum MifareNestedCustomEvent {
  29. // Reserve first 100 events for button types and indexes, starting from 0
  30. MifareNestedCustomEventReserved = 100,
  31. MifareNestedCustomEventViewExit,
  32. MifareNestedCustomEventWorkerExit,
  33. MifareNestedCustomEventByteInputDone,
  34. MifareNestedCustomEventTextInputDone,
  35. MifareNestedCustomEventSceneSettingLock
  36. };
  37. typedef void (*NestedCallback)(void* context);
  38. typedef struct {
  39. FuriMutex* mutex;
  40. FuriMessageQueue* event_queue;
  41. ViewPort* view_port;
  42. View* view;
  43. NestedCallback callback;
  44. void* context;
  45. } NestedState;
  46. typedef void (*CheckKeysCallback)(void* context);
  47. typedef struct {
  48. FuriMutex* mutex;
  49. FuriMessageQueue* event_queue;
  50. ViewPort* view_port;
  51. View* view;
  52. CheckKeysCallback callback;
  53. void* context;
  54. } CheckKeysState;
  55. typedef enum {
  56. EventTypeTick,
  57. EventTypeKey,
  58. } EventType;
  59. typedef struct {
  60. EventType type;
  61. InputEvent input;
  62. } PluginEvent;
  63. typedef struct {
  64. bool only_hardnested;
  65. } MifareNestedSettings;
  66. typedef enum { NestedRunIdle, NestedRunCheckKeys, NestedRunAttack } NestedRunNext;
  67. struct MifareNested {
  68. MifareNestedWorker* worker;
  69. ViewDispatcher* view_dispatcher;
  70. Gui* gui;
  71. NotificationApp* notifications;
  72. SceneManager* scene_manager;
  73. NfcDevice* nfc_dev;
  74. VariableItemList* variable_item_list;
  75. MifareNestedSettings* settings;
  76. FuriString* text_box_store;
  77. // Common Views
  78. Submenu* submenu;
  79. Popup* popup;
  80. Loading* loading;
  81. TextInput* text_input;
  82. Widget* widget;
  83. NonceList_t* nonces;
  84. KeyInfo_t* keys;
  85. NestedState* nested_state;
  86. CheckKeysState* keys_state;
  87. SaveNoncesResult_t* save_state;
  88. MifareNestedWorkerState collecting_type;
  89. NestedRunNext run;
  90. };
  91. typedef enum {
  92. MifareNestedViewMenu,
  93. MifareNestedViewPopup,
  94. MifareNestedViewLoading,
  95. MifareNestedViewTextInput,
  96. MifareNestedViewWidget,
  97. MifareNestedViewVariableList,
  98. MifareNestedViewCollecting,
  99. MifareNestedViewCheckKeys,
  100. } MifareNestedView;
  101. typedef struct {
  102. FuriString* header;
  103. uint32_t keys_count;
  104. uint32_t nonces_collected;
  105. uint32_t hardnested_states;
  106. bool lost_tag;
  107. bool calibrating;
  108. bool need_prediction;
  109. bool hardnested;
  110. } NestedAttackViewModel;
  111. typedef struct {
  112. FuriString* header;
  113. uint32_t keys_count;
  114. uint32_t keys_checked;
  115. uint32_t keys_found;
  116. uint32_t keys_total;
  117. bool lost_tag;
  118. bool processing_keys;
  119. } CheckKeysViewModel;
  120. static const NotificationSequence mifare_nested_sequence_blink_start_blue = {
  121. &message_blink_start_10,
  122. &message_blink_set_color_blue,
  123. &message_do_not_reset,
  124. NULL,
  125. };
  126. static const NotificationSequence mifare_nested_sequence_blink_start_magenta = {
  127. &message_blink_start_10,
  128. &message_blink_set_color_magenta,
  129. &message_do_not_reset,
  130. NULL,
  131. };
  132. static const NotificationSequence mifare_nested_sequence_blink_start_yellow = {
  133. &message_blink_start_10,
  134. &message_blink_set_color_yellow,
  135. &message_do_not_reset,
  136. NULL,
  137. };
  138. static const NotificationSequence mifare_nested_sequence_blink_stop = {
  139. &message_blink_stop,
  140. NULL,
  141. };
  142. MifareNested* mifare_nested_alloc();
  143. void mifare_nested_text_store_set(MifareNested* mifare_nested, const char* text, ...);
  144. void mifare_nested_text_store_clear(MifareNested* mifare_nested);
  145. void mifare_nested_blink_start(MifareNested* mifare_nested);
  146. void mifare_nested_blink_calibration_start(MifareNested* mifare_nested);
  147. void mifare_nested_blink_nonce_collection_start(MifareNested* mifare_nested);
  148. void mifare_nested_blink_stop(MifareNested* mifare_nested);
  149. void mifare_nested_show_loading_popup(void* context, bool show);