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 <assets_icons.h>
  25. #include <nfc/nfc.h>
  26. #include <toolbox/keys_dict.h>
  27. #include "protocol/picopass_poller.h"
  28. #include "protocol/picopass_listener.h"
  29. #include "plugin/interface.h"
  30. #include <flipper_application/flipper_application.h>
  31. #include <flipper_application/plugins/plugin_manager.h>
  32. #include <loader/firmware_api/firmware_api.h>
  33. #define PICOPASS_TEXT_STORE_SIZE 129
  34. #define PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME APP_ASSETS_PATH("iclass_elite_dict.txt")
  35. #define PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME APP_ASSETS_PATH("iclass_standard_dict.txt")
  36. #define PICOPASS_ICLASS_ELITE_DICT_USER_NAME APP_DATA_PATH("assets/iclass_elite_dict_user.txt")
  37. enum PicopassCustomEvent {
  38. // Reserve first 100 events for button types and indexes, starting from 0
  39. PicopassCustomEventReserved = 100,
  40. PicopassCustomEventViewExit,
  41. PicopassCustomEventWorkerExit,
  42. PicopassCustomEventByteInputDone,
  43. PicopassCustomEventTextInputDone,
  44. PicopassCustomEventDictAttackSkip,
  45. PicopassCustomEventDictAttackUpdateView,
  46. PicopassCustomEventLoclassGotMac,
  47. PicopassCustomEventLoclassGotStandardKey,
  48. PicopassCustomEventNrMacSaved,
  49. PicopassCustomEventPollerSuccess,
  50. PicopassCustomEventPollerFail,
  51. };
  52. typedef enum {
  53. EventTypeTick,
  54. EventTypeKey,
  55. } EventType;
  56. typedef struct {
  57. const char* name;
  58. uint16_t total_keys;
  59. uint16_t current_key;
  60. bool card_detected;
  61. } PicopassDictAttackContext;
  62. typedef struct {
  63. uint8_t key_to_write[PICOPASS_BLOCK_LEN];
  64. bool is_elite;
  65. } PicopassWriteKeyContext;
  66. typedef struct {
  67. size_t macs_collected;
  68. } PicopassLoclassContext;
  69. struct Picopass {
  70. ViewDispatcher* view_dispatcher;
  71. Gui* gui;
  72. NotificationApp* notifications;
  73. SceneManager* scene_manager;
  74. PicopassDevice* dev;
  75. Nfc* nfc;
  76. PicopassPoller* poller;
  77. PicopassListener* listener;
  78. KeysDict* dict;
  79. uint32_t last_error_notify_ticks;
  80. char text_store[PICOPASS_TEXT_STORE_SIZE];
  81. FuriString* text_box_store;
  82. uint8_t byte_input_store[PICOPASS_BLOCK_LEN];
  83. // Common Views
  84. Submenu* submenu;
  85. Popup* popup;
  86. Loading* loading;
  87. TextInput* text_input;
  88. ByteInput* byte_input;
  89. TextBox* text_box;
  90. Widget* widget;
  91. DictAttack* dict_attack;
  92. Loclass* loclass;
  93. PluginManager* plugin_manager;
  94. PluginWiegand* plugin_wiegand;
  95. PicopassDictAttackContext dict_attack_ctx;
  96. PicopassWriteKeyContext write_key_context;
  97. PicopassLoclassContext loclass_context;
  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);