[FL-2605] NFC new design (#1364)
* nfc: add new read scene * lib: refactore nfc library * mifare desfire: add read card fuction * lib nfc: add auto read worker * nfc: add supported cards * nfc: add mifare classic read success scene * nfc: add troyka support * submodule: update protobuf * nfc: mifare classic keys cache * nfc: rework mifare classic key cache * Correct spelling * nfc: add user dictionary * nfc: introduce block read map in fff * nfc: rework dict attack * nfc: improve dict attack * nfc: rework mifare classic format * nfc: rework MFC read with Reader * nfc: add gui for MFC read success scene * nfc: fix dict attack view gui * nfc: add retry and exit confirm scenes * nfc: add retry and exit scenes navigation * nfc: check user dictionary * nfc: remove unused scenes * nfc: rename functions in nfc worker * nfc: rename mf_classic_dict_attack -> dict_attack * nfc: change scenes names * nfc: remove scene tick events * nfc: rework dict calls with buffer streams * nfc: fix notifications * nfc: fix mf desfire navigation * nfc: remove notification from mf classic read success * nfc: fix read sectors calculation * nfc: add fallback for unknown card * nfc: show file name while emulating * nfc: fix build * nfc: fix memory leak * nfc: fix desfire read * nfc: add no dict found navigation * nfc: add read views * nfc: update card fix * nfc: fix access bytes save * nfc: add exit and retry confirm to mf ultralight read success * nfc: introduce detect reader * nfc: change record open arg to macros * nfc: fix start from archive Co-authored-by: Astra <astra@astrra.space> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,83 +1,60 @@
|
||||
#include "dict_attack.h"
|
||||
#include <m-string.h>
|
||||
|
||||
#include <m-string.h>
|
||||
#include <gui/elements.h>
|
||||
|
||||
typedef enum {
|
||||
DictAttackStateSearchCard,
|
||||
DictAttackStateSearchKeys,
|
||||
DictAttackStateRead,
|
||||
DictAttackStateCardRemoved,
|
||||
DictAttackStateSuccess,
|
||||
DictAttackStateFail,
|
||||
} DictAttackState;
|
||||
|
||||
struct DictAttack {
|
||||
View* view;
|
||||
DictAttackResultCallback callback;
|
||||
DictAttackCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
DictAttackState state;
|
||||
MfClassicType type;
|
||||
uint8_t current_sector;
|
||||
uint8_t total_sectors;
|
||||
uint8_t keys_a_found;
|
||||
uint8_t keys_a_total;
|
||||
uint8_t keys_b_found;
|
||||
uint8_t keys_b_total;
|
||||
string_t header;
|
||||
uint8_t sectors_total;
|
||||
uint8_t sectors_read;
|
||||
uint8_t sector_current;
|
||||
uint8_t keys_total;
|
||||
uint8_t keys_found;
|
||||
} DictAttackViewModel;
|
||||
|
||||
static void dict_attack_draw_callback(Canvas* canvas, void* model) {
|
||||
DictAttackViewModel* m = model;
|
||||
if(m->state == DictAttackStateSearchCard) {
|
||||
if(m->state == DictAttackStateCardRemoved) {
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 64, 32, AlignCenter, AlignCenter, "Detecting Mifare Classic");
|
||||
} else if(m->state == DictAttackStateCardRemoved) {
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 64, 32, AlignCenter, AlignTop, "Place card back to flipper");
|
||||
} else {
|
||||
char draw_str[32];
|
||||
if(m->state == DictAttackStateSearchKeys) {
|
||||
snprintf(
|
||||
draw_str, sizeof(draw_str), "Searching keys for sector %d", m->current_sector);
|
||||
canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, draw_str);
|
||||
} else if(m->state == DictAttackStateSuccess) {
|
||||
canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Complete!");
|
||||
elements_button_right(canvas, "More");
|
||||
} else if(m->state == DictAttackStateFail) {
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 64, 2, AlignCenter, AlignTop, "Failed to read any sector");
|
||||
}
|
||||
uint16_t keys_found = m->keys_a_found + m->keys_b_found;
|
||||
uint16_t keys_total = m->keys_a_total + m->keys_b_total;
|
||||
float progress = (float)(m->current_sector) / (float)(m->total_sectors);
|
||||
elements_progress_bar(canvas, 5, 12, 120, progress);
|
||||
canvas_draw_str_aligned(canvas, 64, 4, AlignCenter, AlignTop, "Lost the tag!");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
snprintf(draw_str, sizeof(draw_str), "Total keys found: %d/%d", keys_found, keys_total);
|
||||
canvas_draw_str_aligned(canvas, 1, 23, AlignLeft, AlignTop, draw_str);
|
||||
elements_multiline_text_aligned(
|
||||
canvas, 64, 23, AlignCenter, AlignTop, "Make sure the tag is\npositioned correctly.");
|
||||
} else if(m->state == DictAttackStateRead) {
|
||||
char draw_str[32] = {};
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, string_get_cstr(m->header));
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
float progress =
|
||||
m->sectors_total == 0 ? 0 : (float)(m->sector_current) / (float)(m->sectors_total);
|
||||
elements_progress_bar(canvas, 5, 15, 120, progress);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
snprintf(draw_str, sizeof(draw_str), "Keys found: %d/%d", m->keys_found, m->keys_total);
|
||||
canvas_draw_str_aligned(canvas, 1, 28, AlignLeft, AlignTop, draw_str);
|
||||
snprintf(
|
||||
draw_str, sizeof(draw_str), "A keys found: %d/%d", m->keys_a_found, m->keys_a_total);
|
||||
canvas_draw_str_aligned(canvas, 1, 34, AlignLeft, AlignTop, draw_str);
|
||||
snprintf(
|
||||
draw_str, sizeof(draw_str), "B keys found: %d/%d", m->keys_b_found, m->keys_b_total);
|
||||
canvas_draw_str_aligned(canvas, 1, 45, AlignLeft, AlignTop, draw_str);
|
||||
draw_str, sizeof(draw_str), "Sectors Read: %d/%d", m->sectors_read, m->sectors_total);
|
||||
canvas_draw_str_aligned(canvas, 1, 40, AlignLeft, AlignTop, draw_str);
|
||||
}
|
||||
elements_button_center(canvas, "Skip");
|
||||
}
|
||||
|
||||
static bool dict_attack_input_callback(InputEvent* event, void* context) {
|
||||
DictAttack* dict_attack = context;
|
||||
bool consumed = false;
|
||||
DictAttackState state;
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
state = model->state;
|
||||
return false;
|
||||
});
|
||||
if(state == DictAttackStateSuccess && event->type == InputTypeShort &&
|
||||
event->key == InputKeyRight) {
|
||||
if(event->type == InputTypeShort && event->key == InputKeyOk) {
|
||||
if(dict_attack->callback) {
|
||||
dict_attack->callback(dict_attack->context);
|
||||
}
|
||||
@@ -93,11 +70,21 @@ DictAttack* dict_attack_alloc() {
|
||||
view_set_draw_callback(dict_attack->view, dict_attack_draw_callback);
|
||||
view_set_input_callback(dict_attack->view, dict_attack_input_callback);
|
||||
view_set_context(dict_attack->view, dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
string_init(model->header);
|
||||
return false;
|
||||
});
|
||||
return dict_attack;
|
||||
}
|
||||
|
||||
void dict_attack_free(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
string_clear(model->header);
|
||||
return false;
|
||||
});
|
||||
view_free(dict_attack->view);
|
||||
free(dict_attack);
|
||||
}
|
||||
@@ -106,8 +93,15 @@ void dict_attack_reset(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
memset(model, 0, sizeof(DictAttackViewModel));
|
||||
return true;
|
||||
model->state = DictAttackStateRead;
|
||||
model->type = MfClassicType1k;
|
||||
model->sectors_total = 0;
|
||||
model->sectors_read = 0;
|
||||
model->sector_current = 0;
|
||||
model->keys_total = 0;
|
||||
model->keys_found = 0;
|
||||
string_reset(model->header);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -116,78 +110,88 @@ View* dict_attack_get_view(DictAttack* dict_attack) {
|
||||
return dict_attack->view;
|
||||
}
|
||||
|
||||
void dict_attack_set_result_callback(
|
||||
DictAttack* dict_attack,
|
||||
DictAttackResultCallback callback,
|
||||
void* context) {
|
||||
void dict_attack_set_callback(DictAttack* dict_attack, DictAttackCallback callback, void* context) {
|
||||
furi_assert(dict_attack);
|
||||
furi_assert(callback);
|
||||
dict_attack->callback = callback;
|
||||
dict_attack->context = context;
|
||||
}
|
||||
|
||||
void dict_attack_card_detected(DictAttack* dict_attack, MfClassicType type) {
|
||||
void dict_attack_set_header(DictAttack* dict_attack, const char* header) {
|
||||
furi_assert(dict_attack);
|
||||
furi_assert(header);
|
||||
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
string_set_str(model->header, header);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void dict_attack_set_card_detected(DictAttack* dict_attack, MfClassicType type) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->state = DictAttackStateSearchKeys;
|
||||
if(type == MfClassicType1k) {
|
||||
model->total_sectors = 16;
|
||||
model->keys_a_total = 16;
|
||||
model->keys_b_total = 16;
|
||||
} else if(type == MfClassicType4k) {
|
||||
model->total_sectors = 40;
|
||||
model->keys_a_total = 40;
|
||||
model->keys_b_total = 40;
|
||||
model->state = DictAttackStateRead;
|
||||
model->sectors_total = mf_classic_get_total_sectors_num(type);
|
||||
model->keys_total = model->sectors_total * 2;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void dict_attack_set_card_removed(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->state = DictAttackStateCardRemoved;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void dict_attack_set_sector_read(DictAttack* dict_attack, uint8_t sec_read) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->sectors_read = sec_read;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void dict_attack_set_keys_found(DictAttack* dict_attack, uint8_t keys_found) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->keys_found = keys_found;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void dict_attack_set_current_sector(DictAttack* dict_attack, uint8_t curr_sec) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->sector_current = curr_sec;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void dict_attack_inc_current_sector(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
if(model->sector_current < model->sectors_total) {
|
||||
model->sector_current++;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void dict_attack_card_removed(DictAttack* dict_attack) {
|
||||
void dict_attack_inc_keys_found(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
if(model->state == DictAttackStateSearchKeys) {
|
||||
model->state = DictAttackStateCardRemoved;
|
||||
} else {
|
||||
model->state = DictAttackStateSearchCard;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void dict_attack_inc_curr_sector(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->current_sector++;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void dict_attack_inc_found_key(DictAttack* dict_attack, MfClassicKey key) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->state = DictAttackStateSearchKeys;
|
||||
if(key == MfClassicKeyA) {
|
||||
model->keys_a_found++;
|
||||
} else if(key == MfClassicKeyB) {
|
||||
model->keys_b_found++;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void dict_attack_set_result(DictAttack* dict_attack, bool success) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
if(success) {
|
||||
model->state = DictAttackStateSuccess;
|
||||
} else {
|
||||
model->state = DictAttackStateFail;
|
||||
if(model->keys_found < model->keys_total) {
|
||||
model->keys_found++;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
@@ -3,11 +3,11 @@
|
||||
#include <gui/view.h>
|
||||
#include <gui/modules/widget.h>
|
||||
|
||||
#include <lib/nfc_protocols/mifare_classic.h>
|
||||
#include <lib/nfc/protocols/mifare_classic.h>
|
||||
|
||||
typedef struct DictAttack DictAttack;
|
||||
|
||||
typedef void (*DictAttackResultCallback)(void* context);
|
||||
typedef void (*DictAttackCallback)(void* context);
|
||||
|
||||
DictAttack* dict_attack_alloc();
|
||||
|
||||
@@ -17,17 +17,20 @@ void dict_attack_reset(DictAttack* dict_attack);
|
||||
|
||||
View* dict_attack_get_view(DictAttack* dict_attack);
|
||||
|
||||
void dict_attack_set_result_callback(
|
||||
DictAttack* dict_attack,
|
||||
DictAttackResultCallback callback,
|
||||
void* context);
|
||||
void dict_attack_set_callback(DictAttack* dict_attack, DictAttackCallback callback, void* context);
|
||||
|
||||
void dict_attack_card_detected(DictAttack* dict_attack, MfClassicType type);
|
||||
void dict_attack_set_header(DictAttack* dict_attack, const char* header);
|
||||
|
||||
void dict_attack_card_removed(DictAttack* dict_attack);
|
||||
void dict_attack_set_card_detected(DictAttack* dict_attack, MfClassicType type);
|
||||
|
||||
void dict_attack_inc_curr_sector(DictAttack* dict_attack);
|
||||
void dict_attack_set_card_removed(DictAttack* dict_attack);
|
||||
|
||||
void dict_attack_inc_found_key(DictAttack* dict_attack, MfClassicKey key);
|
||||
void dict_attack_set_sector_read(DictAttack* dict_attack, uint8_t sec_read);
|
||||
|
||||
void dict_attack_set_result(DictAttack* dict_attack, bool success);
|
||||
void dict_attack_set_keys_found(DictAttack* dict_attack, uint8_t keys_found);
|
||||
|
||||
void dict_attack_set_current_sector(DictAttack* dict_attack, uint8_t curr_sec);
|
||||
|
||||
void dict_attack_inc_current_sector(DictAttack* dict_attack);
|
||||
|
||||
void dict_attack_inc_keys_found(DictAttack* dict_attack);
|
||||
|
Reference in New Issue
Block a user