mfc_editor_app_i.h 3.4 KB

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