mifare_nested_i.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.1.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 "2"
  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. bool lost_tag;
  96. bool calibrating;
  97. bool need_prediction;
  98. } NestedAttackViewModel;
  99. typedef struct {
  100. FuriString* header;
  101. uint32_t keys_count;
  102. uint32_t keys_checked;
  103. uint32_t keys_found;
  104. uint32_t keys_total;
  105. bool lost_tag;
  106. bool processing_keys;
  107. } CheckKeysViewModel;
  108. static const NotificationSequence mifare_nested_sequence_blink_start_blue = {
  109. &message_blink_start_10,
  110. &message_blink_set_color_blue,
  111. &message_do_not_reset,
  112. NULL,
  113. };
  114. static const NotificationSequence mifare_nested_sequence_blink_start_magenta = {
  115. &message_blink_start_10,
  116. &message_blink_set_color_magenta,
  117. &message_do_not_reset,
  118. NULL,
  119. };
  120. static const NotificationSequence mifare_nested_sequence_blink_start_yellow = {
  121. &message_blink_start_10,
  122. &message_blink_set_color_yellow,
  123. &message_do_not_reset,
  124. NULL,
  125. };
  126. static const NotificationSequence mifare_nested_sequence_blink_stop = {
  127. &message_blink_stop,
  128. NULL,
  129. };
  130. MifareNested* mifare_nested_alloc();
  131. void mifare_nested_text_store_set(MifareNested* mifare_nested, const char* text, ...);
  132. void mifare_nested_text_store_clear(MifareNested* mifare_nested);
  133. void mifare_nested_blink_start(MifareNested* mifare_nested);
  134. void mifare_nested_blink_calibration_start(MifareNested* mifare_nested);
  135. void mifare_nested_blink_nonce_collection_start(MifareNested* mifare_nested);
  136. void mifare_nested_blink_stop(MifareNested* mifare_nested);
  137. void mifare_nested_show_loading_popup(void* context, bool show);