Ver Fonte

Merge branch 'dev-master' into subbrute-rev3

DerSkythe há 3 anos atrás
pai
commit
adb2290eda

+ 1 - 1
applications/plugins/subbrute/application.fam

@@ -1,5 +1,5 @@
 App(
-    appid="subbrute",
+    appid="SubGHz_Bruteforcer",
     name="Sub-GHz Bruteforcer",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="subbrute_app",

+ 13 - 13
applications/plugins/subbrute/scenes/subbrute_scene_load_file.c

@@ -15,10 +15,10 @@ void subbrute_scene_load_file_on_enter(void* context) {
     SubBruteState* instance = (SubBruteState*)context;
 
     // Input events and views are managed by file_browser
-    string_t app_folder;
-    string_t load_path;
-    string_init(load_path);
-    string_init_set_str(app_folder, SUBBRUTE_PATH);
+    FuriString* app_folder;
+    FuriString* load_path;
+    load_path = furi_string_alloc();
+    app_folder = furi_string_alloc_set(SUBBRUTE_PATH);
 
     DialogsFileBrowserOptions browser_options;
     dialog_file_browser_set_basic_options(&browser_options, SUBBRUTE_FILE_EXT, &I_sub1_10px);
@@ -30,8 +30,8 @@ void subbrute_scene_load_file_on_enter(void* context) {
     FURI_LOG_D(
         TAG,
         "load_path: %s, app_folder: %s",
-        string_get_cstr(load_path),
-        string_get_cstr(app_folder));
+        furi_string_get_cstr(load_path),
+        furi_string_get_cstr(app_folder));
 #endif
     if(res) {
         load_result = subbrute_device_load_from_file(instance->device, load_path);
@@ -49,12 +49,12 @@ void subbrute_scene_load_file_on_enter(void* context) {
         } else {
             FURI_LOG_E(TAG, "Returned error: %d", load_result);
 
-            string_t dialog_msg;
-            string_init(dialog_msg);
-            string_cat_printf(
+            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));
-            dialog_message_show_storage_error(instance->dialogs, string_get_cstr(dialog_msg));
-            string_clear(dialog_msg);
+            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(
                 instance->scene_manager, SubBruteSceneStart);
         }
@@ -63,8 +63,8 @@ void subbrute_scene_load_file_on_enter(void* context) {
             instance->scene_manager, SubBruteSceneStart);
     }
 
-    string_clear(app_folder);
-    string_clear(load_path);
+    furi_string_free(app_folder);
+    furi_string_free(load_path);
 }
 
 void subbrute_scene_load_file_on_exit(void* context) {

+ 1 - 1
applications/plugins/subbrute/scenes/subbrute_scene_save_name.c

@@ -44,7 +44,7 @@ bool subbrute_scene_save_name_on_event(void* context, SceneManagerEvent event) {
 #endif
         bool success = false;
         if(strcmp(instance->text_store, "")) {
-            string_cat_printf(
+            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))) {

+ 1 - 1
applications/plugins/subbrute/scenes/subbrute_scene_start.c

@@ -41,7 +41,7 @@ bool subbrute_scene_start_on_event(void* context, SceneManagerEvent event) {
 
     if(event.type == SceneManagerEventTypeCustom) {
 #ifdef FURI_DEBUG
-        FURI_LOG_D(TAG, "Event: %d", event.event);
+        FURI_LOG_D(TAG, "Event: %ld", event.event);
 #endif
         if(event.event == SubBruteCustomEventTypeMenuSelected) {
             SubBruteAttacks attack = subbrute_main_view_get_index(instance->view_main);

+ 32 - 31
applications/plugins/subbrute/subbrute_device.c

@@ -351,41 +351,39 @@ bool subbrute_device_create_packet_parsed(
     bool small) {
     furi_assert(instance);
 
-    string_t candidate;
-    string_init(candidate);
+    FuriString* candidate = furi_string_alloc();
 
     if(instance->attack == SubBruteAttackLoadFile) {
         if(step >= sizeof(instance->file_key)) {
             return false;
         }
         char subbrute_payload_byte[4];
-        string_set_str(candidate, instance->file_key);
+        furi_string_set_str(candidate, instance->file_key);
         snprintf(subbrute_payload_byte, 4, "%02X ", (uint8_t)step);
-        string_replace_at(candidate, instance->load_index * 3, 3, subbrute_payload_byte);
+        furi_string_replace_at(candidate, instance->load_index * 3, 3, subbrute_payload_byte);
         //snprintf(step_payload, sizeof(step_payload), "%02X", (uint8_t)instance->file_key[step]);
     } else {
         //snprintf(step_payload, sizeof(step_payload), "%16X", step);
         //snprintf(step_payload, sizeof(step_payload), "%016llX", step);
-        string_t buffer;
-        string_init(buffer);
-        string_init_printf(buffer, "%16X", step);
+        FuriString* buffer = furi_string_alloc();
+        furi_string_printf(buffer, "%16llX", step);
         int j = 0;
-        string_set_str(candidate, "                       ");
+        furi_string_set_str(candidate, "                       ");
         for(uint8_t i = 0; i < 16; i++) {
-            if(string_get_char(buffer, i) != ' ') {
-                string_set_char(candidate, i + j, string_get_char(buffer, i));
+            if(furi_string_get_char(buffer, i) != ' ') {
+                furi_string_set_char(candidate, i + j, furi_string_get_char(buffer, i));
             } else {
-                string_set_char(candidate, i + j, '0');
+                furi_string_set_char(candidate, i + j, '0');
             }
             if(i % 2 != 0) {
                 j++;
             }
         }
-        string_clear(buffer);
+        furi_string_free(buffer);
     }
 
 #ifdef FURI_DEBUG
-    FURI_LOG_D(TAG, "candidate: %s, step: %d", string_get_cstr(candidate), step);
+    FURI_LOG_D(TAG, "candidate: %s, step: %lld", furi_string_get_cstr(candidate), step);
 #endif
 
     Stream* stream = flipper_format_get_raw_stream(flipper_format);
@@ -397,7 +395,7 @@ bool subbrute_device_create_packet_parsed(
                 stream,
                 subbrute_key_small_with_tail,
                 instance->protocol_info->bits,
-                string_get_cstr(candidate),
+                furi_string_get_cstr(candidate),
                 instance->protocol_info->te,
                 instance->protocol_info->repeat);
         } else {
@@ -414,7 +412,7 @@ bool subbrute_device_create_packet_parsed(
                 stream,
                 subbrute_key_file_key_with_tail,
                 instance->file_template,
-                string_get_cstr(candidate),
+                furi_string_get_cstr(candidate),
                 instance->protocol_info->te,
                 instance->protocol_info->repeat);
         } else {
@@ -430,7 +428,7 @@ bool subbrute_device_create_packet_parsed(
     //FURI_LOG_D(TAG, "payload: %s", instance->payload);
 #endif
 
-    string_clear(candidate);
+    furi_string_free(candidate);
 
     return true;
 }
@@ -477,15 +475,15 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
 
     // Calc max value
     if(instance->attack == SubBruteAttackLoadFile) {
-        instance->max_value = 0xFF;
+        instance->max_value = 0x3F;
     } else {
-        string_t max_value_s;
-        string_init(max_value_s);
+        FuriString* max_value_s;
+        max_value_s = furi_string_alloc();
         for(uint8_t i = 0; i < instance->protocol_info->bits; i++) {
-            string_cat_printf(max_value_s, "1");
+            furi_string_cat_printf(max_value_s, "1");
         }
-        instance->max_value = (uint64_t)strtol(string_get_cstr(max_value_s), NULL, 2);
-        string_clear(max_value_s);
+        instance->max_value = (uint64_t)strtol(furi_string_get_cstr(max_value_s), NULL, 2);
+        furi_string_free(max_value_s);
     }
 
     // Now we are ready to set file template for using in the future with snprintf
@@ -514,18 +512,18 @@ SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBrute
     return SubBruteFileResultOk;
 }
 
-uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_path) {
+uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, FuriString* file_path) {
     furi_assert(instance);
 #ifdef FURI_DEBUG
-    FURI_LOG_D(TAG, "subbrute_device_load_from_file: %s", string_get_cstr(file_path));
+    FURI_LOG_D(TAG, "subbrute_device_load_from_file: %s", furi_string_get_cstr(file_path));
 #endif
     SubBruteFileResult result = SubBruteFileResultUnknown;
 
     Storage* storage = furi_record_open(RECORD_STORAGE);
     FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
 
-    string_t temp_str;
-    string_init(temp_str);
+    FuriString* temp_str;
+    temp_str = furi_string_alloc();
     uint32_t temp_data32;
 
     instance->receiver = subghz_receiver_alloc_init(instance->environment);
@@ -533,8 +531,8 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_p
     furi_hal_subghz_reset();
 
     do {
-        if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_path))) {
-            FURI_LOG_E(TAG, "Error open file %s", string_get_cstr(file_path));
+        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));
             result = SubBruteFileResultErrorOpenFile;
             break;
         }
@@ -618,7 +616,10 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_p
             break;
         } else {
             snprintf(
-                instance->file_key, sizeof(instance->file_key), "%s", string_get_cstr(temp_str));
+                instance->file_key,
+                sizeof(instance->file_key),
+                "%s",
+                furi_string_get_cstr(temp_str));
 #ifdef FURI_DEBUG
             FURI_LOG_D(TAG, "Key: %s", instance->file_key);
 #endif
@@ -636,7 +637,7 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_p
         // Repeat
         if(flipper_format_read_uint32(fff_data_file, "Repeat", &temp_data32, 1)) {
 #ifdef FURI_DEBUG
-            FURI_LOG_D(TAG, "Repeat: %d", temp_data32);
+            FURI_LOG_D(TAG, "Repeat: %ld", temp_data32);
 #endif
             instance->protocol_info->repeat = (uint8_t)temp_data32;
         } else {
@@ -649,7 +650,7 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_p
         result = SubBruteFileResultOk;
     } while(0);
 
-    string_clear(temp_str);
+    furi_string_free(temp_str);
     flipper_format_file_close(fff_data_file);
     flipper_format_free(fff_data_file);
     furi_record_close(RECORD_STORAGE);

+ 50 - 1
applications/plugins/subbrute/subbrute_device.h

@@ -6,7 +6,56 @@
 #include <lib/subghz/receiver.h>
 #include <lib/subghz/environment.h>
 
-struct SubBruteDevice {
+#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 {
+    SubBruteAttackCAME12bit303,
+    SubBruteAttackCAME12bit307,
+    SubBruteAttackCAME12bit433,
+    SubBruteAttackCAME12bit868,
+    SubBruteAttackNICE12bit433,
+    SubBruteAttackNICE12bit868,
+    SubBruteAttackChamberlain9bit300,
+    SubBruteAttackChamberlain9bit315,
+    SubBruteAttackChamberlain9bit390,
+    SubBruteAttackLinear10bit300,
+    SubBruteAttackLinear10bit310,
+    SubBruteAttackLoadFile,
+    SubBruteAttackTotalCount,
+} SubBruteAttacks;
+
+typedef enum {
+    SubBruteFileResultUnknown,
+    SubBruteFileResultOk,
+    SubBruteFileResultErrorOpenFile,
+    SubBruteFileResultMissingOrIncorrectHeader,
+    SubBruteFileResultFrequencyNotAllowed,
+    SubBruteFileResultMissingOrIncorrectFrequency,
+    SubBruteFileResultPresetInvalid,
+    SubBruteFileResultMissingProtocol,
+    SubBruteFileResultProtocolNotSupported,
+    SubBruteFileResultDynamicProtocolNotValid,
+    SubBruteFileResultProtocolNotFound,
+    SubBruteFileResultMissingOrIncorrectBit,
+    SubBruteFileResultMissingOrIncorrectKey,
+    SubBruteFileResultMissingOrIncorrectTe,
+    SubBruteFileResultBigBitSize,
+} SubBruteFileResult;
+
+typedef enum {
+    SubBruteDeviceStateIDLE,
+    SubBruteDeviceStateReady,
+    SubBruteDeviceStateTx,
+    SubBruteDeviceStateFinished,
+} SubBruteDeviceState;
+
+typedef struct {
     SubBruteDeviceState state;
     SubBruteProtocol* protocol_info;
     volatile bool worker_running;

+ 0 - 1
applications/plugins/subbrute/subbrute_i.h

@@ -6,7 +6,6 @@
 
 #include <notification/notification.h>
 #include <notification/notification_messages.h>
-#include <m-string.h>
 
 #include <gui/gui.h>
 #include <gui/view_dispatcher.h>

+ 5 - 1
applications/plugins/subbrute/views/subbrute_attack_view.c

@@ -249,7 +249,11 @@ void subbrute_attack_view_init_values(
     bool is_attacking) {
 #ifdef FURI_DEBUG
     FURI_LOG_D(
-        TAG, "init, index: %d, max_value: %d, current_step: %d", index, max_value, current_step);
+        TAG,
+        "init, index: %d, max_value: %lld, current_step: %lld",
+        index,
+        max_value,
+        current_step);
 #endif
     with_view_model(
         instance->view, (SubBruteAttackViewModel * model) {

+ 7 - 7
applications/plugins/subbrute/views/subbrute_main_view.c

@@ -34,7 +34,7 @@ void subbrute_main_view_set_callback(
     instance->context = context;
 }
 
-void center_displayed_key(string_t result, const char* key_cstr, uint8_t index) {
+FuriString* center_displayed_key(const char* key_cstr, uint8_t index) {
     uint8_t str_index = (index * 3);
 
     char display_menu[] = {
@@ -76,7 +76,7 @@ void center_displayed_key(string_t result, const char* key_cstr, uint8_t index)
             display_menu[15] = ' ';
         }
     }
-    string_init_set_str(result, display_menu);
+    return furi_string_alloc_set(display_menu);
 }
 
 void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) {
@@ -97,19 +97,19 @@ void subbrute_main_view_draw(Canvas* canvas, SubBruteMainViewModel* model) {
         snprintf(msg_index, sizeof(msg_index), "Field index : %d", m->index);
         canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, msg_index);
 
-        string_t menu_items;
-        string_init(menu_items);
+        FuriString* menu_items;
 
-        center_displayed_key(menu_items, m->key_field, m->index);
+        menu_items = center_displayed_key(m->key_field, m->index);
         canvas_set_font(canvas, FontSecondary);
         canvas_draw_str_aligned(
-            canvas, 64, 40, AlignCenter, AlignTop, string_get_cstr(menu_items));
+            canvas, 64, 40, AlignCenter, AlignTop, furi_string_get_cstr(menu_items));
 
         elements_button_center(canvas, "Select");
         elements_button_left(canvas, "<");
         elements_button_right(canvas, ">");
 
-        string_reset(menu_items);
+        furi_string_reset(menu_items);
+        furi_string_free(menu_items);
     } else {
         // Menu
         canvas_set_color(canvas, ColorBlack);