Skip to content

Commit

Permalink
Merge pull request #3 from derskythe/feat/existing-file-two-bytes
Browse files Browse the repository at this point in the history
Feat/existing file two bytes
  • Loading branch information
derskythe authored Dec 2, 2022
2 parents bae275c + 82ddefd commit 63f1bd5
Show file tree
Hide file tree
Showing 20 changed files with 587 additions and 317 deletions.
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ App(
requires=["gui","dialogs"],
stack_size=2 * 1024,
order=11,
fap_icon="subbrute_10px.png",
fap_icon="images/subbrute_10px.png",
fap_category="Tools",
fap_icon_assets="images",
)
59 changes: 59 additions & 0 deletions helpers/gui_top_buttons.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "gui_top_buttons.h"

void elements_button_top_left(Canvas* canvas, const char* str) {
const Icon* icon = &I_ButtonUp_7x4;

const uint8_t button_height = 12;
const uint8_t vertical_offset = 3;
const uint8_t horizontal_offset = 3;
const uint8_t string_width = canvas_string_width(canvas, str);
const uint8_t icon_h_offset = 3;
const uint8_t icon_width_with_offset = icon_get_width(icon) + icon_h_offset;
const uint8_t icon_v_offset = icon_get_height(icon) + vertical_offset;
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;

const uint8_t x = 0;
const uint8_t y = 0 + button_height;

uint8_t line_x = x + button_width;
uint8_t line_y = y - button_height;
canvas_draw_box(canvas, x, line_y, button_width, button_height);
canvas_draw_line(canvas, line_x + 0, line_y, line_x + 0, y - 1);
canvas_draw_line(canvas, line_x + 1, line_y, line_x + 1, y - 2);
canvas_draw_line(canvas, line_x + 2, line_y, line_x + 2, y - 3);

canvas_invert_color(canvas);
canvas_draw_icon(canvas, x + horizontal_offset, y - icon_v_offset, icon);
canvas_draw_str(
canvas, x + horizontal_offset + icon_width_with_offset, y - vertical_offset, str);
canvas_invert_color(canvas);
}

void elements_button_top_right(Canvas* canvas, const char* str) {
const Icon* icon = &I_ButtonDown_7x4;

const uint8_t button_height = 12;
const uint8_t vertical_offset = 3;
const uint8_t horizontal_offset = 3;
const uint8_t string_width = canvas_string_width(canvas, str);
const uint8_t icon_h_offset = 3;
const uint8_t icon_width_with_offset = icon_get_width(icon) + icon_h_offset;
const uint8_t icon_v_offset = icon_get_height(icon) + vertical_offset + 1;
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;

const uint8_t x = canvas_width(canvas);
const uint8_t y = 0 + button_height;

uint8_t line_x = x - button_width;
uint8_t line_y = y - button_height;
canvas_draw_box(canvas, line_x, line_y, button_width, button_height);
canvas_draw_line(canvas, line_x - 1, line_y, line_x - 1, y - 1);
canvas_draw_line(canvas, line_x - 2, line_y, line_x - 2, y - 2);
canvas_draw_line(canvas, line_x - 3, line_y, line_x - 3, y - 3);

canvas_invert_color(canvas);
canvas_draw_str(canvas, x - button_width + horizontal_offset, y - vertical_offset, str);
canvas_draw_icon(
canvas, x - horizontal_offset - icon_get_width(icon), y - icon_v_offset, icon);
canvas_invert_color(canvas);
}
21 changes: 21 additions & 0 deletions helpers/gui_top_buttons.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <input/input.h>
#include <gui/elements.h>
#include <gui/icon.h>
#include <gui/icon_animation.h>
#include <assets_icons.h>

/**
* Thanks to the author of metronome
* @param canvas
* @param str
*/
void elements_button_top_left(Canvas* canvas, const char* str);

/**
* Thanks to the author of metronome
* @param canvas
* @param str
*/
void elements_button_top_right(Canvas* canvas, const char* str);
28 changes: 19 additions & 9 deletions helpers/subbrute_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ bool subbrute_worker_init_default_attack(
instance->te = protocol->te;
instance->repeat = protocol->repeat + extra_repeats;
instance->load_index = 0;
instance->file_key = NULL;
instance->max_value = subbrute_protocol_calc_max_value(instance->attack, instance->bits);
instance->file_key = 0;
instance->two_bytes = false;

instance->max_value =
subbrute_protocol_calc_max_value(instance->attack, instance->bits, instance->two_bytes);

instance->initiated = true;
instance->state = SubBruteWorkerStateReady;
Expand All @@ -122,9 +125,10 @@ bool subbrute_worker_init_file_attack(
SubBruteWorker* instance,
uint64_t step,
uint8_t load_index,
const char* file_key,
uint64_t file_key,
SubBruteProtocol* protocol,
uint8_t extra_repeats) {
uint8_t extra_repeats,
bool two_bytes) {
furi_assert(instance);

if(instance->worker_running) {
Expand All @@ -142,22 +146,26 @@ bool subbrute_worker_init_file_attack(
instance->load_index = load_index;
instance->repeat = protocol->repeat + extra_repeats;
instance->file_key = file_key;
instance->max_value = subbrute_protocol_calc_max_value(instance->attack, instance->bits);
instance->two_bytes = two_bytes;

instance->max_value =
subbrute_protocol_calc_max_value(instance->attack, instance->bits, instance->two_bytes);

instance->initiated = true;
instance->state = SubBruteWorkerStateReady;
subbrute_worker_send_callback(instance);
#ifdef FURI_DEBUG
FURI_LOG_I(
TAG,
"subbrute_worker_init_file_attack: %s, bits: %d, preset: %s, file: %s, te: %d, repeat: %d, max_value: %lld",
"subbrute_worker_init_file_attack: %s, bits: %d, preset: %s, file: %s, te: %d, repeat: %d, max_value: %lld, key: %llX",
subbrute_protocol_name(instance->attack),
instance->bits,
subbrute_protocol_preset(instance->preset),
subbrute_protocol_file(instance->file),
instance->te,
instance->repeat,
instance->max_value);
instance->max_value,
instance->file_key);
#endif

return true;
Expand Down Expand Up @@ -244,7 +252,8 @@ bool subbrute_worker_transmit_current_key(SubBruteWorker* instance, uint64_t ste
instance->te,
instance->repeat,
instance->load_index,
instance->file_key);
instance->file_key,
instance->two_bytes);
} else {
subbrute_protocol_default_payload(
stream, step, instance->bits, instance->te, instance->repeat);
Expand Down Expand Up @@ -373,7 +382,8 @@ int32_t subbrute_worker_thread(void* context) {
instance->te,
instance->repeat,
instance->load_index,
instance->file_key);
instance->file_key,
instance->two_bytes);
} else {
subbrute_protocol_default_payload(
stream, instance->step, instance->bits, instance->te, instance->repeat);
Expand Down
5 changes: 3 additions & 2 deletions helpers/subbrute_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ bool subbrute_worker_init_file_attack(
SubBruteWorker* instance,
uint64_t step,
uint8_t load_index,
const char* file_key,
uint64_t file_key,
SubBruteProtocol* protocol,
uint8_t extra_repeats);
uint8_t extra_repeats,
bool two_bytes);
bool subbrute_worker_start(SubBruteWorker* instance);
void subbrute_worker_stop(SubBruteWorker* instance);
bool subbrute_worker_transmit_current_key(SubBruteWorker* instance, uint64_t step);
Expand Down
3 changes: 2 additions & 1 deletion helpers/subbrute_worker_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ struct SubBruteWorker {
uint8_t te;
uint8_t repeat;
uint8_t load_index; // Index of group to bruteforce in loaded file
const char* file_key;
uint64_t file_key;
uint64_t max_value; // Max step
bool two_bytes;

// Manual transmit
uint32_t last_time_tx_data;
Expand Down
File renamed without changes
22 changes: 11 additions & 11 deletions scenes/subbrute_scene_load_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@

#define TAG "SubBruteSceneLoadFile"

//void subbrute_scene_load_file_callback(SubBruteCustomEvent event, void* context) {
//// furi_assert(context);
////
//// SubBruteState* instance = (SubBruteState*)context;
//// view_dispatcher_send_custom_event(instance->view_dispatcher, event);
//}

void subbrute_scene_load_file_on_enter(void* context) {
furi_assert(context);
SubBruteState* instance = (SubBruteState*)context;
Expand All @@ -24,8 +17,14 @@ void subbrute_scene_load_file_on_enter(void* context) {
dialog_file_browser_set_basic_options(&browser_options, SUBBRUTE_FILE_EXT, &I_sub1_10px);

SubBruteFileResult load_result = SubBruteFileResultUnknown;
// TODO: DELETE IT
#ifdef SUBBRUTE_FAST_TRACK
bool res = true;
furi_string_printf(load_path, "%s", "/ext/subghz/princeton.sub");
#else
bool res =
dialog_file_browser_show(instance->dialogs, load_path, app_folder, &browser_options);
#endif
#ifdef FURI_DEBUG
FURI_LOG_D(
TAG,
Expand All @@ -44,11 +43,12 @@ void subbrute_scene_load_file_on_enter(void* context) {
if(load_result == SubBruteFileResultOk) {
if(!subbrute_worker_init_file_attack(
instance->worker,
instance->device->key_index,
instance->device->load_index,
instance->device->file_key,
instance->device->current_step,
instance->device->bit_index,
instance->device->key_from_file,
instance->device->file_protocol_info,
extra_repeats)) {
extra_repeats,
instance->device->two_bytes)) {
furi_crash("Invalid attack set!");
}
// Ready to run!
Expand Down
31 changes: 24 additions & 7 deletions scenes/subbrute_scene_load_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ void subbrute_scene_load_select_on_enter(void* context) {

instance->current_view = SubBruteViewMain;
subbrute_main_view_set_callback(view, subbrute_scene_load_select_callback, instance);
subbrute_main_view_set_index(view, 7, true, instance->device->file_key);
subbrute_main_view_set_index(
view, 7, true, instance->device->two_bytes, instance->device->key_from_file);

view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
}
Expand All @@ -38,21 +39,37 @@ bool subbrute_scene_load_select_on_event(void* context, SceneManagerEvent event)

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubBruteCustomEventTypeIndexSelected) {
instance->device->load_index = subbrute_main_view_get_index(instance->view_main);
/*#ifdef FURI_DEBUG && !SUBBRUTE_FAST_TRACK
view_dispatcher_stop(instance->view_dispatcher);
consumed = true;
#else*/
instance->device->current_step = 0;
instance->device->bit_index = subbrute_main_view_get_index(instance->view_main);
instance->device->two_bytes = subbrute_main_view_get_two_bytes(instance->view_main);
uint8_t extra_repeats = subbrute_main_view_get_extra_repeats(instance->view_main);
instance->device->max_value = subbrute_protocol_calc_max_value(
instance->device->attack,
instance->device->bit_index,
instance->device->two_bytes);

if(!subbrute_worker_init_file_attack(
instance->worker,
instance->device->key_index,
instance->device->load_index,
instance->device->file_key,
instance->device->current_step,
instance->device->bit_index,
instance->device->key_from_file,
instance->device->file_protocol_info,
extra_repeats)) {
extra_repeats,
instance->device->two_bytes)) {
furi_crash("Invalid attack set!");
}
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
/*#endif*/
consumed = true;
}
} /* else if(event.event == SubBruteCustomEventTypeChangeStepUp) {
instance->device->two_bytes = true;
} else if(event.event == SubBruteCustomEventTypeChangeStepDown) {
instance->device->two_bytes = false;
}*/
} else if(event.type == SceneManagerEventTypeBack) {
if(!scene_manager_search_and_switch_to_previous_scene(
instance->scene_manager, SubBruteSceneStart)) {
Expand Down
8 changes: 4 additions & 4 deletions scenes/subbrute_scene_run_attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ 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);
subbrute_worker_set_step(instance->worker, instance->device->current_step);
if(!subbrute_worker_start(instance->worker)) {
view_dispatcher_send_custom_event(
instance->view_dispatcher, SubBruteCustomEventTypeError);
Expand All @@ -64,7 +64,7 @@ bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event)

if(event.type == SceneManagerEventTypeCustom) {
uint64_t step = subbrute_worker_get_step(instance->worker);
instance->device->key_index = step;
instance->device->current_step = step;
subbrute_attack_view_set_current_step(view, step);

if(event.event == SubBruteCustomEventTypeTransmitFinished) {
Expand All @@ -89,12 +89,12 @@ bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event)
scene_manager_search_and_switch_to_previous_scene(
instance->scene_manager, SubBruteSceneSetupAttack);
} else if(event.event == SubBruteCustomEventTypeUpdateView) {
//subbrute_attack_view_set_current_step(view, instance->device->key_index);
//subbrute_attack_view_set_current_step(view, instance->device->current_step);
}
consumed = true;
} else if(event.type == SceneManagerEventTypeTick) {
uint64_t step = subbrute_worker_get_step(instance->worker);
instance->device->key_index = step;
instance->device->current_step = step;
subbrute_attack_view_set_current_step(view, step);

consumed = true;
Expand Down
14 changes: 7 additions & 7 deletions scenes/subbrute_scene_setup_attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ void subbrute_scene_setup_attack_on_enter(void* context) {
instance->worker, subbrute_scene_setup_attack_device_state_changed, context);
if(subbrute_worker_is_running(instance->worker)) {
subbrute_worker_stop(instance->worker);
instance->device->key_index = subbrute_worker_get_step(instance->worker);
instance->device->current_step = subbrute_worker_get_step(instance->worker);
}

subbrute_attack_view_init_values(
view,
instance->device->attack,
instance->device->max_value,
instance->device->key_index,
instance->device->current_step,
false,
instance->device->extra_repeats);

Expand Down Expand Up @@ -77,7 +77,7 @@ bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event
view,
instance->device->attack,
instance->device->max_value,
instance->device->key_index,
instance->device->current_step,
false,
instance->device->extra_repeats);
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveName);
Expand All @@ -86,7 +86,7 @@ bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event
view,
instance->device->attack,
instance->device->max_value,
instance->device->key_index,
instance->device->current_step,
false,
instance->device->extra_repeats);
scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
Expand All @@ -99,7 +99,7 @@ bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event
// Blink
notification_message(instance->notifications, &sequence_blink_green_100);
subbrute_worker_transmit_current_key(
instance->worker, instance->device->key_index);
instance->worker, instance->device->current_step);
// Stop
notification_message(instance->notifications, &sequence_blink_stop);
}
Expand Down Expand Up @@ -128,9 +128,9 @@ bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event
consumed = true;
} else if(event.type == SceneManagerEventTypeTick) {
if(subbrute_worker_is_running(instance->worker)) {
instance->device->key_index = subbrute_worker_get_step(instance->worker);
instance->device->current_step = subbrute_worker_get_step(instance->worker);
}
subbrute_attack_view_set_current_step(view, instance->device->key_index);
subbrute_attack_view_set_current_step(view, instance->device->current_step);
consumed = true;
}

Expand Down
Loading

0 comments on commit 63f1bd5

Please sign in to comment.