Skip to content

Commit 4da6eba

Browse files
Skorpionmskotopes
andauthored
[FL-2706, FL-2709] SubGhz: checking saved key files for length (#1485)
* [FL-2706] SubGhz: checking saved key files for length * SubGhz: fix RAW file upload error * [FL-2709] GubGhz: RAW screen fix Co-authored-by: あく <alleteam@gmail.com>
1 parent 84550d5 commit 4da6eba

28 files changed

+390
-46
lines changed

applications/subghz/subghz_i.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,10 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
331331
subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name(
332332
subghz->txrx->receiver, string_get_cstr(temp_str));
333333
if(subghz->txrx->decoder_result) {
334-
subghz_protocol_decoder_base_deserialize(
335-
subghz->txrx->decoder_result, subghz->txrx->fff_data);
334+
if(!subghz_protocol_decoder_base_deserialize(
335+
subghz->txrx->decoder_result, subghz->txrx->fff_data)) {
336+
break;
337+
}
336338
} else {
337339
FURI_LOG_E(TAG, "Protocol not found");
338340
break;

applications/subghz/views/subghz_read_raw.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ void subghz_read_raw_draw(Canvas* canvas, SubGhzReadRAWModel* model) {
216216
uint8_t graphics_mode = 1;
217217
canvas_set_color(canvas, ColorBlack);
218218
canvas_set_font(canvas, FontSecondary);
219-
canvas_draw_str(canvas, 5, 8, string_get_cstr(model->frequency_str));
220-
canvas_draw_str(canvas, 40, 8, string_get_cstr(model->preset_str));
219+
canvas_draw_str(canvas, 5, 7, string_get_cstr(model->frequency_str));
220+
canvas_draw_str(canvas, 40, 7, string_get_cstr(model->preset_str));
221221
canvas_draw_str_aligned(
222222
canvas, 126, 0, AlignRight, AlignTop, string_get_cstr(model->sample_write));
223223

lib/subghz/protocols/came.c

+22-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ bool subghz_protocol_encoder_came_deserialize(void* context, FlipperFormat* flip
145145
FURI_LOG_E(TAG, "Deserialize error");
146146
break;
147147
}
148-
148+
if((instance->generic.data_count_bit !=
149+
subghz_protocol_came_const.min_count_bit_for_found) &&
150+
(instance->generic.data_count_bit !=
151+
2 * subghz_protocol_came_const.min_count_bit_for_found)) {
152+
FURI_LOG_E(TAG, "Wrong number of bits in key");
153+
break;
154+
}
149155
//optional parameter parameter
150156
flipper_format_read_uint32(
151157
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
@@ -293,7 +299,21 @@ bool subghz_protocol_decoder_came_serialize(
293299
bool subghz_protocol_decoder_came_deserialize(void* context, FlipperFormat* flipper_format) {
294300
furi_assert(context);
295301
SubGhzProtocolDecoderCame* instance = context;
296-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
302+
bool ret = false;
303+
do {
304+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
305+
break;
306+
}
307+
if((instance->generic.data_count_bit !=
308+
subghz_protocol_came_const.min_count_bit_for_found) &&
309+
(instance->generic.data_count_bit !=
310+
2 * subghz_protocol_came_const.min_count_bit_for_found)) {
311+
FURI_LOG_E(TAG, "Wrong number of bits in key");
312+
break;
313+
}
314+
ret = true;
315+
} while(false);
316+
return ret;
297317
}
298318

299319
void subghz_protocol_decoder_came_get_string(void* context, string_t output) {

lib/subghz/protocols/came_atomo.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,19 @@ bool subghz_protocol_decoder_came_atomo_serialize(
310310
bool subghz_protocol_decoder_came_atomo_deserialize(void* context, FlipperFormat* flipper_format) {
311311
furi_assert(context);
312312
SubGhzProtocolDecoderCameAtomo* instance = context;
313-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
313+
bool ret = false;
314+
do {
315+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
316+
break;
317+
}
318+
if(instance->generic.data_count_bit !=
319+
subghz_protocol_came_atomo_const.min_count_bit_for_found) {
320+
FURI_LOG_E(TAG, "Wrong number of bits in key");
321+
break;
322+
}
323+
ret = true;
324+
} while(false);
325+
return ret;
314326
}
315327

316328
void subghz_protocol_decoder_came_atomo_get_string(void* context, string_t output) {

lib/subghz/protocols/came_twee.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,11 @@ bool subghz_protocol_encoder_came_twee_deserialize(void* context, FlipperFormat*
250250
FURI_LOG_E(TAG, "Deserialize error");
251251
break;
252252
}
253-
253+
if(instance->generic.data_count_bit !=
254+
subghz_protocol_came_twee_const.min_count_bit_for_found) {
255+
FURI_LOG_E(TAG, "Wrong number of bits in key");
256+
break;
257+
}
254258
//optional parameter parameter
255259
flipper_format_read_uint32(
256260
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
@@ -427,7 +431,19 @@ bool subghz_protocol_decoder_came_twee_serialize(
427431
bool subghz_protocol_decoder_came_twee_deserialize(void* context, FlipperFormat* flipper_format) {
428432
furi_assert(context);
429433
SubGhzProtocolDecoderCameTwee* instance = context;
430-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
434+
bool ret = false;
435+
do {
436+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
437+
break;
438+
}
439+
if(instance->generic.data_count_bit !=
440+
subghz_protocol_came_twee_const.min_count_bit_for_found) {
441+
FURI_LOG_E(TAG, "Wrong number of bits in key");
442+
break;
443+
}
444+
ret = true;
445+
} while(false);
446+
return ret;
431447
}
432448

433449
void subghz_protocol_decoder_came_twee_get_string(void* context, string_t output) {

lib/subghz/protocols/chamberlain_code.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ bool subghz_protocol_encoder_chamb_code_deserialize(void* context, FlipperFormat
215215
FURI_LOG_E(TAG, "Deserialize error");
216216
break;
217217
}
218-
218+
if(instance->generic.data_count_bit <
219+
subghz_protocol_chamb_code_const.min_count_bit_for_found) {
220+
FURI_LOG_E(TAG, "Wrong number of bits in key");
221+
break;
222+
}
219223
//optional parameter parameter
220224
flipper_format_read_uint32(
221225
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
@@ -432,7 +436,19 @@ bool subghz_protocol_decoder_chamb_code_serialize(
432436
bool subghz_protocol_decoder_chamb_code_deserialize(void* context, FlipperFormat* flipper_format) {
433437
furi_assert(context);
434438
SubGhzProtocolDecoderChamb_Code* instance = context;
435-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
439+
bool ret = false;
440+
do {
441+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
442+
break;
443+
}
444+
if(instance->generic.data_count_bit <
445+
subghz_protocol_chamb_code_const.min_count_bit_for_found) {
446+
FURI_LOG_E(TAG, "Wrong number of bits in key");
447+
break;
448+
}
449+
ret = true;
450+
} while(false);
451+
return ret;
436452
}
437453

438454
void subghz_protocol_decoder_chamb_code_get_string(void* context, string_t output) {

lib/subghz/protocols/faac_slh.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void subghz_protocol_decoder_faac_slh_feed(void* context, bool level, uint32_t d
115115
if(duration >= ((uint32_t)subghz_protocol_faac_slh_const.te_short * 3 +
116116
subghz_protocol_faac_slh_const.te_delta)) {
117117
instance->decoder.parser_step = FaacSLHDecoderStepFoundPreambula;
118-
if(instance->decoder.decode_count_bit >=
118+
if(instance->decoder.decode_count_bit ==
119119
subghz_protocol_faac_slh_const.min_count_bit_for_found) {
120120
instance->generic.data = instance->decoder.decode_data;
121121
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
@@ -192,7 +192,19 @@ bool subghz_protocol_decoder_faac_slh_serialize(
192192
bool subghz_protocol_decoder_faac_slh_deserialize(void* context, FlipperFormat* flipper_format) {
193193
furi_assert(context);
194194
SubGhzProtocolDecoderFaacSLH* instance = context;
195-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
195+
bool ret = false;
196+
do {
197+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
198+
break;
199+
}
200+
if(instance->generic.data_count_bit !=
201+
subghz_protocol_faac_slh_const.min_count_bit_for_found) {
202+
FURI_LOG_E(TAG, "Wrong number of bits in key");
203+
break;
204+
}
205+
ret = true;
206+
} while(false);
207+
return ret;
196208
}
197209

198210
void subghz_protocol_decoder_faac_slh_get_string(void* context, string_t output) {

lib/subghz/protocols/gate_tx.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ bool subghz_protocol_encoder_gate_tx_deserialize(void* context, FlipperFormat* f
138138
FURI_LOG_E(TAG, "Deserialize error");
139139
break;
140140
}
141-
141+
if(instance->generic.data_count_bit !=
142+
subghz_protocol_gate_tx_const.min_count_bit_for_found) {
143+
FURI_LOG_E(TAG, "Wrong number of bits in key");
144+
break;
145+
}
142146
//optional parameter parameter
143147
flipper_format_read_uint32(
144148
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
@@ -298,7 +302,19 @@ bool subghz_protocol_decoder_gate_tx_serialize(
298302
bool subghz_protocol_decoder_gate_tx_deserialize(void* context, FlipperFormat* flipper_format) {
299303
furi_assert(context);
300304
SubGhzProtocolDecoderGateTx* instance = context;
301-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
305+
bool ret = false;
306+
do {
307+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
308+
break;
309+
}
310+
if(instance->generic.data_count_bit !=
311+
subghz_protocol_gate_tx_const.min_count_bit_for_found) {
312+
FURI_LOG_E(TAG, "Wrong number of bits in key");
313+
break;
314+
}
315+
ret = true;
316+
} while(false);
317+
return ret;
302318
}
303319

304320
void subghz_protocol_decoder_gate_tx_get_string(void* context, string_t output) {

lib/subghz/protocols/holtek.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ bool subghz_protocol_encoder_holtek_deserialize(void* context, FlipperFormat* fl
151151
FURI_LOG_E(TAG, "Deserialize error");
152152
break;
153153
}
154-
154+
if(instance->generic.data_count_bit !=
155+
subghz_protocol_holtek_const.min_count_bit_for_found) {
156+
FURI_LOG_E(TAG, "Wrong number of bits in key");
157+
break;
158+
}
155159
//optional parameter parameter
156160
flipper_format_read_uint32(
157161
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
@@ -331,7 +335,19 @@ bool subghz_protocol_decoder_holtek_serialize(
331335
bool subghz_protocol_decoder_holtek_deserialize(void* context, FlipperFormat* flipper_format) {
332336
furi_assert(context);
333337
SubGhzProtocolDecoderHoltek* instance = context;
334-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
338+
bool ret = false;
339+
do {
340+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
341+
break;
342+
}
343+
if(instance->generic.data_count_bit !=
344+
subghz_protocol_holtek_const.min_count_bit_for_found) {
345+
FURI_LOG_E(TAG, "Wrong number of bits in key");
346+
break;
347+
}
348+
ret = true;
349+
} while(false);
350+
return ret;
335351
}
336352

337353
void subghz_protocol_decoder_holtek_get_string(void* context, string_t output) {

lib/subghz/protocols/hormann.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ bool subghz_protocol_encoder_hormann_deserialize(void* context, FlipperFormat* f
154154
FURI_LOG_E(TAG, "Deserialize error");
155155
break;
156156
}
157-
157+
if(instance->generic.data_count_bit !=
158+
subghz_protocol_hormann_const.min_count_bit_for_found) {
159+
FURI_LOG_E(TAG, "Wrong number of bits in key");
160+
break;
161+
}
158162
//optional parameter parameter
159163
flipper_format_read_uint32(
160164
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
@@ -319,7 +323,19 @@ bool subghz_protocol_decoder_hormann_serialize(
319323
bool subghz_protocol_decoder_hormann_deserialize(void* context, FlipperFormat* flipper_format) {
320324
furi_assert(context);
321325
SubGhzProtocolDecoderHormann* instance = context;
322-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
326+
bool ret = false;
327+
do {
328+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
329+
break;
330+
}
331+
if(instance->generic.data_count_bit !=
332+
subghz_protocol_hormann_const.min_count_bit_for_found) {
333+
FURI_LOG_E(TAG, "Wrong number of bits in key");
334+
break;
335+
}
336+
ret = true;
337+
} while(false);
338+
return ret;
323339
}
324340

325341
void subghz_protocol_decoder_hormann_get_string(void* context, string_t output) {

lib/subghz/protocols/ido.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,18 @@ bool subghz_protocol_decoder_ido_serialize(
191191
bool subghz_protocol_decoder_ido_deserialize(void* context, FlipperFormat* flipper_format) {
192192
furi_assert(context);
193193
SubGhzProtocolDecoderIDo* instance = context;
194-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
194+
bool ret = false;
195+
do {
196+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
197+
break;
198+
}
199+
if(instance->generic.data_count_bit != subghz_protocol_ido_const.min_count_bit_for_found) {
200+
FURI_LOG_E(TAG, "Wrong number of bits in key");
201+
break;
202+
}
203+
ret = true;
204+
} while(false);
205+
return ret;
195206
}
196207

197208
void subghz_protocol_decoder_ido_get_string(void* context, string_t output) {

lib/subghz/protocols/keeloq.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,11 @@ bool subghz_protocol_encoder_keeloq_deserialize(void* context, FlipperFormat* fl
264264
FURI_LOG_E(TAG, "Deserialize error");
265265
break;
266266
}
267-
267+
if(instance->generic.data_count_bit !=
268+
subghz_protocol_keeloq_const.min_count_bit_for_found) {
269+
FURI_LOG_E(TAG, "Wrong number of bits in key");
270+
break;
271+
}
268272
subghz_protocol_keeloq_check_remote_controller(
269273
&instance->generic, instance->keystore, &instance->manufacture_name);
270274

@@ -656,6 +660,11 @@ bool subghz_protocol_decoder_keeloq_deserialize(void* context, FlipperFormat* fl
656660
FURI_LOG_E(TAG, "Deserialize error");
657661
break;
658662
}
663+
if(instance->generic.data_count_bit !=
664+
subghz_protocol_keeloq_const.min_count_bit_for_found) {
665+
FURI_LOG_E(TAG, "Wrong number of bits in key");
666+
break;
667+
}
659668
res = true;
660669
} while(false);
661670

lib/subghz/protocols/kia.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static const SubGhzBlockConst subghz_protocol_kia_const = {
1212
.te_short = 250,
1313
.te_long = 500,
1414
.te_delta = 100,
15-
.min_count_bit_for_found = 60,
15+
.min_count_bit_for_found = 61,
1616
};
1717

1818
struct SubGhzProtocolDecoderKIA {
@@ -145,7 +145,7 @@ void subghz_protocol_decoder_kia_feed(void* context, bool level, uint32_t durati
145145
(uint32_t)(subghz_protocol_kia_const.te_long + subghz_protocol_kia_const.te_delta * 2)) {
146146
//Found stop bit
147147
instance->decoder.parser_step = KIADecoderStepReset;
148-
if(instance->decoder.decode_count_bit >=
148+
if(instance->decoder.decode_count_bit ==
149149
subghz_protocol_kia_const.min_count_bit_for_found) {
150150
instance->generic.data = instance->decoder.decode_data;
151151
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
@@ -242,7 +242,18 @@ bool subghz_protocol_decoder_kia_serialize(
242242
bool subghz_protocol_decoder_kia_deserialize(void* context, FlipperFormat* flipper_format) {
243243
furi_assert(context);
244244
SubGhzProtocolDecoderKIA* instance = context;
245-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
245+
bool ret = false;
246+
do {
247+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
248+
break;
249+
}
250+
if(instance->generic.data_count_bit != subghz_protocol_kia_const.min_count_bit_for_found) {
251+
FURI_LOG_E(TAG, "Wrong number of bits in key");
252+
break;
253+
}
254+
ret = true;
255+
} while(false);
256+
return ret;
246257
}
247258

248259
void subghz_protocol_decoder_kia_get_string(void* context, string_t output) {

lib/subghz/protocols/linear.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ bool subghz_protocol_encoder_linear_deserialize(void* context, FlipperFormat* fl
156156
FURI_LOG_E(TAG, "Deserialize error");
157157
break;
158158
}
159-
159+
if(instance->generic.data_count_bit !=
160+
subghz_protocol_linear_const.min_count_bit_for_found) {
161+
FURI_LOG_E(TAG, "Wrong number of bits in key");
162+
break;
163+
}
160164
//optional parameter parameter
161165
flipper_format_read_uint32(
162166
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
@@ -308,7 +312,19 @@ bool subghz_protocol_decoder_linear_serialize(
308312
bool subghz_protocol_decoder_linear_deserialize(void* context, FlipperFormat* flipper_format) {
309313
furi_assert(context);
310314
SubGhzProtocolDecoderLinear* instance = context;
311-
return subghz_block_generic_deserialize(&instance->generic, flipper_format);
315+
bool ret = false;
316+
do {
317+
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
318+
break;
319+
}
320+
if(instance->generic.data_count_bit !=
321+
subghz_protocol_linear_const.min_count_bit_for_found) {
322+
FURI_LOG_E(TAG, "Wrong number of bits in key");
323+
break;
324+
}
325+
ret = true;
326+
} while(false);
327+
return ret;
312328
}
313329

314330
void subghz_protocol_decoder_linear_get_string(void* context, string_t output) {

0 commit comments

Comments
 (0)