mfc_editor_app_i.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #pragma once
  2. #include <furi.h>
  3. #include <dialogs/dialogs.h>
  4. #include <gui/gui.h>
  5. #include <gui/scene_manager.h>
  6. #include <gui/view_dispatcher.h>
  7. #include <gui/modules/byte_input.h>
  8. #include <gui/modules/dialog_ex.h>
  9. #include <gui/modules/popup.h>
  10. #include <gui/modules/submenu.h>
  11. #include <nfc/nfc.h>
  12. #include <nfc/nfc_device.h>
  13. #include <nfc/protocols/mf_classic/mf_classic.h>
  14. #include <storage/storage.h>
  15. #include "mfc_editor_app.h"
  16. #include "mfc_editor_icons.h"
  17. #include "scenes/mfc_editor_scene.h"
  18. #include <assets_icons.h>
  19. #define TAG "MFCEditor"
  20. #define NFC_APP_FOLDER ANY_PATH("nfc")
  21. #define NFC_APP_EXTENSION ".nfc"
  22. #define NFC_APP_SHADOW_EXTENSION ".shd"
  23. enum MfcEditorCustomEvent {
  24. // Reserve first 100 events for button types and indexes, starting from 0
  25. MfcEditorCustomEventReserved = 100,
  26. MfcEditorCustomEventViewExit,
  27. MfcEditorCustomEventSave,
  28. };
  29. typedef struct {
  30. uint8_t bits : 3;
  31. uint8_t check_bits : 3;
  32. } MfcEditorAccessBits;
  33. struct MfcEditorApp {
  34. ViewDispatcher* view_dispatcher;
  35. SceneManager* scene_manager;
  36. Gui* gui;
  37. Storage* storage;
  38. DialogsApp* dialogs;
  39. Submenu* submenu;
  40. Popup* popup;
  41. DialogEx* dialog_ex;
  42. ByteInput* byte_input;
  43. MfClassicData* mf_classic_data;
  44. FuriString* file_path;
  45. bool is_unsaved_changes;
  46. uint8_t current_sector;
  47. uint8_t current_block;
  48. // DialogEx doesn't copy the strings given to it, so we need these
  49. FuriString* data_view_header;
  50. FuriString* data_view_text;
  51. uint8_t* edit_buffer;
  52. MfcEditorAccessBits access_bits_edit;
  53. };
  54. typedef enum {
  55. MfcEditorAppViewSubmenu,
  56. MfcEditorAppViewPopup,
  57. MfcEditorAppViewDialogEx,
  58. MfcEditorAppViewByteInput,
  59. } MfcEditorAppView;
  60. typedef enum {
  61. // Generic
  62. MfcEditorPromptResponseSuccess,
  63. MfcEditorPromptResponseFailure,
  64. MfcEditorPromptResponseNotMfClassic,
  65. // Backed out of a prompt
  66. MfcEditorPromptResponseExitedFile,
  67. MfcEditorPromptResponseExitedShadow,
  68. } MfcEditorPromptResponse;
  69. typedef enum {
  70. MfcEditorSaveResponseSave,
  71. MfcEditorSaveResponseDiscard,
  72. MfcEditorSaveResponseCancel,
  73. } MfcEditorSaveResponse;
  74. typedef enum {
  75. MfcEditorBlockViewNormal,
  76. // Special options - Sector 0 only
  77. MfcEditorBlockViewUID,
  78. MfcEditorBlockViewBCC,
  79. MfcEditorBlockViewManufacturerBytes,
  80. // Special options - All sectors
  81. MfcEditorBlockViewKeyA,
  82. MfcEditorBlockViewKeyB,
  83. MfcEditorBlockViewAccessBits,
  84. MfcEditorBlockViewUserByte,
  85. } MfcEditorBlockView;
  86. // Main loading methods
  87. MfcEditorPromptResponse mfc_editor_prompt_load_file(MfcEditorApp* instance);
  88. MfcEditorPromptResponse mfc_editor_load_file(MfcEditorApp* instance, FuriString* file_path);
  89. bool mfc_editor_save_file(MfcEditorApp* instance);
  90. // Warning dialogs
  91. bool mfc_editor_warn_risky_operation(MfcEditorApp* instance);
  92. MfcEditorSaveResponse mfc_editor_warn_unsaved_changes(MfcEditorApp* instance);
  93. // Helper methods
  94. uint8_t mfc_editor_calculate_uid_bcc(uint8_t* uid, uint8_t uid_len);
  95. MfcEditorAccessBits mfc_editor_get_block_access_bits(const MfClassicData* data, uint8_t block_num);
  96. void mfc_editor_set_block_access_bits(
  97. MfClassicData* data,
  98. uint8_t block_num,
  99. const MfcEditorAccessBits* access_bits);
  100. void mfc_editor_furi_string_render_bytes(FuriString* string, const uint8_t* data, uint8_t length);
  101. // Strings
  102. extern const char* access_data_block_labels[8];
  103. extern const char* access_sector_trailer_labels[8];