SubGhz: reading keys from encrypted files (#803)

* SubGhz: add file with manufactory codes, and the ability to add your own manufactory codes for KeeLog
* SubGhz: add encrypt RAW data, add decrypt and get RAW data
* SubGhz: add encrypt  magic_xor_atomo
* SubGhz: parsing atomo using file encrypt
* SubGhz: fix calculating the size of the read buffer
* SubGhz: parsing Nice FLOR S using file encrypt
* SubGhz: add file encrypt nice_flor_s_tx, fix name load file
* SubGhz: fix checking read buffer size
* Update subghz_keystore.c
* SubGhz: fix calculating the size of the read buffer

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Skorpionm
2021-11-03 20:41:07 +04:00
committed by GitHub
parent 300302cb7c
commit 6d548637f2
14 changed files with 445 additions and 457 deletions

View File

@@ -1,6 +1,7 @@
#include "subghz_protocol_came_atomo.h"
#include "subghz_protocol_common.h"
#include <lib/toolbox/manchester-decoder.h>
#include "../subghz_keystore.h"
#define SUBGHZ_NO_CAME_ATOMO_RAINBOW_TABLE 0xFFFFFFFFFFFFFFFF
@@ -25,14 +26,8 @@ SubGhzProtocolCameAtomo* subghz_protocol_came_atomo_alloc() {
instance->common.te_delta = 250;
instance->common.type_protocol = SubGhzProtocolCommonTypeStatic;
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_came_atomo_to_str;
// instance->common.to_save_string =
// (SubGhzProtocolCommonGetStrSave)subghz_protocol_came_atomo_to_save_str;
//instance->common.to_load_protocol_from_file =
// (SubGhzProtocolCommonLoadFromFile)subghz_protocol_came_atomo_to_load_protocol_from_file;
instance->common.to_load_protocol =
(SubGhzProtocolCommonLoadFromRAW)subghz_decoder_came_atomo_to_load_protocol;
// instance->common.get_upload_protocol =
// (SubGhzProtocolCommonEncoderGetUpLoad)subghz_protocol_came_atomo_send_key;
return instance;
}
@@ -62,20 +57,14 @@ uint64_t subghz_came_atomo_get_atomo_magic_xor_in_file(
uint32_t address = number_atomo_magic_xor * sizeof(uint64_t);
uint64_t atomo_magic_xor = 0;
FileWorker* file_worker = file_worker_alloc(true);
if(file_worker_open(
file_worker, instance->rainbow_table_file_name, FSAM_READ, FSOM_OPEN_EXISTING)) {
file_worker_seek(file_worker, address, true);
file_worker_read(file_worker, &buffer, sizeof(uint64_t));
if(subghz_keystore_raw_get_data(
instance->rainbow_table_file_name, address, buffer, sizeof(uint64_t))) {
for(size_t i = 0; i < sizeof(uint64_t); i++) {
atomo_magic_xor = (atomo_magic_xor << 8) | buffer[i];
}
} else {
atomo_magic_xor = SUBGHZ_NO_CAME_ATOMO_RAINBOW_TABLE;
}
file_worker_close(file_worker);
file_worker_free(file_worker);
return atomo_magic_xor;
}
@@ -265,64 +254,6 @@ void subghz_protocol_came_atomo_to_str(SubGhzProtocolCameAtomo* instance, string
instance->common.cnt);
}
// void subghz_protocol_came_atomo_to_save_str(SubGhzProtocolCameAtomo* instance, string_t output) {
// string_printf(
// output,
// "Protocol: %s\n"
// "Bit: %d\n"
// "Key: %08lX%08lX\r\n",
// instance->common.name,
// instance->common.code_last_count_bit,
// (uint32_t)(instance->common.code_last_found >> 32),
// (uint32_t)(instance->common.code_last_found & 0xFFFFFFFF));
// }
// bool subghz_protocol_came_atomo_to_load_protocol_from_file(
// FileWorker* file_worker,
// SubGhzProtocolCameAtomo* instance,
// const char* file_path) {
// bool loaded = false;
// string_t temp_str;
// string_init(temp_str);
// int res = 0;
// int data = 0;
// do {
// // Read and parse bit data from 2nd line
// if(!file_worker_read_until(file_worker, temp_str, '\n')) {
// break;
// }
// res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data);
// if(res != 1) {
// break;
// }
// instance->common.code_last_count_bit = (uint8_t)data;
// // Read and parse key data from 3nd line
// if(!file_worker_read_until(file_worker, temp_str, '\n')) {
// break;
// }
// // strlen("Key: ") = 5
// string_right(temp_str, 5);
// uint8_t buf_key[8] = {0};
// if(!subghz_protocol_common_read_hex(temp_str, buf_key, 8)) {
// break;
// }
// for(uint8_t i = 0; i < 8; i++) {
// instance->common.code_last_found = instance->common.code_last_found << 8 | buf_key[i];
// }
// loaded = true;
// } while(0);
// string_clear(temp_str);
// subghz_protocol_came_atomo_remote_controller(instance);
// return loaded;
// }
void subghz_decoder_came_atomo_to_load_protocol(SubGhzProtocolCameAtomo* instance, void* context) {
furi_assert(context);
furi_assert(instance);

View File

@@ -23,16 +23,6 @@ void subghz_protocol_came_atomo_free(SubGhzProtocolCameAtomo* instance);
*/
void subghz_protocol_came_atomo_name_file(SubGhzProtocolCameAtomo* instance, const char* name);
// /** Get upload protocol
// *
// * @param instance - SubGhzProtocolCameAtomo instance
// * @param encoder - SubGhzProtocolCommonEncoder encoder
// * @return bool
// */
// bool subghz_protocol_came_atomo_send_key(
// SubGhzProtocolCameAtomo* instance,
// SubGhzProtocolCommonEncoder* encoder);
/** Reset internal state
* @param instance - SubGhzProtocolCameAtomo instance
*/
@@ -55,25 +45,6 @@ void subghz_protocol_came_atomo_parse(
*/
void subghz_protocol_came_atomo_to_str(SubGhzProtocolCameAtomo* instance, string_t output);
// /** Get a string to save the protocol
// *
// * @param instance - SubGhzProtocolCameAtomo instance
// * @param output - the resulting string
// */
// void subghz_protocol_came_atomo_to_save_str(SubGhzProtocolCameAtomo* instance, string_t output);
// /** Loading protocol from file
// *
// * @param file_worker - FileWorker file_worker
// * @param instance - SubGhzProtocolCameAtomo instance
// * @param file_path - file path
// * @return bool
// */
// bool subghz_protocol_came_atomo_to_load_protocol_from_file(
// FileWorker* file_worker,
// SubGhzProtocolCameAtomo* instance,
// const char* file_path);
/** Loading protocol from bin data
*
* @param instance - SubGhzProtocolCameAtomo instance

View File

@@ -167,7 +167,7 @@ void subghz_protocol_faac_slh_to_str(SubGhzProtocolFaacSLH* instance, string_t o
string_cat_printf(
output,
"%s %dbit\r\n"
"Key:0x%lX%08lX\r\n"
"Key:%lX%08lX\r\n"
"Fix:%08lX \r\n"
"Hop:%08lX \r\n"
"Sn:%07lX Btn:%lX\r\n",

View File

@@ -69,7 +69,7 @@ uint8_t subghz_protocol_keeloq_check_remote_controller_selector(
M_EACH(manufacture_code, *subghz_keystore_get_data(instance->keystore), SubGhzKeyArray_t) {
switch(manufacture_code->type) {
case KEELOQ_LEARNING_SIMPLE:
//Simple Learning
// Simple Learning
decrypt = subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key);
if((decrypt >> 28 == btn) &&
(((((uint16_t)(decrypt >> 16)) & 0x3FF) == end_serial) ||

View File

@@ -2,6 +2,7 @@
#include <furi.h>
#include "file-worker.h"
#include "../subghz_keystore.h"
/*
* https://phreakerclub.com/1615
* https://phreakerclub.com/forum/showthread.php?t=2360
@@ -103,17 +104,13 @@ void subghz_protocol_nice_flor_s_send_key(
uint8_t subghz_nice_flor_s_get_byte_in_file(SubGhzProtocolNiceFlorS* instance, uint32_t address) {
if(!instance->rainbow_table_file_name) return 0;
uint8_t buffer = 0;
FileWorker* file_worker = file_worker_alloc(true);
if(file_worker_open(
file_worker, instance->rainbow_table_file_name, FSAM_READ, FSOM_OPEN_EXISTING)) {
file_worker_seek(file_worker, address, true);
file_worker_read(file_worker, &buffer, 1);
uint8_t buffer[1] = {0};
if(subghz_keystore_raw_get_data(
instance->rainbow_table_file_name, address, buffer, sizeof(uint8_t))) {
return buffer[0];
} else {
return 0;
}
file_worker_close(file_worker);
file_worker_free(file_worker);
return buffer;
}
/** Decrypt protocol Nice Flor S