|
@@ -1,64 +1,45 @@
|
|
|
#include "subbrute_device.h"
|
|
#include "subbrute_device.h"
|
|
|
-#include "subbrute_i.h"
|
|
|
|
|
-
|
|
|
|
|
-#include <furi.h>
|
|
|
|
|
-#include <furi_hal.h>
|
|
|
|
|
-#include <furi_hal_subghz.h>
|
|
|
|
|
|
|
|
|
|
|
|
+#include <lib/toolbox/stream/stream.h>
|
|
|
#include <stdint.h>
|
|
#include <stdint.h>
|
|
|
-#include <stdbool.h>
|
|
|
|
|
-
|
|
|
|
|
-#include <lib/subghz/types.h>
|
|
|
|
|
-#include <lib/subghz/protocols/base.h>
|
|
|
|
|
-
|
|
|
|
|
-#include <storage/storage.h>
|
|
|
|
|
-#include <dialogs/dialogs.h>
|
|
|
|
|
-#include <stream/stream.h>
|
|
|
|
|
#include <stream/buffered_file_stream.h>
|
|
#include <stream/buffered_file_stream.h>
|
|
|
-#include <lib/toolbox/path.h>
|
|
|
|
|
#include <lib/flipper_format/flipper_format_i.h>
|
|
#include <lib/flipper_format/flipper_format_i.h>
|
|
|
|
|
|
|
|
#define TAG "SubBruteDevice"
|
|
#define TAG "SubBruteDevice"
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * List of protocols
|
|
|
|
|
- */
|
|
|
|
|
-static const char* protocol_came = "CAME";
|
|
|
|
|
-static const char* protocol_cham_code = "Cham_Code";
|
|
|
|
|
-static const char* protocol_linear = "Linear";
|
|
|
|
|
-static const char* protocol_nice_flo = "Nice FLO";
|
|
|
|
|
-static const char* protocol_princeton = "Princeton";
|
|
|
|
|
-static const char* protocol_raw = "RAW";
|
|
|
|
|
|
|
+#define SUBBRUTE_TX_TIMEOUT 5
|
|
|
|
|
+#define SUBBRUTE_MANUAL_TRANSMIT_INTERVAL 400
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Values to not use less memory for packet parse operations
|
|
* Values to not use less memory for packet parse operations
|
|
|
*/
|
|
*/
|
|
|
static const char* subbrute_key_file_start =
|
|
static const char* subbrute_key_file_start =
|
|
|
"Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d";
|
|
"Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d";
|
|
|
-static const char* subbrute_key_file_key = "%s\nKey: %s\n";
|
|
|
|
|
-static const char* subbrute_key_file_princeton_end = "%s\nKey: %s\nTE: %d\n";
|
|
|
|
|
-static const char* subbrute_key_small_no_tail = "Bit: %d\nKey: %s\n";
|
|
|
|
|
-static const char* subbrute_key_small_with_tail = "Bit: %d\nKey: %s\nTE: %d\n";
|
|
|
|
|
-
|
|
|
|
|
-// Why nobody set in as const in all codebase?
|
|
|
|
|
-static const char* preset_ook270_async = "FuriHalSubGhzPresetOok270Async";
|
|
|
|
|
-static const char* preset_ook650_async = "FuriHalSubGhzPresetOok650Async";
|
|
|
|
|
-static const char* preset_2fsk_dev238_async = "FuriHalSubGhzPreset2FSKDev238Async";
|
|
|
|
|
-static const char* preset_2fsk_dev476_async = "FuriHalSubGhzPreset2FSKDev476Async";
|
|
|
|
|
-static const char* preset_msk99_97_kb_async = "FuriHalSubGhzPresetMSK99_97KbAsync";
|
|
|
|
|
-static const char* preset_gfs99_97_kb_async = "FuriHalSubGhzPresetGFS99_97KbAsync";
|
|
|
|
|
|
|
+static const char* subbrute_key_file_key = "%s\nKey: %s\nRepeat: %d\n";
|
|
|
|
|
+static const char* subbrute_key_file_key_with_tail = "%s\nKey: %s\nTE: %d\nRepeat: %d\n";
|
|
|
|
|
+static const char* subbrute_key_small_no_tail = "Bit: %d\nKey: %s\nRepeat: %d\nRepeat: %d\n";
|
|
|
|
|
+static const char* subbrute_key_small_with_tail = "Bit: %d\nKey: %s\nTE: %d\nRepeat: %d\n";
|
|
|
|
|
|
|
|
SubBruteDevice* subbrute_device_alloc() {
|
|
SubBruteDevice* subbrute_device_alloc() {
|
|
|
SubBruteDevice* instance = malloc(sizeof(SubBruteDevice));
|
|
SubBruteDevice* instance = malloc(sizeof(SubBruteDevice));
|
|
|
|
|
|
|
|
instance->state = SubBruteDeviceStateIDLE;
|
|
instance->state = SubBruteDeviceStateIDLE;
|
|
|
instance->key_index = 0;
|
|
instance->key_index = 0;
|
|
|
|
|
+ instance->worker_running = false;
|
|
|
|
|
+ instance->last_time_tx_data = 0;
|
|
|
|
|
+
|
|
|
|
|
+ instance->thread = furi_thread_alloc();
|
|
|
|
|
+ furi_thread_set_name(instance->thread, "SubBruteAttackWorker");
|
|
|
|
|
+ furi_thread_set_stack_size(instance->thread, 2048);
|
|
|
|
|
+ furi_thread_set_context(instance->thread, instance);
|
|
|
|
|
+ furi_thread_set_callback(instance->thread, subbrute_worker_thread);
|
|
|
|
|
|
|
|
- string_init(instance->load_path);
|
|
|
|
|
- string_init(instance->preset_name);
|
|
|
|
|
- string_init(instance->protocol_name);
|
|
|
|
|
|
|
+ instance->context = NULL;
|
|
|
|
|
+ instance->callback = NULL;
|
|
|
|
|
|
|
|
|
|
+ instance->protocol_info = NULL;
|
|
|
instance->decoder_result = NULL;
|
|
instance->decoder_result = NULL;
|
|
|
|
|
+ instance->transmitter = NULL;
|
|
|
instance->receiver = NULL;
|
|
instance->receiver = NULL;
|
|
|
instance->environment = subghz_environment_alloc();
|
|
instance->environment = subghz_environment_alloc();
|
|
|
|
|
|
|
@@ -84,6 +65,11 @@ void subbrute_device_free(SubBruteDevice* instance) {
|
|
|
instance->receiver = NULL;
|
|
instance->receiver = NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if(instance->transmitter != NULL) {
|
|
|
|
|
+ subghz_transmitter_free(instance->transmitter);
|
|
|
|
|
+ instance->transmitter = NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
subghz_environment_free(instance->environment);
|
|
subghz_environment_free(instance->environment);
|
|
|
instance->environment = NULL;
|
|
instance->environment = NULL;
|
|
|
|
|
|
|
@@ -91,109 +77,280 @@ void subbrute_device_free(SubBruteDevice* instance) {
|
|
|
FURI_LOG_D(TAG, "before free");
|
|
FURI_LOG_D(TAG, "before free");
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- string_clear(instance->load_path);
|
|
|
|
|
- string_clear(instance->preset_name);
|
|
|
|
|
- string_clear(instance->protocol_name);
|
|
|
|
|
|
|
+ furi_thread_free(instance->thread);
|
|
|
|
|
+ subbrute_device_free_protocol_info(instance);
|
|
|
|
|
|
|
|
free(instance);
|
|
free(instance);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_name) {
|
|
|
|
|
- furi_assert(instance);
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Entrypoint for worker
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param context SubBruteWorker*
|
|
|
|
|
+ * @return 0 if ok
|
|
|
|
|
+ */
|
|
|
|
|
+int32_t subbrute_worker_thread(void* context) {
|
|
|
|
|
+ furi_assert(context);
|
|
|
|
|
+ SubBruteDevice* instance = (SubBruteDevice*)context;
|
|
|
|
|
|
|
|
|
|
+ if(!instance->worker_running) {
|
|
|
|
|
+ FURI_LOG_W(TAG, "Worker is not set to running state!");
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(instance->state != SubBruteDeviceStateReady &&
|
|
|
|
|
+ instance->state != SubBruteDeviceStateFinished) {
|
|
|
|
|
+ FURI_LOG_W(TAG, "Invalid state for running worker! State: %d", instance->state);
|
|
|
|
|
+ return -2;
|
|
|
|
|
+ }
|
|
|
#ifdef FURI_DEBUG
|
|
#ifdef FURI_DEBUG
|
|
|
- FURI_LOG_D(TAG, "subbrute_device_save_file: %s", dev_file_name);
|
|
|
|
|
|
|
+ FURI_LOG_I(TAG, "Worker start");
|
|
|
#endif
|
|
#endif
|
|
|
- bool result = subbrute_device_create_packet_parsed(instance, instance->key_index, false);
|
|
|
|
|
|
|
|
|
|
- if(!result) {
|
|
|
|
|
- FURI_LOG_E(TAG, "subbrute_device_create_packet_parsed failed!");
|
|
|
|
|
- //subbrute_device_notification_message(instance, &sequence_error);
|
|
|
|
|
|
|
+ SubBruteDeviceState local_state = instance->state = SubBruteDeviceStateTx;
|
|
|
|
|
+ subbrute_device_send_callback(instance);
|
|
|
|
|
+
|
|
|
|
|
+ FlipperFormat* flipper_format = flipper_format_string_alloc();
|
|
|
|
|
+
|
|
|
|
|
+ while(instance->worker_running) {
|
|
|
|
|
+ if(!subbrute_device_create_packet_parsed(
|
|
|
|
|
+ instance, flipper_format, instance->key_index, true)) {
|
|
|
|
|
+ FURI_LOG_W(TAG, "Error creating packet! BREAK");
|
|
|
|
|
+ instance->worker_running = false;
|
|
|
|
|
+ local_state = SubBruteDeviceStateIDLE;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ subbrute_device_subghz_transmit(instance, flipper_format);
|
|
|
|
|
+
|
|
|
|
|
+ if(instance->key_index + 1 > instance->max_value) {
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_I(TAG, "Worker finished to end");
|
|
|
|
|
+#endif
|
|
|
|
|
+ local_state = SubBruteDeviceStateFinished;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ instance->key_index++;
|
|
|
|
|
+
|
|
|
|
|
+ furi_delay_ms(SUBBRUTE_TX_TIMEOUT);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ flipper_format_free(flipper_format);
|
|
|
|
|
+
|
|
|
|
|
+ instance->worker_running = false; // Because we have error states
|
|
|
|
|
+ instance->state = local_state == SubBruteDeviceStateTx ? SubBruteDeviceStateReady :
|
|
|
|
|
+ local_state;
|
|
|
|
|
+ subbrute_device_send_callback(instance);
|
|
|
|
|
+
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_I(TAG, "Worker stop");
|
|
|
|
|
+#endif
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool subbrute_worker_start(SubBruteDevice* instance) {
|
|
|
|
|
+ furi_assert(instance);
|
|
|
|
|
+
|
|
|
|
|
+ if(instance->worker_running) {
|
|
|
|
|
+ FURI_LOG_W(TAG, "Worker is already running!");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(instance->state != SubBruteDeviceStateReady &&
|
|
|
|
|
+ instance->state != SubBruteDeviceStateFinished) {
|
|
|
|
|
+ FURI_LOG_W(TAG, "Worker cannot start, invalid device state: %d", instance->state);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(instance->protocol_info == NULL) {
|
|
|
|
|
+ FURI_LOG_W(TAG, "Worker cannot start, protocol_info is NULL!");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ instance->worker_running = true;
|
|
|
|
|
+ furi_thread_start(instance->thread);
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void subbrute_worker_stop(SubBruteDevice* instance) {
|
|
|
|
|
+ furi_assert(instance);
|
|
|
|
|
+
|
|
|
|
|
+ instance->worker_running = false;
|
|
|
|
|
+
|
|
|
|
|
+ furi_thread_join(instance->thread);
|
|
|
|
|
+
|
|
|
|
|
+ furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
|
|
|
|
+ furi_hal_subghz_sleep();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+SubBruteAttacks subbrute_device_get_attack(SubBruteDevice* instance) {
|
|
|
|
|
+ return instance->attack;
|
|
|
|
|
+}
|
|
|
|
|
+bool subbrute_device_is_worker_running(SubBruteDevice* instance) {
|
|
|
|
|
+ return instance->worker_running;
|
|
|
|
|
+}
|
|
|
|
|
+uint64_t subbrute_device_get_step(SubBruteDevice* instance) {
|
|
|
|
|
+ return instance->key_index;
|
|
|
|
|
+}
|
|
|
|
|
+const char* subbrute_device_get_file_key(SubBruteDevice* instance) {
|
|
|
|
|
+ return instance->file_key;
|
|
|
|
|
+}
|
|
|
|
|
+uint64_t subbrute_device_add_step(SubBruteDevice* instance, int8_t step) {
|
|
|
|
|
+ if(!subbrute_device_can_manual_transmit(instance)) {
|
|
|
|
|
+ return instance->key_index;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(step > 0) {
|
|
|
|
|
+ if((instance->key_index + step) - instance->max_value == 1) {
|
|
|
|
|
+ instance->key_index = 0x00;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uint64_t value = instance->key_index + step;
|
|
|
|
|
+ if(value == instance->max_value) {
|
|
|
|
|
+ instance->key_index = value;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ instance->key_index = value % instance->max_value;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if(instance->key_index + step == 0) {
|
|
|
|
|
+ instance->key_index = 0x00;
|
|
|
|
|
+ } else if(instance->key_index == 0) {
|
|
|
|
|
+ instance->key_index = instance->max_value;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uint64_t value = ((instance->key_index - step) + instance->max_value);
|
|
|
|
|
+ if(value == instance->max_value) {
|
|
|
|
|
+ instance->key_index = value;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ instance->key_index = value % instance->max_value;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return instance->key_index;
|
|
|
|
|
+}
|
|
|
|
|
+void subbrute_device_set_load_index(SubBruteDevice* instance, uint64_t load_index) {
|
|
|
|
|
+ instance->load_index = load_index;
|
|
|
|
|
+}
|
|
|
|
|
+void subbrute_device_reset_step(SubBruteDevice* instance) {
|
|
|
|
|
+ instance->key_index = 0x00;
|
|
|
|
|
+}
|
|
|
|
|
+void subbrute_device_subghz_transmit(SubBruteDevice* instance, FlipperFormat* flipper_format) {
|
|
|
|
|
+ instance->transmitter = subghz_transmitter_alloc_init(
|
|
|
|
|
+ instance->environment, subbrute_protocol_name(instance->attack));
|
|
|
|
|
+ subghz_transmitter_deserialize(instance->transmitter, flipper_format);
|
|
|
|
|
+ furi_hal_subghz_reset();
|
|
|
|
|
+ furi_hal_subghz_load_preset(instance->protocol_info->preset);
|
|
|
|
|
+ furi_hal_subghz_set_frequency_and_path(instance->protocol_info->preset);
|
|
|
|
|
+
|
|
|
|
|
+ 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_hal_subghz_stop_async_tx();
|
|
|
|
|
+
|
|
|
|
|
+ furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
|
|
|
|
+ furi_hal_subghz_sleep();
|
|
|
|
|
+ subghz_transmitter_free(instance->transmitter);
|
|
|
|
|
+ instance->transmitter = NULL;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool subbrute_device_transmit_current_key(SubBruteDevice* instance) {
|
|
|
|
|
+ furi_assert(instance);
|
|
|
|
|
+
|
|
|
|
|
+ if(instance->worker_running) {
|
|
|
|
|
+ FURI_LOG_W(TAG, "Worker in running state!");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(instance->state != SubBruteDeviceStateReady &&
|
|
|
|
|
+ instance->state != SubBruteDeviceStateFinished) {
|
|
|
|
|
+ FURI_LOG_W(TAG, "Invalid state for running worker! State: %d", instance->state);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ uint32_t ticks = furi_get_tick();
|
|
|
|
|
+ if((ticks - instance->last_time_tx_data) < SUBBRUTE_MANUAL_TRANSMIT_INTERVAL) {
|
|
|
|
|
+#if FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "Need to wait, current: %d", ticks - instance->last_time_tx_data);
|
|
|
|
|
+#endif
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ instance->last_time_tx_data = ticks;
|
|
|
|
|
+ FlipperFormat* flipper_format = flipper_format_string_alloc();
|
|
|
|
|
+
|
|
|
|
|
+ if(!subbrute_device_create_packet_parsed(instance, flipper_format, instance->key_index, true)) {
|
|
|
|
|
+ FURI_LOG_W(TAG, "Error creating packet! EXIT");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ subbrute_device_subghz_transmit(instance, flipper_format);
|
|
|
|
|
+
|
|
|
|
|
+ flipper_format_free(flipper_format);
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void subbrute_device_set_callback(
|
|
|
|
|
+ SubBruteDevice* instance,
|
|
|
|
|
+ SubBruteDeviceWorkerCallback callback,
|
|
|
|
|
+ void* context) {
|
|
|
|
|
+ furi_assert(instance);
|
|
|
|
|
+
|
|
|
|
|
+ instance->callback = callback;
|
|
|
|
|
+ instance->context = context;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool subbrute_device_can_manual_transmit(SubBruteDevice* instance) {
|
|
|
|
|
+ furi_assert(instance);
|
|
|
|
|
+
|
|
|
|
|
+ return !instance->worker_running && instance->state != SubBruteDeviceStateIDLE &&
|
|
|
|
|
+ instance->state != SubBruteDeviceStateTx &&
|
|
|
|
|
+ ((furi_get_tick() - instance->last_time_tx_data) > SUBBRUTE_MANUAL_TRANSMIT_INTERVAL);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_name) {
|
|
|
|
|
+ furi_assert(instance);
|
|
|
|
|
+
|
|
|
|
|
+ if(instance->state != SubBruteDeviceStateReady &&
|
|
|
|
|
+ instance->state != SubBruteDeviceStateFinished) {
|
|
|
|
|
+ FURI_LOG_W(TAG, "Worker is not set to running state!");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "subbrute_device_save_file: %s", dev_file_name);
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
- Stream* stream = buffered_file_stream_alloc(storage);
|
|
|
|
|
|
|
+ FlipperFormat* file = flipper_format_file_alloc(storage);
|
|
|
|
|
|
|
|
- result = false;
|
|
|
|
|
|
|
+ bool result = false;
|
|
|
do {
|
|
do {
|
|
|
- if(!buffered_file_stream_open(stream, dev_file_name, FSAM_READ_WRITE, FSOM_OPEN_ALWAYS)) {
|
|
|
|
|
- buffered_file_stream_close(stream);
|
|
|
|
|
|
|
+ if(!flipper_format_file_open_always(file, dev_file_name)) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!subbrute_device_create_packet_parsed(instance, file, instance->key_index, false)) {
|
|
|
|
|
+ FURI_LOG_E(TAG, "subbrute_device_create_packet_parsed failed!");
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- stream_write_cstring(stream, instance->payload);
|
|
|
|
|
|
|
|
|
|
result = true;
|
|
result = true;
|
|
|
} while(false);
|
|
} while(false);
|
|
|
|
|
|
|
|
- buffered_file_stream_close(stream);
|
|
|
|
|
- stream_free(stream);
|
|
|
|
|
if(!result) {
|
|
if(!result) {
|
|
|
- FURI_LOG_E(TAG, "stream_write_string failed!");
|
|
|
|
|
- //subbrute_device_notification_message(instance, &sequence_error);
|
|
|
|
|
|
|
+ FURI_LOG_E(TAG, "flipper_format_file_open_always failed!");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ flipper_format_free(file);
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
|
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const char* subbrute_device_error_get_desc(SubBruteFileResult error_id) {
|
|
|
|
|
- const char* result;
|
|
|
|
|
- switch(error_id) {
|
|
|
|
|
- case(SubBruteFileResultOk):
|
|
|
|
|
- result = "OK";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultErrorOpenFile):
|
|
|
|
|
- result = "invalid name/path";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultMissingOrIncorrectHeader):
|
|
|
|
|
- result = "Missing or incorrect header";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultFrequencyNotAllowed):
|
|
|
|
|
- result = "Invalid frequency!";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultMissingOrIncorrectFrequency):
|
|
|
|
|
- result = "Missing or incorrect Frequency";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultPresetInvalid):
|
|
|
|
|
- result = "Preset FAIL";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultMissingProtocol):
|
|
|
|
|
- result = "Missing Protocol";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultProtocolNotSupported):
|
|
|
|
|
- result = "RAW unsupported";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultDynamicProtocolNotValid):
|
|
|
|
|
- result = "Dynamic protocol unsupported";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultProtocolNotFound):
|
|
|
|
|
- result = "Protocol not found";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultMissingOrIncorrectBit):
|
|
|
|
|
- result = "Missing or incorrect Bit";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultMissingOrIncorrectKey):
|
|
|
|
|
- result = "Missing or incorrect Key";
|
|
|
|
|
- break;
|
|
|
|
|
- case(SubBruteFileResultMissingOrIncorrectTe):
|
|
|
|
|
- result = "Missing or incorrect TE";
|
|
|
|
|
- break;
|
|
|
|
|
- case SubBruteFileResultUnknown:
|
|
|
|
|
- default:
|
|
|
|
|
- result = "Unknown error";
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- return result;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-bool subbrute_device_create_packet_parsed(SubBruteDevice* instance, uint64_t step, bool small) {
|
|
|
|
|
|
|
+bool subbrute_device_create_packet_parsed(
|
|
|
|
|
+ SubBruteDevice* instance,
|
|
|
|
|
+ FlipperFormat* flipper_format,
|
|
|
|
|
+ uint64_t step,
|
|
|
|
|
+ bool small) {
|
|
|
furi_assert(instance);
|
|
furi_assert(instance);
|
|
|
|
|
|
|
|
- //char step_payload[32];
|
|
|
|
|
- //memset(step_payload, '0', sizeof(step_payload));
|
|
|
|
|
- memset(instance->payload, 0, sizeof(instance->payload));
|
|
|
|
|
string_t candidate;
|
|
string_t candidate;
|
|
|
string_init(candidate);
|
|
string_init(candidate);
|
|
|
|
|
|
|
@@ -231,42 +388,44 @@ bool subbrute_device_create_packet_parsed(SubBruteDevice* instance, uint64_t ste
|
|
|
FURI_LOG_D(TAG, "candidate: %s, step: %d", string_get_cstr(candidate), step);
|
|
FURI_LOG_D(TAG, "candidate: %s, step: %d", string_get_cstr(candidate), step);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
+ Stream* stream = flipper_format_get_raw_stream(flipper_format);
|
|
|
|
|
+ stream_clean(stream);
|
|
|
|
|
+
|
|
|
if(small) {
|
|
if(small) {
|
|
|
- if(instance->has_tail) {
|
|
|
|
|
- snprintf(
|
|
|
|
|
- instance->payload,
|
|
|
|
|
- sizeof(instance->payload),
|
|
|
|
|
|
|
+ if(instance->protocol_info->te) {
|
|
|
|
|
+ stream_write_format(
|
|
|
|
|
+ stream,
|
|
|
subbrute_key_small_with_tail,
|
|
subbrute_key_small_with_tail,
|
|
|
- instance->bit,
|
|
|
|
|
|
|
+ instance->protocol_info->bits,
|
|
|
string_get_cstr(candidate),
|
|
string_get_cstr(candidate),
|
|
|
- instance->te);
|
|
|
|
|
|
|
+ instance->protocol_info->te,
|
|
|
|
|
+ instance->protocol_info->repeat);
|
|
|
} else {
|
|
} else {
|
|
|
- snprintf(
|
|
|
|
|
- instance->payload,
|
|
|
|
|
- sizeof(instance->payload),
|
|
|
|
|
|
|
+ stream_write_format(
|
|
|
|
|
+ stream,
|
|
|
subbrute_key_small_no_tail,
|
|
subbrute_key_small_no_tail,
|
|
|
- instance->bit,
|
|
|
|
|
- string_get_cstr(candidate));
|
|
|
|
|
|
|
+ instance->protocol_info->bits,
|
|
|
|
|
+ string_get_cstr(candidate),
|
|
|
|
|
+ instance->protocol_info->repeat);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- if(instance->has_tail) {
|
|
|
|
|
- snprintf(
|
|
|
|
|
- instance->payload,
|
|
|
|
|
- sizeof(instance->payload),
|
|
|
|
|
- subbrute_key_file_princeton_end,
|
|
|
|
|
|
|
+ if(instance->protocol_info->te) {
|
|
|
|
|
+ stream_write_format(
|
|
|
|
|
+ stream,
|
|
|
|
|
+ subbrute_key_file_key_with_tail,
|
|
|
instance->file_template,
|
|
instance->file_template,
|
|
|
string_get_cstr(candidate),
|
|
string_get_cstr(candidate),
|
|
|
- instance->te);
|
|
|
|
|
|
|
+ instance->protocol_info->te,
|
|
|
|
|
+ instance->protocol_info->repeat);
|
|
|
} else {
|
|
} else {
|
|
|
- snprintf(
|
|
|
|
|
- instance->payload,
|
|
|
|
|
- sizeof(instance->payload),
|
|
|
|
|
|
|
+ stream_write_format(
|
|
|
|
|
+ stream,
|
|
|
subbrute_key_file_key,
|
|
subbrute_key_file_key,
|
|
|
instance->file_template,
|
|
instance->file_template,
|
|
|
- string_get_cstr(candidate));
|
|
|
|
|
|
|
+ string_get_cstr(candidate),
|
|
|
|
|
+ instance->protocol_info->repeat);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
#ifdef FURI_DEBUG
|
|
#ifdef FURI_DEBUG
|
|
|
//FURI_LOG_D(TAG, "payload: %s", instance->payload);
|
|
//FURI_LOG_D(TAG, "payload: %s", instance->payload);
|
|
|
#endif
|
|
#endif
|
|
@@ -282,77 +441,11 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
|
|
|
FURI_LOG_D(TAG, "subbrute_device_attack_set: %d", type);
|
|
FURI_LOG_D(TAG, "subbrute_device_attack_set: %d", type);
|
|
|
#endif
|
|
#endif
|
|
|
subbrute_device_attack_set_default_values(instance, type);
|
|
subbrute_device_attack_set_default_values(instance, type);
|
|
|
- switch(type) {
|
|
|
|
|
- case SubBruteAttackLoadFile:
|
|
|
|
|
- // In this case values must be already set
|
|
|
|
|
- // file_result =
|
|
|
|
|
- // subbrute_device_load_from_file(instance, string_get_cstr(instance->load_path));
|
|
|
|
|
- // if(file_result != SubBruteFileResultOk) {
|
|
|
|
|
- // // Failed load file so failed to set attack type
|
|
|
|
|
- // return file_result; // RETURN
|
|
|
|
|
- // }
|
|
|
|
|
- break;
|
|
|
|
|
- case SubBruteAttackCAME12bit307:
|
|
|
|
|
- case SubBruteAttackCAME12bit433:
|
|
|
|
|
- case SubBruteAttackCAME12bit868:
|
|
|
|
|
- if(type == SubBruteAttackCAME12bit307) {
|
|
|
|
|
- instance->frequency = 307800000;
|
|
|
|
|
- } else if(type == SubBruteAttackCAME12bit433) {
|
|
|
|
|
- instance->frequency = 433920000;
|
|
|
|
|
- } else /* ALWAYS TRUE if(type == SubBruteAttackCAME12bit868) */ {
|
|
|
|
|
- instance->frequency = 868350000;
|
|
|
|
|
- }
|
|
|
|
|
- instance->bit = 12;
|
|
|
|
|
- string_set_str(instance->protocol_name, protocol_came);
|
|
|
|
|
- string_set_str(instance->preset_name, preset_ook650_async);
|
|
|
|
|
- break;
|
|
|
|
|
- case SubBruteAttackChamberlain9bit300:
|
|
|
|
|
- case SubBruteAttackChamberlain9bit315:
|
|
|
|
|
- case SubBruteAttackChamberlain9bit390:
|
|
|
|
|
- if(type == SubBruteAttackChamberlain9bit300) {
|
|
|
|
|
- instance->frequency = 300000000;
|
|
|
|
|
- } else if(type == SubBruteAttackChamberlain9bit315) {
|
|
|
|
|
- instance->frequency = 315000000;
|
|
|
|
|
- } else /* ALWAYS TRUE if(type == SubBruteAttackChamberlain9bit390) */ {
|
|
|
|
|
- instance->frequency = 390000000;
|
|
|
|
|
- }
|
|
|
|
|
- instance->bit = 9;
|
|
|
|
|
- string_set_str(instance->protocol_name, protocol_cham_code);
|
|
|
|
|
- string_set_str(instance->preset_name, preset_ook650_async);
|
|
|
|
|
- break;
|
|
|
|
|
- case SubBruteAttackLinear10bit300:
|
|
|
|
|
- instance->frequency = 300000000;
|
|
|
|
|
- instance->bit = 10;
|
|
|
|
|
- string_set_str(instance->protocol_name, protocol_linear);
|
|
|
|
|
- string_set_str(instance->preset_name, preset_ook650_async);
|
|
|
|
|
- break;
|
|
|
|
|
- case SubBruteAttackLinear10bit310:
|
|
|
|
|
- instance->frequency = 310000000;
|
|
|
|
|
- instance->bit = 10;
|
|
|
|
|
- string_set_str(instance->protocol_name, protocol_linear);
|
|
|
|
|
- string_set_str(instance->preset_name, preset_ook650_async);
|
|
|
|
|
- break;
|
|
|
|
|
- case SubBruteAttackNICE12bit433:
|
|
|
|
|
- instance->frequency = 433920000;
|
|
|
|
|
- instance->bit = 12;
|
|
|
|
|
- string_set_str(instance->protocol_name, protocol_nice_flo);
|
|
|
|
|
- string_set_str(instance->preset_name, preset_ook650_async);
|
|
|
|
|
- break;
|
|
|
|
|
- case SubBruteAttackNICE12bit868:
|
|
|
|
|
- instance->frequency = 868350000;
|
|
|
|
|
- instance->bit = 12;
|
|
|
|
|
- string_set_str(instance->protocol_name, protocol_nice_flo);
|
|
|
|
|
- string_set_str(instance->preset_name, preset_ook650_async);
|
|
|
|
|
- break;
|
|
|
|
|
- default:
|
|
|
|
|
- FURI_LOG_E(TAG, "Unknown attack type: %d", type);
|
|
|
|
|
- return SubBruteFileResultProtocolNotFound; // RETURN
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- /*if(!furi_hal_subghz_is_tx_allowed(instance->frequency)) {
|
|
|
|
|
- FURI_LOG_E(TAG, "Frequency invalid: %d", instance->frequency);
|
|
|
|
|
- return SubBruteFileResultMissingOrIncorrectFrequency; // RETURN
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+ if(type != SubBruteAttackLoadFile) {
|
|
|
|
|
+ subbrute_device_free_protocol_info(instance);
|
|
|
|
|
+ instance->protocol_info = subbrute_protocol(type);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// For non-file types we didn't set SubGhzProtocolDecoderBase
|
|
// For non-file types we didn't set SubGhzProtocolDecoderBase
|
|
|
instance->receiver = subghz_receiver_alloc_init(instance->environment);
|
|
instance->receiver = subghz_receiver_alloc_init(instance->environment);
|
|
@@ -362,7 +455,7 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
|
|
|
uint8_t protocol_check_result = SubBruteFileResultProtocolNotFound;
|
|
uint8_t protocol_check_result = SubBruteFileResultProtocolNotFound;
|
|
|
if(type != SubBruteAttackLoadFile) {
|
|
if(type != SubBruteAttackLoadFile) {
|
|
|
instance->decoder_result = subghz_receiver_search_decoder_base_by_name(
|
|
instance->decoder_result = subghz_receiver_search_decoder_base_by_name(
|
|
|
- instance->receiver, string_get_cstr(instance->protocol_name));
|
|
|
|
|
|
|
+ instance->receiver, subbrute_protocol_file(instance->protocol_info->file));
|
|
|
|
|
|
|
|
if(!instance->decoder_result ||
|
|
if(!instance->decoder_result ||
|
|
|
instance->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) {
|
|
instance->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) {
|
|
@@ -372,7 +465,6 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// And here we need to set preset enum
|
|
// And here we need to set preset enum
|
|
|
- instance->preset = subbrute_device_convert_preset(string_get_cstr(instance->preset_name));
|
|
|
|
|
protocol_check_result = SubBruteFileResultOk;
|
|
protocol_check_result = SubBruteFileResultOk;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -383,16 +475,13 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
|
|
|
return SubBruteFileResultProtocolNotFound;
|
|
return SubBruteFileResultProtocolNotFound;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- instance->has_tail =
|
|
|
|
|
- (strcmp(string_get_cstr(instance->protocol_name), protocol_princeton) == 0);
|
|
|
|
|
-
|
|
|
|
|
// Calc max value
|
|
// Calc max value
|
|
|
if(instance->attack == SubBruteAttackLoadFile) {
|
|
if(instance->attack == SubBruteAttackLoadFile) {
|
|
|
instance->max_value = 0xFF;
|
|
instance->max_value = 0xFF;
|
|
|
} else {
|
|
} else {
|
|
|
string_t max_value_s;
|
|
string_t max_value_s;
|
|
|
string_init(max_value_s);
|
|
string_init(max_value_s);
|
|
|
- for(uint8_t i = 0; i < instance->bit; i++) {
|
|
|
|
|
|
|
+ for(uint8_t i = 0; i < instance->protocol_info->bits; i++) {
|
|
|
string_cat_printf(max_value_s, "1");
|
|
string_cat_printf(max_value_s, "1");
|
|
|
}
|
|
}
|
|
|
instance->max_value = (uint64_t)strtol(string_get_cstr(max_value_s), NULL, 2);
|
|
instance->max_value = (uint64_t)strtol(string_get_cstr(max_value_s), NULL, 2);
|
|
@@ -405,24 +494,22 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
|
|
|
instance->file_template,
|
|
instance->file_template,
|
|
|
sizeof(instance->file_template),
|
|
sizeof(instance->file_template),
|
|
|
subbrute_key_file_start,
|
|
subbrute_key_file_start,
|
|
|
- instance->frequency,
|
|
|
|
|
- string_get_cstr(instance->preset_name),
|
|
|
|
|
- string_get_cstr(instance->protocol_name),
|
|
|
|
|
- instance->bit);
|
|
|
|
|
-// strncat(instance->file_template, "\n", sizeof(instance->file_template));
|
|
|
|
|
-// strncat(instance->file_template, subbrute_key_file_key, sizeof(instance->file_template));
|
|
|
|
|
-// if(instance->has_tail) {
|
|
|
|
|
-// strncat(
|
|
|
|
|
-// instance->file_template,
|
|
|
|
|
-// subbrute_key_file_princeton_end,
|
|
|
|
|
-// sizeof(instance->file_template));
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ instance->protocol_info->frequency,
|
|
|
|
|
+ subbrute_protocol_preset(instance->protocol_info->preset),
|
|
|
|
|
+ subbrute_protocol_file(instance->protocol_info->file),
|
|
|
|
|
+ instance->protocol_info->bits);
|
|
|
#ifdef FURI_DEBUG
|
|
#ifdef FURI_DEBUG
|
|
|
- FURI_LOG_D(TAG, "tail: %d, file_template: %s", instance->has_tail, instance->file_template);
|
|
|
|
|
|
|
+ FURI_LOG_D(
|
|
|
|
|
+ TAG, "tail: %d, file_template: %s", instance->protocol_info->te, instance->file_template);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
// Init payload
|
|
// Init payload
|
|
|
- subbrute_device_create_packet_parsed(instance, instance->key_index, false);
|
|
|
|
|
|
|
+ FlipperFormat* flipper_format = flipper_format_string_alloc();
|
|
|
|
|
+ if(subbrute_device_create_packet_parsed(instance, flipper_format, instance->key_index, false)) {
|
|
|
|
|
+ instance->state = SubBruteDeviceStateReady;
|
|
|
|
|
+ subbrute_device_send_callback(instance);
|
|
|
|
|
+ }
|
|
|
|
|
+ flipper_format_free(flipper_format);
|
|
|
|
|
|
|
|
return SubBruteFileResultOk;
|
|
return SubBruteFileResultOk;
|
|
|
}
|
|
}
|
|
@@ -459,8 +546,8 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_p
|
|
|
|
|
|
|
|
// Frequency
|
|
// Frequency
|
|
|
if(flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) {
|
|
if(flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) {
|
|
|
- instance->frequency = temp_data32;
|
|
|
|
|
- if(!furi_hal_subghz_is_tx_allowed(instance->frequency)) {
|
|
|
|
|
|
|
+ instance->protocol_info->frequency = temp_data32;
|
|
|
|
|
+ if(!furi_hal_subghz_is_tx_allowed(instance->protocol_info->frequency)) {
|
|
|
result = SubBruteFileResultFrequencyNotAllowed;
|
|
result = SubBruteFileResultFrequencyNotAllowed;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -469,31 +556,33 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_p
|
|
|
result = SubBruteFileResultMissingOrIncorrectFrequency;
|
|
result = SubBruteFileResultMissingOrIncorrectFrequency;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// Preset
|
|
// Preset
|
|
|
if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) {
|
|
if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) {
|
|
|
FURI_LOG_E(TAG, "Preset FAIL");
|
|
FURI_LOG_E(TAG, "Preset FAIL");
|
|
|
result = SubBruteFileResultPresetInvalid;
|
|
result = SubBruteFileResultPresetInvalid;
|
|
|
} else {
|
|
} else {
|
|
|
- string_init_set_str(instance->preset_name, string_get_cstr(temp_str));
|
|
|
|
|
|
|
+ instance->protocol_info->preset = subbrute_protocol_convert_preset(temp_str);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const char* protocol_file = NULL;
|
|
|
// Protocol
|
|
// Protocol
|
|
|
if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
|
|
if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
|
|
|
FURI_LOG_E(TAG, "Missing Protocol");
|
|
FURI_LOG_E(TAG, "Missing Protocol");
|
|
|
result = SubBruteFileResultMissingProtocol;
|
|
result = SubBruteFileResultMissingProtocol;
|
|
|
break;
|
|
break;
|
|
|
} else {
|
|
} else {
|
|
|
- string_init_set_str(instance->protocol_name, string_get_cstr(temp_str));
|
|
|
|
|
|
|
+ instance->protocol_info->file = subbrute_protocol_file_protocol_name(temp_str);
|
|
|
|
|
+ protocol_file = subbrute_protocol_file(instance->protocol_info->file);
|
|
|
#ifdef FURI_DEBUG
|
|
#ifdef FURI_DEBUG
|
|
|
- FURI_LOG_D(TAG, "Protocol: %s", string_get_cstr(instance->protocol_name));
|
|
|
|
|
|
|
+ FURI_LOG_D(TAG, "Protocol: %s", protocol_file);
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- instance->decoder_result = subghz_receiver_search_decoder_base_by_name(
|
|
|
|
|
- instance->receiver, string_get_cstr(instance->protocol_name));
|
|
|
|
|
|
|
+ instance->decoder_result =
|
|
|
|
|
+ subghz_receiver_search_decoder_base_by_name(instance->receiver, protocol_file);
|
|
|
|
|
|
|
|
- if(!instance->decoder_result ||
|
|
|
|
|
- strcmp(string_get_cstr(instance->protocol_name), "RAW") == 0) {
|
|
|
|
|
|
|
+ if(!instance->decoder_result || strcmp(protocol_file, "RAW") == 0) {
|
|
|
FURI_LOG_E(TAG, "RAW unsupported");
|
|
FURI_LOG_E(TAG, "RAW unsupported");
|
|
|
result = SubBruteFileResultProtocolNotSupported;
|
|
result = SubBruteFileResultProtocolNotSupported;
|
|
|
break;
|
|
break;
|
|
@@ -510,24 +599,15 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_p
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- // instance->decoder_result = subghz_receiver_search_decoder_base_by_name(
|
|
|
|
|
- // instance->receiver, string_get_cstr(instance->protocol_name));
|
|
|
|
|
- //
|
|
|
|
|
- // if(!instance->decoder_result) {
|
|
|
|
|
- // FURI_LOG_E(TAG, "Protocol not found");
|
|
|
|
|
- // result = SubBruteFileResultProtocolNotFound;
|
|
|
|
|
- // break;
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
// Bit
|
|
// Bit
|
|
|
if(!flipper_format_read_uint32(fff_data_file, "Bit", &temp_data32, 1)) {
|
|
if(!flipper_format_read_uint32(fff_data_file, "Bit", &temp_data32, 1)) {
|
|
|
FURI_LOG_E(TAG, "Missing or incorrect Bit");
|
|
FURI_LOG_E(TAG, "Missing or incorrect Bit");
|
|
|
result = SubBruteFileResultMissingOrIncorrectBit;
|
|
result = SubBruteFileResultMissingOrIncorrectBit;
|
|
|
break;
|
|
break;
|
|
|
} else {
|
|
} else {
|
|
|
- instance->bit = temp_data32;
|
|
|
|
|
|
|
+ instance->protocol_info->bits = temp_data32;
|
|
|
#ifdef FURI_DEBUG
|
|
#ifdef FURI_DEBUG
|
|
|
- FURI_LOG_D(TAG, "Bit: %d", instance->bit);
|
|
|
|
|
|
|
+ FURI_LOG_D(TAG, "Bit: %d", instance->protocol_info->bits);
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -550,8 +630,7 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_p
|
|
|
//result = SubBruteFileResultMissingOrIncorrectTe;
|
|
//result = SubBruteFileResultMissingOrIncorrectTe;
|
|
|
//break;
|
|
//break;
|
|
|
} else {
|
|
} else {
|
|
|
- instance->te = temp_data32;
|
|
|
|
|
- instance->has_tail = true;
|
|
|
|
|
|
|
+ instance->protocol_info->te = temp_data32 != 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Repeat
|
|
// Repeat
|
|
@@ -559,12 +638,12 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_p
|
|
|
#ifdef FURI_DEBUG
|
|
#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Repeat: %d", temp_data32);
|
|
FURI_LOG_D(TAG, "Repeat: %d", temp_data32);
|
|
|
#endif
|
|
#endif
|
|
|
- instance->repeat = temp_data32;
|
|
|
|
|
|
|
+ instance->protocol_info->repeat = (uint8_t)temp_data32;
|
|
|
} else {
|
|
} else {
|
|
|
#ifdef FURI_DEBUG
|
|
#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Repeat: 3 (default)");
|
|
FURI_LOG_D(TAG, "Repeat: 3 (default)");
|
|
|
#endif
|
|
#endif
|
|
|
- instance->repeat = 3;
|
|
|
|
|
|
|
+ instance->protocol_info->repeat = 3;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
result = SubBruteFileResultOk;
|
|
result = SubBruteFileResultOk;
|
|
@@ -601,55 +680,66 @@ void subbrute_device_attack_set_default_values(
|
|
|
instance->load_index = 0x00;
|
|
instance->load_index = 0x00;
|
|
|
memset(instance->file_template, 0, sizeof(instance->file_template));
|
|
memset(instance->file_template, 0, sizeof(instance->file_template));
|
|
|
memset(instance->current_key, 0, sizeof(instance->current_key));
|
|
memset(instance->current_key, 0, sizeof(instance->current_key));
|
|
|
- memset(instance->text_store, 0, sizeof(instance->text_store));
|
|
|
|
|
- memset(instance->payload, 0, sizeof(instance->payload));
|
|
|
|
|
|
|
|
|
|
if(default_attack != SubBruteAttackLoadFile) {
|
|
if(default_attack != SubBruteAttackLoadFile) {
|
|
|
memset(instance->file_key, 0, sizeof(instance->file_key));
|
|
memset(instance->file_key, 0, sizeof(instance->file_key));
|
|
|
|
|
|
|
|
instance->max_value = (uint64_t)0x00;
|
|
instance->max_value = (uint64_t)0x00;
|
|
|
-
|
|
|
|
|
- string_clear(instance->protocol_name);
|
|
|
|
|
- string_clear(instance->preset_name);
|
|
|
|
|
-
|
|
|
|
|
- string_clear(instance->load_path);
|
|
|
|
|
- string_init(instance->load_path);
|
|
|
|
|
-
|
|
|
|
|
- string_init_set_str(instance->protocol_name, protocol_raw);
|
|
|
|
|
- string_init_set_str(instance->preset_name, preset_ook650_async);
|
|
|
|
|
- instance->preset = FuriHalSubGhzPresetOok650Async;
|
|
|
|
|
-
|
|
|
|
|
- instance->repeat = 5;
|
|
|
|
|
- instance->te = 0;
|
|
|
|
|
- instance->has_tail = false;
|
|
|
|
|
}
|
|
}
|
|
|
-#ifdef FURI_DEBUG
|
|
|
|
|
- FURI_LOG_D(
|
|
|
|
|
- TAG, "subbrute_device_attack_set_default_values done. has_tail: %d", instance->has_tail);
|
|
|
|
|
- //furi_delay_ms(250);
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-FuriHalSubGhzPreset subbrute_device_convert_preset(const char* preset_name) {
|
|
|
|
|
- string_t preset;
|
|
|
|
|
- string_init_set_str(preset, preset_name);
|
|
|
|
|
- FuriHalSubGhzPreset preset_value;
|
|
|
|
|
- if(string_cmp_str(preset, preset_ook270_async) == 0) {
|
|
|
|
|
- preset_value = FuriHalSubGhzPresetOok270Async;
|
|
|
|
|
- } else if(string_cmp_str(preset, preset_ook650_async) == 0) {
|
|
|
|
|
- preset_value = FuriHalSubGhzPresetOok650Async;
|
|
|
|
|
- } else if(string_cmp_str(preset, preset_2fsk_dev238_async) == 0) {
|
|
|
|
|
- preset_value = FuriHalSubGhzPreset2FSKDev238Async;
|
|
|
|
|
- } else if(string_cmp_str(preset, preset_2fsk_dev476_async) == 0) {
|
|
|
|
|
- preset_value = FuriHalSubGhzPreset2FSKDev476Async;
|
|
|
|
|
- } else if(string_cmp_str(preset, preset_msk99_97_kb_async) == 0) {
|
|
|
|
|
- preset_value = FuriHalSubGhzPresetMSK99_97KbAsync;
|
|
|
|
|
- } else if(string_cmp_str(preset, preset_gfs99_97_kb_async) == 0) {
|
|
|
|
|
- preset_value = FuriHalSubGhzPresetMSK99_97KbAsync;
|
|
|
|
|
- } else {
|
|
|
|
|
- preset_value = FuriHalSubGhzPresetCustom;
|
|
|
|
|
|
|
+void subbrute_device_send_callback(SubBruteDevice* instance) {
|
|
|
|
|
+ if(instance->callback != NULL) {
|
|
|
|
|
+ instance->callback(instance->context, instance->state);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- string_clear(preset);
|
|
|
|
|
- return preset_value;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+const char* subbrute_device_error_get_desc(SubBruteFileResult error_id) {
|
|
|
|
|
+ const char* result;
|
|
|
|
|
+ switch(error_id) {
|
|
|
|
|
+ case(SubBruteFileResultOk):
|
|
|
|
|
+ result = "OK";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultErrorOpenFile):
|
|
|
|
|
+ result = "invalid name/path";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultMissingOrIncorrectHeader):
|
|
|
|
|
+ result = "Missing or incorrect header";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultFrequencyNotAllowed):
|
|
|
|
|
+ result = "Invalid frequency!";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultMissingOrIncorrectFrequency):
|
|
|
|
|
+ result = "Missing or incorrect Frequency";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultPresetInvalid):
|
|
|
|
|
+ result = "Preset FAIL";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultMissingProtocol):
|
|
|
|
|
+ result = "Missing Protocol";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultProtocolNotSupported):
|
|
|
|
|
+ result = "RAW unsupported";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultDynamicProtocolNotValid):
|
|
|
|
|
+ result = "Dynamic protocol unsupported";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultProtocolNotFound):
|
|
|
|
|
+ result = "Protocol not found";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultMissingOrIncorrectBit):
|
|
|
|
|
+ result = "Missing or incorrect Bit";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultMissingOrIncorrectKey):
|
|
|
|
|
+ result = "Missing or incorrect Key";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case(SubBruteFileResultMissingOrIncorrectTe):
|
|
|
|
|
+ result = "Missing or incorrect TE";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case SubBruteFileResultUnknown:
|
|
|
|
|
+ default:
|
|
|
|
|
+ result = "Unknown error";
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|