From 22daa7cfc31b7f686bb5079e10732ee9aa0db186 Mon Sep 17 00:00:00 2001 From: Andrea Santaniello Date: Wed, 18 Mar 2026 15:36:32 +0100 Subject: [PATCH] Correct bit order --- .../subghz/scenes/subghz_scene_keeloq_bf2.c | 12 +++++--- .../scenes/subghz_scene_keeloq_decrypt.c | 29 ++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_keeloq_bf2.c b/applications/main/subghz/scenes/subghz_scene_keeloq_bf2.c index 4f208fc5..5b4bd552 100644 --- a/applications/main/subghz/scenes/subghz_scene_keeloq_bf2.c +++ b/applications/main/subghz/scenes/subghz_scene_keeloq_bf2.c @@ -1,5 +1,6 @@ #include "../subghz_i.h" #include +#include #include enum { @@ -22,10 +23,13 @@ static bool kl_bf2_extract_key(SubGhz* subghz, uint32_t* out_fix, uint32_t* out_ flipper_format_rewind(fff); uint8_t key_data[8] = {0}; if(!flipper_format_read_hex(fff, "Key", key_data, 8)) return false; - *out_fix = ((uint32_t)key_data[0] << 24) | ((uint32_t)key_data[1] << 16) | - ((uint32_t)key_data[2] << 8) | key_data[3]; - *out_hop = ((uint32_t)key_data[4] << 24) | ((uint32_t)key_data[5] << 16) | - ((uint32_t)key_data[6] << 8) | key_data[7]; + uint64_t raw = 0; + for(uint8_t i = 0; i < 8; i++) { + raw = (raw << 8) | key_data[i]; + } + uint64_t reversed = subghz_protocol_blocks_reverse_key(raw, 64); + *out_fix = (uint32_t)(reversed >> 32); + *out_hop = (uint32_t)(reversed & 0xFFFFFFFF); return true; } diff --git a/applications/main/subghz/scenes/subghz_scene_keeloq_decrypt.c b/applications/main/subghz/scenes/subghz_scene_keeloq_decrypt.c index ee7d82dd..efaca565 100644 --- a/applications/main/subghz/scenes/subghz_scene_keeloq_decrypt.c +++ b/applications/main/subghz/scenes/subghz_scene_keeloq_decrypt.c @@ -2,6 +2,7 @@ #include "../helpers/subghz_txrx_i.h" #include #include +#include #include #include #include @@ -137,10 +138,13 @@ void subghz_scene_keeloq_decrypt_on_enter(void* context) { uint8_t key_data[8] = {0}; if(flipper_format_read_hex(fff, "Key", key_data, 8)) { - ctx->fix = ((uint32_t)key_data[0] << 24) | ((uint32_t)key_data[1] << 16) | - ((uint32_t)key_data[2] << 8) | key_data[3]; - ctx->hop = ((uint32_t)key_data[4] << 24) | ((uint32_t)key_data[5] << 16) | - ((uint32_t)key_data[6] << 8) | key_data[7]; + uint64_t raw = 0; + for(uint8_t i = 0; i < 8; i++) { + raw = (raw << 8) | key_data[i]; + } + uint64_t reversed = subghz_protocol_blocks_reverse_key(raw, 64); + ctx->fix = (uint32_t)(reversed >> 32); + ctx->hop = (uint32_t)(reversed & 0xFFFFFFFF); } ctx->serial = ctx->fix & 0x0FFFFFFF; @@ -188,7 +192,7 @@ bool subghz_scene_keeloq_decrypt_on_event(void* context, SceneManagerEvent event subghz_keeloq_keys_add( subghz->keeloq_keys_manager, ctx->recovered_mfkey, - ctx->recovered_type, + KEELOQ_LEARNING_SIMPLE, key_name); subghz_keeloq_keys_save(subghz->keeloq_keys_manager); @@ -198,7 +202,7 @@ bool subghz_scene_keeloq_decrypt_on_event(void* context, SceneManagerEvent event SubGhzKey* entry = SubGhzKeyArray_push_raw(*env_arr); entry->name = furi_string_alloc_set(key_name); entry->key = ctx->recovered_mfkey; - entry->type = ctx->recovered_type; + entry->type = KEELOQ_LEARNING_SIMPLE; return true; } else if(event.event == KL_DECRYPT_EVENT_DONE) { @@ -235,11 +239,22 @@ bool subghz_scene_keeloq_decrypt_on_event(void* context, SceneManagerEvent event flipper_format_insert_or_update_uint32(fff, "Hop2", &ctx->hop2, 1); } + flipper_format_rewind(fff); + subghz_protocol_decoder_base_deserialize( + subghz_txrx_get_decoder(subghz->txrx), fff); + + const char* save_path = NULL; if(subghz_path_is_file(subghz->file_path)) { + save_path = furi_string_get_cstr(subghz->file_path); + } else if(subghz_path_is_file(subghz->keeloq_bf2.sig1_path)) { + save_path = furi_string_get_cstr(subghz->keeloq_bf2.sig1_path); + } + if(save_path) { subghz_save_protocol_to_file( subghz, subghz_txrx_get_fff_data(subghz->txrx), - furi_string_get_cstr(subghz->file_path)); + save_path); + furi_string_set_str(subghz->file_path, save_path); } subghz_view_keeloq_decrypt_set_result(