picopass_i.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. struct Picopass {
  69. ViewDispatcher* view_dispatcher;
  70. Gui* gui;
  71. NotificationApp* notifications;
  72. SceneManager* scene_manager;
  73. PicopassDevice* dev;
  74. Nfc* nfc;
  75. PicopassPoller* poller;
  76. PicopassListener* listener;
  77. KeysDict* dict;
  78. uint32_t last_error_notify_ticks;
  79. char text_store[PICOPASS_TEXT_STORE_SIZE];
  80. FuriString* text_box_store;
  81. uint8_t byte_input_store[PICOPASS_BLOCK_LEN];
  82. // Common Views
  83. Submenu* submenu;
  84. Popup* popup;
  85. Loading* loading;
  86. TextInput* text_input;
  87. ByteInput* byte_input;
  88. TextBox* text_box;
  89. Widget* widget;
  90. DictAttack* dict_attack;
  91. Loclass* loclass;
  92. PluginManager* plugin_manager;
  93. PluginWiegand* plugin_wiegand;
  94. PicopassDictAttackContext dict_attack_ctx;
  95. PicopassWriteKeyContext write_key_context;
  96. PicopassLoclassContext loclass_context;
  97. bool auto_nr_mac;
  98. };
  99. typedef enum {
  100. PicopassViewMenu,
  101. PicopassViewPopup,
  102. PicopassViewLoading,
  103. PicopassViewTextInput,
  104. PicopassViewByteInput,
  105. PicopassViewTextBox,
  106. PicopassViewWidget,
  107. PicopassViewDictAttack,
  108. PicopassViewLoclass,
  109. } PicopassView;
  110. Picopass* picopass_alloc();
  111. void picopass_text_store_set(Picopass* picopass, const char* text, ...);
  112. void picopass_text_store_clear(Picopass* picopass);
  113. void picopass_blink_start(Picopass* picopass);
  114. void picopass_blink_emulate_start(Picopass* picopass);
  115. void picopass_blink_stop(Picopass* picopass);
  116. void picopass_show_loading_popup(void* context, bool show);
  117. /** Check if memory is set to pattern
  118. *
  119. * @warning zero size will return false
  120. *
  121. * @param[in] data Pointer to the byte array
  122. * @param[in] pattern The pattern
  123. * @param[in] size The byte array size
  124. *
  125. * @return True if memory is set to pattern, false otherwise
  126. */
  127. bool picopass_is_memset(const uint8_t* data, const uint8_t pattern, size_t size);