diff --git a/applications/plugins/subbrute/helpers/subbrute_worker.c b/applications/plugins/subbrute/helpers/subbrute_worker.c index 345539eb5..0188cfecc 100644 --- a/applications/plugins/subbrute/helpers/subbrute_worker.c +++ b/applications/plugins/subbrute/helpers/subbrute_worker.c @@ -225,11 +225,11 @@ bool subbrute_worker_transmit_current_key(SubBruteWorker* instance, uint64_t ste FlipperFormat* flipper_format = flipper_format_string_alloc(); Stream* stream = flipper_format_get_raw_stream(flipper_format); - FuriString* payload = NULL; stream_clean(stream); if(instance->attack == SubBruteAttackLoadFile) { - payload = subbrute_protocol_file_payload( + subbrute_protocol_file_payload( + stream, step, instance->bits, instance->te, @@ -237,25 +237,25 @@ bool subbrute_worker_transmit_current_key(SubBruteWorker* instance, uint64_t ste instance->load_index, instance->file_key); } else { - payload = subbrute_protocol_default_payload( - step, instance->bits, instance->te, instance->repeat); + subbrute_protocol_default_payload( + stream, step, instance->bits, instance->te, instance->repeat); } - size_t written = stream_write_string(stream, payload); - if(written <= 0) { - FURI_LOG_W(TAG, "Error creating packet! EXIT"); - result = false; - } else { - subbrute_worker_subghz_transmit(instance, flipper_format); + // size_t written = stream_write_string(stream, payload); + // if(written <= 0) { + // FURI_LOG_W(TAG, "Error creating packet! EXIT"); + // result = false; + // } else { + subbrute_worker_subghz_transmit(instance, flipper_format); - result = true; + result = true; #if FURI_DEBUG - FURI_LOG_D(TAG, "Manual transmit done"); + FURI_LOG_D(TAG, "Manual transmit done"); #endif - } + // } flipper_format_free(flipper_format); - furi_string_free(payload); +// furi_string_free(payload); return result; } @@ -353,11 +353,10 @@ int32_t subbrute_worker_thread(void* context) { Stream* stream = flipper_format_get_raw_stream(flipper_format); while(instance->worker_running) { - FuriString* payload = NULL; stream_clean(stream); - if(instance->attack == SubBruteAttackLoadFile) { - payload = subbrute_protocol_file_payload( + subbrute_protocol_file_payload( + stream, instance->step, instance->bits, instance->te, @@ -365,22 +364,22 @@ int32_t subbrute_worker_thread(void* context) { instance->load_index, instance->file_key); } else { - payload = subbrute_protocol_default_payload( - instance->step, instance->bits, instance->te, instance->repeat); + subbrute_protocol_default_payload( + stream, instance->step, instance->bits, instance->te, instance->repeat); } #ifdef FURI_DEBUG - FURI_LOG_I(TAG, "Payload: %s", furi_string_get_cstr(payload)); - furi_delay_ms(SUBBRUTE_MANUAL_TRANSMIT_INTERVAL / 4); + //FURI_LOG_I(TAG, "Payload: %s", furi_string_get_cstr(payload)); + //furi_delay_ms(SUBBRUTE_MANUAL_TRANSMIT_INTERVAL / 4); #endif - size_t written = stream_write_string(stream, payload); - if(written <= 0) { - FURI_LOG_W(TAG, "Error creating packet! BREAK"); - instance->worker_running = false; - local_state = SubBruteWorkerStateIDLE; - furi_string_free(payload); - break; - } + // size_t written = stream_write_stream_write_string(stream, payload); + // if(written <= 0) { + // FURI_LOG_W(TAG, "Error creating packet! BREAK"); + // instance->worker_running = false; + // local_state = SubBruteWorkerStateIDLE; + // furi_string_free(payload); + // break; + // } subbrute_worker_subghz_transmit(instance, flipper_format); @@ -389,12 +388,12 @@ int32_t subbrute_worker_thread(void* context) { FURI_LOG_I(TAG, "Worker finished to end"); #endif local_state = SubBruteWorkerStateFinished; - furi_string_free(payload); + // furi_string_free(payload); break; } instance->step++; - furi_string_free(payload); + // furi_string_free(payload); furi_delay_ms(SUBBRUTE_TX_TIMEOUT); } diff --git a/applications/plugins/subbrute/scenes/subbrute_scene_run_attack.c b/applications/plugins/subbrute/scenes/subbrute_scene_run_attack.c index 6e449e227..d6e4bad0b 100644 --- a/applications/plugins/subbrute/scenes/subbrute_scene_run_attack.c +++ b/applications/plugins/subbrute/scenes/subbrute_scene_run_attack.c @@ -46,9 +46,13 @@ void subbrute_scene_run_attack_on_enter(void* context) { instance->worker, subbrute_scene_run_attack_device_state_changed, instance); if(!subbrute_worker_is_running(instance->worker)) { + subbrute_worker_set_step(instance->worker, instance->device->key_index); if(!subbrute_worker_start(instance->worker)) { view_dispatcher_send_custom_event( instance->view_dispatcher, SubBruteCustomEventTypeError); + } else { + notification_message(instance->notifications, &sequence_single_vibro); + notification_message(instance->notifications, &sequence_blink_start_yellow); } } } @@ -60,11 +64,14 @@ bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { - subbrute_attack_view_set_current_step(view, subbrute_worker_get_step(instance->worker)); + uint64_t step = subbrute_worker_get_step(instance->worker); + instance->device->key_index = step; + subbrute_attack_view_set_current_step(view, step); if(event.event == SubBruteCustomEventTypeTransmitFinished) { notification_message(instance->notifications, &sequence_display_backlight_on); - notification_message(instance->notifications, &sequence_single_vibro); + notification_message(instance->notifications, &sequence_double_vibro); + scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack); } else if( @@ -84,7 +91,9 @@ bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event) } consumed = true; } else if(event.type == SceneManagerEventTypeTick) { - subbrute_attack_view_set_current_step(view, subbrute_worker_get_step(instance->worker)); + uint64_t step = subbrute_worker_get_step(instance->worker); + instance->device->key_index = step; + subbrute_attack_view_set_current_step(view, step); consumed = true; } diff --git a/applications/plugins/subbrute/subbrute_device.c b/applications/plugins/subbrute/subbrute_device.c index 8e94c4255..0b23e61e2 100644 --- a/applications/plugins/subbrute/subbrute_device.c +++ b/applications/plugins/subbrute/subbrute_device.c @@ -19,8 +19,11 @@ SubBruteDevice* subbrute_device_alloc() { instance->receiver = NULL; instance->environment = subghz_environment_alloc(); +#ifdef FURI_DEBUG + subbrute_device_attack_set_default_values(instance, SubBruteAttackLoadFile); +#else subbrute_device_attack_set_default_values(instance, SubBruteAttackCAME12bit433); - +#endif return instance; } @@ -61,7 +64,7 @@ uint64_t subbrute_device_add_step(SubBruteDevice* instance, int8_t step) { } else if(instance->key_index == 0) { instance->key_index = instance->max_value; } else { - uint64_t value = ((instance->key_index - step) + instance->max_value); + uint64_t value = ((instance->key_index + step) + instance->max_value); if(value == instance->max_value) { instance->key_index = value; } else { @@ -82,16 +85,15 @@ bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_na Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* file = flipper_format_file_alloc(storage); - FuriString* file_content = furi_string_alloc(); - bool result = false; do { if(!flipper_format_file_open_always(file, dev_file_name)) { break; } - + Stream* stream = flipper_format_get_raw_stream(file); if(instance->attack == SubBruteAttackLoadFile) { - file_content = subbrute_protocol_file_generate_file( + subbrute_protocol_file_generate_file( + stream, instance->file_protocol_info->frequency, instance->file_protocol_info->preset, instance->file_protocol_info->file, @@ -102,7 +104,8 @@ bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_na instance->load_index, instance->file_key); } else { - file_content = subbrute_protocol_default_generate_file( + subbrute_protocol_default_generate_file( + stream, instance->protocol_info->frequency, instance->protocol_info->preset, instance->protocol_info->file, @@ -112,14 +115,6 @@ bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_na instance->protocol_info->repeat); } - Stream* stream = flipper_format_get_raw_stream(file); - stream_clean(stream); - size_t written = stream_write_string(stream, file_content); - if(written <= 0) { - FURI_LOG_E(TAG, "create_packet_parsed failed!"); - break; - } - result = true; } while(false); @@ -130,7 +125,6 @@ bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_na flipper_format_file_close(file); flipper_format_free(file); furi_record_close(RECORD_STORAGE); - furi_string_free(file_content); return result; } @@ -342,7 +336,7 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, const char* fil //result = SubBruteFileResultMissingOrIncorrectTe; //break; } else { - instance->file_protocol_info->te = temp_data32 != 0; + instance->file_protocol_info->te = temp_data32 != 0 ? temp_data32 : 0; } // Repeat diff --git a/applications/plugins/subbrute/subbrute_protocols.c b/applications/plugins/subbrute/subbrute_protocols.c index 512152e61..c4ef1c662 100644 --- a/applications/plugins/subbrute/subbrute_protocols.c +++ b/applications/plugins/subbrute/subbrute_protocols.c @@ -1,4 +1,5 @@ #include "subbrute_protocols.h" +#include #define TAG "SubBruteProtocols" @@ -249,8 +250,12 @@ SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name) { return RAWFileProtocol; } -FuriString* - subbrute_protocol_default_payload(uint64_t step, uint8_t bits, uint8_t te, uint8_t repeat) { +void subbrute_protocol_default_payload( + Stream* stream, + uint64_t step, + uint8_t bits, + uint8_t te, + uint8_t repeat) { FuriString* candidate = furi_string_alloc_set_str(" "); FuriString* buffer = furi_string_alloc_printf("%16llX", step); @@ -270,25 +275,25 @@ FuriString* #ifdef FURI_DEBUG //FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step); #endif - FuriString* result; - + stream_clean(stream); if(te) { - result = furi_string_alloc_printf( - subbrute_key_small_with_tail, bits, furi_string_get_cstr(candidate), te, repeat); + stream_write_format( + stream, + subbrute_key_small_with_tail, + bits, + furi_string_get_cstr(candidate), + te, + repeat); } else { - result = furi_string_alloc_printf( - subbrute_key_small_no_tail, bits, furi_string_get_cstr(candidate), repeat); + stream_write_format( + stream, subbrute_key_small_no_tail, bits, furi_string_get_cstr(candidate), repeat); } -#ifdef FURI_DEBUG - //FURI_LOG_D(TAG, "result: %s", furi_string_get_cstr(result)); -#endif furi_string_free(candidate); - - return result; } -FuriString* subbrute_protocol_file_payload( +void subbrute_protocol_file_payload( + Stream* stream, uint64_t step, uint8_t bits, uint8_t te, @@ -296,9 +301,6 @@ FuriString* subbrute_protocol_file_payload( uint8_t load_index, const char* file_key) { FuriString* candidate = furi_string_alloc(); - if(step >= sizeof(file_key)) { - return false; - } char subbrute_payload_byte[4]; furi_string_set_str(candidate, file_key); snprintf(subbrute_payload_byte, 4, "%02X ", (uint8_t)step); @@ -307,26 +309,26 @@ FuriString* subbrute_protocol_file_payload( #ifdef FURI_DEBUG //FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step); #endif - FuriString* result; + stream_clean(stream); if(te) { - result = furi_string_alloc_printf( - subbrute_key_small_with_tail, bits, furi_string_get_cstr(candidate), te, repeat); + stream_write_format( + stream, + subbrute_key_small_with_tail, + bits, + furi_string_get_cstr(candidate), + te, + repeat); } else { - result = furi_string_alloc_printf( - subbrute_key_small_no_tail, bits, furi_string_get_cstr(candidate), repeat); + stream_write_format( + stream, subbrute_key_small_no_tail, bits, furi_string_get_cstr(candidate), repeat); } -#ifdef FURI_DEBUG - //FURI_LOG_D(TAG, "result: %s", furi_string_get_cstr(result)); -#endif - furi_string_free(candidate); - - return result; } -FuriString* subbrute_protocol_default_generate_file( +void subbrute_protocol_default_generate_file( + Stream* stream, uint32_t frequency, FuriHalSubGhzPreset preset, SubBruteFileProtocol file, @@ -353,10 +355,11 @@ FuriString* subbrute_protocol_default_generate_file( #ifdef FURI_DEBUG FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step); #endif - FuriString* result; + stream_clean(stream); if(te) { - result = furi_string_alloc_printf( + stream_write_format( + stream, subbrute_key_file_start_with_tail, frequency, preset, @@ -366,7 +369,8 @@ FuriString* subbrute_protocol_default_generate_file( te, repeat); } else { - result = furi_string_alloc_printf( + stream_write_format( + stream, subbrute_key_file_start_no_tail, frequency, preset, @@ -375,16 +379,12 @@ FuriString* subbrute_protocol_default_generate_file( furi_string_get_cstr(candidate), repeat); } -#ifdef FURI_DEBUG - FURI_LOG_D(TAG, "result: %s", furi_string_get_cstr(result)); -#endif furi_string_free(candidate); - - return result; } -FuriString* subbrute_protocol_file_generate_file( +void subbrute_protocol_file_generate_file( + Stream* stream, uint32_t frequency, FuriHalSubGhzPreset preset, SubBruteFileProtocol file, @@ -395,9 +395,6 @@ FuriString* subbrute_protocol_file_generate_file( uint8_t load_index, const char* file_key) { FuriString* candidate = furi_string_alloc(); - if(step >= sizeof(file_key)) { - return false; - } char subbrute_payload_byte[4]; furi_string_set_str(candidate, file_key); snprintf(subbrute_payload_byte, 4, "%02X ", (uint8_t)step); @@ -406,10 +403,10 @@ FuriString* subbrute_protocol_file_generate_file( #ifdef FURI_DEBUG FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step); #endif - FuriString* result; - + stream_clean(stream); if(te) { - result = furi_string_alloc_printf( + stream_write_format( + stream, subbrute_key_file_start_with_tail, frequency, preset, @@ -419,7 +416,8 @@ FuriString* subbrute_protocol_file_generate_file( te, repeat); } else { - result = furi_string_alloc_printf( + stream_write_format( + stream, subbrute_key_file_start_no_tail, frequency, preset, @@ -429,13 +427,7 @@ FuriString* subbrute_protocol_file_generate_file( repeat); } -#ifdef FURI_DEBUG - FURI_LOG_D(TAG, "result: %s", furi_string_get_cstr(result)); -#endif - furi_string_free(candidate); - - return result; } uint64_t subbrute_protocol_calc_max_value(SubBruteAttacks attack_type, uint8_t bits) { diff --git a/applications/plugins/subbrute/subbrute_protocols.h b/applications/plugins/subbrute/subbrute_protocols.h index 747328d5b..e0a97eef2 100644 --- a/applications/plugins/subbrute/subbrute_protocols.h +++ b/applications/plugins/subbrute/subbrute_protocols.h @@ -3,7 +3,7 @@ #include #include #include - +#include //typedef enum { // FrequencyProtocolField, // BitsProtocolField, @@ -56,16 +56,22 @@ FuriHalSubGhzPreset subbrute_protocol_convert_preset(FuriString* preset_name); SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name); const char* subbrute_protocol_name(SubBruteAttacks index); -FuriString* - subbrute_protocol_default_payload(uint64_t step, uint8_t bits, uint8_t te, uint8_t repeat); -FuriString* subbrute_protocol_file_payload( +void subbrute_protocol_default_payload( + Stream* stream, + uint64_t step, + uint8_t bits, + uint8_t te, + uint8_t repeat); +void subbrute_protocol_file_payload( + Stream* stream, uint64_t step, uint8_t bits, uint8_t te, uint8_t repeat, uint8_t load_index, const char* file_key); -FuriString* subbrute_protocol_default_generate_file( +void subbrute_protocol_default_generate_file( + Stream* stream, uint32_t frequency, FuriHalSubGhzPreset preset, SubBruteFileProtocol file, @@ -73,7 +79,8 @@ FuriString* subbrute_protocol_default_generate_file( uint8_t bits, uint8_t te, uint8_t repeat); -FuriString* subbrute_protocol_file_generate_file( +void subbrute_protocol_file_generate_file( + Stream* stream, uint32_t frequency, FuriHalSubGhzPreset preset, SubBruteFileProtocol file, diff --git a/applications/plugins/subbrute/views/subbrute_main_view.c b/applications/plugins/subbrute/views/subbrute_main_view.c index bfac24b8b..9d3486797 100644 --- a/applications/plugins/subbrute/views/subbrute_main_view.c +++ b/applications/plugins/subbrute/views/subbrute_main_view.c @@ -91,7 +91,7 @@ void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) { if(m->is_select_byte) { #ifdef FURI_DEBUG - FURI_LOG_D(TAG, "key_field: %s", m->key_field); + //FURI_LOG_D(TAG, "key_field: %s", m->key_field); #endif char msg_index[18]; snprintf(msg_index, sizeof(msg_index), "Field index : %d", m->index); @@ -118,7 +118,7 @@ void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) { const uint8_t item_height = 16; #ifdef FURI_DEBUG - FURI_LOG_D(TAG, "window_position: %d, index: %d", model->window_position, m->index); + //FURI_LOG_D(TAG, "window_position: %d, index: %d", model->window_position, m->index); #endif for(uint8_t position = 0; position < SubBruteAttackTotalCount; ++position) { uint8_t item_position = position - model->window_position;