Skip to content

Commit

Permalink
big upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Sep 8, 2022
1 parent 4588f38 commit 18891ad
Show file tree
Hide file tree
Showing 12 changed files with 390 additions and 85 deletions.
2 changes: 1 addition & 1 deletion applications/flipfrid/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ App(
cdefines=["APP_FLIP_FRID"],
requires=["gui"],
stack_size=1 * 1024,
order=29,
order=13,
)
12 changes: 7 additions & 5 deletions applications/flipfrid/scene/flipfrid_scene_run_attack.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "flipfrid_scene_run_attack.h"
#include <gui/elements.h>

uint8_t counter = 0;
#define TIME_BETWEEN_CARDS 5
Expand Down Expand Up @@ -182,7 +183,7 @@ void flipfrid_scene_run_attack_on_draw(Canvas* canvas, FlipFridState* context) {
canvas_set_color(canvas, ColorBlack);

// Frame
canvas_draw_frame(canvas, 0, 0, 128, 64);
//canvas_draw_frame(canvas, 0, 0, 128, 64);

// Title
canvas_set_font(canvas, FontPrimary);
Expand All @@ -202,11 +203,12 @@ void flipfrid_scene_run_attack_on_draw(Canvas* canvas, FlipFridState* context) {
canvas_draw_str_aligned(canvas, 64, 24, AlignCenter, AlignTop, uid);

canvas_set_font(canvas, FontSecondary);
char start_stop_msg[20];
//char start_stop_msg[20];
if(context->is_attacking) {
snprintf(start_stop_msg, sizeof(start_stop_msg), " Press OK to stop ");
elements_button_center(canvas, "Stop");
//snprintf(start_stop_msg, sizeof(start_stop_msg), " Press OK to stop ");
} else {
snprintf(start_stop_msg, sizeof(start_stop_msg), " Press OK to start ");
elements_button_center(canvas, "Start");
}
canvas_draw_str_aligned(canvas, 64, 44, AlignCenter, AlignTop, start_stop_msg);
//canvas_draw_str_aligned(canvas, 64, 44, AlignCenter, AlignTop, start_stop_msg);
}
2 changes: 1 addition & 1 deletion applications/flipfrid/scene/flipfrid_scene_select_field.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void flipfrid_scene_select_field_on_draw(Canvas* canvas, FlipFridState* context)
canvas_set_color(canvas, ColorBlack);

// Frame
canvas_draw_frame(canvas, 0, 0, 128, 64);
//canvas_draw_frame(canvas, 0, 0, 128, 64);

// Title
canvas_set_font(canvas, FontPrimary);
Expand Down
2 changes: 1 addition & 1 deletion applications/subbrute/application.fam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
App(
appid="subbrute",
name="SubGhz Bruteforcer",
name="SubGHz Bruteforcer",
apptype=FlipperAppType.PLUGIN,
entry_point="subbrute_start",
cdefines=["APP_SUB_BRUTE"],
Expand Down
2 changes: 1 addition & 1 deletion applications/subbrute/scene/subbrute_scene_entrypoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void subbrute_scene_entrypoint_on_draw(Canvas* canvas, SubBruteState* context) {

// Title
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 64, 6, AlignCenter, AlignTop, "SubGhz Fuzzer");
canvas_draw_str_aligned(canvas, 64, 6, AlignCenter, AlignTop, "SubGHz Fuzzer");

if(context->menu_index > SubBruteAttackLoadFile) {
canvas_set_font(canvas, FontSecondary);
Expand Down
39 changes: 25 additions & 14 deletions applications/subbrute/scene/subbrute_scene_load_file.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "subbrute_scene_load_file.h"
#include "subbrute_scene_entrypoint.h"
#include "../subbrute_utils.h"
#include <lib/subghz/protocols/registry.h>

#define SUBGHZ_APP_PATH_FOLDER "/ext/subghz"

bool subbrute_load(SubBruteState* context, const char* file_path) {
bool result = false;
Expand Down Expand Up @@ -61,6 +64,16 @@ bool subbrute_load(SubBruteState* context, const char* file_path) {
break;
}

const SubGhzProtocol* registry =
subghz_protocol_registry_get_by_name(string_get_cstr(context->protocol));

if(registry && registry->type == SubGhzProtocolTypeDynamic) {
FURI_LOG_D(TAG, "Protocol is dynamic - not supported");
string_reset(context->notification_msg);
string_set_str(context->notification_msg, "Dynamic protocol unsupported");
break;
}

context->decoder_result = subghz_receiver_search_decoder_base_by_name(
context->receiver, string_get_cstr(context->protocol));

Expand Down Expand Up @@ -98,9 +111,9 @@ bool subbrute_load(SubBruteState* context, const char* file_path) {
// TE
if(!flipper_format_read_uint32(fff_data_file, "TE", &temp_data32, 1)) {
FURI_LOG_E(TAG, "Missing or incorrect TE");
string_reset(context->notification_msg);
string_set_str(context->notification_msg, "Missing or incorrect TE");
break;
//string_reset(context->notification_msg);
//string_set_str(context->notification_msg, "Missing or incorrect TE");
//break;
} else {
FURI_LOG_I(TAG, "TE: %d", temp_data32);
context->te = temp_data32;
Expand All @@ -119,6 +132,7 @@ bool subbrute_load(SubBruteState* context, const char* file_path) {
} while(0);

string_clear(temp_str);
flipper_format_file_close(fff_data_file);
flipper_format_free(fff_data_file);
if(result) {
FURI_LOG_I(TAG, "Loaded successfully");
Expand Down Expand Up @@ -156,7 +170,9 @@ void subbrute_scene_load_file_on_event(SubBruteEvent event, SubBruteState* conte
case InputKeyLeft:
case InputKeyRight:
case InputKeyOk:
break;
case InputKeyBack:
context->current_scene = SceneEntryPoint;
break;
}
}
Expand All @@ -169,30 +185,25 @@ void subbrute_scene_load_file_on_draw(Canvas* canvas, SubBruteState* context) {
canvas_set_color(canvas, ColorBlack);

// Frame
canvas_draw_frame(canvas, 0, 0, 128, 64);
//canvas_draw_frame(canvas, 0, 0, 128, 64);

// Title
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 64, 16, AlignCenter, AlignTop, "SubGhz Fuzzer");
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignTop, "Press OK to choose file");
canvas_draw_str_aligned(canvas, 64, 16, AlignCenter, AlignTop, "SubGHz Fuzzer");
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignTop, "Error: Press back");
}

bool subbrute_load_protocol_from_file(SubBruteState* context) {
string_t file_path;
string_init(file_path);
string_set_str(file_path, SUBGHZ_APP_PATH_FOLDER);

// Input events and views are managed by file_select
bool res = dialog_file_browser_show(
context->dialogs,
context->file_path,
context->file_path,
SUBGHZ_APP_EXTENSION,
true,
&I_sub1_10px,
true);
context->dialogs, file_path, file_path, SUBGHZ_APP_EXTENSION, true, &I_sub1_10px, true);

if(res) {
res = subbrute_load(context, string_get_cstr(context->file_path));
res = subbrute_load(context, string_get_cstr(file_path));
}

string_clear(file_path);
Expand Down
125 changes: 76 additions & 49 deletions applications/subbrute/scene/subbrute_scene_run_attack.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "subbrute_scene_run_attack.h"
#include <lib/subghz/transmitter.h>
#include <gui/elements.h>

uint64_t subbrute_counter = 0;
uint64_t max_value;
bool is_running = false;
bool locked = false;
bool toSave = false;
char subbrute_payload_byte[4];
#define SUBBRUTE_DELAY 1

Expand All @@ -31,43 +32,34 @@ FuriHalSubGhzPreset str_to_preset(string_t preset) {
}

void subbrute_emit(SubBruteState* context) {
FURI_LOG_I(TAG, string_get_cstr(context->flipper_format_string));
//FURI_LOG_D(TAG, string_get_cstr(context->flipper_format_string));

furi_hal_subghz_start_async_tx(subghz_transmitter_yield, context->transmitter);
while(!(furi_hal_subghz_is_async_tx_complete())) {
furi_delay_ms(50);
furi_delay_ms(5);
}

furi_hal_subghz_stop_async_tx();
furi_hal_subghz_idle();
}

void prepare_emit(SubBruteState* context) {
is_running = true;
furi_hal_subghz_init();

stream_clean(context->stream);
stream_write_string(context->stream, context->flipper_format_string);

context->transmitter =
subghz_transmitter_alloc_init(context->environment, string_get_cstr(context->protocol));

subghz_transmitter_deserialize(context->transmitter, context->flipper_format);
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(str_to_preset(context->preset));

context->frequency = furi_hal_subghz_set_frequency_and_path(context->frequency);
furi_hal_subghz_set_frequency_and_path(context->frequency);
}

void clear_emit(SubBruteState* context) {
furi_hal_subghz_stop_async_tx();
furi_hal_subghz_sleep();

if(context->attack == SubBruteAttackLoadFile) {
subghz_transmitter_free(context->transmitter);
}
subghz_transmitter_free(context->transmitter);
is_running = false;
}
/*
void subbrute_send_raw_packet(SubBruteState* context) {
Expand Down Expand Up @@ -138,18 +130,43 @@ void subbrute_send_packet_parsed(SubBruteState* context) {
}
string_clear(buffer);
}
string_init_printf(
context->flipper_format_string,
"Filetype: Flipper SubGhz Key File\n"
"Version: 1\n"
"Protocol: %s\n"
"Bit: %d\n"
"Key: %s\n"
"TE: %d\n",
string_get_cstr(context->protocol),
context->bit,
string_get_cstr(context->candidate),
context->te);
if(strcmp(string_get_cstr(context->protocol), "Princeton") == 0) {
string_init_printf(
context->flipper_format_string,
"Filetype: Flipper SubGhz Key File\n"
"Version: 1\n"
"Frequency: %u\n"
"Preset: %s\n"
"Protocol: %s\n"
"Bit: %d\n"
"Key: %s\n"
"TE: %d\n",
context->frequency,
string_get_cstr(context->preset),
string_get_cstr(context->protocol),
context->bit,
string_get_cstr(context->candidate),
context->te);
} else {
string_init_printf(
context->flipper_format_string,
"Filetype: Flipper SubGhz Key File\n"
"Version: 1\n"
"Frequency: %u\n"
"Preset: %s\n"
"Protocol: %s\n"
"Bit: %d\n"
"Key: %s\n",
context->frequency,
string_get_cstr(context->preset),
string_get_cstr(context->protocol),
context->bit,
string_get_cstr(context->candidate));
}

stream_clean(context->stream);
stream_write_string(context->stream, context->flipper_format_string);
subghz_transmitter_deserialize(context->transmitter, context->flipper_format);

subbrute_emit(context);
}
Expand All @@ -164,32 +181,35 @@ void subbrute_send_packet(SubBruteState* context) {
}

void subbrute_scene_run_attack_on_enter(SubBruteState* context) {
if(context->attack == SubBruteAttackLoadFile) {
max_value = 0xFF;
} else {
string_t max_value_s;
string_init(max_value_s);
for(uint8_t i = 0; i < context->bit; i++) {
string_cat_printf(max_value_s, "1");
if(!toSave) {
if(context->attack == SubBruteAttackLoadFile) {
max_value = 0xFF;
} else {
string_t max_value_s;
string_init(max_value_s);
for(uint8_t i = 0; i < context->bit; i++) {
string_cat_printf(max_value_s, "1");
}
max_value = (uint64_t)strtol(string_get_cstr(max_value_s), NULL, 2);
string_clear(max_value_s);
}
max_value = (uint64_t)strtol(string_get_cstr(max_value_s), NULL, 2);
string_clear(max_value_s);
context->str_index = (context->key_index * 3);
string_init_set(context->candidate, context->key);
context->flipper_format = flipper_format_string_alloc();
context->stream = flipper_format_get_raw_stream(context->flipper_format);
context->environment = subghz_environment_alloc();
context->transmitter = subghz_transmitter_alloc_init(
context->environment, string_get_cstr(context->protocol));
prepare_emit(context);
} else {
toSave = false;
}
context->str_index = (context->key_index * 3);
string_init_set(context->candidate, context->key);
context->flipper_format = flipper_format_string_alloc();
context->stream = flipper_format_get_raw_stream(context->flipper_format);
context->environment = subghz_environment_alloc();
context->transmitter =
subghz_transmitter_alloc_init(context->environment, string_get_cstr(context->protocol));
prepare_emit(context);
}

void subbrute_scene_run_attack_on_exit(SubBruteState* context) {
if(is_running) {
is_running = false;
if(!toSave) {
clear_emit(context);
}
clear_emit(context);
}

void subbrute_scene_run_attack_on_tick(SubBruteState* context) {
Expand Down Expand Up @@ -223,6 +243,10 @@ void subbrute_scene_run_attack_on_event(SubBruteEvent event, SubBruteState* cont
if(event.input_type == InputTypeShort) {
switch(event.key) {
case InputKeyDown:
if(!context->is_attacking) {
toSave = true;
context->current_scene = SceneSaveName;
}
case InputKeyUp:
break;
case InputKeyLeft:
Expand Down Expand Up @@ -254,6 +278,8 @@ void subbrute_scene_run_attack_on_event(SubBruteEvent event, SubBruteState* cont
context->is_attacking = false;
string_reset(context->notification_msg);
context->payload = 0x00;
subbrute_counter = 0;
notification_message(context->notify, &sequence_blink_stop);
if(context->attack == SubBruteAttackLoadFile) {
context->current_scene = SceneSelectField;
} else {
Expand All @@ -270,7 +296,7 @@ void subbrute_scene_run_attack_on_draw(Canvas* canvas, SubBruteState* context) {
canvas_set_color(canvas, ColorBlack);

// Frame
canvas_draw_frame(canvas, 0, 0, 128, 64);
//canvas_draw_frame(canvas, 0, 0, 128, 64);

// Title
canvas_set_font(canvas, FontPrimary);
Expand All @@ -284,10 +310,11 @@ void subbrute_scene_run_attack_on_draw(Canvas* canvas, SubBruteState* context) {

canvas_set_font(canvas, FontSecondary);
char start_stop_msg[20];
snprintf(start_stop_msg, sizeof(start_stop_msg), " Press (V) to save ");
if(context->is_attacking) {
snprintf(start_stop_msg, sizeof(start_stop_msg), " Press OK to stop ");
elements_button_center(canvas, "Stop");
} else {
snprintf(start_stop_msg, sizeof(start_stop_msg), " Press OK to start ");
elements_button_center(canvas, "Start");
}
canvas_draw_str_aligned(canvas, 64, 44, AlignCenter, AlignTop, start_stop_msg);
canvas_draw_str_aligned(canvas, 64, 39, AlignCenter, AlignTop, start_stop_msg);
}
Loading

0 comments on commit 18891ad

Please sign in to comment.