2022-09-24 17:47:21 +00:00
|
|
|
#include "../subbrute_i.h"
|
|
|
|
#include "../subbrute_custom_event.h"
|
|
|
|
#include "../views/subbrute_attack_view.h"
|
|
|
|
|
2022-09-25 13:05:52 +00:00
|
|
|
#define TAG "SubBruteSceneSetupAttack"
|
|
|
|
|
2022-09-24 17:47:21 +00:00
|
|
|
static void subbrute_scene_setup_attack_callback(SubBruteCustomEvent event, void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
|
|
|
|
SubBruteState* instance = (SubBruteState*)context;
|
|
|
|
view_dispatcher_send_custom_event(instance->view_dispatcher, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void subbrute_scene_setup_attack_on_enter(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubBruteState* instance = (SubBruteState*)context;
|
|
|
|
SubBruteAttackView* view = instance->view_attack;
|
|
|
|
|
2022-09-25 13:05:52 +00:00
|
|
|
#ifdef FURI_DEBUG
|
|
|
|
FURI_LOG_D(TAG, "Enter Attack: %d", instance->device->attack);
|
|
|
|
#endif
|
2022-09-24 17:47:21 +00:00
|
|
|
|
|
|
|
subbrute_attack_view_init_values(
|
|
|
|
view,
|
2022-09-25 13:05:52 +00:00
|
|
|
instance->device->attack,
|
2022-09-24 17:47:21 +00:00
|
|
|
instance->device->max_value,
|
2022-09-25 13:05:52 +00:00
|
|
|
instance->device->key_index,
|
|
|
|
false);
|
2022-09-24 17:47:21 +00:00
|
|
|
|
2022-09-26 14:27:58 +00:00
|
|
|
if(!subbrute_worker_init_manual_transmit(
|
2022-09-26 16:14:33 +00:00
|
|
|
instance->worker,
|
|
|
|
instance->device->frequency,
|
|
|
|
instance->device->preset,
|
2022-10-05 18:27:13 +00:00
|
|
|
furi_string_get_cstr(instance->device->protocol_name))) {
|
2022-09-26 14:27:58 +00:00
|
|
|
FURI_LOG_W(TAG, "Worker init failed!");
|
|
|
|
}
|
2022-09-25 13:05:52 +00:00
|
|
|
|
|
|
|
instance->current_view = SubBruteViewAttack;
|
|
|
|
subbrute_attack_view_set_callback(view, subbrute_scene_setup_attack_callback, instance);
|
|
|
|
view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
|
2022-09-24 17:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void subbrute_scene_setup_attack_on_exit(void* context) {
|
|
|
|
furi_assert(context);
|
2022-09-25 17:31:33 +00:00
|
|
|
#ifdef FURI_DEBUG
|
|
|
|
FURI_LOG_D(TAG, "subbrute_scene_setup_attack_on_exit");
|
|
|
|
#endif
|
2022-09-24 17:47:21 +00:00
|
|
|
SubBruteState* instance = (SubBruteState*)context;
|
2022-09-25 21:07:16 +00:00
|
|
|
subbrute_worker_manual_transmit_stop(instance->worker);
|
2022-09-24 17:47:21 +00:00
|
|
|
notification_message(instance->notifications, &sequence_blink_stop);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
SubBruteState* instance = (SubBruteState*)context;
|
2022-09-25 13:05:52 +00:00
|
|
|
SubBruteAttackView* view = instance->view_attack;
|
2022-09-24 17:47:21 +00:00
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == SubBruteCustomEventTypeTransmitStarted) {
|
2022-09-26 16:14:33 +00:00
|
|
|
subbrute_worker_set_continuous_worker(instance->worker, false);
|
|
|
|
subbrute_attack_view_set_worker_type(view, false);
|
|
|
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
|
|
|
|
} else if(event.event == SubBruteCustomEventTypeTransmitContinuousStarted) {
|
|
|
|
// Setting different type of worker
|
|
|
|
subbrute_worker_set_continuous_worker(instance->worker, true);
|
|
|
|
subbrute_attack_view_set_worker_type(view, true);
|
2022-09-24 17:47:21 +00:00
|
|
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
|
2022-09-25 17:31:33 +00:00
|
|
|
} else if(event.event == SubBruteCustomEventTypeSaveFile) {
|
2022-09-25 21:07:16 +00:00
|
|
|
subbrute_worker_manual_transmit_stop(instance->worker);
|
2022-09-25 17:31:33 +00:00
|
|
|
|
|
|
|
subbrute_attack_view_init_values(
|
|
|
|
view,
|
|
|
|
instance->device->attack,
|
|
|
|
instance->device->max_value,
|
|
|
|
instance->device->key_index,
|
|
|
|
false);
|
2022-09-25 13:05:52 +00:00
|
|
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveName);
|
|
|
|
} else if(event.event == SubBruteCustomEventTypeBackPressed) {
|
2022-09-25 17:31:33 +00:00
|
|
|
#ifdef FURI_DEBUG
|
|
|
|
FURI_LOG_D(TAG, "SubBruteCustomEventTypeBackPressed");
|
|
|
|
#endif
|
2022-09-25 13:05:52 +00:00
|
|
|
instance->device->key_index = 0x00;
|
2022-09-25 20:07:14 +00:00
|
|
|
//subbrute_attack_view_stop_worker(view);
|
2022-09-25 17:31:33 +00:00
|
|
|
subbrute_attack_view_init_values(
|
|
|
|
view,
|
|
|
|
instance->device->attack,
|
|
|
|
instance->device->max_value,
|
|
|
|
instance->device->key_index,
|
|
|
|
false);
|
2022-09-24 17:47:21 +00:00
|
|
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
|
2022-09-25 13:05:52 +00:00
|
|
|
} else if(event.event == SubBruteCustomEventTypeChangeStepUp) {
|
|
|
|
// +1
|
2022-09-25 22:03:36 +00:00
|
|
|
if((instance->device->key_index + 1) - instance->device->max_value == 1) {
|
2022-09-25 21:48:51 +00:00
|
|
|
instance->device->key_index = 0x00;
|
|
|
|
} else {
|
|
|
|
uint64_t value = instance->device->key_index + 1;
|
|
|
|
if(value == instance->device->max_value) {
|
|
|
|
instance->device->key_index = value;
|
|
|
|
} else {
|
|
|
|
instance->device->key_index = value % instance->device->max_value;
|
|
|
|
}
|
|
|
|
}
|
2022-09-25 13:05:52 +00:00
|
|
|
subbrute_attack_view_set_current_step(view, instance->device->key_index);
|
|
|
|
} else if(event.event == SubBruteCustomEventTypeChangeStepUpMore) {
|
2022-09-26 17:15:46 +00:00
|
|
|
// +50
|
|
|
|
uint64_t value = instance->device->key_index + 50;
|
2022-09-25 21:48:51 +00:00
|
|
|
if(value == instance->device->max_value) {
|
|
|
|
instance->device->key_index += value;
|
|
|
|
} else {
|
|
|
|
instance->device->key_index = value % instance->device->max_value;
|
|
|
|
}
|
2022-09-25 13:05:52 +00:00
|
|
|
subbrute_attack_view_set_current_step(view, instance->device->key_index);
|
|
|
|
} else if(event.event == SubBruteCustomEventTypeChangeStepDown) {
|
|
|
|
// -1
|
2022-09-25 22:03:36 +00:00
|
|
|
if(instance->device->key_index - 1 == 0) {
|
2022-09-25 21:48:51 +00:00
|
|
|
instance->device->key_index = 0x00;
|
2022-09-25 22:03:36 +00:00
|
|
|
} else if(instance->device->key_index == 0) {
|
2022-09-25 21:48:51 +00:00
|
|
|
instance->device->key_index = instance->device->max_value;
|
|
|
|
} else {
|
|
|
|
uint64_t value = ((instance->device->key_index - 1) + instance->device->max_value);
|
|
|
|
if(value == instance->device->max_value) {
|
|
|
|
instance->device->key_index = value;
|
|
|
|
} else {
|
|
|
|
instance->device->key_index = value % instance->device->max_value;
|
|
|
|
}
|
|
|
|
}
|
2022-09-25 13:05:52 +00:00
|
|
|
subbrute_attack_view_set_current_step(view, instance->device->key_index);
|
|
|
|
} else if(event.event == SubBruteCustomEventTypeChangeStepDownMore) {
|
2022-09-26 17:15:46 +00:00
|
|
|
// -50
|
|
|
|
uint64_t value = ((instance->device->key_index - 50) + instance->device->max_value);
|
2022-09-25 21:48:51 +00:00
|
|
|
if(value == instance->device->max_value) {
|
|
|
|
instance->device->key_index = value;
|
|
|
|
} else {
|
|
|
|
instance->device->key_index = value % instance->device->max_value;
|
|
|
|
}
|
2022-09-25 13:05:52 +00:00
|
|
|
subbrute_attack_view_set_current_step(view, instance->device->key_index);
|
2022-09-24 17:47:21 +00:00
|
|
|
} else if(event.event == SubBruteCustomEventTypeTransmitCustom) {
|
2022-09-26 17:10:41 +00:00
|
|
|
if(subbrute_worker_can_manual_transmit(instance->worker, true)) {
|
2022-09-24 17:47:21 +00:00
|
|
|
// Blink
|
|
|
|
notification_message(instance->notifications, &sequence_blink_green_100);
|
|
|
|
|
2022-09-25 20:07:14 +00:00
|
|
|
// if(!subbrute_attack_view_is_worker_running(view)) {
|
|
|
|
// subbrute_attack_view_start_worker(
|
|
|
|
// view,
|
|
|
|
// instance->device->frequency,
|
|
|
|
// instance->device->preset,
|
2022-10-05 18:27:13 +00:00
|
|
|
// furi_string_get_cstr(instance->device->protocol_name));
|
2022-09-25 20:07:14 +00:00
|
|
|
// }
|
2022-09-24 17:47:21 +00:00
|
|
|
subbrute_device_create_packet_parsed(
|
2022-09-26 14:27:58 +00:00
|
|
|
instance->device, instance->device->key_index, false);
|
2022-09-25 21:07:16 +00:00
|
|
|
subbrute_worker_manual_transmit(instance->worker, instance->device->payload);
|
2022-09-24 17:47:21 +00:00
|
|
|
|
|
|
|
// Stop
|
|
|
|
notification_message(instance->notifications, &sequence_blink_stop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
// switch(event.event) {
|
|
|
|
// case SubBruteCustomEventTypeMenuSelected:
|
|
|
|
// with_view_model(
|
|
|
|
// view, (SubBruteMainViewModel * model) {
|
|
|
|
// instance->menu_index = model->index;
|
|
|
|
// return false;
|
|
|
|
// });
|
|
|
|
// scene_manager_next_scene(instance->scene_manager, SubBruteSceneLoadFile);
|
|
|
|
// consumed = true;
|
|
|
|
// break;
|
|
|
|
// case SubBruteCustomEventTypeLoadFile:
|
|
|
|
// with_view_model(
|
|
|
|
// view, (SubBruteMainViewModel * model) {
|
|
|
|
// instance->menu_index = model->index;
|
|
|
|
// return false;
|
|
|
|
// });
|
|
|
|
// scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
|
|
|
|
// consumed = true;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|