1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-13 13:09:49 +04:00

Fix compile errors

This commit is contained in:
DerSkythe
2022-10-08 02:24:19 +04:00
parent 0c5146e047
commit 7ec4cb4b7a
14 changed files with 106 additions and 177 deletions

View File

@@ -4,17 +4,17 @@ App(
apptype=FlipperAppType.METAPACKAGE,
provides=[
"gpio",
"ibutton",
"infrared",
"lfrfid",
"nfc",
#"ibutton",
#"infrared",
#"lfrfid",
#"nfc",
"subghz",
"bad_usb",
"u2f",
#"bad_usb",
#"u2f",
"fap_loader",
"archive",
"clock",
"unirfremix",
#"unirfremix",
],
)

View File

@@ -34,7 +34,8 @@ 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) {
@@ -51,8 +52,7 @@ void subbrute_scene_load_file_on_enter(void* context) {
FuriString* dialog_msg;
dialog_msg = furi_string_alloc();
furi_string_cat_printf(
dialog_msg, "Cannot parse\nfile: %s", subbrute_device_error_get_desc(load_result));
furi_string_cat_printf(dialog_msg, "Cannot parse\nfile: %s", subbrute_device_error_get_desc(load_result));
dialog_message_show_storage_error(instance->dialogs, furi_string_get_cstr(dialog_msg));
furi_string_free(dialog_msg);
scene_manager_search_and_switch_to_previous_scene(

View File

@@ -7,9 +7,6 @@ void subbrute_scene_load_select_callback(SubBruteCustomEvent event, void* contex
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);
}

View File

@@ -1,5 +1,6 @@
#include "../subbrute_i.h"
#include "subbrute_scene.h"
#include <core/string.h>
#include <lib/toolbox/random_name.h>
#define TAG "SubBruteSceneSaveFile"
@@ -20,10 +21,11 @@ void subbrute_scene_save_name_on_enter(void* context) {
SUBBRUTE_MAX_LEN_NAME,
true);
string_set_str(instance->file_path, SUBBRUTE_PATH);
furi_string_reset(instance->file_path);
furi_string_set_str(instance->file_path, SUBBRUTE_PATH);
ValidatorIsFile* validator_is_file =
validator_is_file_alloc_init(string_get_cstr(instance->file_path), SUBBRUTE_FILE_EXT, "");
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
furi_string_get_cstr(instance->file_path), SUBBRUTE_FILE_EXT, "");
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
view_dispatcher_switch_to_view(instance->view_dispatcher, SubBruteViewTextInput);
@@ -44,10 +46,11 @@ bool subbrute_scene_save_name_on_event(void* context, SceneManagerEvent event) {
#endif
bool success = false;
if(strcmp(instance->text_store, "")) {
furi_string_reset(instance->file_path);
furi_string_cat_printf(
instance->file_path, "/%s%s", instance->text_store, SUBBRUTE_FILE_EXT);
if(subbrute_device_save_file(instance->device, string_get_cstr(instance->file_path))) {
if(subbrute_device_save_file(instance->device, furi_string_get_cstr(instance->file_path))) {
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveSuccess);
success = true;
consumed = true;
@@ -73,5 +76,5 @@ void subbrute_scene_save_name_on_exit(void* context) {
text_input_reset(instance->text_input);
string_reset(instance->file_path);
furi_string_reset(instance->file_path);
}

View File

@@ -26,7 +26,7 @@ SubBruteState* subbrute_alloc() {
SubBruteState* instance = malloc(sizeof(SubBruteState));
memset(instance->text_store, 0, sizeof(instance->text_store));
string_init(instance->file_path);
instance->file_path = furi_string_alloc();
instance->scene_manager = scene_manager_alloc(&subbrute_scene_handlers, instance);
instance->view_dispatcher = view_dispatcher_alloc();
@@ -187,13 +187,9 @@ void subbrute_free(SubBruteState* instance) {
furi_record_close(RECORD_GUI);
instance->gui = NULL;
string_clear(instance->file_path);
string_init(instance->file_path);
furi_string_free(instance->file_path);
// The rest
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "free instance");
#endif
free(instance);
}

View File

@@ -1,8 +1,10 @@
#include "subbrute_device.h"
//#include "subbrute_device.h"
#include <lib/toolbox/stream/stream.h>
#include <stdint.h>
#include <stream/buffered_file_stream.h>
#include <storage/storage.h>
#include <lib/toolbox/stream/stream.h>
#include <lib/flipper_format/flipper_format.h>
#include <lib/flipper_format/flipper_format_i.h>
#define TAG "SubBruteDevice"
@@ -50,17 +52,11 @@ SubBruteDevice* subbrute_device_alloc() {
void subbrute_device_free(SubBruteDevice* instance) {
furi_assert(instance);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subbrute_device_free");
#endif
// I don't know how to free this
instance->decoder_result = NULL;
if(instance->receiver != NULL) {
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subghz_receiver_free");
#endif
subghz_receiver_free(instance->receiver);
instance->receiver = NULL;
}
@@ -73,10 +69,6 @@ void subbrute_device_free(SubBruteDevice* instance) {
subghz_environment_free(instance->environment);
instance->environment = NULL;
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "before free");
#endif
furi_thread_free(instance->thread);
subbrute_device_free_protocol_info(instance);
@@ -186,6 +178,9 @@ SubBruteAttacks subbrute_device_get_attack(SubBruteDevice* instance) {
bool subbrute_device_is_worker_running(SubBruteDevice* instance) {
return instance->worker_running;
}
uint64_t subbrute_device_get_max_value(SubBruteDevice* instance) {
return instance->max_value;
}
uint64_t subbrute_device_get_step(SubBruteDevice* instance) {
return instance->key_index;
}
@@ -267,7 +262,7 @@ bool subbrute_device_transmit_current_key(SubBruteDevice* instance) {
uint32_t ticks = furi_get_tick();
if((ticks - instance->last_time_tx_data) < SUBBRUTE_MANUAL_TRANSMIT_INTERVAL) {
#if FURI_DEBUG
FURI_LOG_D(TAG, "Need to wait, current: %d", ticks - instance->last_time_tx_data);
FURI_LOG_D(TAG, "Need to wait, current: %ld", ticks - instance->last_time_tx_data);
#endif
return false;
}
@@ -403,7 +398,7 @@ bool subbrute_device_create_packet_parsed(
stream,
subbrute_key_small_no_tail,
instance->protocol_info->bits,
string_get_cstr(candidate),
furi_string_get_cstr(candidate),
instance->protocol_info->repeat);
}
} else {
@@ -420,7 +415,7 @@ bool subbrute_device_create_packet_parsed(
stream,
subbrute_key_file_key,
instance->file_template,
string_get_cstr(candidate),
furi_string_get_cstr(candidate),
instance->protocol_info->repeat);
}
}
@@ -512,10 +507,10 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
return SubBruteFileResultOk;
}
uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, FuriString* file_path) {
uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, const char* file_path) {
furi_assert(instance);
#ifdef FURI_DEBUG
FURI_LOG_D(TAG, "subbrute_device_load_from_file: %s", furi_string_get_cstr(file_path));
FURI_LOG_D(TAG, "subbrute_device_load_from_file: %s", file_path);
#endif
SubBruteFileResult result = SubBruteFileResultUnknown;
@@ -531,8 +526,8 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, FuriString* fil
furi_hal_subghz_reset();
do {
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_path))) {
FURI_LOG_E(TAG, "Error open file %s", furi_string_get_cstr(file_path));
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
FURI_LOG_E(TAG, "Error open file %s", file_path);
result = SubBruteFileResultErrorOpenFile;
break;
}
@@ -743,4 +738,11 @@ const char* subbrute_device_error_get_desc(SubBruteFileResult error_id) {
break;
}
return result;
}
void subbrute_device_free_protocol_info(SubBruteDevice* instance) {
furi_assert(instance);
free(instance->protocol_info);
instance->protocol_info = NULL;
}

View File

@@ -1,6 +1,6 @@
#pragma once
#include "subbrute_device_i.h"
#include "subbrute_protocols.h"
#include <lib/subghz/protocols/base.h>
#include <lib/subghz/transmitter.h>
#include <lib/subghz/receiver.h>
@@ -14,22 +14,6 @@
#define SUBBRUTE_PAYLOAD_SIZE 16
typedef enum {
SubBruteAttackCAME12bit303,
SubBruteAttackCAME12bit307,
SubBruteAttackCAME12bit433,
SubBruteAttackCAME12bit868,
SubBruteAttackNICE12bit433,
SubBruteAttackNICE12bit868,
SubBruteAttackChamberlain9bit300,
SubBruteAttackChamberlain9bit315,
SubBruteAttackChamberlain9bit390,
SubBruteAttackLinear10bit300,
SubBruteAttackLinear10bit310,
SubBruteAttackLoadFile,
SubBruteAttackTotalCount,
} SubBruteAttacks;
typedef enum {
SubBruteFileResultUnknown,
SubBruteFileResultOk,
@@ -45,16 +29,16 @@ typedef enum {
SubBruteFileResultMissingOrIncorrectBit,
SubBruteFileResultMissingOrIncorrectKey,
SubBruteFileResultMissingOrIncorrectTe,
SubBruteFileResultBigBitSize,
} SubBruteFileResult;
typedef enum {
SubBruteDeviceStateIDLE,
SubBruteDeviceStateReady,
SubBruteDeviceStateTx,
SubBruteDeviceStateFinished,
SubBruteDeviceStateFinished
} SubBruteDeviceState;
typedef void (*SubBruteDeviceWorkerCallback)(void* context, SubBruteDeviceState state);
typedef struct {
SubBruteDeviceState state;
SubBruteProtocol* protocol_info;
@@ -88,11 +72,34 @@ typedef struct {
// Callback for changed states
SubBruteDeviceWorkerCallback callback;
void* context;
};
} SubBruteDevice;
SubBruteDevice* subbrute_device_alloc();
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);
uint8_t subbrute_device_load_from_file(SubBruteDevice* context, const char* file_path);
bool subbrute_device_is_worker_running(SubBruteDevice* instance);
SubBruteAttacks subbrute_device_get_attack(SubBruteDevice* instance);
uint64_t subbrute_device_get_max_value(SubBruteDevice* instance);
uint64_t subbrute_device_get_step(SubBruteDevice* instance);
uint64_t subbrute_device_add_step(SubBruteDevice* instance, int8_t step);
void subbrute_device_set_load_index(SubBruteDevice* instance, uint64_t load_index);
void subbrute_device_reset_step(SubBruteDevice* instance);
const char* subbrute_device_get_file_key(SubBruteDevice* instance);
bool subbrute_worker_start(SubBruteDevice* instance);
void subbrute_worker_stop(SubBruteDevice* instance);
bool subbrute_device_transmit_current_key(SubBruteDevice* instance);
bool subbrute_device_can_manual_transmit(SubBruteDevice* instance);
void subbrute_device_set_callback(
SubBruteDevice* instance,
SubBruteDeviceWorkerCallback callback,
void* context);
/*
* PRIVATE METHODS
*/
void subbrute_device_free_protocol_info(SubBruteDevice* instance);
int32_t subbrute_worker_thread(void* context);
void subbrute_device_attack_set_default_values(
@@ -104,4 +111,4 @@ bool subbrute_device_create_packet_parsed(
uint64_t step,
bool small);
void subbrute_device_send_callback(SubBruteDevice* instance);
void subbrute_device_subghz_transmit(SubBruteDevice* instance, FlipperFormat* flipper_format);
void subbrute_device_subghz_transmit(SubBruteDevice* instance, FlipperFormat* flipper_format);

View File

@@ -1,64 +0,0 @@
#pragma once
#include "subbrute_protocols.h"
#define SUBBRUTE_TEXT_STORE_SIZE 256
#define SUBBRUTE_MAX_LEN_NAME 64
#define SUBBRUTE_PATH EXT_PATH("subghz")
#define SUBBRUTE_FILE_EXT ".sub"
#define SUBBRUTE_PAYLOAD_SIZE 16
typedef enum {
SubBruteFileResultUnknown,
SubBruteFileResultOk,
SubBruteFileResultErrorOpenFile,
SubBruteFileResultMissingOrIncorrectHeader,
SubBruteFileResultFrequencyNotAllowed,
SubBruteFileResultMissingOrIncorrectFrequency,
SubBruteFileResultPresetInvalid,
SubBruteFileResultMissingProtocol,
SubBruteFileResultProtocolNotSupported,
SubBruteFileResultDynamicProtocolNotValid,
SubBruteFileResultProtocolNotFound,
SubBruteFileResultMissingOrIncorrectBit,
SubBruteFileResultMissingOrIncorrectKey,
SubBruteFileResultMissingOrIncorrectTe,
} SubBruteFileResult;
typedef enum {
SubBruteDeviceStateIDLE,
SubBruteDeviceStateReady,
SubBruteDeviceStateTx,
SubBruteDeviceStateFinished
} SubBruteDeviceState;
typedef void (*SubBruteDeviceWorkerCallback)(void* context, SubBruteDeviceState state);
typedef struct SubBruteDevice SubBruteDevice;
SubBruteDevice* subbrute_device_alloc();
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);
uint8_t subbrute_device_load_from_file(SubBruteDevice* context, string_t file_path);
bool subbrute_device_is_worker_running(SubBruteDevice* instance);
SubBruteAttacks subbrute_device_get_attack(SubBruteDevice* instance);
uint64_t subbrute_device_get_max_value(SubBruteDevice* instance);
uint64_t subbrute_device_get_step(SubBruteDevice* instance);
uint64_t subbrute_device_add_step(SubBruteDevice* instance, int8_t step);
void subbrute_device_set_load_index(SubBruteDevice* instance, uint64_t load_index);
void subbrute_device_reset_step(SubBruteDevice* instance);
const char* subbrute_device_get_file_key(SubBruteDevice* instance);
bool subbrute_worker_start(SubBruteDevice* instance);
void subbrute_worker_stop(SubBruteDevice* instance);
bool subbrute_device_transmit_current_key(SubBruteDevice* instance);
bool subbrute_device_can_manual_transmit(SubBruteDevice* instance);
void subbrute_device_set_callback(
SubBruteDevice* instance,
SubBruteDeviceWorkerCallback callback,
void* context);

View File

@@ -22,7 +22,7 @@
#include <notification/notification_messages.h>
#include "subbrute.h"
#include "subbrute_device_i.h"
#include "subbrute_device.h"
#include "views/subbrute_attack_view.h"
#include "views/subbrute_main_view.h"
@@ -51,7 +51,7 @@ struct SubBruteState {
// Text store
char text_store[SUBBRUTE_MAX_LEN_NAME];
string_t file_path;
FuriString* file_path;
// Views
SubBruteMainView* view_main;

View File

@@ -1,6 +1,8 @@
#include "subbrute_protocols.h"
static const SubBruteProtocol subbrute_protocols[SubBruteAttackTotalCount] = {
[SubBruteAttackCAME12bit303] =
{303875000, 12, 0, 3, FuriHalSubGhzPresetOok650Async, CAMEFileProtocol},
[SubBruteAttackCAME12bit307] =
{307800000, 12, 0, 3, FuriHalSubGhzPresetOok650Async, CAMEFileProtocol},
[SubBruteAttackCAME12bit433] =
@@ -38,6 +40,7 @@ static const SubBruteProtocol subbrute_protocols[SubBruteAttackTotalCount] = {
//};
static const char* subbrute_protocol_names[] = {
[SubBruteAttackCAME12bit303] = "CAME 12bit 303MHz",
[SubBruteAttackCAME12bit307] = "CAME 12bit 307MHz",
[SubBruteAttackCAME12bit433] = "CAME 12bit 433MHz",
[SubBruteAttackCAME12bit868] = "CAME 12bit 868MHz",
@@ -106,9 +109,9 @@ const char* subbrute_protocol_file(SubBruteFileProtocol protocol) {
return subbrute_protocol_file_types[protocol];
}
FuriHalSubGhzPreset subbrute_protocol_convert_preset(string_t preset_name) {
for(size_t i = FuriHalSubGhzPresetIDLE; i<FuriHalSubGhzPresetCustom;i++) {
if(string_cmp_str(preset_name, subbrute_protocol_presets[i]) == 0) {
FuriHalSubGhzPreset subbrute_protocol_convert_preset(FuriString* preset_name) {
for(size_t i = FuriHalSubGhzPresetIDLE; i < FuriHalSubGhzPresetCustom; i++) {
if(furi_string_cmp_str(preset_name, subbrute_protocol_presets[i]) == 0) {
return i;
}
}
@@ -116,9 +119,9 @@ FuriHalSubGhzPreset subbrute_protocol_convert_preset(string_t preset_name) {
return FuriHalSubGhzPresetIDLE;
}
SubBruteFileProtocol subbrute_protocol_file_protocol_name(string_t name) {
for(size_t i = CAMEFileProtocol; i<TotalFileProtocol-1;i++) {
if(string_cmp_str(name, subbrute_protocol_file_types[i]) == 0) {
SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name) {
for(size_t i = CAMEFileProtocol; i < TotalFileProtocol - 1; i++) {
if(furi_string_cmp_str(name, subbrute_protocol_file_types[i]) == 0) {
return i;
}
}

View File

@@ -1,9 +1,8 @@
#pragma once
#include "subbrute_protocols_i.h"
#include <furi.h>
#include <m-string.h>
#include <furi_hal_subghz.h>
#include <core/string.h>
//typedef enum {
// FrequencyProtocolField,
@@ -25,6 +24,22 @@ typedef enum {
TotalFileProtocol,
} SubBruteFileProtocol;
typedef enum {
SubBruteAttackCAME12bit303,
SubBruteAttackCAME12bit307,
SubBruteAttackCAME12bit433,
SubBruteAttackCAME12bit868,
SubBruteAttackNICE12bit433,
SubBruteAttackNICE12bit868,
SubBruteAttackChamberlain9bit300,
SubBruteAttackChamberlain9bit315,
SubBruteAttackChamberlain9bit390,
SubBruteAttackLinear10bit300,
SubBruteAttackLinear10bit310,
SubBruteAttackLoadFile,
SubBruteAttackTotalCount,
} SubBruteAttacks;
typedef struct {
uint32_t frequency;
uint8_t bits;
@@ -38,5 +53,6 @@ SubBruteProtocol* subbrute_protocol_alloc(void);
SubBruteProtocol* subbrute_protocol(SubBruteAttacks index);
const char* subbrute_protocol_preset(FuriHalSubGhzPreset preset);
const char* subbrute_protocol_file(SubBruteFileProtocol protocol);
FuriHalSubGhzPreset subbrute_protocol_convert_preset(string_t preset_name);
SubBruteFileProtocol subbrute_protocol_file_protocol_name(string_t name);
FuriHalSubGhzPreset subbrute_protocol_convert_preset(FuriString* preset_name);
SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name);
const char* subbrute_protocol_name(SubBruteAttacks index);

View File

@@ -1,18 +0,0 @@
#pragma once
typedef enum {
SubBruteAttackCAME12bit307,
SubBruteAttackCAME12bit433,
SubBruteAttackCAME12bit868,
SubBruteAttackNICE12bit433,
SubBruteAttackNICE12bit868,
SubBruteAttackChamberlain9bit300,
SubBruteAttackChamberlain9bit315,
SubBruteAttackChamberlain9bit390,
SubBruteAttackLinear10bit300,
SubBruteAttackLinear10bit310,
SubBruteAttackLoadFile,
SubBruteAttackTotalCount,
} SubBruteAttacks;
const char* subbrute_protocol_name(SubBruteAttacks index);

View File

@@ -1,6 +1,6 @@
#include "subbrute_attack_view.h"
#include "../subbrute_i.h"
#include "../subbrute_protocols_i.h"
#include "../subbrute_protocols.h"
#include "assets_icons.h"
#include <input/input.h>
@@ -299,10 +299,6 @@ void elements_button_top_left(Canvas* canvas, const char* str) {
const uint8_t y = 0;
canvas_draw_box(canvas, x, y, button_width, button_height);
#ifdef FURI_DEBUG
FURI_LOG_D(
TAG, "lbox, x: %d, y: %d, width: %d, height: %d", x, y, button_width, button_height);
#endif
// canvas_draw_line(canvas, x + button_width + 0, y, x + button_width + 0, y + button_height - 0); //
// canvas_draw_line(canvas, x + button_width + 1, y, x + button_width + 1, y + button_height - 1);
// canvas_draw_line(canvas, x + button_width + 2, y, x + button_width + 2, y + button_height - 2);
@@ -330,15 +326,6 @@ void elements_button_top_right(Canvas* canvas, const char* str) {
const uint8_t y = 0;
canvas_draw_box(canvas, x - button_width, y, button_width, button_height);
#ifdef FURI_DEBUG
FURI_LOG_D(
TAG,
"rbox, x: %d, y: %d, width: %d, height: %d",
x - button_width,
y,
button_width,
button_height);
#endif
// canvas_draw_line(canvas, x - button_width - 1, y, x + button_width - 1, y + button_height - 0);
// canvas_draw_line(canvas, x - button_width - 2, y, x + button_width - 2, y + button_height - 1);
// canvas_draw_line(canvas, x - button_width - 3, y, x + button_width - 3, y + button_height - 2);

View File

@@ -1,6 +1,6 @@
#include "subbrute_main_view.h"
#include "../subbrute_i.h"
#include "../subbrute_protocols_i.h"
#include "../subbrute_protocols.h"
#include <input/input.h>
#include <gui/elements.h>
@@ -86,7 +86,7 @@ void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) {
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");
canvas_draw_str_aligned(canvas, 64, 3, AlignCenter, AlignTop, "Sub-GHz BruteForcer v3");
canvas_invert_color(canvas);
if(m->is_select_byte) {