From d2b0aa8513e9df980d6d1d94261663e5838605c9 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 6 Jun 2023 15:13:50 +0300 Subject: [PATCH] Fuzzer App: fix time_delay --- applications/external/pacs_fuzzer/fuzzer_i.h | 1 - .../pacs_fuzzer/lib/worker/fake_worker.c | 65 ++++++++++++------- .../pacs_fuzzer/lib/worker/protocol.c | 4 ++ .../pacs_fuzzer/lib/worker/protocol.h | 6 ++ .../pacs_fuzzer/lib/worker/protocol_i.h | 4 ++ .../external/pacs_fuzzer/views/attack.c | 10 +-- 6 files changed, 61 insertions(+), 29 deletions(-) diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h index 1dad1608a..63bf85d24 100644 --- a/applications/external/pacs_fuzzer/fuzzer_i.h +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -22,7 +22,6 @@ #include #include "fuzzer_icons.h" -#define FUZZ_TIME_DELAY_MIN (5) #define FUZZ_TIME_DELAY_MAX (80) typedef struct { diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c index 9d3d89cdf..896088308 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c @@ -8,7 +8,6 @@ #include #define TAG "Fuzzer worker" -#define FUZZ_TIME_DELAY_DEFAULT (10) #if defined(RFID_125_PROTOCOL) @@ -39,7 +38,8 @@ struct FuzzerWorker { const FuzzerProtocol* protocol; FuzzerWorkerAttackType attack_type; - uint8_t timeer_delay; + uint8_t timer_idle_delay; + uint8_t timer_emu_delay; uint8_t payload[MAX_PAYLOAD_SIZE]; Stream* uids_stream; @@ -47,6 +47,7 @@ struct FuzzerWorker { uint8_t chusen_byte; bool treead_running; + bool in_emu_phase; FuriTimer* timer; FuzzerWorkerUidChagedCallback tick_callback; @@ -147,29 +148,35 @@ static void fuzzer_worker_on_tick_callback(void* context) { FuzzerWorker* instance = context; - if(instance->treead_running) { -#if defined(RFID_125_PROTOCOL) - lfrfid_worker_stop(instance->proto_worker); -#else - ibutton_worker_stop(instance->proto_worker); -#endif - } - - if(!fuzzer_worker_load_key(instance, true)) { - fuzzer_worker_pause(instance); // XXX - if(instance->end_callback) { - instance->end_callback(instance->end_context); - } - } else { + if(instance->in_emu_phase) { if(instance->treead_running) { #if defined(RFID_125_PROTOCOL) - lfrfid_worker_emulate_start(instance->proto_worker, instance->protocol_id); + lfrfid_worker_stop(instance->proto_worker); #else - ibutton_worker_emulate_start(instance->proto_worker, instance->key); + ibutton_worker_stop(instance->proto_worker); #endif } - if(instance->tick_callback) { - instance->tick_callback(instance->tick_context); + instance->in_emu_phase = false; + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_idle_delay * 100)); + } else { + if(!fuzzer_worker_load_key(instance, true)) { + fuzzer_worker_pause(instance); // XXX + if(instance->end_callback) { + instance->end_callback(instance->end_context); + } + } else { + if(instance->treead_running) { +#if defined(RFID_125_PROTOCOL) + lfrfid_worker_emulate_start(instance->proto_worker, instance->protocol_id); +#else + ibutton_worker_emulate_start(instance->proto_worker, instance->key); +#endif + } + instance->in_emu_phase = true; + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_delay * 100)); + if(instance->tick_callback) { + instance->tick_callback(instance->tick_context); + } } } } @@ -338,13 +345,15 @@ FuzzerWorker* fuzzer_worker_alloc() { instance->attack_type = FuzzerWorkerAttackTypeMax; instance->index = 0; instance->treead_running = false; + instance->in_emu_phase = false; memset(instance->payload, 0x00, sizeof(instance->payload)); - instance->timeer_delay = FUZZ_TIME_DELAY_DEFAULT; + instance->timer_idle_delay = PROTOCOL_MIN_IDLE_DELAY; + instance->timer_emu_delay = PROTOCOL_MIN_IDLE_DELAY; instance->timer = - furi_timer_alloc(fuzzer_worker_on_tick_callback, FuriTimerTypePeriodic, instance); + furi_timer_alloc(fuzzer_worker_on_tick_callback, FuriTimerTypeOnce, instance); return instance; } @@ -374,9 +383,15 @@ bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t timer_dellay) { furi_assert(instance); if(instance->attack_type < FuzzerWorkerAttackTypeMax) { - instance->timeer_delay = timer_dellay; + uint8_t temp = timer_dellay / 2; + instance->timer_emu_delay = temp; + instance->timer_idle_delay = temp + timer_dellay % 2; - furi_timer_start(instance->timer, furi_ms_to_ticks(timer_dellay * 100)); + FURI_LOG_D( + TAG, + "Emu_delay %u Idle_delay %u", + instance->timer_emu_delay, + instance->timer_idle_delay); if(!instance->treead_running) { #if defined(RFID_125_PROTOCOL) @@ -397,6 +412,8 @@ bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t timer_dellay) { // ibutton_worker_start_thread(instance->proto_worker); ibutton_worker_emulate_start(instance->proto_worker, instance->key); #endif + instance->in_emu_phase = true; + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_delay * 100)); return true; } return false; diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.c b/applications/external/pacs_fuzzer/lib/worker/protocol.c index c295289ae..fb7651901 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.c +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.c @@ -254,6 +254,10 @@ uint8_t fuzzer_proto_get_max_data_size() { return MAX_PAYLOAD_SIZE; } +uint8_t fuzzer_proto_get_min_delay() { + return PROTOCOL_TIME_DELAY_MIN; +} + const char* fuzzer_proto_get_menu_label(uint8_t index) { return fuzzer_menu_items[index].menu_label; } diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.h b/applications/external/pacs_fuzzer/lib/worker/protocol.h index 4c2c70e0c..62ce88d5c 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.h @@ -37,6 +37,12 @@ struct FuzzerPayload { */ uint8_t fuzzer_proto_get_max_data_size(); +/** + * Get minimum time delay for protocols + * @return Minimum time delay + */ +uint8_t fuzzer_proto_get_min_delay(); + /** * Get protocol name based on its index * @param index protocol index diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h index 841784f16..793b3e043 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h @@ -4,8 +4,12 @@ #if defined(RFID_125_PROTOCOL) #define MAX_PAYLOAD_SIZE (6) +#define PROTOCOL_MIN_IDLE_DELAY (5) +#define PROTOCOL_TIME_DELAY_MIN PROTOCOL_MIN_IDLE_DELAY + 4 #else #define MAX_PAYLOAD_SIZE (8) +#define PROTOCOL_MIN_IDLE_DELAY (2) +#define PROTOCOL_TIME_DELAY_MIN PROTOCOL_MIN_IDLE_DELAY + 2 #endif typedef struct ProtoDict ProtoDict; diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index 13e2325fd..1df6d5eb3 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -15,6 +15,7 @@ struct FuzzerViewAttack { typedef struct { uint8_t time_delay; + uint8_t time_delay_min; const char* attack_name; const char* protocol_name; FuzzerAttackState attack_state; @@ -157,14 +158,14 @@ bool fuzzer_view_attack_input(InputEvent* event, void* context) { if(model->attack_state == FuzzerAttackStateIdle) { // TimeDelay if(event->type == InputTypeShort) { - if(model->time_delay > FUZZ_TIME_DELAY_MIN) { + if(model->time_delay > model->time_delay_min) { model->time_delay--; } } else if(event->type == InputTypeLong) { - if((model->time_delay - 10) >= FUZZ_TIME_DELAY_MIN) { + if((model->time_delay - 10) >= model->time_delay_min) { model->time_delay -= 10; } else { - model->time_delay = FUZZ_TIME_DELAY_MIN; + model->time_delay = model->time_delay_min; } } } else if( @@ -232,7 +233,8 @@ FuzzerViewAttack* fuzzer_view_attack_alloc() { view_attack->view, FuzzerViewAttackModel * model, { - model->time_delay = FUZZ_TIME_DELAY_MIN; + model->time_delay_min = fuzzer_proto_get_min_delay(); + model->time_delay = model->time_delay_min; model->uid_str = furi_string_alloc_set_str("Not_set"); // malloc(ATTACK_SCENE_MAX_UID_LENGTH + 1); model->attack_state = FuzzerAttackStateOff;