Skip to content

Commit 40dc804

Browse files
authored
Merge pull request #97 from derskythe/subbrute-rev3
SubBrute Rev3
2 parents a76259a + b0c31da commit 40dc804

21 files changed

+1330
-1219
lines changed

applications/plugins/subbrute/helpers/subbrute_worker.c

Lines changed: 307 additions & 239 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
#pragma once
22

3-
#include <furi_hal_subghz.h>
4-
5-
typedef struct SubBruteWorker SubBruteWorker;
6-
/**
7-
* Same like SubGhzTxRxWorkerStatus in subghz_tx_rx_worker.h
8-
* using just to not include that file
3+
#include "../subbrute_protocols.h"
94

105
typedef enum {
11-
SubBruteWorkerStatusIDLE,
12-
SubBruteWorkerStatusTx,
13-
// SubBruteWorkerStatusRx,
14-
} SubBruteWorkerStatus;
6+
SubBruteWorkerStateIDLE,
7+
SubBruteWorkerStateReady,
8+
SubBruteWorkerStateTx,
9+
SubBruteWorkerStateFinished
10+
} SubBruteWorkerState;
11+
12+
typedef void (*SubBruteWorkerCallback)(void* context, SubBruteWorkerState state);
13+
14+
typedef struct SubBruteWorker SubBruteWorker;
1515

16-
//typedef void (*SubBruteWorkerCallback)(SubBruteWorkerStatus event, void* context);
17-
*/
1816
SubBruteWorker* subbrute_worker_alloc();
1917
void subbrute_worker_free(SubBruteWorker* instance);
20-
bool subbrute_worker_start(
18+
uint64_t subbrute_worker_get_step(SubBruteWorker* instance);
19+
bool subbrute_worker_set_step(SubBruteWorker* instance, uint64_t step);
20+
bool subbrute_worker_is_running(SubBruteWorker* instance);
21+
bool subbrute_worker_init_default_attack(
2122
SubBruteWorker* instance,
22-
uint32_t frequency,
23-
FuriHalSubGhzPreset preset,
24-
const char* protocol_name);
23+
SubBruteAttacks attack_type,
24+
uint64_t step,
25+
const SubBruteProtocol* protocol);
26+
bool subbrute_worker_init_file_attack(
27+
SubBruteWorker* instance,
28+
uint64_t step,
29+
uint8_t load_index,
30+
const char* file_key,
31+
SubBruteProtocol* protocol);
32+
bool subbrute_worker_start(SubBruteWorker* instance);
2533
void subbrute_worker_stop(SubBruteWorker* instance);
26-
bool subbrute_worker_get_continuous_worker(SubBruteWorker* instance);
27-
void subbrute_worker_set_continuous_worker(SubBruteWorker* instance, bool is_continuous_worker);
28-
//bool subbrute_worker_write(SubBruteWorker* instance, uint8_t* data, size_t size);
29-
bool subbrute_worker_is_running(SubBruteWorker* instance);
30-
bool subbrute_worker_can_transmit(SubBruteWorker* instance);
31-
bool subbrute_worker_can_manual_transmit(SubBruteWorker* instance, bool is_button_pressed);
32-
bool subbrute_worker_transmit(SubBruteWorker* instance, const char* payload);
33-
bool subbrute_worker_init_manual_transmit(
34+
bool subbrute_worker_transmit_current_key(SubBruteWorker* instance, uint64_t step);
35+
bool subbrute_worker_can_manual_transmit(SubBruteWorker* instance);
36+
void subbrute_worker_set_callback(
3437
SubBruteWorker* instance,
35-
uint32_t frequency,
36-
FuriHalSubGhzPreset preset,
37-
const char* protocol_name);
38-
bool subbrute_worker_manual_transmit(SubBruteWorker* instance, const char* payload);
39-
void subbrute_worker_manual_transmit_stop(SubBruteWorker* instance);
38+
SubBruteWorkerCallback callback,
39+
void* context);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
3+
#include "subbrute_worker.h"
4+
#include <lib/subghz/protocols/base.h>
5+
#include <lib/subghz/transmitter.h>
6+
#include <lib/subghz/receiver.h>
7+
#include <lib/subghz/environment.h>
8+
9+
struct SubBruteWorker {
10+
SubBruteWorkerState state;
11+
volatile bool worker_running;
12+
volatile bool initiated;
13+
volatile bool transmit_mode;
14+
15+
// Current step
16+
uint64_t step;
17+
18+
// SubGhz
19+
FuriThread* thread;
20+
SubGhzProtocolDecoderBase* decoder_result;
21+
SubGhzEnvironment* environment;
22+
SubGhzTransmitter* transmitter;
23+
const char* protocol_name;
24+
25+
// Initiated values
26+
SubBruteAttacks attack; // Attack state
27+
uint32_t frequency;
28+
FuriHalSubGhzPreset preset;
29+
SubBruteFileProtocol file;
30+
uint8_t bits;
31+
uint8_t te;
32+
uint8_t repeat;
33+
uint8_t load_index; // Index of group to bruteforce in loaded file
34+
const char* file_key;
35+
uint64_t max_value; // Max step
36+
37+
// Manual transmit
38+
uint32_t last_time_tx_data;
39+
40+
// Callback for changed states
41+
SubBruteWorkerCallback callback;
42+
void* context;
43+
};
44+
45+
int32_t subbrute_worker_thread(void* context);
46+
void subbrute_worker_subghz_transmit(SubBruteWorker* instance, FlipperFormat* flipper_format);
47+
void subbrute_worker_send_callback(SubBruteWorker* instance);

applications/plugins/subbrute/scenes/subbrute_scene_load_file.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "../subbrute_i.h"
2-
#include "../subbrute_custom_event.h"
3-
#include <lib/subghz/protocols/registry.h>
2+
#include "subbrute_scene.h"
43

54
#define TAG "SubBruteSceneLoadFile"
65

@@ -35,12 +34,20 @@ void subbrute_scene_load_file_on_enter(void* context) {
3534
furi_string_get_cstr(app_folder));
3635
#endif
3736
if(res) {
38-
load_result = subbrute_device_load_from_file(instance->device, load_path);
37+
load_result =
38+
subbrute_device_load_from_file(instance->device, furi_string_get_cstr(load_path));
3939
if(load_result == SubBruteFileResultOk) {
4040
load_result = subbrute_device_attack_set(instance->device, SubBruteAttackLoadFile);
4141
if(load_result == SubBruteFileResultOk) {
42+
if(!subbrute_worker_init_file_attack(
43+
instance->worker,
44+
instance->device->key_index,
45+
instance->device->load_index,
46+
instance->device->file_key,
47+
instance->device->file_protocol_info)) {
48+
furi_crash("Invalid attack set!");
49+
}
4250
// Ready to run!
43-
instance->device->state = SubBruteDeviceStateReady;
4451
FURI_LOG_I(TAG, "Ready to run");
4552
res = true;
4653
}

applications/plugins/subbrute/scenes/subbrute_scene_load_select.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
#include "../subbrute_i.h"
2-
#include "../subbrute_custom_event.h"
3-
#include "../views/subbrute_main_view.h"
2+
#include "subbrute_scene.h"
43

54
#define TAG "SubBruteSceneStart"
65

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

109
SubBruteState* instance = (SubBruteState*)context;
11-
#ifdef FURI_DEBUG
12-
FURI_LOG_D(TAG, "subbrute_scene_load_select_callback");
13-
#endif
1410
view_dispatcher_send_custom_event(instance->view_dispatcher, event);
1511
}
1612

@@ -43,9 +39,14 @@ bool subbrute_scene_load_select_on_event(void* context, SceneManagerEvent event)
4339
if(event.type == SceneManagerEventTypeCustom) {
4440
if(event.event == SubBruteCustomEventTypeIndexSelected) {
4541
instance->device->load_index = subbrute_main_view_get_index(instance->view_main);
46-
#ifdef FURI_DEBUG
47-
FURI_LOG_D(TAG, "load_index: %d", instance->device->load_index);
48-
#endif
42+
if(!subbrute_worker_init_file_attack(
43+
instance->worker,
44+
instance->device->key_index,
45+
instance->device->load_index,
46+
instance->device->file_key,
47+
instance->device->file_protocol_info)) {
48+
furi_crash("Invalid attack set!");
49+
}
4950
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
5051
consumed = true;
5152
}

0 commit comments

Comments
 (0)