Skip to content

Commit

Permalink
Merge pull request #1 from derskythe/feat/more-repeats
Browse files Browse the repository at this point in the history
Feat/more repeats
  • Loading branch information
derskythe authored Oct 28, 2022
2 parents ed49dcb + 40e4712 commit eca764a
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 281 deletions.
5 changes: 3 additions & 2 deletions helpers/subbrute_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ bool subbrute_worker_init_default_attack(
SubBruteWorker* instance,
SubBruteAttacks attack_type,
uint64_t step,
const SubBruteProtocol* protocol) {
const SubBruteProtocol* protocol,
uint8_t extra_repeats) {
furi_assert(instance);

if(instance->worker_running) {
Expand All @@ -93,7 +94,7 @@ bool subbrute_worker_init_default_attack(
instance->step = step;
instance->bits = protocol->bits;
instance->te = protocol->te;
instance->repeat = protocol->repeat;
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);
Expand Down
3 changes: 2 additions & 1 deletion helpers/subbrute_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ bool subbrute_worker_init_default_attack(
SubBruteWorker* instance,
SubBruteAttacks attack_type,
uint64_t step,
const SubBruteProtocol* protocol);
const SubBruteProtocol* protocol,
uint8_t extra_repeats);
bool subbrute_worker_init_file_attack(
SubBruteWorker* instance,
uint64_t step,
Expand Down
2 changes: 1 addition & 1 deletion scenes/subbrute_scene_load_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void subbrute_scene_load_file_on_enter(void* context) {
load_result =
subbrute_device_load_from_file(instance->device, furi_string_get_cstr(load_path));
if(load_result == SubBruteFileResultOk) {
load_result = subbrute_device_attack_set(instance->device, SubBruteAttackLoadFile);
load_result = subbrute_device_attack_set(instance->device, SubBruteAttackLoadFile, 0);
if(load_result == SubBruteFileResultOk) {
if(!subbrute_worker_init_file_attack(
instance->worker,
Expand Down
10 changes: 6 additions & 4 deletions scenes/subbrute_scene_setup_attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void subbrute_scene_setup_attack_on_enter(void* context) {
instance->device->attack,
instance->device->max_value,
instance->device->key_index,
false);
false,
instance->device->extra_repeats);

instance->current_view = SubBruteViewAttack;
subbrute_attack_view_set_callback(view, subbrute_scene_setup_attack_callback, instance);
Expand All @@ -70,23 +71,24 @@ bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubBruteCustomEventTypeTransmitStarted) {
subbrute_attack_view_set_worker_type(view, false);
scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
} else if(event.event == SubBruteCustomEventTypeSaveFile) {
subbrute_attack_view_init_values(
view,
instance->device->attack,
instance->device->max_value,
instance->device->key_index,
false);
false,
instance->device->extra_repeats);
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveName);
} else if(event.event == SubBruteCustomEventTypeBackPressed) {
subbrute_attack_view_init_values(
view,
instance->device->attack,
instance->device->max_value,
instance->device->key_index,
false);
false,
instance->device->extra_repeats);
scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
} else if(event.event == SubBruteCustomEventTypeError) {
notification_message(instance->notifications, &sequence_error);
Expand Down
7 changes: 5 additions & 2 deletions scenes/subbrute_scene_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@ bool subbrute_scene_start_on_event(void* context, SceneManagerEvent event) {
#endif
if(event.event == SubBruteCustomEventTypeMenuSelected) {
SubBruteAttacks attack = subbrute_main_view_get_index(instance->view_main);
uint8_t extra_repeats = subbrute_main_view_get_extra_repeats(instance->view_main);

if(subbrute_device_attack_set(instance->device, attack) != SubBruteFileResultOk ||
if(subbrute_device_attack_set(instance->device, attack, extra_repeats) != SubBruteFileResultOk ||
!subbrute_worker_init_default_attack(
instance->worker,
attack,
instance->device->key_index,
instance->device->protocol_info)) {
instance->device->protocol_info,
instance->device->extra_repeats)) {
furi_crash("Invalid attack set!");
}
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);

consumed = true;
} else if(event.event == SubBruteCustomEventTypeLoadFile) {
instance->device->extra_repeats = 0;
scene_manager_next_scene(instance->scene_manager, SubBruteSceneLoadFile);
consumed = true;
}
Expand Down
13 changes: 9 additions & 4 deletions subbrute_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,20 @@ bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_na
return result;
}

SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBruteAttacks type) {
SubBruteFileResult subbrute_device_attack_set(
SubBruteDevice* instance,
SubBruteAttacks type,
uint8_t extra_repeats) {
furi_assert(instance);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subbrute_device_attack_set: %d", type);
FURI_LOG_D(TAG, "subbrute_device_attack_set: %d, extra_repeats: %d", type, extra_repeats);
#endif
subbrute_device_attack_set_default_values(instance, type);

if(type != SubBruteAttackLoadFile) {
subbrute_device_free_protocol_info(instance);
instance->protocol_info = subbrute_protocol(type);
instance->extra_repeats = extra_repeats;
}

// For non-file types we didn't set SubGhzProtocolDecoderBase
Expand Down Expand Up @@ -175,7 +179,7 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
#ifdef FURI_DEBUG
bits = instance->protocol_info->bits;
te = instance->protocol_info->te;
repeat = instance->protocol_info->repeat;
repeat = instance->protocol_info->repeat + instance->extra_repeats;
preset = instance->protocol_info->preset;
file = instance->protocol_info->file;
#endif
Expand All @@ -189,7 +193,7 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
#ifdef FURI_DEBUG
bits = instance->file_protocol_info->bits;
te = instance->file_protocol_info->te;
repeat = instance->file_protocol_info->repeat;
repeat = instance->file_protocol_info->repeat + instance->extra_repeats;
preset = instance->file_protocol_info->preset;
file = instance->file_protocol_info->file;
#endif
Expand Down Expand Up @@ -390,6 +394,7 @@ void subbrute_device_attack_set_default_values(
instance->attack = default_attack;
instance->key_index = 0x00;
instance->load_index = 0x00;
instance->extra_repeats = 0;
memset(instance->current_key, 0, sizeof(instance->current_key));

if(default_attack != SubBruteAttackLoadFile) {
Expand Down
6 changes: 5 additions & 1 deletion subbrute_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef struct {
// Attack state
SubBruteAttacks attack;
uint64_t max_value;
uint8_t extra_repeats;

// Loaded info for attack type
char current_key[SUBBRUTE_PAYLOAD_SIZE];
Expand All @@ -59,7 +60,10 @@ void subbrute_device_free(SubBruteDevice* instance);

bool subbrute_device_save_file(SubBruteDevice* instance, const char* key_name);
const char* subbrute_device_error_get_desc(SubBruteFileResult error_id);
SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* context, SubBruteAttacks type);
SubBruteFileResult subbrute_device_attack_set(
SubBruteDevice* context,
SubBruteAttacks type,
uint8_t extra_repeats);
uint8_t subbrute_device_load_from_file(SubBruteDevice* context, const char* file_path);

uint64_t subbrute_device_add_step(SubBruteDevice* instance, int8_t step);
Expand Down
20 changes: 18 additions & 2 deletions subbrute_protocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ const SubBruteProtocol* subbrute_protocol(SubBruteAttacks index) {
return subbrute_protocol_registry[index];
}

uint8_t subbrute_protocol_repeats_count(SubBruteAttacks index) {
return subbrute_protocol_registry[index]->repeat;
}

const char* subbrute_protocol_preset(FuriHalSubGhzPreset preset) {
return subbrute_protocol_presets[preset];
}
Expand Down Expand Up @@ -338,7 +342,13 @@ void subbrute_protocol_default_payload(
furi_string_free(buffer);

#ifdef FURI_DEBUG
//FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
FURI_LOG_D(
TAG,
"candidate: %s, step: %lld, repeat: %d, te: %s",
furi_string_get_cstr(candidate),
step,
repeat,
te ? "true" : "false");
#endif
stream_clean(stream);
if(te) {
Expand Down Expand Up @@ -372,7 +382,13 @@ void subbrute_protocol_file_payload(
furi_string_replace_at(candidate, load_index * 3, 3, subbrute_payload_byte);

#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
FURI_LOG_D(
TAG,
"candidate: %s, step: %lld, repeat: %d, te: %s",
furi_string_get_cstr(candidate),
step,
repeat,
te ? "true" : "false");
#endif
stream_clean(stream);

Expand Down
10 changes: 1 addition & 9 deletions subbrute_protocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
#include <furi_hal_subghz.h>
#include <core/string.h>
#include <toolbox/stream/stream.h>
//typedef enum {
// FrequencyProtocolField,
// BitsProtocolField,
// HasTeProtocolField,
// RepeatProtocolField,
// PresetProtocolField,
// FileProtocolField,
// TotalProtocolFields
//} ProtocolFields;

typedef enum {
CAMEFileProtocol,
Expand Down Expand Up @@ -61,6 +52,7 @@ const char* subbrute_protocol_preset(FuriHalSubGhzPreset preset);
const char* subbrute_protocol_file(SubBruteFileProtocol protocol);
FuriHalSubGhzPreset subbrute_protocol_convert_preset(FuriString* preset_name);
SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name);
uint8_t subbrute_protocol_repeats_count(SubBruteAttacks index);
const char* subbrute_protocol_name(SubBruteAttacks index);

void subbrute_protocol_default_payload(
Expand Down
Loading

0 comments on commit eca764a

Please sign in to comment.