derskythe 3 vuotta sitten
vanhempi
commit
d8fe9697f9

+ 8 - 2
scenes/subbrute_scene_load_file.c

@@ -17,8 +17,14 @@ void subbrute_scene_load_file_on_enter(void* context) {
     dialog_file_browser_set_basic_options(&browser_options, SUBBRUTE_FILE_EXT, &I_sub1_10px);
 
     SubBruteFileResult load_result = SubBruteFileResultUnknown;
+    // TODO: DELETE IT
+#ifdef SUBBRUTE_FAST_TRACK
+    bool res = true;
+    furi_string_printf(load_path, "%s", "/ext/subghz/princeton.sub");
+#else
     bool res =
         dialog_file_browser_show(instance->dialogs, load_path, app_folder, &browser_options);
+#endif
 #ifdef FURI_DEBUG
     FURI_LOG_D(
         TAG,
@@ -37,8 +43,8 @@ void subbrute_scene_load_file_on_enter(void* context) {
             if(load_result == SubBruteFileResultOk) {
                 if(!subbrute_worker_init_file_attack(
                        instance->worker,
-                       instance->device->key_index,
-                       instance->device->load_index,
+                       instance->device->current_step,
+                       instance->device->current_step,
                        instance->device->file_key,
                        instance->device->file_protocol_info,
                        extra_repeats)) {

+ 8 - 3
scenes/subbrute_scene_load_select.c

@@ -38,19 +38,24 @@ 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 && !SUBBRUTE_FAST_TRACK
+            view_dispatcher_stop(instance->view_dispatcher);
+            consumed = true;
+#else*/
+            instance->device->current_step = subbrute_main_view_get_index(instance->view_main);
             uint8_t extra_repeats = subbrute_main_view_get_extra_repeats(instance->view_main);
 
             if(!subbrute_worker_init_file_attack(
                    instance->worker,
-                   instance->device->key_index,
-                   instance->device->load_index,
+                   instance->device->current_step,
+                   instance->device->current_step,
                    instance->device->file_key,
                    instance->device->file_protocol_info,
                    extra_repeats)) {
                 furi_crash("Invalid attack set!");
             }
             scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
+            /*#endif*/
             consumed = true;
         }
     } else if(event.type == SceneManagerEventTypeBack) {

+ 6 - 1
scenes/subbrute_scene_start.c

@@ -26,6 +26,11 @@ void subbrute_scene_start_on_enter(void* context) {
     subbrute_main_view_set_index(view, instance->device->attack, false, NULL);
 
     view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
+
+    // TODO: DELETE IT
+#ifdef SUBBRUTE_FAST_TRACK
+    scene_manager_next_scene(instance->scene_manager, SubBruteSceneLoadFile);
+#endif
 }
 
 void subbrute_scene_start_on_exit(void* context) {
@@ -57,7 +62,7 @@ bool subbrute_scene_start_on_event(void* context, SceneManagerEvent event) {
                (!subbrute_worker_init_default_attack(
                    instance->worker,
                    attack,
-                   instance->device->key_index,
+                   instance->device->current_step,
                    instance->device->protocol_info,
                    instance->device->extra_repeats))) {
                 furi_crash("Invalid attack set!");

+ 81 - 32
subbrute_device.c

@@ -12,7 +12,7 @@
 SubBruteDevice* subbrute_device_alloc() {
     SubBruteDevice* instance = malloc(sizeof(SubBruteDevice));
 
-    instance->key_index = 0;
+    instance->current_step = 0;
 
     instance->protocol_info = NULL;
     instance->file_protocol_info = NULL;
@@ -25,7 +25,7 @@ SubBruteDevice* subbrute_device_alloc() {
 #ifdef FURI_DEBUG
     subbrute_device_attack_set_default_values(instance, SubBruteAttackCAME12bit433);
 #else
-    subbrute_device_attack_set_default_values(instance, SubBruteAttackCAME12bit433);
+    subbrute_device_attack_set_default_values(instance, SubBruteAttackLoadFile);
 #endif
     return instance;
 }
@@ -51,32 +51,32 @@ void subbrute_device_free(SubBruteDevice* instance) {
 
 uint64_t subbrute_device_add_step(SubBruteDevice* instance, int8_t step) {
     if(step > 0) {
-        if((instance->key_index + step) - instance->max_value == 1) {
-            instance->key_index = 0x00;
+        if((instance->current_step + step) - instance->max_value == 1) {
+            instance->current_step = 0x00;
         } else {
-            uint64_t value = instance->key_index + step;
+            uint64_t value = instance->current_step + step;
             if(value == instance->max_value) {
-                instance->key_index = value;
+                instance->current_step = value;
             } else {
-                instance->key_index = value % instance->max_value;
+                instance->current_step = value % instance->max_value;
             }
         }
     } else {
-        if(instance->key_index + step == 0) {
-            instance->key_index = 0x00;
-        } else if(instance->key_index == 0) {
-            instance->key_index = instance->max_value;
+        if(instance->current_step + step == 0) {
+            instance->current_step = 0x00;
+        } else if(instance->current_step == 0) {
+            instance->current_step = instance->max_value;
         } else {
-            uint64_t value = ((instance->key_index + step) + instance->max_value);
+            uint64_t value = ((instance->current_step + step) + instance->max_value);
             if(value == instance->max_value) {
-                instance->key_index = value;
+                instance->current_step = value;
             } else {
-                instance->key_index = value % instance->max_value;
+                instance->current_step = value % instance->max_value;
             }
         }
     }
 
-    return instance->key_index;
+    return instance->current_step;
 }
 
 bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_name) {
@@ -101,19 +101,20 @@ bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_na
                 instance->file_protocol_info->frequency,
                 instance->file_protocol_info->preset,
                 instance->file_protocol_info->file,
-                instance->key_index,
+                instance->current_step,
                 instance->file_protocol_info->bits,
                 instance->file_protocol_info->te,
                 instance->file_protocol_info->repeat,
-                instance->load_index,
-                instance->file_key);
+                instance->bit_index,
+                instance->key_from_file,
+                instance->two_bytes);
         } else {
             subbrute_protocol_default_generate_file(
                 stream,
                 instance->protocol_info->frequency,
                 instance->protocol_info->preset,
                 instance->protocol_info->file,
-                instance->key_index,
+                instance->current_step,
                 instance->protocol_info->bits,
                 instance->protocol_info->te,
                 instance->protocol_info->repeat);
@@ -324,21 +325,68 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, const char* fil
 #endif
         }
 
+        // TODO: Delete this
         // Key
-        if(!flipper_format_read_string(fff_data_file, "Key", temp_str)) {
-            FURI_LOG_E(TAG, "Missing or incorrect Key");
+        //         if(!flipper_format_read_string(fff_data_file, "Key", temp_str)) {
+        //             FURI_LOG_E(TAG, "Missing or incorrect Key");
+        //             result = SubBruteFileResultMissingOrIncorrectKey;
+        //             break;
+        //         } else {
+        //             snprintf(
+        //                 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
+        //         }
+        //
+        //         flipper_format_rewind(fff_data_file);
+
+        uint8_t key_data[sizeof(uint64_t)] = {0};
+        if(!flipper_format_read_hex(fff_data_file, "Key", key_data, sizeof(uint64_t))) {
+            FURI_LOG_E(TAG, "Missing Key");
             result = SubBruteFileResultMissingOrIncorrectKey;
             break;
-        } else {
-            snprintf(
-                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
         }
+        uint64_t data = 0;
+        for(uint8_t i = 0; i < sizeof(uint64_t); i++) {
+            data = (data << 8) | key_data[i];
+        }
+        instance->key_from_file = data;
+
+        uint16_t add_value = 0x0001;
+        uint8_t bit_index = 7;
+        bool two_bytes = true;
+
+        uint8_t p[8];
+        for(int i = 0; i < 8; i++) {
+            p[i] = (uint8_t)(instance->key_from_file >> 8 * (7 - i)) & 0xFF;
+        }
+        uint16_t num = two_bytes ? (p[bit_index - 1] << 8) | p[bit_index] : p[bit_index];
+        FURI_LOG_D(TAG, "num: 0x%04X", num);
+        num += add_value;
+        FURI_LOG_D(TAG, "num added: 0x%04X", num);
+        uint8_t low_byte = num & (0xff);
+        uint8_t high_byte = (num >> 8) & 0xff;
+
+        data = 0;
+        for(uint8_t i = 0; i < sizeof(uint64_t); i++) {
+            if(i == bit_index - 1 && two_bytes) {
+                data = (data << 8) | high_byte;
+                data = (data << 8) | low_byte;
+                i++;
+            } else if(i == bit_index) {
+                data = (data << 8) | low_byte;
+            } else {
+                data = (data << 8) | p[i];
+            }
+        }
+
+        furi_string_printf(temp_str, "Key: %lX", (uint32_t)(data & 0xFFFFFFFF));
+        FURI_LOG_D(
+            TAG, "H: 0x%02X, L: 0x%02X, %s", high_byte, low_byte, furi_string_get_cstr(temp_str));
 
         // TE
         if(!flipper_format_read_uint32(fff_data_file, "TE", &temp_data32, 1)) {
@@ -394,9 +442,10 @@ void subbrute_device_attack_set_default_values(
     FURI_LOG_D(TAG, "subbrute_device_attack_set_default_values");
 #endif
     instance->attack = default_attack;
-    instance->key_index = 0x00;
-    instance->load_index = 0x00;
+    instance->current_step = 0x00;
+    instance->bit_index = 0x00;
     instance->extra_repeats = 0;
+    instance->two_bytes = false;
     memset(instance->current_key, 0, sizeof(instance->current_key));
 
     if(default_attack != SubBruteAttackLoadFile) {

+ 6 - 3
subbrute_device.h

@@ -36,9 +36,7 @@ typedef struct {
     SubBruteProtocol* file_protocol_info;
 
     // Current step
-    uint64_t key_index;
-    // Index of group to bruteforce in loaded file
-    uint8_t load_index;
+    uint64_t current_step;
 
     // SubGhz
     SubGhzReceiver* receiver;
@@ -53,6 +51,11 @@ typedef struct {
     // Loaded info for attack type
     char current_key[SUBBRUTE_PAYLOAD_SIZE];
     char file_key[SUBBRUTE_MAX_LEN_NAME];
+    uint64_t key_from_file;
+    uint64_t current_key_from_file;
+    bool two_bytes;
+    // Index of group to bruteforce in loaded file
+    uint8_t bit_index;
 } SubBruteDevice;
 
 SubBruteDevice* subbrute_device_alloc();

+ 4 - 0
subbrute_i.h

@@ -29,6 +29,10 @@
 #include "views/subbrute_attack_view.h"
 #include "views/subbrute_main_view.h"
 
+#ifdef FURI_DEBUG
+#define SUBBRUTE_FAST_TRACK true
+#endif
+
 typedef enum {
     SubBruteViewNone,
     SubBruteViewMain,

+ 32 - 10
subbrute_protocols.c

@@ -480,21 +480,43 @@ void subbrute_protocol_file_generate_file(
     uint8_t bits,
     uint8_t te,
     uint8_t repeat,
-    uint8_t load_index,
-    const char* file_key) {
+    uint8_t bit_index,
+    uint64_t file_key,
+    bool two_bytes) {
     FuriString* candidate = furi_string_alloc();
-    char subbrute_payload_byte[8];
-    furi_string_set_str(candidate, file_key);
+    // char subbrute_payload_byte[8];
+    //furi_string_set_str(candidate, file_key);
 
-    for(int8_t shift = 8 * sizeof(step) - 4; shift >= 0; shift -= 4) {
-        uint8_t hexDigit = (step >> shift) & 0xF;
-        snprintf(subbrute_payload_byte, 4, "%02X ", hexDigit);
+    uint8_t p[8];
+    for(int i = 0; i < 8; i++) {
+        p[i] = (uint8_t)(file_key >> 8 * (7 - i)) & 0xFF;
+    }
+    uint16_t num = two_bytes ? (p[bit_index - 1] << 8) | p[bit_index] : p[bit_index];
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "num: 0x%04X", num);
+#endif
+    num += step;
+#ifdef FURI_DEBUG
+    FURI_LOG_D(TAG, "num added: 0x%04X", num);
+#endif
+    uint8_t low_byte = num & (0xff);
+    uint8_t high_byte = (num >> 8) & 0xff;
+
+    size_t size = sizeof(uint64_t);
+    for(uint8_t i = 0; i < size; i++) {
+        if(i == bit_index - 1 && two_bytes) {
+            furi_string_cat_printf(candidate, "%02X %02X", high_byte, low_byte);
+            i++;
+        } else if(i == bit_index) {
+            furi_string_cat_printf(candidate, "%02X", low_byte);
+        } else {
+            furi_string_cat_printf(candidate, "%02X", p[i]);
+        }
 
-        if(((shift & 0xF) == 0) && (shift > 0)) {
-            //ptr->print(" ");
+        if(i < size - 1) {
+            furi_string_push_back(candidate, ' ');
         }
     }
-    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);

+ 3 - 2
subbrute_protocols.h

@@ -94,6 +94,7 @@ void subbrute_protocol_file_generate_file(
     uint8_t bits,
     uint8_t te,
     uint8_t repeat,
-    uint8_t load_index,
-    const char* file_key);
+    uint8_t bit_index,
+    uint64_t file_key,
+    bool two_bytes);
 uint64_t subbrute_protocol_calc_max_value(SubBruteAttacks attack_type, uint8_t bits);

+ 4 - 4
views/subbrute_main_view.c

@@ -264,18 +264,18 @@ bool subbrute_main_view_input(InputEvent* event, void* context) {
                 }
             }
         }
-    } else {
-        if(event->key == InputKeyLeft && is_short) {
+    } else if (is_short) {
+        if(event->key == InputKeyLeft) {
             if(instance->index > 0) {
                 instance->index--;
             }
             updated = true;
-        } else if(event->key == InputKeyRight && is_short) {
+        } else if(event->key == InputKeyRight) {
             if(instance->index < 7) {
                 instance->index++;
             }
             updated = true;
-        } else if(event->key == InputKeyOk && is_short) {
+        } else if(event->key == InputKeyOk) {
             instance->callback(SubBruteCustomEventTypeIndexSelected, instance->context);
             consumed = true;
             updated = true;