picopass_i.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #pragma once
  2. #include "picopass.h"
  3. #include "picopass_device.h"
  4. #include "rfal_picopass.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/byte_input.h>
  15. #include <gui/modules/text_box.h>
  16. #include <gui/modules/widget.h>
  17. #include <input/input.h>
  18. #include "scenes/picopass_scene.h"
  19. #include "views/dict_attack.h"
  20. #include "views/loclass.h"
  21. #include <storage/storage.h>
  22. #include <lib/toolbox/path.h>
  23. #include <picopass_icons.h>
  24. #include <nfc/nfc.h>
  25. #include <toolbox/keys_dict.h>
  26. #include "protocol/picopass_poller.h"
  27. #include "protocol/picopass_listener.h"
  28. #include "plugin/interface.h"
  29. #include <flipper_application/flipper_application.h>
  30. #include <flipper_application/plugins/plugin_manager.h>
  31. #include <loader/firmware_api/firmware_api.h>
  32. #define PICOPASS_TEXT_STORE_SIZE 129
  33. #define PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME APP_ASSETS_PATH("iclass_elite_dict.txt")
  34. #define PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME APP_ASSETS_PATH("iclass_standard_dict.txt")
  35. #define PICOPASS_ICLASS_ELITE_DICT_USER_NAME APP_DATA_PATH("assets/iclass_elite_dict_user.txt")
  36. enum PicopassCustomEvent {
  37. // Reserve first 100 events for button types and indexes, starting from 0
  38. PicopassCustomEventReserved = 100,
  39. PicopassCustomEventViewExit,
  40. PicopassCustomEventWorkerExit,
  41. PicopassCustomEventByteInputDone,
  42. PicopassCustomEventTextInputDone,
  43. PicopassCustomEventDictAttackSkip,
  44. PicopassCustomEventDictAttackUpdateView,
  45. PicopassCustomEventLoclassGotMac,
  46. PicopassCustomEventLoclassGotStandardKey,
  47. PicopassCustomEventNrMacSaved,
  48. PicopassCustomEventPollerSuccess,
  49. PicopassCustomEventPollerFail,
  50. };
  51. typedef enum {
  52. EventTypeTick,
  53. EventTypeKey,
  54. } EventType;
  55. typedef struct {
  56. const char* name;
  57. uint16_t total_keys;
  58. uint16_t current_key;
  59. bool card_detected;
  60. } PicopassDictAttackContext;
  61. typedef struct {
  62. uint8_t key_to_write[PICOPASS_BLOCK_LEN];
  63. bool is_elite;
  64. } PicopassWriteKeyContext;
  65. typedef struct {
  66. size_t macs_collected;
  67. } PicopassLoclassContext;
  68. typedef enum {
  69. ManualNRMAC,
  70. AutoNRMAC
  71. } NRMACType;
  72. struct Picopass {
  73. ViewDispatcher* view_dispatcher;
  74. Gui* gui;
  75. NotificationApp* notifications;
  76. SceneManager* scene_manager;
  77. PicopassDevice* dev;
  78. Nfc* nfc;
  79. PicopassPoller* poller;
  80. PicopassListener* listener;
  81. KeysDict* dict;
  82. uint32_t last_error_notify_ticks;
  83. char text_store[PICOPASS_TEXT_STORE_SIZE];
  84. FuriString* text_box_store;
  85. uint8_t byte_input_store[PICOPASS_BLOCK_LEN];
  86. // Common Views
  87. Submenu* submenu;
  88. Popup* popup;
  89. Loading* loading;
  90. TextInput* text_input;
  91. ByteInput* byte_input;
  92. TextBox* text_box;
  93. Widget* widget;
  94. DictAttack* dict_attack;
  95. Loclass* loclass;
  96. PluginManager* plugin_wiegand_manager;
  97. PluginWiegand* plugin_wiegand;
  98. PicopassDictAttackContext dict_attack_ctx;
  99. PicopassWriteKeyContext write_key_context;
  100. PicopassLoclassContext loclass_context;
  101. NRMACType nr_mac_type;
  102. };
  103. typedef enum {
  104. PicopassViewMenu,
  105. PicopassViewPopup,
  106. PicopassViewLoading,
  107. PicopassViewTextInput,
  108. PicopassViewByteInput,
  109. PicopassViewTextBox,
  110. PicopassViewWidget,
  111. PicopassViewDictAttack,
  112. PicopassViewLoclass,
  113. } PicopassView;
  114. Picopass* picopass_alloc();
  115. void picopass_text_store_set(Picopass* picopass, const char* text, ...);
  116. void picopass_text_store_clear(Picopass* picopass);
  117. void picopass_blink_start(Picopass* picopass);
  118. void picopass_blink_emulate_start(Picopass* picopass);
  119. void picopass_blink_stop(Picopass* picopass);
  120. void picopass_show_loading_popup(void* context, bool show);
  121. /** Check if memory is set to pattern
  122. *
  123. * @warning zero size will return false
  124. *
  125. * @param[in] data Pointer to the byte array
  126. * @param[in] pattern The pattern
  127. * @param[in] size The byte array size
  128. *
  129. * @return True if memory is set to pattern, false otherwise
  130. */
  131. bool picopass_is_memset(const uint8_t* data, const uint8_t pattern, size_t size);