TollyH 2 лет назад
Родитель
Сommit
cb31b4d037
4 измененных файлов с 47 добавлено и 0 удалено
  1. 7 0
      mfc_editor_app_i.h
  2. 12 0
      mfc_editor_helpers.c
  3. 12 0
      scenes/mfc_editor_scene_block_select.c
  4. 16 0
      scenes/mfc_editor_scene_data_view.c

+ 7 - 0
mfc_editor_app_i.h

@@ -82,6 +82,7 @@ typedef enum {
 
 
     // Special options - Sector 0 only
     // Special options - Sector 0 only
     MfcEditorBlockViewUID,
     MfcEditorBlockViewUID,
+    MfcEditorBlockViewBCC,
     MfcEditorBlockViewManufacturerBytes,
     MfcEditorBlockViewManufacturerBytes,
 
 
     // Special options - All sectors
     // Special options - All sectors
@@ -91,6 +92,12 @@ typedef enum {
     MfcEditorBlockViewUserByte,
     MfcEditorBlockViewUserByte,
 } MfcEditorBlockView;
 } MfcEditorBlockView;
 
 
+// Main loading methods
+
 MfcEditorPromptResponse mfc_editor_prompt_load_file(MfcEditorApp* instance);
 MfcEditorPromptResponse mfc_editor_prompt_load_file(MfcEditorApp* instance);
 
 
 MfcEditorPromptResponse mfc_editor_load_file(MfcEditorApp* instance, FuriString* file_path);
 MfcEditorPromptResponse mfc_editor_load_file(MfcEditorApp* instance, FuriString* file_path);
+
+// Helper methods
+
+uint8_t mfc_editor_calculate_uid_bcc(uint8_t* uid, uint8_t uid_len);

+ 12 - 0
mfc_editor_helpers.c

@@ -0,0 +1,12 @@
+#include "mfc_editor_app_i.h"
+
+uint8_t mfc_editor_calculate_uid_bcc(uint8_t* uid, uint8_t uid_len) {
+    furi_check(uid_len > 0);
+
+    uint8_t bcc = uid[0];
+    for(int i = 1; i < uid_len; i++) {
+        bcc ^= uid[i];
+    }
+
+    return bcc;
+}

+ 12 - 0
scenes/mfc_editor_scene_block_select.c

@@ -6,6 +6,7 @@ enum SubmenuIndex {
 
 
     // Special options - Sector 0 only
     // Special options - Sector 0 only
     SubmenuIndexUID,
     SubmenuIndexUID,
+    SubmenuIndexBCC,
     SubmenuIndexManufacturerBytes,
     SubmenuIndexManufacturerBytes,
 
 
     // Special options - All sectors
     // Special options - All sectors
@@ -48,6 +49,15 @@ void mfc_editor_scene_block_select_on_enter(void* context) {
             SubmenuIndexUID,
             SubmenuIndexUID,
             mfc_editor_scene_block_select_submenu_callback,
             mfc_editor_scene_block_select_submenu_callback,
             instance);
             instance);
+        if(instance->mf_classic_data->iso14443_3a_data->uid_len == 4) {
+            // 7-byte UID cards don't store a BCC byte
+            submenu_add_item(
+                submenu,
+                "BCC",
+                SubmenuIndexBCC,
+                mfc_editor_scene_block_select_submenu_callback,
+                instance);
+        }
         submenu_add_item(
         submenu_add_item(
             submenu,
             submenu,
             "Manufacturer Bytes",
             "Manufacturer Bytes",
@@ -98,6 +108,8 @@ bool mfc_editor_scene_block_select_on_event(void* context, SceneManagerEvent eve
         MfcEditorBlockView block_view;
         MfcEditorBlockView block_view;
         if(event.event == SubmenuIndexUID) {
         if(event.event == SubmenuIndexUID) {
             block_view = MfcEditorBlockViewUID;
             block_view = MfcEditorBlockViewUID;
+        } else if(event.event == SubmenuIndexBCC) {
+            block_view = MfcEditorBlockViewBCC;
         } else if(event.event == SubmenuIndexManufacturerBytes) {
         } else if(event.event == SubmenuIndexManufacturerBytes) {
             block_view = MfcEditorBlockViewManufacturerBytes;
             block_view = MfcEditorBlockViewManufacturerBytes;
         } else if(event.event == SubmenuIndexKeyA) {
         } else if(event.event == SubmenuIndexKeyA) {

+ 16 - 0
scenes/mfc_editor_scene_data_view.c

@@ -21,6 +21,22 @@ void mfc_editor_scene_data_view_on_enter(void* context) {
         }
         }
         // Remove trailing space
         // Remove trailing space
         furi_string_trim(instance->data_view_text);
         furi_string_trim(instance->data_view_text);
+    } else if(block_view == MfcEditorBlockViewBCC) {
+        dialog_ex_set_header(dialog_ex, "Block Check Character", 63, 3, AlignCenter, AlignTop);
+
+        uint8_t stored_bcc = mf_classic_data->block[0].data[4];
+        uint8_t calculated_bcc =
+            mfc_editor_calculate_uid_bcc(iso14443_3a_data->uid, iso14443_3a_data->uid_len);
+
+        furi_string_printf(
+            instance->data_view_text,
+            "Stored BCC: %02hhX\nActual BCC: %02hhX",
+            stored_bcc,
+            calculated_bcc);
+
+        if(stored_bcc != calculated_bcc) {
+            furi_string_cat(instance->data_view_text, "\n(Mismatch!)");
+        }
     } else if(block_view == MfcEditorBlockViewManufacturerBytes) {
     } else if(block_view == MfcEditorBlockViewManufacturerBytes) {
         dialog_ex_set_header(dialog_ex, "Manufacturer Bytes", 63, 3, AlignCenter, AlignTop);
         dialog_ex_set_header(dialog_ex, "Manufacturer Bytes", 63, 3, AlignCenter, AlignTop);