From 02943dd1db46fdbb45e426de9eb23e320ed6ff78 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 4 Jul 2023 23:30:32 +0200 Subject: [PATCH] Update subbrute --- .../helpers/subbrute_worker.c | 32 +++++++-- .../helpers/subbrute_worker.h | 8 ++- .../helpers/subbrute_worker_private.h | 1 + .../scenes/subbrute_scene_config.h | 1 + .../scenes/subbrute_scene_setup_attack.c | 2 + .../scenes/subbrute_scene_setup_extra.c | 66 +++++++++++++++++++ .../external/subghz_bruteforcer/subbrute.c | 6 ++ .../subbrute_custom_event.h | 1 + .../external/subghz_bruteforcer/subbrute_i.h | 2 +- .../views/subbrute_attack_view.c | 5 +- .../views/subbrute_main_view.c | 11 +++- 11 files changed, 124 insertions(+), 11 deletions(-) create mode 100644 applications/external/subghz_bruteforcer/scenes/subbrute_scene_setup_extra.c diff --git a/applications/external/subghz_bruteforcer/helpers/subbrute_worker.c b/applications/external/subghz_bruteforcer/helpers/subbrute_worker.c index 72f9f57b9..ef622482f 100644 --- a/applications/external/subghz_bruteforcer/helpers/subbrute_worker.c +++ b/applications/external/subghz_bruteforcer/helpers/subbrute_worker.c @@ -28,6 +28,7 @@ SubBruteWorker* subbrute_worker_alloc() { instance->context = NULL; instance->callback = NULL; + instance->tx_timeout_ms = SUBBRUTE_TX_TIMEOUT; instance->decoder_result = NULL; instance->transmitter = NULL; instance->environment = subghz_environment_alloc(); @@ -206,6 +207,7 @@ void subbrute_worker_stop(SubBruteWorker* instance) { furi_thread_join(instance->thread); furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate); + furi_hal_subghz_idle(); furi_hal_subghz_sleep(); } @@ -306,8 +308,9 @@ void subbrute_worker_set_callback( } void subbrute_worker_subghz_transmit(SubBruteWorker* instance, FlipperFormat* flipper_format) { + const uint8_t timeout = instance->tx_timeout_ms; while(instance->transmit_mode) { - furi_delay_ms(SUBBRUTE_TX_TIMEOUT); + furi_delay_ms(timeout); } instance->transmit_mode = true; if(instance->transmitter != NULL) { @@ -318,17 +321,20 @@ void subbrute_worker_subghz_transmit(SubBruteWorker* instance, FlipperFormat* fl subghz_transmitter_alloc_init(instance->environment, instance->protocol_name); subghz_transmitter_deserialize(instance->transmitter, flipper_format); furi_hal_subghz_reset(); + furi_hal_subghz_idle(); furi_hal_subghz_load_preset(instance->preset); furi_hal_subghz_set_frequency_and_path(instance->frequency); furi_hal_subghz_start_async_tx(subghz_transmitter_yield, instance->transmitter); while(!furi_hal_subghz_is_async_tx_complete()) { - furi_delay_ms(SUBBRUTE_TX_TIMEOUT); + furi_delay_ms(timeout); } furi_hal_subghz_stop_async_tx(); - furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate); - furi_hal_subghz_sleep(); + //furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate); + furi_hal_subghz_idle(); + //furi_hal_subghz_sleep(); + subghz_transmitter_stop(instance->transmitter); subghz_transmitter_free(instance->transmitter); instance->transmitter = NULL; @@ -420,7 +426,7 @@ int32_t subbrute_worker_thread(void* context) { instance->step++; // furi_string_free(payload); - furi_delay_ms(SUBBRUTE_TX_TIMEOUT); + furi_delay_ms(instance->tx_timeout_ms); } flipper_format_free(flipper_format); @@ -435,3 +441,19 @@ int32_t subbrute_worker_thread(void* context) { #endif return 0; } + +uint8_t subbrute_worker_get_timeout(SubBruteWorker* instance) { + return instance->tx_timeout_ms; +} + +void subbrute_worker_timeout_inc(SubBruteWorker* instance) { + if(instance->tx_timeout_ms < 255) { + instance->tx_timeout_ms++; + } +} + +void subbrute_worker_timeout_dec(SubBruteWorker* instance) { + if(instance->tx_timeout_ms > 0) { + instance->tx_timeout_ms--; + } +} \ No newline at end of file diff --git a/applications/external/subghz_bruteforcer/helpers/subbrute_worker.h b/applications/external/subghz_bruteforcer/helpers/subbrute_worker.h index 4046f997c..f7c32dd4b 100644 --- a/applications/external/subghz_bruteforcer/helpers/subbrute_worker.h +++ b/applications/external/subghz_bruteforcer/helpers/subbrute_worker.h @@ -39,4 +39,10 @@ bool subbrute_worker_can_manual_transmit(SubBruteWorker* instance); void subbrute_worker_set_callback( SubBruteWorker* instance, SubBruteWorkerCallback callback, - void* context); \ No newline at end of file + void* context); + +uint8_t subbrute_worker_get_timeout(SubBruteWorker* instance); + +void subbrute_worker_timeout_inc(SubBruteWorker* instance); + +void subbrute_worker_timeout_dec(SubBruteWorker* instance); diff --git a/applications/external/subghz_bruteforcer/helpers/subbrute_worker_private.h b/applications/external/subghz_bruteforcer/helpers/subbrute_worker_private.h index e38e77dc4..a660ca731 100644 --- a/applications/external/subghz_bruteforcer/helpers/subbrute_worker_private.h +++ b/applications/external/subghz_bruteforcer/helpers/subbrute_worker_private.h @@ -21,6 +21,7 @@ struct SubBruteWorker { SubGhzEnvironment* environment; SubGhzTransmitter* transmitter; const char* protocol_name; + uint8_t tx_timeout_ms; // Initiated values SubBruteAttacks attack; // Attack state diff --git a/applications/external/subghz_bruteforcer/scenes/subbrute_scene_config.h b/applications/external/subghz_bruteforcer/scenes/subbrute_scene_config.h index 3541df9ac..3c7a3bfda 100644 --- a/applications/external/subghz_bruteforcer/scenes/subbrute_scene_config.h +++ b/applications/external/subghz_bruteforcer/scenes/subbrute_scene_config.h @@ -4,4 +4,5 @@ ADD_SCENE(subbrute, run_attack, RunAttack) ADD_SCENE(subbrute, save_name, SaveName) ADD_SCENE(subbrute, save_success, SaveSuccess) ADD_SCENE(subbrute, setup_attack, SetupAttack) +ADD_SCENE(subbrute, setup_extra, SetupExtra) ADD_SCENE(subbrute, start, Start) \ No newline at end of file diff --git a/applications/external/subghz_bruteforcer/scenes/subbrute_scene_setup_attack.c b/applications/external/subghz_bruteforcer/scenes/subbrute_scene_setup_attack.c index c2877c7cb..5aa5e840a 100644 --- a/applications/external/subghz_bruteforcer/scenes/subbrute_scene_setup_attack.c +++ b/applications/external/subghz_bruteforcer/scenes/subbrute_scene_setup_attack.c @@ -81,6 +81,8 @@ bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event false, instance->device->extra_repeats); scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveName); + } else if(event.event == SubBruteCustomEventTypeExtraSettings) { + scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupExtra); } else if(event.event == SubBruteCustomEventTypeBackPressed) { subbrute_attack_view_init_values( view, diff --git a/applications/external/subghz_bruteforcer/scenes/subbrute_scene_setup_extra.c b/applications/external/subghz_bruteforcer/scenes/subbrute_scene_setup_extra.c new file mode 100644 index 000000000..c798e055b --- /dev/null +++ b/applications/external/subghz_bruteforcer/scenes/subbrute_scene_setup_extra.c @@ -0,0 +1,66 @@ +#include "../subbrute_i.h" +#include "subbrute_scene.h" + +#define TAG "SubBruteSceneLoadFile" + +void setup_extra_widget_callback(GuiButtonType result, InputType type, void* context); + +static void setup_extra_widget_draw(void* context) { + furi_assert(context); + SubBruteState* instance = context; + + Widget* widget = instance->widget; + + widget_add_button_element( + widget, GuiButtonTypeLeft, "-TD", setup_extra_widget_callback, instance); + widget_add_button_element( + widget, GuiButtonTypeRight, "TD+", setup_extra_widget_callback, instance); + + char str[20]; + snprintf(&str[0], 20, "%d", subbrute_worker_get_timeout(instance->worker)); + + widget_add_string_element( + instance->widget, 64, 15, AlignCenter, AlignCenter, FontPrimary, "Time Delay"); + + widget_add_string_element( + instance->widget, 64, 32, AlignCenter, AlignCenter, FontBigNumbers, &str[0]); +} + +void setup_extra_widget_callback(GuiButtonType result, InputType type, void* context) { + furi_assert(context); + SubBruteState* instance = context; + + if((result == GuiButtonTypeLeft) && ((type == InputTypeShort) || (type == InputTypeRepeat))) { + widget_reset(instance->widget); + subbrute_worker_timeout_dec(instance->worker); + setup_extra_widget_draw(instance); + } else if( + (result == GuiButtonTypeRight) && + ((type == InputTypeShort) || (type == InputTypeRepeat))) { + widget_reset(instance->widget); + subbrute_worker_timeout_inc(instance->worker); + setup_extra_widget_draw(instance); + } +} + +void subbrute_scene_setup_extra_on_enter(void* context) { + furi_assert(context); + SubBruteState* instance = context; + + setup_extra_widget_draw(instance); + + view_dispatcher_switch_to_view(instance->view_dispatcher, SubBruteViewWidget); +} + +void subbrute_scene_setup_extra_on_exit(void* context) { + furi_assert(context); + SubBruteState* instance = context; + + widget_reset(instance->widget); +} + +bool subbrute_scene_setup_extra_on_event(void* context, SceneManagerEvent event) { + UNUSED(context); + UNUSED(event); + return false; +} \ No newline at end of file diff --git a/applications/external/subghz_bruteforcer/subbrute.c b/applications/external/subghz_bruteforcer/subbrute.c index dbe83a5c4..f47c75943 100644 --- a/applications/external/subghz_bruteforcer/subbrute.c +++ b/applications/external/subghz_bruteforcer/subbrute.c @@ -94,12 +94,18 @@ SubBruteState* subbrute_alloc() { //instance->flipper_format = flipper_format_string_alloc(); //instance->environment = subghz_environment_alloc(); + // Uncomment to enable Debug pin output on PIN 17(1W) + //furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton); + return instance; } void subbrute_free(SubBruteState* instance) { furi_assert(instance); + // Uncomment to enable Debug pin output on PIN 17(1W) + //furi_hal_subghz_set_async_mirror_pin(NULL); + // SubBruteWorker subbrute_worker_stop(instance->worker); subbrute_worker_free(instance->worker); diff --git a/applications/external/subghz_bruteforcer/subbrute_custom_event.h b/applications/external/subghz_bruteforcer/subbrute_custom_event.h index 2864f8934..4e0c1214d 100644 --- a/applications/external/subghz_bruteforcer/subbrute_custom_event.h +++ b/applications/external/subghz_bruteforcer/subbrute_custom_event.h @@ -12,6 +12,7 @@ typedef enum { SubBruteCustomEventTypeTransmitNotStarted, SubBruteCustomEventTypeTransmitCustom, SubBruteCustomEventTypeSaveFile, + SubBruteCustomEventTypeExtraSettings, SubBruteCustomEventTypeUpdateView, SubBruteCustomEventTypeChangeStepUp, SubBruteCustomEventTypeChangeStepDown, diff --git a/applications/external/subghz_bruteforcer/subbrute_i.h b/applications/external/subghz_bruteforcer/subbrute_i.h index 4ec8f6cd3..9f1bd57d4 100644 --- a/applications/external/subghz_bruteforcer/subbrute_i.h +++ b/applications/external/subghz_bruteforcer/subbrute_i.h @@ -29,7 +29,7 @@ #include "views/subbrute_attack_view.h" #include "views/subbrute_main_view.h" -#define SUBBRUTEFORCER_VER "Sub-GHz BruteForcer 3.5" +#define SUBBRUTEFORCER_VER "Sub-GHz BruteForcer 3.6" #ifdef FURI_DEBUG //#define SUBBRUTE_FAST_TRACK false diff --git a/applications/external/subghz_bruteforcer/views/subbrute_attack_view.c b/applications/external/subghz_bruteforcer/views/subbrute_attack_view.c index d7770bb44..c05fb8084 100644 --- a/applications/external/subghz_bruteforcer/views/subbrute_attack_view.c +++ b/applications/external/subghz_bruteforcer/views/subbrute_attack_view.c @@ -72,9 +72,12 @@ bool subbrute_attack_view_input(InputEvent* event, void* context) { instance->is_attacking = true; instance->callback(SubBruteCustomEventTypeTransmitStarted, instance->context); update = true; - } else if(event->key == InputKeyUp) { + } else if(event->key == InputKeyUp && event->type == InputTypeShort) { instance->callback(SubBruteCustomEventTypeSaveFile, instance->context); update = true; + } else if(event->key == InputKeyUp && event->type == InputTypeLong) { + instance->callback(SubBruteCustomEventTypeExtraSettings, instance->context); + update = true; } else if(event->key == InputKeyDown) { instance->callback(SubBruteCustomEventTypeTransmitCustom, instance->context); update = true; diff --git a/applications/external/subghz_bruteforcer/views/subbrute_main_view.c b/applications/external/subghz_bruteforcer/views/subbrute_main_view.c index c21f2ea33..925188db1 100644 --- a/applications/external/subghz_bruteforcer/views/subbrute_main_view.c +++ b/applications/external/subghz_bruteforcer/views/subbrute_main_view.c @@ -167,7 +167,7 @@ void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) { if(model->index == position) { canvas_draw_str_aligned( canvas, - 4, + 3, 9 + (item_position * item_height) + STATUS_BAR_Y_SHIFT, AlignLeft, AlignCenter, @@ -181,9 +181,14 @@ void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) { sizeof(buffer), "x%d", model->extra_repeats + subbrute_protocol_repeats_count(model->index)); + uint8_t temp_x_offset_repeats = 18; + if(model->extra_repeats + subbrute_protocol_repeats_count(model->index) < + 10) { + temp_x_offset_repeats = 15; + } canvas_draw_str_aligned( canvas, - screen_width - 15, + screen_width - temp_x_offset_repeats, 9 + (item_position * item_height) + STATUS_BAR_Y_SHIFT, AlignLeft, AlignCenter, @@ -232,7 +237,7 @@ bool subbrute_main_view_input(InputEvent* event, void* context) { #endif const uint8_t min_value = 0; const uint8_t correct_total = SubBruteAttackTotalCount - 1; - uint8_t max_repeats = 9 - subbrute_protocol_repeats_count(instance->index); + uint8_t max_repeats = 14 - subbrute_protocol_repeats_count(instance->index); bool updated = false; bool consumed = false;