mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 08:08:35 -07:00
subbrute
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "subbrute_main_view.h"
|
||||
#include "../subbrute_i.h"
|
||||
#include "../subbrute_protocols.h"
|
||||
#include "../helpers/gui_top_buttons.h"
|
||||
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
@@ -10,6 +11,15 @@
|
||||
#define TAG "SubBruteMainView"
|
||||
|
||||
#define ITEMS_ON_SCREEN 3
|
||||
#define ITEMS_INTERVAL 1
|
||||
#define ITEM_WIDTH 14
|
||||
#define ITEM_Y 27
|
||||
#define ITEM_HEIGHT 13
|
||||
#define TEXT_X 6
|
||||
#define TEXT_Y 37
|
||||
#define TEXT_INTERVAL 3
|
||||
#define TEXT_WIDTH 12
|
||||
#define ITEM_FRAME_RADIUS 2
|
||||
|
||||
struct SubBruteMainView {
|
||||
View* view;
|
||||
@@ -17,7 +27,8 @@ struct SubBruteMainView {
|
||||
void* context;
|
||||
uint8_t index;
|
||||
bool is_select_byte;
|
||||
const char* key_field;
|
||||
bool two_bytes;
|
||||
uint64_t key_from_file;
|
||||
uint8_t extra_repeats;
|
||||
uint8_t window_position;
|
||||
};
|
||||
@@ -27,7 +38,8 @@ typedef struct {
|
||||
uint8_t extra_repeats;
|
||||
uint8_t window_position;
|
||||
bool is_select_byte;
|
||||
const char* key_field;
|
||||
bool two_bytes;
|
||||
uint64_t key_from_file;
|
||||
} SubBruteMainViewModel;
|
||||
|
||||
void subbrute_main_view_set_callback(
|
||||
@@ -41,84 +53,105 @@ void subbrute_main_view_set_callback(
|
||||
instance->context = context;
|
||||
}
|
||||
|
||||
FuriString* center_displayed_key(const char* key_cstr, uint8_t index) {
|
||||
uint8_t str_index = (index * 3);
|
||||
void subbrute_main_view_center_displayed_key(
|
||||
Canvas* canvas,
|
||||
uint64_t key,
|
||||
uint8_t index,
|
||||
bool two_bytes) {
|
||||
uint8_t text_x = TEXT_X;
|
||||
uint8_t item_x = TEXT_X - ITEMS_INTERVAL;
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
||||
char display_menu[] = {
|
||||
'X', 'X', ' ', 'X', 'X', ' ', '<', 'X', 'X', '>', ' ', 'X', 'X', ' ', 'X', 'X', '\0'};
|
||||
for(int i = 0; i < 8; i++) {
|
||||
char current_value[3] = {0};
|
||||
uint8_t byte_value = (uint8_t)(key >> 8 * (7 - i)) & 0xFF;
|
||||
snprintf(current_value, sizeof(current_value), "%02X", byte_value);
|
||||
|
||||
if(key_cstr != NULL) {
|
||||
if(index > 1) {
|
||||
display_menu[0] = key_cstr[str_index - 6];
|
||||
display_menu[1] = key_cstr[str_index - 5];
|
||||
// For two bytes we need to select prev location
|
||||
if(!two_bytes && i == index) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_rbox(
|
||||
canvas, item_x - 1, ITEM_Y, ITEM_WIDTH + 1, ITEM_HEIGHT, ITEM_FRAME_RADIUS);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_str(canvas, text_x, TEXT_Y, current_value);
|
||||
} else if(two_bytes && (i == index || i == index - 1)) {
|
||||
if(i == index) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_rbox(
|
||||
canvas,
|
||||
item_x - ITEMS_INTERVAL - ITEM_WIDTH - 1,
|
||||
ITEM_Y,
|
||||
ITEM_WIDTH * 2 + ITEMS_INTERVAL * 2 + 1,
|
||||
ITEM_HEIGHT,
|
||||
ITEM_FRAME_RADIUS);
|
||||
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_str(canvas, text_x, TEXT_Y, current_value);
|
||||
|
||||
// Redraw prev element with white
|
||||
memset(current_value, 0, sizeof(current_value));
|
||||
byte_value = (uint8_t)(key >> 8 * (7 - i + 1)) & 0xFF;
|
||||
snprintf(current_value, sizeof(current_value), "%02X", byte_value);
|
||||
canvas_draw_str(
|
||||
canvas, text_x - (TEXT_WIDTH + TEXT_INTERVAL), TEXT_Y, current_value);
|
||||
} else {
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_str(canvas, text_x, TEXT_Y, current_value);
|
||||
}
|
||||
} else {
|
||||
display_menu[0] = ' ';
|
||||
display_menu[1] = ' ';
|
||||
}
|
||||
|
||||
if(index > 0) {
|
||||
display_menu[3] = key_cstr[str_index - 3];
|
||||
display_menu[4] = key_cstr[str_index - 2];
|
||||
} else {
|
||||
display_menu[3] = ' ';
|
||||
display_menu[4] = ' ';
|
||||
}
|
||||
|
||||
display_menu[7] = key_cstr[str_index];
|
||||
display_menu[8] = key_cstr[str_index + 1];
|
||||
|
||||
if((str_index + 4) <= (uint8_t)strlen(key_cstr)) {
|
||||
display_menu[11] = key_cstr[str_index + 3];
|
||||
display_menu[12] = key_cstr[str_index + 4];
|
||||
} else {
|
||||
display_menu[11] = ' ';
|
||||
display_menu[12] = ' ';
|
||||
}
|
||||
|
||||
if((str_index + 8) <= (uint8_t)strlen(key_cstr)) {
|
||||
display_menu[14] = key_cstr[str_index + 6];
|
||||
display_menu[15] = key_cstr[str_index + 7];
|
||||
} else {
|
||||
display_menu[14] = ' ';
|
||||
display_menu[15] = ' ';
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_str(canvas, text_x, TEXT_Y, current_value);
|
||||
}
|
||||
text_x = text_x + TEXT_WIDTH + TEXT_INTERVAL;
|
||||
item_x = item_x + ITEM_WIDTH + ITEMS_INTERVAL;
|
||||
}
|
||||
return furi_string_alloc_set(display_menu);
|
||||
|
||||
// Return normal color
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
}
|
||||
|
||||
void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) {
|
||||
// Title
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_box(canvas, 0, 0, canvas_width(canvas), STATUS_BAR_Y_SHIFT);
|
||||
canvas_invert_color(canvas);
|
||||
canvas_draw_str_aligned(canvas, 64, 3, AlignCenter, AlignTop, "Sub-GHz BruteForcer 3.2");
|
||||
canvas_invert_color(canvas);
|
||||
|
||||
uint16_t screen_width = canvas_width(canvas);
|
||||
uint16_t screen_height = canvas_height(canvas);
|
||||
|
||||
if(model->is_select_byte) {
|
||||
#ifdef FURI_DEBUG
|
||||
//FURI_LOG_D(TAG, "key_field: %s", model->key_field);
|
||||
//FURI_LOG_D(TAG, "key_from_file: %s", model->key_from_file);
|
||||
#endif
|
||||
char msg_index[18];
|
||||
snprintf(msg_index, sizeof(msg_index), "Field index : %d", model->index);
|
||||
canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, msg_index);
|
||||
|
||||
FuriString* menu_items;
|
||||
|
||||
menu_items = center_displayed_key(model->key_field, model->index);
|
||||
//char msg_index[18];
|
||||
//snprintf(msg_index, sizeof(msg_index), "Field index: %d", model->index);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 64, 40, AlignCenter, AlignTop, furi_string_get_cstr(menu_items));
|
||||
canvas, 64, 17, AlignCenter, AlignTop, "Please select values to calc:");
|
||||
|
||||
subbrute_main_view_center_displayed_key(
|
||||
canvas, model->key_from_file, model->index, model->two_bytes);
|
||||
//const char* line = furi_string_get_cstr(menu_items);
|
||||
//canvas_set_font(canvas, FontSecondary);
|
||||
//canvas_draw_str_aligned(
|
||||
// canvas, 64, 37, AlignCenter, AlignTop, furi_string_get_cstr(menu_items));
|
||||
|
||||
elements_button_center(canvas, "Select");
|
||||
elements_button_left(canvas, "<");
|
||||
elements_button_right(canvas, ">");
|
||||
|
||||
furi_string_reset(menu_items);
|
||||
furi_string_free(menu_items);
|
||||
if(model->index > 0) {
|
||||
elements_button_left(canvas, " ");
|
||||
}
|
||||
if(model->index < 7) {
|
||||
elements_button_right(canvas, " ");
|
||||
}
|
||||
// Switch to another mode
|
||||
if(model->two_bytes) {
|
||||
elements_button_top_left(canvas, "One byte");
|
||||
} else {
|
||||
elements_button_top_left(canvas, "Two bytes");
|
||||
}
|
||||
} else {
|
||||
// Title
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_box(canvas, 0, 0, canvas_width(canvas), STATUS_BAR_Y_SHIFT);
|
||||
canvas_invert_color(canvas);
|
||||
canvas_draw_str_aligned(canvas, 64, 3, AlignCenter, AlignTop, "Sub-GHz BruteForcer 3.3");
|
||||
canvas_invert_color(canvas);
|
||||
|
||||
// Menu
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
@@ -257,18 +290,34 @@ bool subbrute_main_view_input(InputEvent* event, void* context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(event->key == InputKeyLeft && is_short) {
|
||||
if(instance->index > 0) {
|
||||
} else if(is_short) {
|
||||
if(event->key == InputKeyLeft) {
|
||||
if((instance->index > 0 && !instance->two_bytes) ||
|
||||
(instance->two_bytes && instance->index > 1)) {
|
||||
instance->index--;
|
||||
}
|
||||
updated = true;
|
||||
} else if(event->key == InputKeyRight && is_short) {
|
||||
consumed = true;
|
||||
} else if(event->key == InputKeyRight) {
|
||||
if(instance->index < 7) {
|
||||
instance->index++;
|
||||
}
|
||||
updated = true;
|
||||
} else if(event->key == InputKeyOk && is_short) {
|
||||
consumed = true;
|
||||
} else if(event->key == InputKeyUp) {
|
||||
instance->two_bytes = !instance->two_bytes;
|
||||
// Because index is changing
|
||||
if(instance->two_bytes && instance->index < 7) {
|
||||
instance->index++;
|
||||
}
|
||||
// instance->callback(
|
||||
// instance->two_bytes ? SubBruteCustomEventTypeChangeStepUp :
|
||||
// SubBruteCustomEventTypeChangeStepDown,
|
||||
// instance->context);
|
||||
|
||||
updated = true;
|
||||
consumed = true;
|
||||
} else if(event->key == InputKeyOk) {
|
||||
instance->callback(SubBruteCustomEventTypeIndexSelected, instance->context);
|
||||
consumed = true;
|
||||
updated = true;
|
||||
@@ -282,8 +331,9 @@ bool subbrute_main_view_input(InputEvent* event, void* context) {
|
||||
{
|
||||
model->index = instance->index;
|
||||
model->window_position = instance->window_position;
|
||||
model->key_field = instance->key_field;
|
||||
model->key_from_file = instance->key_from_file;
|
||||
model->is_select_byte = instance->is_select_byte;
|
||||
model->two_bytes = instance->two_bytes;
|
||||
model->extra_repeats = instance->extra_repeats;
|
||||
},
|
||||
true);
|
||||
@@ -318,24 +368,25 @@ SubBruteMainView* subbrute_main_view_alloc() {
|
||||
view_set_enter_callback(instance->view, subbrute_main_view_enter);
|
||||
view_set_exit_callback(instance->view, subbrute_main_view_exit);
|
||||
|
||||
instance->index = 0;
|
||||
instance->window_position = 0;
|
||||
instance->key_from_file = 0;
|
||||
instance->is_select_byte = false;
|
||||
instance->two_bytes = false;
|
||||
instance->extra_repeats = 0;
|
||||
with_view_model(
|
||||
instance->view,
|
||||
SubBruteMainViewModel * model,
|
||||
{
|
||||
model->index = 0;
|
||||
model->window_position = 0;
|
||||
model->key_field = NULL;
|
||||
model->is_select_byte = false;
|
||||
model->extra_repeats = 0;
|
||||
model->index = instance->index;
|
||||
model->window_position = instance->window_position;
|
||||
model->key_from_file = instance->key_from_file;
|
||||
model->is_select_byte = instance->is_select_byte;
|
||||
model->two_bytes = instance->two_bytes;
|
||||
model->extra_repeats = instance->extra_repeats;
|
||||
},
|
||||
true);
|
||||
|
||||
instance->index = 0;
|
||||
instance->window_position = 0;
|
||||
instance->key_field = NULL;
|
||||
instance->is_select_byte = false;
|
||||
instance->extra_repeats = 0;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -355,14 +406,16 @@ void subbrute_main_view_set_index(
|
||||
SubBruteMainView* instance,
|
||||
uint8_t idx,
|
||||
bool is_select_byte,
|
||||
const char* key_field) {
|
||||
bool two_bytes,
|
||||
uint64_t key_from_file) {
|
||||
furi_assert(instance);
|
||||
furi_assert(idx < SubBruteAttackTotalCount);
|
||||
#ifdef FURI_DEBUG
|
||||
FURI_LOG_I(TAG, "Set index: %d, IS_SELECT_BYTE: %d", idx, is_select_byte);
|
||||
FURI_LOG_I(TAG, "Set index: %d, is_select_byte: %d", idx, is_select_byte);
|
||||
#endif
|
||||
instance->is_select_byte = is_select_byte;
|
||||
instance->key_field = key_field;
|
||||
instance->two_bytes = two_bytes;
|
||||
instance->key_from_file = key_from_file;
|
||||
instance->index = idx;
|
||||
instance->window_position = idx;
|
||||
|
||||
@@ -386,8 +439,9 @@ void subbrute_main_view_set_index(
|
||||
{
|
||||
model->index = instance->index;
|
||||
model->window_position = instance->window_position;
|
||||
model->key_field = instance->key_field;
|
||||
model->key_from_file = instance->key_from_file;
|
||||
model->is_select_byte = instance->is_select_byte;
|
||||
model->two_bytes = instance->two_bytes;
|
||||
model->extra_repeats = instance->extra_repeats;
|
||||
},
|
||||
true);
|
||||
@@ -401,4 +455,9 @@ SubBruteAttacks subbrute_main_view_get_index(SubBruteMainView* instance) {
|
||||
uint8_t subbrute_main_view_get_extra_repeats(SubBruteMainView* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->extra_repeats;
|
||||
}
|
||||
|
||||
bool subbrute_main_view_get_two_bytes(SubBruteMainView* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->two_bytes;
|
||||
}
|
||||
Reference in New Issue
Block a user