Working prototype, but not yet tested on a real device

This commit is contained in:
DerSkythe
2022-09-25 17:05:52 +04:00
parent 666821e9ce
commit ec9ce0cad7
14 changed files with 465 additions and 199 deletions
@@ -18,8 +18,8 @@ struct SubBruteAttackView {
typedef struct {
SubBruteAttacks index;
uint8_t max_value;
uint8_t current_step;
uint64_t max_value;
uint64_t current_step;
bool is_attacking;
} SubBruteAttackViewModel;
@@ -44,6 +44,11 @@ bool subbrute_attack_view_input(InputEvent* event, void* context) {
if(event->key == InputKeyBack && event->type == InputTypeShort) {
instance->callback(SubBruteCustomEventTypeBackPressed, instance->context);
with_view_model(
instance->view, (SubBruteAttackViewModel * model) {
model->is_attacking = false;
return true;
});
return true;
}
@@ -62,7 +67,11 @@ bool subbrute_attack_view_input(InputEvent* event, void* context) {
// }
if(!is_attacking) {
if(event->key == InputKeyOk) {
if((event->type == InputTypeShort || event->type == InputTypeRepeat) &&
event->key == InputKeyOk) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "InputKey: %d OK", event->key);
#endif
with_view_model(
instance->view, (SubBruteAttackViewModel * model) {
model->is_attacking = true;
@@ -76,11 +85,39 @@ bool subbrute_attack_view_input(InputEvent* event, void* context) {
// instance->callback(SubBruteCustomEventTypeBackPressed, instance->context);
// }
} else if(event->key == InputKeyUp) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "InputKey: %d UP", event->key);
#endif
instance->callback(SubBruteCustomEventTypeSaveFile, instance->context);
} else if(event->key == InputKeyDown) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "InputKey: %d DOWN", event->key);
#endif
instance->callback(SubBruteCustomEventTypeTransmitCustom, instance->context);
} else if(event->type == InputTypePress) {
with_view_model(
} else if(event->type == InputTypeShort) {
if(event->key == InputKeyLeft) {
instance->callback(SubBruteCustomEventTypeChangeStepDown, instance->context);
} else if(event->key == InputKeyRight) {
instance->callback(SubBruteCustomEventTypeChangeStepUp, instance->context);
}
// with_view_model(
// instance->view, (SubBruteAttackViewModel * model) {
// if(event->key == InputKeyLeft) {
// model->current_step =
// ((model->current_step - 1) + model->max_value) % model->max_value;
// } else if(event->key == InputKeyRight) {
// model->current_step = (model->current_step + 1) % model->max_value;
// }
// return true;
// });
// instance->callback(SubBruteCustomEventTypeChangeStep, instance->context);
} else if(event->type == InputTypeRepeat) {
if(event->key == InputKeyLeft) {
instance->callback(SubBruteCustomEventTypeChangeStepDownMore, instance->context);
} else if(event->key == InputKeyRight) {
instance->callback(SubBruteCustomEventTypeChangeStepUpMore, instance->context);
}
/*with_view_model(
instance->view, (SubBruteAttackViewModel * model) {
if(event->key == InputKeyLeft) {
model->current_step =
@@ -90,19 +127,7 @@ bool subbrute_attack_view_input(InputEvent* event, void* context) {
}
return true;
});
instance->callback(SubBruteCustomEventTypeChangeStep, instance->context);
} else if(event->type == InputTypeShort || event->type == InputTypeRepeat) {
with_view_model(
instance->view, (SubBruteAttackViewModel * model) {
if(event->key == InputKeyLeft) {
model->current_step =
((model->current_step - 1) + model->max_value) % model->max_value;
} else if(event->key == InputKeyRight) {
model->current_step = (model->current_step + 1) % model->max_value;
}
return true;
});
instance->callback(SubBruteCustomEventTypeChangeStep, instance->context);
instance->callback(SubBruteCustomEventTypeChangeStep, instance->context);*/
}
} else {
if((event->type == InputTypeShort || event->type == InputTypeRepeat) &&
@@ -146,6 +171,9 @@ void subbrute_attack_view_enter(void* context) {
void subbrute_attack_view_free(SubBruteAttackView* instance) {
furi_assert(instance);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subbrute_attack_view_free");
#endif
subbrute_worker_free(instance->worker);
view_free(instance->view);
@@ -157,7 +185,8 @@ View* subbrute_attack_view_get_view(SubBruteAttackView* instance) {
return instance->view;
}
void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint8_t current_step) {
void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint64_t current_step) {
furi_assert(instance);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "Set step: %d", current_step);
#endif
@@ -168,8 +197,8 @@ void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint8_t
});
}
uint8_t subbrute_attack_view_get_current_step(SubBruteAttackView* instance) {
uint8_t current_step;
uint64_t subbrute_attack_view_get_current_step(SubBruteAttackView* instance) {
uint64_t current_step;
with_view_model(
instance->view, (SubBruteAttackViewModel * model) {
current_step = model->current_step;
@@ -186,25 +215,33 @@ uint8_t subbrute_attack_view_get_current_step(SubBruteAttackView* instance) {
void subbrute_attack_view_init_values(
SubBruteAttackView* instance,
uint8_t index,
uint8_t max_value,
uint8_t current_step) {
uint64_t max_value,
uint64_t current_step,
bool is_attacking) {
#ifdef FURI_DEBUG
FURI_LOG_D(
TAG, "init, index: %d, max_value: %d, current_step: %d", index, max_value, current_step);
#endif
with_view_model(
instance->view, (SubBruteAttackViewModel * model) {
model->max_value = max_value;
model->index = index;
model->current_step = current_step;
model->is_attacking = is_attacking;
return true;
});
}
void subbrute_attack_view_stop_worker(SubBruteAttackView* instance) {
furi_assert(instance);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subbrute_attack_view_stop_worker");
#endif
subbrute_worker_stop(instance->worker);
}
bool subbrute_attack_view_can_send(SubBruteAttackView* instance) {
furi_assert(instance);
return subbrute_worker_can_transmit(instance->worker);
}
@@ -212,14 +249,22 @@ void subbrute_attack_view_start_worker(
SubBruteAttackView* instance,
uint32_t frequency,
FuriHalSubGhzPreset preset,
string_t protocol_name) {
const char* protocol_name) {
furi_assert(instance);
#ifdef FURI_DEBUG
FURI_LOG_D(
TAG,
"start_worker. frequency: %d, preset: %d, protocol_name: %s",
frequency,
preset,
protocol_name);
#endif
if(!subbrute_worker_is_running(instance->worker)) {
subbrute_worker_start(instance->worker, frequency, preset, protocol_name);
}
}
bool subbrute_attack_view_transmit(SubBruteAttackView* instance, string_t payload) {
bool subbrute_attack_view_transmit(SubBruteAttackView* instance, const char* payload) {
furi_assert(instance);
return subbrute_worker_transmit(instance->worker, payload);
@@ -245,21 +290,25 @@ 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 vertical_offset = 9; //
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->width + icon_h_offset;
const uint8_t icon_v_offset = icon->height + vertical_offset;
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
const uint8_t icon_v_offset = icon->height; //
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset + 1;
const uint8_t x = 0;
const uint8_t y = 0;
canvas_draw_box(canvas, x, y - button_height, button_width, button_height);
canvas_draw_line(canvas, x + button_width - 0, y, x + button_width - 0, y + button_height - 0);
canvas_draw_line(canvas, x + button_width - 1, y, x + button_width - 1, y + button_height - 1);
canvas_draw_line(canvas, x + button_width - 2, y, x + button_width - 2, y + button_height - 2);
canvas_draw_box(canvas, x, y, button_width, button_height);
#ifdef FURI_DEBUG
FURI_LOG_D(
TAG, "lbox, x: %d, y: %d, width: %d, height: %d", x, y, button_width, button_height);
#endif
// canvas_draw_line(canvas, x + button_width + 0, y, x + button_width + 0, y + button_height - 0); //
// canvas_draw_line(canvas, x + button_width + 1, y, x + button_width + 1, y + button_height - 1);
// canvas_draw_line(canvas, x + button_width + 2, y, x + button_width + 2, y + button_height - 2);
canvas_invert_color(canvas);
canvas_draw_icon(canvas, x + horizontal_offset, y + icon_v_offset, icon);
@@ -272,45 +321,66 @@ 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 vertical_offset = 9;
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->width + icon_h_offset;
const uint8_t icon_v_offset = icon->height + vertical_offset;
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
const uint8_t icon_v_offset = icon->height; // + vertical_offset;
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset + 1;
const uint8_t x = canvas_width(canvas);
const uint8_t y = 0;
canvas_draw_box(canvas, x - button_width, y - button_height, button_width, button_height);
canvas_draw_line(canvas, x - button_width - 1, y, x + button_width + 1, y + button_height - 0);
canvas_draw_line(canvas, x - button_width - 2, y, x + button_width + 2, y + button_height - 1);
canvas_draw_line(canvas, x - button_width - 3, y, x + button_width + 3, y + button_height - 2);
canvas_draw_box(canvas, x - button_width, y, button_width, button_height);
#ifdef FURI_DEBUG
FURI_LOG_D(
TAG,
"rbox, x: %d, y: %d, width: %d, height: %d",
x - button_width,
y,
button_width,
button_height);
#endif
// canvas_draw_line(canvas, x - button_width - 1, y, x + button_width - 1, y + button_height - 0);
// canvas_draw_line(canvas, x - button_width - 2, y, x + button_width - 2, y + button_height - 1);
// canvas_draw_line(canvas, x - button_width - 3, y, x + button_width - 3, y + button_height - 2);
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->width, y - icon_v_offset, icon);
canvas_draw_str(canvas, x - button_width + horizontal_offset, y + vertical_offset, str);
canvas_draw_icon(canvas, x - horizontal_offset - icon->width, y + icon_v_offset, icon);
canvas_invert_color(canvas);
}
void subbrute_attack_view_draw(Canvas* canvas, void* context) {
furi_assert(context);
SubBruteAttackViewModel* model = (SubBruteAttackViewModel*)context;
//char buffer[64];
char buffer[26];
// Title
const char* attack_name = NULL;
attack_name = subbrute_get_menu_name(model->index);
canvas_set_color(canvas, ColorBlack);
// Title
if(model->is_attacking) {
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, attack_name);
}
// Value
canvas_set_font(canvas, FontBigNumbers);
snprintf(buffer, sizeof(buffer), "%04d/%04d", (int)model->current_step, (int)model->max_value);
canvas_draw_str_aligned(canvas, 64, 17, AlignCenter, AlignTop, buffer);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 20, 8, attack_name ? attack_name : "Sub-GHz Bruteforcer");
// Progress bar
// Resolution: 128x64 px
float progress_value = model->max_value / model->current_step;
elements_progress_bar(canvas, 8, 30, 98, progress_value > 1 ? 1 : progress_value);
if (model->is_attacking) {
float progress_value = (float)model->current_step / model->max_value;
elements_progress_bar(canvas, 8, 37, 110, progress_value > 1 ? 1 : progress_value);
} else {
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 64, 44, AlignCenter, AlignBottom, attack_name);
}
// Selected attack type
// const char* attack_name = NULL;
// attack_name = subbrute_get_menu_name(model->index);
@@ -328,7 +398,7 @@ void subbrute_attack_view_draw(Canvas* canvas, void* context) {
elements_button_right(canvas, "+1");
elements_button_center(canvas, "Start");
elements_button_top_left(canvas, "Save");
elements_button_top_right(canvas, "Repeat");
elements_button_top_right(canvas, "Resend");
} else {
elements_button_center(canvas, "Stop");
}
@@ -18,19 +18,20 @@ void subbrute_attack_view_set_callback(
SubBruteAttackView* subbrute_attack_view_alloc();
void subbrute_attack_view_free(SubBruteAttackView* instance);
View* subbrute_attack_view_get_view(SubBruteAttackView* instance);
void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint8_t current_step);
uint8_t subbrute_attack_view_get_current_step(SubBruteAttackView* instance);
void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint64_t current_step);
uint64_t subbrute_attack_view_get_current_step(SubBruteAttackView* instance);
void subbrute_attack_view_init_values(
SubBruteAttackView* instance,
uint8_t index,
uint8_t max_value,
uint8_t current_step);
uint64_t max_value,
uint64_t current_step,
bool is_attacking);
void subbrute_attack_view_stop_worker(SubBruteAttackView* instance);
bool subbrute_attack_view_can_send(SubBruteAttackView* instance);
void subbrute_attack_view_start_worker(
SubBruteAttackView* instance,
uint32_t frequency,
FuriHalSubGhzPreset preset,
string_t protocol_name);
bool subbrute_attack_view_transmit(SubBruteAttackView* instance, string_t payload);
const char* protocol_name);
bool subbrute_attack_view_transmit(SubBruteAttackView* instance, const char* payload);
bool subbrute_attack_view_is_worker_running(SubBruteAttackView* instance);