|
|
@@ -8,40 +8,14 @@
|
|
|
|
|
|
#define TAG "SubBruteDevice"
|
|
|
|
|
|
-#define SUBBRUTE_TX_TIMEOUT 5
|
|
|
-#define SUBBRUTE_MANUAL_TRANSMIT_INTERVAL 400
|
|
|
-
|
|
|
-/**
|
|
|
- * Values to not use less memory for packet parse operations
|
|
|
- */
|
|
|
-static const char* subbrute_key_file_start =
|
|
|
- "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\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* instance = malloc(sizeof(SubBruteDevice));
|
|
|
|
|
|
- instance->state = SubBruteDeviceStateIDLE;
|
|
|
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);
|
|
|
-
|
|
|
- instance->context = NULL;
|
|
|
- instance->callback = NULL;
|
|
|
|
|
|
instance->protocol_info = NULL;
|
|
|
instance->file_protocol_info = NULL;
|
|
|
instance->decoder_result = NULL;
|
|
|
- instance->transmitter = NULL;
|
|
|
instance->receiver = NULL;
|
|
|
instance->environment = subghz_environment_alloc();
|
|
|
|
|
|
@@ -61,137 +35,15 @@ void subbrute_device_free(SubBruteDevice* instance) {
|
|
|
instance->receiver = NULL;
|
|
|
}
|
|
|
|
|
|
- if(instance->transmitter != NULL) {
|
|
|
- subghz_transmitter_free(instance->transmitter);
|
|
|
- instance->transmitter = NULL;
|
|
|
- }
|
|
|
-
|
|
|
subghz_environment_free(instance->environment);
|
|
|
instance->environment = NULL;
|
|
|
|
|
|
- furi_thread_free(instance->thread);
|
|
|
subbrute_device_free_protocol_info(instance);
|
|
|
|
|
|
free(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
|
|
|
- FURI_LOG_I(TAG, "Worker start");
|
|
|
-#endif
|
|
|
-
|
|
|
- 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 && instance->attack != SubBruteAttackLoadFile) ||
|
|
|
- (instance->attack == SubBruteAttackLoadFile && instance->file_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_max_value(SubBruteDevice* instance) {
|
|
|
- return instance->max_value;
|
|
|
-}
|
|
|
-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;
|
|
|
@@ -220,122 +72,17 @@ uint64_t subbrute_device_add_step(SubBruteDevice* instance, int8_t step) {
|
|
|
|
|
|
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();
|
|
|
- if(instance->attack == SubBruteAttackLoadFile) {
|
|
|
- furi_hal_subghz_load_preset(instance->file_protocol_info->preset);
|
|
|
- furi_hal_subghz_set_frequency_and_path(instance->file_protocol_info->preset);
|
|
|
- } else {
|
|
|
- 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: %ld", ticks - instance->last_time_tx_data);
|
|
|
-#endif
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- instance->last_time_tx_data = ticks;
|
|
|
-
|
|
|
-#ifdef FURI_DEBUG
|
|
|
- if(instance->attack == SubBruteAttackLoadFile) {
|
|
|
- FURI_LOG_D(
|
|
|
- TAG,
|
|
|
- "Protocol: %d, Frequency: %ld",
|
|
|
- instance->file_protocol_info->file,
|
|
|
- instance->file_protocol_info->frequency);
|
|
|
- } else {
|
|
|
- FURI_LOG_D(
|
|
|
- TAG,
|
|
|
- "Protocol: %d, Frequency: %ld",
|
|
|
- instance->protocol_info->file,
|
|
|
- instance->protocol_info->frequency);
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "subbrute_device_save_file: %s", dev_file_name);
|
|
|
#endif
|
|
|
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
FlipperFormat* file = flipper_format_file_alloc(storage);
|
|
|
+ FuriString* file_content = furi_string_alloc();
|
|
|
|
|
|
bool result = false;
|
|
|
do {
|
|
|
@@ -343,7 +90,32 @@ bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_na
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if(!subbrute_device_create_packet_parsed(instance, file, instance->key_index, false)) {
|
|
|
+ if(instance->attack == SubBruteAttackLoadFile) {
|
|
|
+ file_content = subbrute_protocol_file_generate_file(
|
|
|
+ instance->file_protocol_info->frequency,
|
|
|
+ instance->file_protocol_info->preset,
|
|
|
+ instance->file_protocol_info->file,
|
|
|
+ instance->key_index,
|
|
|
+ instance->file_protocol_info->bits,
|
|
|
+ instance->file_protocol_info->te,
|
|
|
+ instance->file_protocol_info->repeat,
|
|
|
+ instance->load_index,
|
|
|
+ instance->file_key);
|
|
|
+ } else {
|
|
|
+ file_content = subbrute_protocol_default_generate_file(
|
|
|
+ instance->protocol_info->frequency,
|
|
|
+ instance->protocol_info->preset,
|
|
|
+ instance->protocol_info->file,
|
|
|
+ instance->key_index,
|
|
|
+ instance->protocol_info->bits,
|
|
|
+ instance->protocol_info->te,
|
|
|
+ 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;
|
|
|
}
|
|
|
@@ -352,140 +124,17 @@ bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_na
|
|
|
} while(false);
|
|
|
|
|
|
if(!result) {
|
|
|
- FURI_LOG_E(TAG, "flipper_format_file_open_always failed!");
|
|
|
+ FURI_LOG_E(TAG, "subbrute_device_save_file failed!");
|
|
|
}
|
|
|
|
|
|
+ flipper_format_file_close(file);
|
|
|
flipper_format_free(file);
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
+ furi_string_free(file_content);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-bool subbrute_device_create_packet_parsed(
|
|
|
- SubBruteDevice* instance,
|
|
|
- FlipperFormat* flipper_format,
|
|
|
- uint64_t step,
|
|
|
- bool small) {
|
|
|
- furi_assert(instance);
|
|
|
-
|
|
|
- FuriString* candidate = furi_string_alloc();
|
|
|
-
|
|
|
- Stream* stream = flipper_format_get_raw_stream(flipper_format);
|
|
|
- stream_clean(stream);
|
|
|
-
|
|
|
- if(instance->attack == SubBruteAttackLoadFile) {
|
|
|
- if(step >= sizeof(instance->file_key)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- char subbrute_payload_byte[4];
|
|
|
- furi_string_set_str(candidate, instance->file_key);
|
|
|
- snprintf(subbrute_payload_byte, 4, "%02X ", (uint8_t)step);
|
|
|
- furi_string_replace_at(candidate, instance->load_index * 3, 3, subbrute_payload_byte);
|
|
|
- //snprintf(step_payload, sizeof(step_payload), "%02X", (uint8_t)instance->file_key[step]);
|
|
|
-
|
|
|
- if(small) {
|
|
|
- if(instance->file_protocol_info->te) {
|
|
|
- stream_write_format(
|
|
|
- stream,
|
|
|
- subbrute_key_small_with_tail,
|
|
|
- instance->file_protocol_info->bits,
|
|
|
- furi_string_get_cstr(candidate),
|
|
|
- instance->file_protocol_info->te,
|
|
|
- instance->file_protocol_info->repeat);
|
|
|
- } else {
|
|
|
- stream_write_format(
|
|
|
- stream,
|
|
|
- subbrute_key_small_no_tail,
|
|
|
- instance->file_protocol_info->bits,
|
|
|
- furi_string_get_cstr(candidate),
|
|
|
- instance->file_protocol_info->repeat);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if(instance->file_protocol_info->te) {
|
|
|
- stream_write_format(
|
|
|
- stream,
|
|
|
- subbrute_key_file_key_with_tail,
|
|
|
- instance->file_template,
|
|
|
- furi_string_get_cstr(candidate),
|
|
|
- instance->file_protocol_info->te,
|
|
|
- instance->file_protocol_info->repeat);
|
|
|
- } else {
|
|
|
- stream_write_format(
|
|
|
- stream,
|
|
|
- subbrute_key_file_key,
|
|
|
- instance->file_template,
|
|
|
- furi_string_get_cstr(candidate),
|
|
|
- instance->file_protocol_info->repeat);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- //snprintf(step_payload, sizeof(step_payload), "%16X", step);
|
|
|
- //snprintf(step_payload, sizeof(step_payload), "%016llX", step);
|
|
|
- FuriString* buffer = furi_string_alloc();
|
|
|
- furi_string_printf(buffer, "%16llX", step);
|
|
|
- int j = 0;
|
|
|
- furi_string_set_str(candidate, " ");
|
|
|
- for(uint8_t i = 0; i < 16; i++) {
|
|
|
- if(furi_string_get_char(buffer, i) != ' ') {
|
|
|
- furi_string_set_char(candidate, i + j, furi_string_get_char(buffer, i));
|
|
|
- } else {
|
|
|
- furi_string_set_char(candidate, i + j, '0');
|
|
|
- }
|
|
|
- if(i % 2 != 0) {
|
|
|
- j++;
|
|
|
- }
|
|
|
- }
|
|
|
- furi_string_free(buffer);
|
|
|
-
|
|
|
-#ifdef FURI_DEBUG
|
|
|
- FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
|
|
|
-#endif
|
|
|
-
|
|
|
- if(small) {
|
|
|
- if(instance->protocol_info->te) {
|
|
|
- stream_write_format(
|
|
|
- stream,
|
|
|
- subbrute_key_small_with_tail,
|
|
|
- instance->protocol_info->bits,
|
|
|
- furi_string_get_cstr(candidate),
|
|
|
- instance->protocol_info->te,
|
|
|
- instance->protocol_info->repeat);
|
|
|
- } else {
|
|
|
- stream_write_format(
|
|
|
- stream,
|
|
|
- subbrute_key_small_no_tail,
|
|
|
- instance->protocol_info->bits,
|
|
|
- furi_string_get_cstr(candidate),
|
|
|
- instance->protocol_info->repeat);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if(instance->protocol_info->te) {
|
|
|
- stream_write_format(
|
|
|
- stream,
|
|
|
- subbrute_key_file_key_with_tail,
|
|
|
- instance->file_template,
|
|
|
- furi_string_get_cstr(candidate),
|
|
|
- instance->protocol_info->te,
|
|
|
- instance->protocol_info->repeat);
|
|
|
- } else {
|
|
|
- stream_write_format(
|
|
|
- stream,
|
|
|
- subbrute_key_file_key,
|
|
|
- instance->file_template,
|
|
|
- furi_string_get_cstr(candidate),
|
|
|
- instance->protocol_info->repeat);
|
|
|
- }
|
|
|
- }
|
|
|
-#ifdef FURI_DEBUG
|
|
|
- FURI_LOG_D(TAG, "candidate: %s", furi_string_get_cstr(candidate));
|
|
|
-#endif
|
|
|
- }
|
|
|
-
|
|
|
- furi_string_free(candidate);
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBruteAttacks type) {
|
|
|
furi_assert(instance);
|
|
|
#ifdef FURI_DEBUG
|
|
|
@@ -513,10 +162,18 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
|
|
|
FURI_LOG_E(TAG, "Can't load SubGhzProtocolDecoderBase in phase non-file decoder set");
|
|
|
} else {
|
|
|
protocol_check_result = SubBruteFileResultOk;
|
|
|
+
|
|
|
+ // Calc max value
|
|
|
+ instance->max_value =
|
|
|
+ subbrute_protocol_calc_max_value(instance->attack, instance->protocol_info->bits);
|
|
|
}
|
|
|
} else {
|
|
|
// And here we need to set preset enum
|
|
|
protocol_check_result = SubBruteFileResultOk;
|
|
|
+
|
|
|
+ // Calc max value
|
|
|
+ instance->max_value =
|
|
|
+ subbrute_protocol_calc_max_value(instance->attack, instance->file_protocol_info->bits);
|
|
|
}
|
|
|
|
|
|
subghz_receiver_free(instance->receiver);
|
|
|
@@ -526,56 +183,6 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
|
|
|
return SubBruteFileResultProtocolNotFound;
|
|
|
}
|
|
|
|
|
|
- // Calc max value
|
|
|
- if(instance->attack == SubBruteAttackLoadFile) {
|
|
|
- instance->max_value = 0x3F;
|
|
|
-
|
|
|
- // Now we are ready to set file template for using in the future with snprintf
|
|
|
- // for sending attack payload ONLY for files!
|
|
|
- snprintf(
|
|
|
- instance->file_template,
|
|
|
- sizeof(instance->file_template),
|
|
|
- subbrute_key_file_start,
|
|
|
- instance->file_protocol_info->frequency,
|
|
|
- subbrute_protocol_preset(instance->file_protocol_info->preset),
|
|
|
- subbrute_protocol_file(instance->file_protocol_info->file),
|
|
|
- instance->file_protocol_info->bits);
|
|
|
- } else {
|
|
|
- FuriString* max_value_s;
|
|
|
- max_value_s = furi_string_alloc();
|
|
|
- for(uint8_t i = 0; i < instance->protocol_info->bits; i++) {
|
|
|
- furi_string_cat_printf(max_value_s, "1");
|
|
|
- }
|
|
|
- instance->max_value = (uint64_t)strtol(furi_string_get_cstr(max_value_s), NULL, 2);
|
|
|
- furi_string_free(max_value_s);
|
|
|
-
|
|
|
- // Now we are ready to set file template for using in the future with snprintf
|
|
|
- // for sending attack payload
|
|
|
- snprintf(
|
|
|
- instance->file_template,
|
|
|
- sizeof(instance->file_template),
|
|
|
- subbrute_key_file_start,
|
|
|
- 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
|
|
|
- FURI_LOG_D(
|
|
|
- TAG,
|
|
|
- "tail: %d, file_template: %s",
|
|
|
- instance->protocol_info->te,
|
|
|
- instance->file_template);
|
|
|
-#endif
|
|
|
- }
|
|
|
-
|
|
|
- // Init payload
|
|
|
- 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;
|
|
|
}
|
|
|
|
|
|
@@ -751,7 +358,6 @@ void subbrute_device_attack_set_default_values(
|
|
|
instance->attack = default_attack;
|
|
|
instance->key_index = 0x00;
|
|
|
instance->load_index = 0x00;
|
|
|
- memset(instance->file_template, 0, sizeof(instance->file_template));
|
|
|
memset(instance->current_key, 0, sizeof(instance->current_key));
|
|
|
|
|
|
if(default_attack != SubBruteAttackLoadFile) {
|
|
|
@@ -761,12 +367,6 @@ void subbrute_device_attack_set_default_values(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void subbrute_device_send_callback(SubBruteDevice* instance) {
|
|
|
- if(instance->callback != NULL) {
|
|
|
- instance->callback(instance->context, instance->state);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
const char* subbrute_device_error_get_desc(SubBruteFileResult error_id) {
|
|
|
const char* result;
|
|
|
switch(error_id) {
|