mifare_nested_i.h 4.3 KB

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