Skip to content

Commit ca3d804

Browse files
authored
Merge pull request #942 from Dmitry422/dev
Alutech_at_4n and Nice Flor S protocols acceleration and Debug status for desktop clock
2 parents 1412a45 + 4a4e9a5 commit ca3d804

File tree

3 files changed

+87
-45
lines changed

3 files changed

+87
-45
lines changed

applications/services/desktop/desktop.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ static void desktop_clock_draw_callback(Canvas* canvas, void* context) {
105105
}
106106

107107
char buffer[20];
108-
snprintf(buffer, sizeof(buffer), "%02u:%02u", hour, desktop->clock.minute);
108+
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
109+
snprintf(buffer, sizeof(buffer), "D %02u:%02u", hour, desktop->clock.minute);
110+
} else {
111+
snprintf(buffer, sizeof(buffer), "%02u:%02u", hour, desktop->clock.minute);
112+
}
109113

110114
view_port_set_width(
111115
desktop->clock_viewport,

lib/subghz/protocols/alutech_at_4n.c

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
#define TAG "SubGhzProtocoAlutech_at_4n"
1111

12-
#define SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE 0xFFFFFFFF
12+
#define SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE 0xFFFFFFFFFFFFFFFF
13+
#define SUBGHZ_ALUTECH_AT_4N_RAINBOW_TABLE_SIZE_BYTES 32
1314

1415
static const SubGhzBlockConst subghz_protocol_alutech_at_4n_const = {
1516
.te_short = 400,
@@ -140,27 +141,21 @@ LevelDuration subghz_protocol_encoder_alutech_at_4n_yield(void* context) {
140141
}
141142

142143
/**
143-
* Read bytes from rainbow table
144-
* @param file_name Full path to rainbow table the file
144+
* Read bytes from buffer array with rainbow table
145+
* @param buffer Pointer to decrypted magic data buffer
145146
* @param number_alutech_at_4n_magic_data number in the array
146147
* @return alutech_at_4n_magic_data
147148
*/
148-
static uint32_t subghz_protocol_alutech_at_4n_get_magic_data_in_file(
149-
const char* file_name,
149+
static uint32_t subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(
150+
uint8_t* buffer,
150151
uint8_t number_alutech_at_4n_magic_data) {
151-
if(!strcmp(file_name, "")) return SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE;
152-
153-
uint8_t buffer[sizeof(uint32_t)] = {0};
154152
uint32_t address = number_alutech_at_4n_magic_data * sizeof(uint32_t);
155153
uint32_t alutech_at_4n_magic_data = 0;
156154

157-
if(subghz_keystore_raw_get_data(file_name, address, buffer, sizeof(uint32_t))) {
158-
for(size_t i = 0; i < sizeof(uint32_t); i++) {
159-
alutech_at_4n_magic_data = (alutech_at_4n_magic_data << 8) | buffer[i];
160-
}
161-
} else {
162-
alutech_at_4n_magic_data = SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE;
155+
for(size_t i = address; i < (address + sizeof(uint32_t)); i++) {
156+
alutech_at_4n_magic_data = (alutech_at_4n_magic_data << 8) | buffer[i];
163157
}
158+
164159
return alutech_at_4n_magic_data;
165160
}
166161

@@ -195,17 +190,29 @@ static uint8_t subghz_protocol_alutech_at_4n_decrypt_data_crc(uint8_t data) {
195190
}
196191

197192
static uint64_t subghz_protocol_alutech_at_4n_decrypt(uint64_t data, const char* file_name) {
193+
// load and decrypt rainbow table from file to buffer array in RAM
194+
if(!file_name) return SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE;
195+
196+
uint8_t buffer[SUBGHZ_ALUTECH_AT_4N_RAINBOW_TABLE_SIZE_BYTES] = {0};
197+
uint8_t* buffer_ptr = (uint8_t*)&buffer;
198+
199+
if(subghz_keystore_raw_get_data(
200+
file_name, 0, buffer, SUBGHZ_ALUTECH_AT_4N_RAINBOW_TABLE_SIZE_BYTES)) {
201+
} else {
202+
return SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE;
203+
}
204+
198205
uint8_t* p = (uint8_t*)&data;
199206
uint32_t data1 = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
200207
uint32_t data2 = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
201208
uint32_t data3 = 0;
202209
uint32_t magic_data[] = {
203-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 0),
204-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 1),
205-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 2),
206-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 3),
207-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 4),
208-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 5)};
210+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 0),
211+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 1),
212+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 2),
213+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 3),
214+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 4),
215+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 5)};
209216

210217
uint32_t i = magic_data[0];
211218
do {
@@ -230,17 +237,29 @@ static uint64_t subghz_protocol_alutech_at_4n_decrypt(uint64_t data, const char*
230237
}
231238

232239
static uint64_t subghz_protocol_alutech_at_4n_encrypt(uint64_t data, const char* file_name) {
240+
// load and decrypt rainbow table from file to buffer array in RAM
241+
if(!file_name) return SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE;
242+
243+
uint8_t buffer[SUBGHZ_ALUTECH_AT_4N_RAINBOW_TABLE_SIZE_BYTES] = {0};
244+
uint8_t* buffer_ptr = (uint8_t*)&buffer;
245+
246+
if(subghz_keystore_raw_get_data(
247+
file_name, 0, buffer, SUBGHZ_ALUTECH_AT_4N_RAINBOW_TABLE_SIZE_BYTES)) {
248+
} else {
249+
return SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE;
250+
}
251+
233252
uint8_t* p = (uint8_t*)&data;
234253
uint32_t data1 = 0;
235254
uint32_t data2 = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
236255
uint32_t data3 = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
237256
uint32_t magic_data[] = {
238-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 6),
239-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 4),
240-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 5),
241-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 1),
242-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 2),
243-
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 0)};
257+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 6),
258+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 4),
259+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 5),
260+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 1),
261+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 2),
262+
subghz_protocol_alutech_at_4n_get_magic_data_from_buffer(buffer_ptr, 0)};
244263

245264
do {
246265
data1 = data1 + magic_data[0];

lib/subghz/protocols/nice_flor_s.c

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
#define TAG "SubGhzProtocolNiceFlorS"
1818

19-
#define NICE_ONE_COUNT_BIT 72
20-
#define NICE_ONE_NAME "Nice One"
19+
#define NICE_ONE_COUNT_BIT 72
20+
#define NICE_ONE_NAME "Nice One"
21+
#define SUBGHZ_NICE_FLOR_S_RAINBOW_TABLE_SIZE_BYTES 32
22+
#define SUBGHZ_NO_NICE_FLOR_S_RAINBOW_TABLE 0
2123

2224
static const SubGhzBlockConst subghz_protocol_nice_flor_s_const = {
2325
.te_short = 500,
@@ -414,21 +416,13 @@ static void subghz_protocol_nice_one_get_data(uint8_t* p, uint8_t num_parcel, ui
414416
}
415417

416418
/**
417-
* Read bytes from rainbow table
418-
* @param file_name Full path to rainbow table the file
419+
* Read bytes from buffer array with rainbow table
420+
* @param buffer pointer to decrypted rainbow table
419421
* @param address Byte address in file
420422
* @return data
421423
*/
422-
static uint8_t
423-
subghz_protocol_nice_flor_s_get_byte_in_file(const char* file_name, uint32_t address) {
424-
if(!file_name) return 0;
425-
426-
uint8_t buffer[1] = {0};
427-
if(subghz_keystore_raw_get_data(file_name, address, buffer, sizeof(uint8_t))) {
428-
return buffer[0];
429-
} else {
430-
return 0;
431-
}
424+
static uint8_t subghz_protocol_nice_flor_s_get_byte_from_buffer(uint8_t* buffer, uint8_t address) {
425+
return buffer[address];
432426
}
433427

434428
static inline void subghz_protocol_decoder_nice_flor_s_magic_xor(uint8_t* p, uint8_t k) {
@@ -438,16 +432,28 @@ static inline void subghz_protocol_decoder_nice_flor_s_magic_xor(uint8_t* p, uin
438432
}
439433

440434
uint64_t subghz_protocol_nice_flor_s_encrypt(uint64_t data, const char* file_name) {
435+
// load and decrypt rainbow table from file to buffer array in RAM
436+
if(!file_name) return SUBGHZ_NO_NICE_FLOR_S_RAINBOW_TABLE;
437+
438+
uint8_t buffer[SUBGHZ_NICE_FLOR_S_RAINBOW_TABLE_SIZE_BYTES] = {0};
439+
uint8_t* buffer_ptr = (uint8_t*)&buffer;
440+
441+
if(subghz_keystore_raw_get_data(
442+
file_name, 0, buffer, SUBGHZ_NICE_FLOR_S_RAINBOW_TABLE_SIZE_BYTES)) {
443+
} else {
444+
return SUBGHZ_NO_NICE_FLOR_S_RAINBOW_TABLE;
445+
}
446+
441447
uint8_t* p = (uint8_t*)&data;
442448

443449
uint8_t k = 0;
444450
for(uint8_t y = 0; y < 2; y++) {
445-
k = subghz_protocol_nice_flor_s_get_byte_in_file(file_name, p[0] & 0x1f);
451+
k = subghz_protocol_nice_flor_s_get_byte_from_buffer(buffer_ptr, p[0] & 0x1f);
446452
subghz_protocol_decoder_nice_flor_s_magic_xor(p, k);
447453

448454
p[5] &= 0x0f;
449455
p[0] ^= k & 0xe0;
450-
k = subghz_protocol_nice_flor_s_get_byte_in_file(file_name, p[0] >> 3) + 0x25;
456+
k = subghz_protocol_nice_flor_s_get_byte_from_buffer(buffer_ptr, p[0] >> 3) + 0x25;
451457
subghz_protocol_decoder_nice_flor_s_magic_xor(p, k);
452458

453459
p[5] &= 0x0f;
@@ -475,6 +481,19 @@ static uint64_t
475481
subghz_protocol_nice_flor_s_decrypt(SubGhzBlockGeneric* instance, const char* file_name) {
476482
furi_assert(instance);
477483
uint64_t data = instance->data;
484+
485+
// load and decrypt rainbow table from file to buffer array in RAM
486+
if(!file_name) return SUBGHZ_NO_NICE_FLOR_S_RAINBOW_TABLE;
487+
488+
uint8_t buffer[SUBGHZ_NICE_FLOR_S_RAINBOW_TABLE_SIZE_BYTES] = {0};
489+
uint8_t* buffer_ptr = (uint8_t*)&buffer;
490+
491+
if(subghz_keystore_raw_get_data(
492+
file_name, 0, buffer, SUBGHZ_NICE_FLOR_S_RAINBOW_TABLE_SIZE_BYTES)) {
493+
} else {
494+
return SUBGHZ_NO_NICE_FLOR_S_RAINBOW_TABLE;
495+
}
496+
478497
uint8_t* p = (uint8_t*)&data;
479498

480499
uint8_t k = 0;
@@ -489,12 +508,12 @@ static uint64_t
489508
p[1] = k;
490509

491510
for(uint8_t y = 0; y < 2; y++) {
492-
k = subghz_protocol_nice_flor_s_get_byte_in_file(file_name, p[0] >> 3) + 0x25;
511+
k = subghz_protocol_nice_flor_s_get_byte_from_buffer(buffer_ptr, p[0] >> 3) + 0x25;
493512
subghz_protocol_decoder_nice_flor_s_magic_xor(p, k);
494513

495514
p[5] &= 0x0f;
496515
p[0] ^= k & 0x7;
497-
k = subghz_protocol_nice_flor_s_get_byte_in_file(file_name, p[0] & 0x1f);
516+
k = subghz_protocol_nice_flor_s_get_byte_from_buffer(buffer_ptr, p[0] & 0x1f);
498517
subghz_protocol_decoder_nice_flor_s_magic_xor(p, k);
499518

500519
p[5] &= 0x0f;

0 commit comments

Comments
 (0)