Skip to content

Commit

Permalink
Merge pull request #97 from derskythe/subbrute-rev3
Browse files Browse the repository at this point in the history
SubBrute Rev3
  • Loading branch information
xMasterX authored Oct 10, 2022
2 parents a76259a + b0c31da commit 40dc804
Show file tree
Hide file tree
Showing 21 changed files with 1,330 additions and 1,219 deletions.
546 changes: 307 additions & 239 deletions applications/plugins/subbrute/helpers/subbrute_worker.c

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions applications/plugins/subbrute/helpers/subbrute_worker.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#pragma once

#include <furi_hal_subghz.h>

typedef struct SubBruteWorker SubBruteWorker;
/**
* Same like SubGhzTxRxWorkerStatus in subghz_tx_rx_worker.h
* using just to not include that file
#include "../subbrute_protocols.h"

typedef enum {
SubBruteWorkerStatusIDLE,
SubBruteWorkerStatusTx,
// SubBruteWorkerStatusRx,
} SubBruteWorkerStatus;
SubBruteWorkerStateIDLE,
SubBruteWorkerStateReady,
SubBruteWorkerStateTx,
SubBruteWorkerStateFinished
} SubBruteWorkerState;

typedef void (*SubBruteWorkerCallback)(void* context, SubBruteWorkerState state);

typedef struct SubBruteWorker SubBruteWorker;

//typedef void (*SubBruteWorkerCallback)(SubBruteWorkerStatus event, void* context);
*/
SubBruteWorker* subbrute_worker_alloc();
void subbrute_worker_free(SubBruteWorker* instance);
bool subbrute_worker_start(
uint64_t subbrute_worker_get_step(SubBruteWorker* instance);
bool subbrute_worker_set_step(SubBruteWorker* instance, uint64_t step);
bool subbrute_worker_is_running(SubBruteWorker* instance);
bool subbrute_worker_init_default_attack(
SubBruteWorker* instance,
uint32_t frequency,
FuriHalSubGhzPreset preset,
const char* protocol_name);
SubBruteAttacks attack_type,
uint64_t step,
const SubBruteProtocol* protocol);
bool subbrute_worker_init_file_attack(
SubBruteWorker* instance,
uint64_t step,
uint8_t load_index,
const char* file_key,
SubBruteProtocol* protocol);
bool subbrute_worker_start(SubBruteWorker* instance);
void subbrute_worker_stop(SubBruteWorker* instance);
bool subbrute_worker_get_continuous_worker(SubBruteWorker* instance);
void subbrute_worker_set_continuous_worker(SubBruteWorker* instance, bool is_continuous_worker);
//bool subbrute_worker_write(SubBruteWorker* instance, uint8_t* data, size_t size);
bool subbrute_worker_is_running(SubBruteWorker* instance);
bool subbrute_worker_can_transmit(SubBruteWorker* instance);
bool subbrute_worker_can_manual_transmit(SubBruteWorker* instance, bool is_button_pressed);
bool subbrute_worker_transmit(SubBruteWorker* instance, const char* payload);
bool subbrute_worker_init_manual_transmit(
bool subbrute_worker_transmit_current_key(SubBruteWorker* instance, uint64_t step);
bool subbrute_worker_can_manual_transmit(SubBruteWorker* instance);
void subbrute_worker_set_callback(
SubBruteWorker* instance,
uint32_t frequency,
FuriHalSubGhzPreset preset,
const char* protocol_name);
bool subbrute_worker_manual_transmit(SubBruteWorker* instance, const char* payload);
void subbrute_worker_manual_transmit_stop(SubBruteWorker* instance);
SubBruteWorkerCallback callback,
void* context);
47 changes: 47 additions & 0 deletions applications/plugins/subbrute/helpers/subbrute_worker_private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include "subbrute_worker.h"
#include <lib/subghz/protocols/base.h>
#include <lib/subghz/transmitter.h>
#include <lib/subghz/receiver.h>
#include <lib/subghz/environment.h>

struct SubBruteWorker {
SubBruteWorkerState state;
volatile bool worker_running;
volatile bool initiated;
volatile bool transmit_mode;

// Current step
uint64_t step;

// SubGhz
FuriThread* thread;
SubGhzProtocolDecoderBase* decoder_result;
SubGhzEnvironment* environment;
SubGhzTransmitter* transmitter;
const char* protocol_name;

// Initiated values
SubBruteAttacks attack; // Attack state
uint32_t frequency;
FuriHalSubGhzPreset preset;
SubBruteFileProtocol file;
uint8_t bits;
uint8_t te;
uint8_t repeat;
uint8_t load_index; // Index of group to bruteforce in loaded file
const char* file_key;
uint64_t max_value; // Max step

// Manual transmit
uint32_t last_time_tx_data;

// Callback for changed states
SubBruteWorkerCallback callback;
void* context;
};

int32_t subbrute_worker_thread(void* context);
void subbrute_worker_subghz_transmit(SubBruteWorker* instance, FlipperFormat* flipper_format);
void subbrute_worker_send_callback(SubBruteWorker* instance);
15 changes: 11 additions & 4 deletions applications/plugins/subbrute/scenes/subbrute_scene_load_file.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../subbrute_i.h"
#include "../subbrute_custom_event.h"
#include <lib/subghz/protocols/registry.h>
#include "subbrute_scene.h"

#define TAG "SubBruteSceneLoadFile"

Expand Down Expand Up @@ -35,12 +34,20 @@ void subbrute_scene_load_file_on_enter(void* context) {
furi_string_get_cstr(app_folder));
#endif
if(res) {
load_result = subbrute_device_load_from_file(instance->device, load_path);
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);
if(load_result == SubBruteFileResultOk) {
if(!subbrute_worker_init_file_attack(
instance->worker,
instance->device->key_index,
instance->device->load_index,
instance->device->file_key,
instance->device->file_protocol_info)) {
furi_crash("Invalid attack set!");
}
// Ready to run!
instance->device->state = SubBruteDeviceStateReady;
FURI_LOG_I(TAG, "Ready to run");
res = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#include "../subbrute_i.h"
#include "../subbrute_custom_event.h"
#include "../views/subbrute_main_view.h"
#include "subbrute_scene.h"

#define TAG "SubBruteSceneStart"

void subbrute_scene_load_select_callback(SubBruteCustomEvent event, void* context) {
furi_assert(context);

SubBruteState* instance = (SubBruteState*)context;
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subbrute_scene_load_select_callback");
#endif
view_dispatcher_send_custom_event(instance->view_dispatcher, event);
}

Expand Down Expand Up @@ -43,9 +39,14 @@ bool subbrute_scene_load_select_on_event(void* context, SceneManagerEvent event)
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubBruteCustomEventTypeIndexSelected) {
instance->device->load_index = subbrute_main_view_get_index(instance->view_main);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "load_index: %d", instance->device->load_index);
#endif
if(!subbrute_worker_init_file_attack(
instance->worker,
instance->device->key_index,
instance->device->load_index,
instance->device->file_key,
instance->device->file_protocol_info)) {
furi_crash("Invalid attack set!");
}
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
consumed = true;
}
Expand Down
Loading

0 comments on commit 40dc804

Please sign in to comment.