Skip to content

Commit 63f1bd5

Browse files
authored
Merge pull request #3 from derskythe/feat/existing-file-two-bytes
Feat/existing file two bytes
2 parents bae275c + 82ddefd commit 63f1bd5

20 files changed

+587
-317
lines changed

application.fam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ App(
77
requires=["gui","dialogs"],
88
stack_size=2 * 1024,
99
order=11,
10-
fap_icon="subbrute_10px.png",
10+
fap_icon="images/subbrute_10px.png",
1111
fap_category="Tools",
1212
fap_icon_assets="images",
1313
)

helpers/gui_top_buttons.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "gui_top_buttons.h"
2+
3+
void elements_button_top_left(Canvas* canvas, const char* str) {
4+
const Icon* icon = &I_ButtonUp_7x4;
5+
6+
const uint8_t button_height = 12;
7+
const uint8_t vertical_offset = 3;
8+
const uint8_t horizontal_offset = 3;
9+
const uint8_t string_width = canvas_string_width(canvas, str);
10+
const uint8_t icon_h_offset = 3;
11+
const uint8_t icon_width_with_offset = icon_get_width(icon) + icon_h_offset;
12+
const uint8_t icon_v_offset = icon_get_height(icon) + vertical_offset;
13+
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
14+
15+
const uint8_t x = 0;
16+
const uint8_t y = 0 + button_height;
17+
18+
uint8_t line_x = x + button_width;
19+
uint8_t line_y = y - button_height;
20+
canvas_draw_box(canvas, x, line_y, button_width, button_height);
21+
canvas_draw_line(canvas, line_x + 0, line_y, line_x + 0, y - 1);
22+
canvas_draw_line(canvas, line_x + 1, line_y, line_x + 1, y - 2);
23+
canvas_draw_line(canvas, line_x + 2, line_y, line_x + 2, y - 3);
24+
25+
canvas_invert_color(canvas);
26+
canvas_draw_icon(canvas, x + horizontal_offset, y - icon_v_offset, icon);
27+
canvas_draw_str(
28+
canvas, x + horizontal_offset + icon_width_with_offset, y - vertical_offset, str);
29+
canvas_invert_color(canvas);
30+
}
31+
32+
void elements_button_top_right(Canvas* canvas, const char* str) {
33+
const Icon* icon = &I_ButtonDown_7x4;
34+
35+
const uint8_t button_height = 12;
36+
const uint8_t vertical_offset = 3;
37+
const uint8_t horizontal_offset = 3;
38+
const uint8_t string_width = canvas_string_width(canvas, str);
39+
const uint8_t icon_h_offset = 3;
40+
const uint8_t icon_width_with_offset = icon_get_width(icon) + icon_h_offset;
41+
const uint8_t icon_v_offset = icon_get_height(icon) + vertical_offset + 1;
42+
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
43+
44+
const uint8_t x = canvas_width(canvas);
45+
const uint8_t y = 0 + button_height;
46+
47+
uint8_t line_x = x - button_width;
48+
uint8_t line_y = y - button_height;
49+
canvas_draw_box(canvas, line_x, line_y, button_width, button_height);
50+
canvas_draw_line(canvas, line_x - 1, line_y, line_x - 1, y - 1);
51+
canvas_draw_line(canvas, line_x - 2, line_y, line_x - 2, y - 2);
52+
canvas_draw_line(canvas, line_x - 3, line_y, line_x - 3, y - 3);
53+
54+
canvas_invert_color(canvas);
55+
canvas_draw_str(canvas, x - button_width + horizontal_offset, y - vertical_offset, str);
56+
canvas_draw_icon(
57+
canvas, x - horizontal_offset - icon_get_width(icon), y - icon_v_offset, icon);
58+
canvas_invert_color(canvas);
59+
}

helpers/gui_top_buttons.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include <input/input.h>
4+
#include <gui/elements.h>
5+
#include <gui/icon.h>
6+
#include <gui/icon_animation.h>
7+
#include <assets_icons.h>
8+
9+
/**
10+
* Thanks to the author of metronome
11+
* @param canvas
12+
* @param str
13+
*/
14+
void elements_button_top_left(Canvas* canvas, const char* str);
15+
16+
/**
17+
* Thanks to the author of metronome
18+
* @param canvas
19+
* @param str
20+
*/
21+
void elements_button_top_right(Canvas* canvas, const char* str);

helpers/subbrute_worker.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ bool subbrute_worker_init_default_attack(
9696
instance->te = protocol->te;
9797
instance->repeat = protocol->repeat + extra_repeats;
9898
instance->load_index = 0;
99-
instance->file_key = NULL;
100-
instance->max_value = subbrute_protocol_calc_max_value(instance->attack, instance->bits);
99+
instance->file_key = 0;
100+
instance->two_bytes = false;
101+
102+
instance->max_value =
103+
subbrute_protocol_calc_max_value(instance->attack, instance->bits, instance->two_bytes);
101104

102105
instance->initiated = true;
103106
instance->state = SubBruteWorkerStateReady;
@@ -122,9 +125,10 @@ bool subbrute_worker_init_file_attack(
122125
SubBruteWorker* instance,
123126
uint64_t step,
124127
uint8_t load_index,
125-
const char* file_key,
128+
uint64_t file_key,
126129
SubBruteProtocol* protocol,
127-
uint8_t extra_repeats) {
130+
uint8_t extra_repeats,
131+
bool two_bytes) {
128132
furi_assert(instance);
129133

130134
if(instance->worker_running) {
@@ -142,22 +146,26 @@ bool subbrute_worker_init_file_attack(
142146
instance->load_index = load_index;
143147
instance->repeat = protocol->repeat + extra_repeats;
144148
instance->file_key = file_key;
145-
instance->max_value = subbrute_protocol_calc_max_value(instance->attack, instance->bits);
149+
instance->two_bytes = two_bytes;
150+
151+
instance->max_value =
152+
subbrute_protocol_calc_max_value(instance->attack, instance->bits, instance->two_bytes);
146153

147154
instance->initiated = true;
148155
instance->state = SubBruteWorkerStateReady;
149156
subbrute_worker_send_callback(instance);
150157
#ifdef FURI_DEBUG
151158
FURI_LOG_I(
152159
TAG,
153-
"subbrute_worker_init_file_attack: %s, bits: %d, preset: %s, file: %s, te: %d, repeat: %d, max_value: %lld",
160+
"subbrute_worker_init_file_attack: %s, bits: %d, preset: %s, file: %s, te: %d, repeat: %d, max_value: %lld, key: %llX",
154161
subbrute_protocol_name(instance->attack),
155162
instance->bits,
156163
subbrute_protocol_preset(instance->preset),
157164
subbrute_protocol_file(instance->file),
158165
instance->te,
159166
instance->repeat,
160-
instance->max_value);
167+
instance->max_value,
168+
instance->file_key);
161169
#endif
162170

163171
return true;
@@ -244,7 +252,8 @@ bool subbrute_worker_transmit_current_key(SubBruteWorker* instance, uint64_t ste
244252
instance->te,
245253
instance->repeat,
246254
instance->load_index,
247-
instance->file_key);
255+
instance->file_key,
256+
instance->two_bytes);
248257
} else {
249258
subbrute_protocol_default_payload(
250259
stream, step, instance->bits, instance->te, instance->repeat);
@@ -373,7 +382,8 @@ int32_t subbrute_worker_thread(void* context) {
373382
instance->te,
374383
instance->repeat,
375384
instance->load_index,
376-
instance->file_key);
385+
instance->file_key,
386+
instance->two_bytes);
377387
} else {
378388
subbrute_protocol_default_payload(
379389
stream, instance->step, instance->bits, instance->te, instance->repeat);

helpers/subbrute_worker.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ bool subbrute_worker_init_file_attack(
2828
SubBruteWorker* instance,
2929
uint64_t step,
3030
uint8_t load_index,
31-
const char* file_key,
31+
uint64_t file_key,
3232
SubBruteProtocol* protocol,
33-
uint8_t extra_repeats);
33+
uint8_t extra_repeats,
34+
bool two_bytes);
3435
bool subbrute_worker_start(SubBruteWorker* instance);
3536
void subbrute_worker_stop(SubBruteWorker* instance);
3637
bool subbrute_worker_transmit_current_key(SubBruteWorker* instance, uint64_t step);

helpers/subbrute_worker_private.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ struct SubBruteWorker {
3131
uint8_t te;
3232
uint8_t repeat;
3333
uint8_t load_index; // Index of group to bruteforce in loaded file
34-
const char* file_key;
34+
uint64_t file_key;
3535
uint64_t max_value; // Max step
36+
bool two_bytes;
3637

3738
// Manual transmit
3839
uint32_t last_time_tx_data;
File renamed without changes.

scenes/subbrute_scene_load_file.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33

44
#define TAG "SubBruteSceneLoadFile"
55

6-
//void subbrute_scene_load_file_callback(SubBruteCustomEvent event, void* context) {
7-
//// furi_assert(context);
8-
////
9-
//// SubBruteState* instance = (SubBruteState*)context;
10-
//// view_dispatcher_send_custom_event(instance->view_dispatcher, event);
11-
//}
12-
136
void subbrute_scene_load_file_on_enter(void* context) {
147
furi_assert(context);
158
SubBruteState* instance = (SubBruteState*)context;
@@ -24,8 +17,14 @@ void subbrute_scene_load_file_on_enter(void* context) {
2417
dialog_file_browser_set_basic_options(&browser_options, SUBBRUTE_FILE_EXT, &I_sub1_10px);
2518

2619
SubBruteFileResult load_result = SubBruteFileResultUnknown;
20+
// TODO: DELETE IT
21+
#ifdef SUBBRUTE_FAST_TRACK
22+
bool res = true;
23+
furi_string_printf(load_path, "%s", "/ext/subghz/princeton.sub");
24+
#else
2725
bool res =
2826
dialog_file_browser_show(instance->dialogs, load_path, app_folder, &browser_options);
27+
#endif
2928
#ifdef FURI_DEBUG
3029
FURI_LOG_D(
3130
TAG,
@@ -44,11 +43,12 @@ void subbrute_scene_load_file_on_enter(void* context) {
4443
if(load_result == SubBruteFileResultOk) {
4544
if(!subbrute_worker_init_file_attack(
4645
instance->worker,
47-
instance->device->key_index,
48-
instance->device->load_index,
49-
instance->device->file_key,
46+
instance->device->current_step,
47+
instance->device->bit_index,
48+
instance->device->key_from_file,
5049
instance->device->file_protocol_info,
51-
extra_repeats)) {
50+
extra_repeats,
51+
instance->device->two_bytes)) {
5252
furi_crash("Invalid attack set!");
5353
}
5454
// Ready to run!

scenes/subbrute_scene_load_select.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ void subbrute_scene_load_select_on_enter(void* context) {
2020

2121
instance->current_view = SubBruteViewMain;
2222
subbrute_main_view_set_callback(view, subbrute_scene_load_select_callback, instance);
23-
subbrute_main_view_set_index(view, 7, true, instance->device->file_key);
23+
subbrute_main_view_set_index(
24+
view, 7, true, instance->device->two_bytes, instance->device->key_from_file);
2425

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

3940
if(event.type == SceneManagerEventTypeCustom) {
4041
if(event.event == SubBruteCustomEventTypeIndexSelected) {
41-
instance->device->load_index = subbrute_main_view_get_index(instance->view_main);
42+
/*#ifdef FURI_DEBUG && !SUBBRUTE_FAST_TRACK
43+
view_dispatcher_stop(instance->view_dispatcher);
44+
consumed = true;
45+
#else*/
46+
instance->device->current_step = 0;
47+
instance->device->bit_index = subbrute_main_view_get_index(instance->view_main);
48+
instance->device->two_bytes = subbrute_main_view_get_two_bytes(instance->view_main);
4249
uint8_t extra_repeats = subbrute_main_view_get_extra_repeats(instance->view_main);
50+
instance->device->max_value = subbrute_protocol_calc_max_value(
51+
instance->device->attack,
52+
instance->device->bit_index,
53+
instance->device->two_bytes);
4354

4455
if(!subbrute_worker_init_file_attack(
4556
instance->worker,
46-
instance->device->key_index,
47-
instance->device->load_index,
48-
instance->device->file_key,
57+
instance->device->current_step,
58+
instance->device->bit_index,
59+
instance->device->key_from_file,
4960
instance->device->file_protocol_info,
50-
extra_repeats)) {
61+
extra_repeats,
62+
instance->device->two_bytes)) {
5163
furi_crash("Invalid attack set!");
5264
}
5365
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
66+
/*#endif*/
5467
consumed = true;
55-
}
68+
} /* else if(event.event == SubBruteCustomEventTypeChangeStepUp) {
69+
instance->device->two_bytes = true;
70+
} else if(event.event == SubBruteCustomEventTypeChangeStepDown) {
71+
instance->device->two_bytes = false;
72+
}*/
5673
} else if(event.type == SceneManagerEventTypeBack) {
5774
if(!scene_manager_search_and_switch_to_previous_scene(
5875
instance->scene_manager, SubBruteSceneStart)) {

scenes/subbrute_scene_run_attack.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void subbrute_scene_run_attack_on_enter(void* context) {
4545
instance->worker, subbrute_scene_run_attack_device_state_changed, instance);
4646

4747
if(!subbrute_worker_is_running(instance->worker)) {
48-
subbrute_worker_set_step(instance->worker, instance->device->key_index);
48+
subbrute_worker_set_step(instance->worker, instance->device->current_step);
4949
if(!subbrute_worker_start(instance->worker)) {
5050
view_dispatcher_send_custom_event(
5151
instance->view_dispatcher, SubBruteCustomEventTypeError);
@@ -64,7 +64,7 @@ bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event)
6464

6565
if(event.type == SceneManagerEventTypeCustom) {
6666
uint64_t step = subbrute_worker_get_step(instance->worker);
67-
instance->device->key_index = step;
67+
instance->device->current_step = step;
6868
subbrute_attack_view_set_current_step(view, step);
6969

7070
if(event.event == SubBruteCustomEventTypeTransmitFinished) {
@@ -89,12 +89,12 @@ bool subbrute_scene_run_attack_on_event(void* context, SceneManagerEvent event)
8989
scene_manager_search_and_switch_to_previous_scene(
9090
instance->scene_manager, SubBruteSceneSetupAttack);
9191
} else if(event.event == SubBruteCustomEventTypeUpdateView) {
92-
//subbrute_attack_view_set_current_step(view, instance->device->key_index);
92+
//subbrute_attack_view_set_current_step(view, instance->device->current_step);
9393
}
9494
consumed = true;
9595
} else if(event.type == SceneManagerEventTypeTick) {
9696
uint64_t step = subbrute_worker_get_step(instance->worker);
97-
instance->device->key_index = step;
97+
instance->device->current_step = step;
9898
subbrute_attack_view_set_current_step(view, step);
9999

100100
consumed = true;

0 commit comments

Comments
 (0)