nfc_scene_mf_classic_data.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "../nfc_i.h"
  2. void nfc_scene_mf_classic_data_on_enter(void* context) {
  3. Nfc* nfc = context;
  4. MfClassicType type = nfc->dev->dev_data.mf_classic_data.type;
  5. MfClassicData* data = &nfc->dev->dev_data.mf_classic_data;
  6. TextBox* text_box = nfc->text_box;
  7. text_box_set_font(text_box, TextBoxFontHex);
  8. int card_blocks = 0;
  9. if(type == MfClassicType1k) {
  10. card_blocks = MF_CLASSIC_1K_TOTAL_SECTORS_NUM * 4;
  11. } else if(type == MfClassicType4k) {
  12. // 16 sectors of 4 blocks each plus 8 sectors of 16 blocks each
  13. card_blocks = MF_CLASSIC_1K_TOTAL_SECTORS_NUM * 4 + 8 * 16;
  14. } else if(type == MfClassicTypeMini) {
  15. card_blocks = MF_MINI_TOTAL_SECTORS_NUM * 4;
  16. }
  17. int bytes_written = 0;
  18. for(int block_num = 0; block_num < card_blocks; block_num++) {
  19. bool is_sec_trailer = mf_classic_is_sector_trailer(block_num);
  20. if(is_sec_trailer) {
  21. uint8_t sector_num = mf_classic_get_sector_by_block(block_num);
  22. MfClassicSectorTrailer* sec_tr =
  23. mf_classic_get_sector_trailer_by_sector(data, sector_num);
  24. // Key A
  25. for(size_t i = 0; i < sizeof(sec_tr->key_a); i += 2) {
  26. if((bytes_written % 8 == 0) && (bytes_written != 0)) {
  27. furi_string_push_back(nfc->text_box_store, '\n');
  28. }
  29. if(mf_classic_is_key_found(data, sector_num, MfClassicKeyA)) {
  30. furi_string_cat_printf(
  31. nfc->text_box_store, "%02X%02X ", sec_tr->key_a[i], sec_tr->key_a[i + 1]);
  32. } else {
  33. furi_string_cat_printf(nfc->text_box_store, "???? ");
  34. }
  35. bytes_written += 2;
  36. }
  37. // Access bytes
  38. for(size_t i = 0; i < MF_CLASSIC_ACCESS_BYTES_SIZE; i += 2) {
  39. if((bytes_written % 8 == 0) && (bytes_written != 0)) {
  40. furi_string_push_back(nfc->text_box_store, '\n');
  41. }
  42. if(mf_classic_is_block_read(data, block_num)) {
  43. furi_string_cat_printf(
  44. nfc->text_box_store,
  45. "%02X%02X ",
  46. sec_tr->access_bits[i],
  47. sec_tr->access_bits[i + 1]);
  48. } else {
  49. furi_string_cat_printf(nfc->text_box_store, "???? ");
  50. }
  51. bytes_written += 2;
  52. }
  53. // Key B
  54. for(size_t i = 0; i < sizeof(sec_tr->key_b); i += 2) {
  55. if((bytes_written % 8 == 0) && (bytes_written != 0)) {
  56. furi_string_push_back(nfc->text_box_store, '\n');
  57. }
  58. if(mf_classic_is_key_found(data, sector_num, MfClassicKeyB)) {
  59. furi_string_cat_printf(
  60. nfc->text_box_store, "%02X%02X ", sec_tr->key_b[i], sec_tr->key_b[i + 1]);
  61. } else {
  62. furi_string_cat_printf(nfc->text_box_store, "???? ");
  63. }
  64. bytes_written += 2;
  65. }
  66. } else {
  67. // Write data block
  68. for(size_t i = 0; i < MF_CLASSIC_BLOCK_SIZE; i += 2) {
  69. if((bytes_written % 8 == 0) && (bytes_written != 0)) {
  70. furi_string_push_back(nfc->text_box_store, '\n');
  71. }
  72. if(mf_classic_is_block_read(data, block_num)) {
  73. furi_string_cat_printf(
  74. nfc->text_box_store,
  75. "%02X%02X ",
  76. data->block[block_num].value[i],
  77. data->block[block_num].value[i + 1]);
  78. } else {
  79. furi_string_cat_printf(nfc->text_box_store, "???? ");
  80. }
  81. bytes_written += 2;
  82. }
  83. }
  84. }
  85. text_box_set_text(text_box, furi_string_get_cstr(nfc->text_box_store));
  86. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox);
  87. }
  88. bool nfc_scene_mf_classic_data_on_event(void* context, SceneManagerEvent event) {
  89. UNUSED(context);
  90. UNUSED(event);
  91. return false;
  92. }
  93. void nfc_scene_mf_classic_data_on_exit(void* context) {
  94. Nfc* nfc = context;
  95. // Clean view
  96. text_box_reset(nfc->text_box);
  97. furi_string_reset(nfc->text_box_store);
  98. }