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-25 21:07:16 +00:00
|
|
|
subbrute_worker_init_manual_transmit(
|
|
|
|
instance->worker,
|
|
|
|
instance->device->frequency,
|
|
|
|
instance->device->preset,
|
|
|
|
string_get_cstr(instance->device->protocol_name));
|
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-25 22:03:36 +00:00
|
|
|
subbrute_device_create_packet_parsed(instance->device, instance->device->key_index);
|
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) {
|
|
|
|
// +100
|
2022-09-25 21:48:51 +00:00
|
|
|
uint64_t value = instance->device->key_index + 100;
|
|
|
|
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) {
|
|
|
|
// -100
|
2022-09-25 21:48:51 +00:00
|
|
|
uint64_t value = ((instance->device->key_index - 100) + 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);
|
2022-09-24 17:47:21 +00:00
|
|
|
} else if(event.event == SubBruteCustomEventTypeTransmitCustom) {
|
2022-09-25 21:07:16 +00:00
|
|
|
if(subbrute_worker_can_transmit(instance->worker)) {
|
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,
|
|
|
|
// string_get_cstr(instance->device->protocol_name));
|
|
|
|
// }
|
2022-09-24 17:47:21 +00:00
|
|
|
subbrute_device_create_packet_parsed(
|
|
|
|
instance->device, instance->device->key_index);
|
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;
|
|
|
|
}
|