Merge branch 'dev' into nfcf

This commit is contained in:
nullableVoidPtr
2022-12-28 17:23:43 +08:00
244 changed files with 2591 additions and 1130 deletions

View File

@@ -39,7 +39,7 @@ static void nfc_scene_emulate_uid_widget_config(Nfc* nfc, bool data_received) {
widget_add_icon_element(widget, 0, 3, &I_NFC_dolphin_emulation_47x61);
widget_add_string_element(widget, 57, 13, AlignLeft, AlignTop, FontPrimary, "Emulating UID");
if(strcmp(nfc->dev->dev_name, "")) {
if(strcmp(nfc->dev->dev_name, "") != 0) {
furi_string_printf(info_str, "%s", nfc->dev->dev_name);
} else {
for(uint8_t i = 0; i < data->uid_len; i++) {

View File

@@ -43,7 +43,7 @@ bool nfc_scene_extra_actions_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexMfClassicKeys) {
if(mf_classic_dict_check_presence(MfClassicDictTypeFlipper)) {
if(mf_classic_dict_check_presence(MfClassicDictTypeSystem)) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicKeys);
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneDictNotFound);

View File

@@ -53,10 +53,10 @@ static void nfc_scene_mf_classic_dict_attack_prepare_view(Nfc* nfc, DictAttackSt
// Setup view
if(state == DictAttackStateUserDictInProgress) {
worker_state = NfcWorkerStateMfClassicDictAttack;
dict_attack_set_header(nfc->dict_attack, "Mf Classic User Dict.");
dict_attack_set_header(nfc->dict_attack, "MF Classic User Dictionary");
dict = mf_classic_dict_alloc(MfClassicDictTypeUser);
// If failed to load user dictionary - try flipper dictionary
// If failed to load user dictionary - try the system dictionary
if(!dict) {
FURI_LOG_E(TAG, "User dictionary not found");
state = DictAttackStateFlipperDictInProgress;
@@ -64,11 +64,11 @@ static void nfc_scene_mf_classic_dict_attack_prepare_view(Nfc* nfc, DictAttackSt
}
if(state == DictAttackStateFlipperDictInProgress) {
worker_state = NfcWorkerStateMfClassicDictAttack;
dict_attack_set_header(nfc->dict_attack, "Mf Classic Flipper Dict.");
dict = mf_classic_dict_alloc(MfClassicDictTypeFlipper);
dict_attack_set_header(nfc->dict_attack, "MF Classic System Dictionary");
dict = mf_classic_dict_alloc(MfClassicDictTypeSystem);
if(!dict) {
FURI_LOG_E(TAG, "Flipper dictionary not found");
// Pass through to let worker handle the failure
// Pass through to let the worker handle the failure
}
}
// Free previous dictionary
@@ -153,6 +153,15 @@ bool nfc_scene_mf_classic_dict_attack_on_event(void* context, SceneManagerEvent
nfc_worker_stop(nfc->worker);
consumed = true;
}
} else if(event.event == NfcWorkerEventKeyAttackStart) {
dict_attack_set_key_attack(
nfc->dict_attack,
true,
nfc->dev->dev_data.mf_classic_dict_attack_data.current_sector);
} else if(event.event == NfcWorkerEventKeyAttackStop) {
dict_attack_set_key_attack(nfc->dict_attack, false, 0);
} else if(event.event == NfcWorkerEventKeyAttackNextSector) {
dict_attack_inc_key_attack_current_sector(nfc->dict_attack);
}
} else if(event.type == SceneManagerEventTypeBack) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);

View File

@@ -18,7 +18,7 @@ void nfc_scene_mf_classic_emulate_on_enter(void* context) {
// Setup view
Popup* popup = nfc->popup;
popup_set_header(popup, "Emulating", 67, 13, AlignLeft, AlignTop);
if(strcmp(nfc->dev->dev_name, "")) {
if(strcmp(nfc->dev->dev_name, "") != 0) {
nfc_text_store_set(nfc, "%s", nfc->dev->dev_name);
} else {
nfc_text_store_set(nfc, "MIFARE\nClassic");

View File

@@ -12,7 +12,7 @@ void nfc_scene_mf_classic_keys_on_enter(void* context) {
// Load flipper dict keys total
uint32_t flipper_dict_keys_total = 0;
MfClassicDict* dict = mf_classic_dict_alloc(MfClassicDictTypeFlipper);
MfClassicDict* dict = mf_classic_dict_alloc(MfClassicDictTypeSystem);
if(dict) {
flipper_dict_keys_total = mf_classic_dict_get_total_keys(dict);
mf_classic_dict_free(dict);
@@ -26,11 +26,11 @@ void nfc_scene_mf_classic_keys_on_enter(void* context) {
}
widget_add_string_element(
nfc->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Mifare Classic Keys");
nfc->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "MIFARE Classic Keys");
char temp_str[32];
snprintf(temp_str, sizeof(temp_str), "Flipper list: %ld", flipper_dict_keys_total);
snprintf(temp_str, sizeof(temp_str), "System dict: %lu", flipper_dict_keys_total);
widget_add_string_element(nfc->widget, 0, 20, AlignLeft, AlignTop, FontSecondary, temp_str);
snprintf(temp_str, sizeof(temp_str), "User list: %ld", user_dict_keys_total);
snprintf(temp_str, sizeof(temp_str), "User dict: %lu", user_dict_keys_total);
widget_add_string_element(nfc->widget, 0, 32, AlignLeft, AlignTop, FontSecondary, temp_str);
widget_add_button_element(
nfc->widget, GuiButtonTypeCenter, "Add", nfc_scene_mf_classic_keys_widget_callback, nfc);

View File

@@ -27,7 +27,7 @@ void nfc_scene_mf_classic_keys_list_prepare(Nfc* nfc, MfClassicDict* dict) {
char* current_key = (char*)malloc(sizeof(char) * 13);
strncpy(current_key, furi_string_get_cstr(temp_key), 12);
MfClassicUserKeys_push_back(nfc->mfc_key_strs, current_key);
FURI_LOG_D("ListKeys", "Key %ld: %s", index, current_key);
FURI_LOG_D("ListKeys", "Key %lu: %s", index, current_key);
submenu_add_item(
submenu, current_key, index++, nfc_scene_mf_classic_keys_list_submenu_callback, nfc);
}

View File

@@ -26,13 +26,13 @@ void nfc_scene_mf_desfire_read_success_on_enter(void* context) {
furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
}
uint32_t bytes_total = 1 << (data->version.sw_storage >> 1);
uint32_t bytes_total = 1UL << (data->version.sw_storage >> 1);
uint32_t bytes_free = data->free_memory ? data->free_memory->bytes : 0;
furi_string_cat_printf(temp_str, "\n%ld", bytes_total);
furi_string_cat_printf(temp_str, "\n%lu", bytes_total);
if(data->version.sw_storage & 1) {
furi_string_push_back(temp_str, '+');
}
furi_string_cat_printf(temp_str, " bytes, %ld bytes free\n", bytes_free);
furi_string_cat_printf(temp_str, " bytes, %lu bytes free\n", bytes_free);
uint16_t n_apps = 0;
uint16_t n_files = 0;

View File

@@ -21,7 +21,7 @@ void nfc_scene_mf_ultralight_emulate_on_enter(void* context) {
(type == MfUltralightTypeUnknown);
Popup* popup = nfc->popup;
popup_set_header(popup, "Emulating", 67, 13, AlignLeft, AlignTop);
if(strcmp(nfc->dev->dev_name, "")) {
if(strcmp(nfc->dev->dev_name, "") != 0) {
nfc_text_store_set(nfc, "%s", nfc->dev->dev_name);
} else if(is_ultralight) {
nfc_text_store_set(nfc, "MIFARE\nUltralight");

View File

@@ -58,13 +58,13 @@ void nfc_scene_nfc_data_info_on_enter(void* context) {
// Set application specific data
if(protocol == NfcDeviceProtocolMifareDesfire) {
MifareDesfireData* data = &dev_data->mf_df_data;
uint32_t bytes_total = 1 << (data->version.sw_storage >> 1);
uint32_t bytes_total = 1UL << (data->version.sw_storage >> 1);
uint32_t bytes_free = data->free_memory ? data->free_memory->bytes : 0;
furi_string_cat_printf(temp_str, "\n%ld", bytes_total);
furi_string_cat_printf(temp_str, "\n%lu", bytes_total);
if(data->version.sw_storage & 1) {
furi_string_push_back(temp_str, '+');
}
furi_string_cat_printf(temp_str, " bytes, %ld bytes free\n", bytes_free);
furi_string_cat_printf(temp_str, " bytes, %lu bytes free\n", bytes_free);
uint16_t n_apps = 0;
uint16_t n_files = 0;
@@ -148,4 +148,4 @@ void nfc_scene_nfc_data_info_on_exit(void* context) {
Nfc* nfc = context;
widget_reset(nfc->widget);
}
}

View File

@@ -71,7 +71,7 @@ bool nfc_scene_read_on_event(void* context, SceneManagerEvent event) {
} else if(event.event == NfcWorkerEventReadMfUltralight) {
notification_message(nfc->notifications, &sequence_success);
// Set unlock password input to 0xFFFFFFFF only on fresh read
memset(nfc->byte_input_store, 0xFF, 4);
memset(nfc->byte_input_store, 0xFF, sizeof(nfc->byte_input_store));
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfUltralightReadSuccess);
DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
consumed = true;
@@ -91,7 +91,7 @@ bool nfc_scene_read_on_event(void* context, SceneManagerEvent event) {
DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
consumed = true;
} else if(event.event == NfcWorkerEventReadMfClassicDictAttackRequired) {
if(mf_classic_dict_check_presence(MfClassicDictTypeFlipper)) {
if(mf_classic_dict_check_presence(MfClassicDictTypeSystem)) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicDictAttack);
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneDictNotFound);

View File

@@ -55,7 +55,7 @@ bool nfc_scene_save_name_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventTextInputDone) {
if(strcmp(nfc->dev->dev_name, "")) {
if(strcmp(nfc->dev->dev_name, "") != 0) {
nfc_device_delete(nfc->dev, true);
}
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSetUid)) {

View File

@@ -24,6 +24,8 @@ typedef struct {
uint8_t keys_found;
uint16_t dict_keys_total;
uint16_t dict_keys_current;
bool is_key_attack;
uint8_t key_attack_current_sector;
} DictAttackViewModel;
static void dict_attack_draw_callback(Canvas* canvas, void* model) {
@@ -36,10 +38,19 @@ static void dict_attack_draw_callback(Canvas* canvas, void* model) {
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, furi_string_get_cstr(m->header));
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(
canvas, 64, 0, AlignCenter, AlignTop, furi_string_get_cstr(m->header));
if(m->is_key_attack) {
snprintf(
draw_str,
sizeof(draw_str),
"Reuse key check for sector: %d",
m->key_attack_current_sector);
} else {
snprintf(draw_str, sizeof(draw_str), "Unlocking sector: %d", m->sector_current);
}
canvas_draw_str_aligned(canvas, 0, 10, AlignLeft, AlignTop, draw_str);
float dict_progress = m->dict_keys_total == 0 ?
0 :
(float)(m->dict_keys_current) / (float)(m->dict_keys_total);
@@ -49,13 +60,14 @@ static void dict_attack_draw_callback(Canvas* canvas, void* model) {
if(progress > 1.0) {
progress = 1.0;
}
elements_progress_bar(canvas, 5, 15, 120, progress);
snprintf(draw_str, sizeof(draw_str), "%d/%d", m->dict_keys_current, m->dict_keys_total);
elements_progress_bar_with_text(canvas, 0, 20, 128, dict_progress, draw_str);
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);
canvas_draw_str_aligned(canvas, 0, 33, AlignLeft, AlignTop, draw_str);
snprintf(
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);
canvas_draw_str_aligned(canvas, 0, 43, AlignLeft, AlignTop, draw_str);
}
elements_button_center(canvas, "Skip");
}
@@ -113,6 +125,7 @@ void dict_attack_reset(DictAttack* dict_attack) {
model->keys_found = 0;
model->dict_keys_total = 0;
model->dict_keys_current = 0;
model->is_key_attack = false;
furi_string_reset(model->header);
},
false);
@@ -235,3 +248,28 @@ void dict_attack_inc_current_dict_key(DictAttack* dict_attack, uint16_t keys_tri
},
true);
}
void dict_attack_set_key_attack(DictAttack* dict_attack, bool is_key_attack, uint8_t sector) {
furi_assert(dict_attack);
with_view_model(
dict_attack->view,
DictAttackViewModel * model,
{
model->is_key_attack = is_key_attack;
model->key_attack_current_sector = sector;
},
true);
}
void dict_attack_inc_key_attack_current_sector(DictAttack* dict_attack) {
furi_assert(dict_attack);
with_view_model(
dict_attack->view,
DictAttackViewModel * model,
{
if(model->key_attack_current_sector < model->sectors_total) {
model->key_attack_current_sector++;
}
},
true);
}

View File

@@ -38,3 +38,7 @@ void dict_attack_inc_keys_found(DictAttack* dict_attack);
void dict_attack_set_total_dict_keys(DictAttack* dict_attack, uint16_t dict_keys_total);
void dict_attack_inc_current_dict_key(DictAttack* dict_attack, uint16_t keys_tried);
void dict_attack_set_key_attack(DictAttack* dict_attack, bool is_key_attack, uint8_t sector);
void dict_attack_inc_key_attack_current_sector(DictAttack* dict_attack);