From 575f863942bd9f727d0bdeba168e07bddcab6e53 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 15 May 2023 01:27:45 +0300 Subject: [PATCH 1/4] Fix UART terminal crashes --- .../uart_terminal/uart_terminal_uart.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/applications/external/uart_terminal/uart_terminal_uart.c b/applications/external/uart_terminal/uart_terminal_uart.c index 136bd5d38..e906c9e8e 100644 --- a/applications/external/uart_terminal/uart_terminal_uart.c +++ b/applications/external/uart_terminal/uart_terminal_uart.c @@ -38,8 +38,6 @@ void uart_terminal_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) static int32_t uart_worker(void* context) { UART_TerminalUart* uart = (void*)context; - uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1); - while(1) { uint32_t events = furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever); @@ -64,6 +62,16 @@ void uart_terminal_uart_tx(uint8_t* data, size_t len) { UART_TerminalUart* uart_terminal_uart_init(UART_TerminalApp* app) { UART_TerminalUart* uart = malloc(sizeof(UART_TerminalUart)); + uart->app = app; + // Init all rx stream and thread early to avoid crashes + uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1); + uart->rx_thread = furi_thread_alloc(); + furi_thread_set_name(uart->rx_thread, "UART_TerminalUartRxThread"); + furi_thread_set_stack_size(uart->rx_thread, 1024); + furi_thread_set_context(uart->rx_thread, uart); + furi_thread_set_callback(uart->rx_thread, uart_worker); + + furi_thread_start(uart->rx_thread); furi_hal_console_disable(); if(app->BAUDRATE == 0) { @@ -72,14 +80,6 @@ UART_TerminalUart* uart_terminal_uart_init(UART_TerminalApp* app) { furi_hal_uart_set_br(UART_CH, app->BAUDRATE); furi_hal_uart_set_irq_cb(UART_CH, uart_terminal_uart_on_irq_cb, uart); - uart->app = app; - uart->rx_thread = furi_thread_alloc(); - furi_thread_set_name(uart->rx_thread, "UART_TerminalUartRxThread"); - furi_thread_set_stack_size(uart->rx_thread, 1024); - furi_thread_set_context(uart->rx_thread, uart); - furi_thread_set_callback(uart->rx_thread, uart_worker); - - furi_thread_start(uart->rx_thread); return uart; } From 89c69ed622e8529156481437385e08c4339cb3f7 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 15 May 2023 01:29:24 +0300 Subject: [PATCH 2/4] Dont use temp str for manipulating text input by @Willy-JL --- applications/services/gui/modules/text_input.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/applications/services/gui/modules/text_input.c b/applications/services/gui/modules/text_input.c index 1152f496c..e14639614 100644 --- a/applications/services/gui/modules/text_input.c +++ b/applications/services/gui/modules/text_input.c @@ -155,10 +155,9 @@ static void text_input_backspace_cb(TextInputModel* model) { model->text_buffer[0] = 0; model->cursor_pos = 0; } else if(model->cursor_pos > 0) { - furi_string_set_str(model->temp_str, model->text_buffer); - furi_string_replace_at(model->temp_str, model->cursor_pos - 1, 1, ""); + char* move = model->text_buffer + model->cursor_pos; + memmove(move - 1, move, strlen(move) + 1); model->cursor_pos--; - strcpy(model->text_buffer, furi_string_get_cstr(model->temp_str)); } } @@ -373,16 +372,16 @@ static void text_input_handle_ok(TextInput* text_input, TextInputModel* model, I if(shift != (text_length == 0)) { selected = char_to_uppercase(selected); } - const char replace[2] = {selected, 0}; if(model->clear_default_text) { - furi_string_set_str(model->temp_str, replace); + model->text_buffer[0] = selected; + model->text_buffer[1] = '\0'; model->cursor_pos = 1; } else { - furi_string_set_str(model->temp_str, model->text_buffer); - furi_string_replace_at(model->temp_str, model->cursor_pos, 0, replace); + char* move = model->text_buffer + model->cursor_pos; + memmove(move + 1, move, strlen(move) + 1); + model->text_buffer[model->cursor_pos] = selected; model->cursor_pos++; } - strcpy(model->text_buffer, furi_string_get_cstr(model->temp_str)); } } model->clear_default_text = false; From 07c0889d102d1caa9e1ce4370a02efec0d449ff9 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 15 May 2023 03:11:20 +0300 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae9a20161..85d918843 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ -### New changes +### New changes +* **Warning! After installing, Desktop settings (Favoutite apps, PIN Code, AutoLock time..) will be resetted to default due to OFW changes, Please set your PIN code, Favourite apps again in Settings->Desktop** * New way of changing device name -> **Now can be changed in Settings->Desktop** (by @xMasterX and @Willy-JL) * Plugins: BadBT plugin (BT version of BadKB) [(by Willy-JL, ClaraCrazy, XFW contributors)](https://github.com/ClaraCrazy/Flipper-Xtreme/tree/dev/applications/main/bad_kb) * Plugins: WiFi Marauder -> Added sniff pmkid on selected aps from 0.10.4 update (by @clipboard1) -* Plugins: SubGHz Bruteforcer - Increase delay just a little bit to fix some cases when receiver will not get codes and decrease manual transmit delay +* Plugins: SubGHz Bruteforcer -> Increase delay just a little bit to fix some cases when receiver will not get codes and decrease manual transmit delay +* Plugins: UART Terminal -> Fix crashes on plugin load with RX connected * SubGHz: App refactoring (OFW code ported + our code was refactored/cleaned up too) (by @gid9798 and @xMasterX | PR #461) * SubGHz: Using scene manager functions in DecodeRAW (by @gid9798 | PR #462) * SubGHz: Protocols and custom buttons refactoring (by @gid9798 | PR #465) @@ -12,7 +14,9 @@ * BT API: Functions that allow to change bt mac address and device broadcasted name (by @Willy-JL and XFW contributors) * Infrared: `External output` move out of debug and add power option for external modules * Extra pack: Some app fixes -* OFW: Rpc: add desktop service. Desktop: refactor locking routine. +* OFW: fix PIN retry count reset on reboot +* OFW: fbt: allow strings for fap_version field in app manifests +* OFW: Rpc: add desktop service. Desktop: refactor locking routine. **Now PIN lock is actually cannot be bypassed by reboot!** / **Desktop settings will be reset, please set your PIN and favourite apps again!** * OFW: Part 2 of hooking C2 IPC * OFW: ble: attempt to handle hardfaulted c2 * OFW: Add Mfkey32 application From 89ca69b111ce9f33d82fab52f4c21d2fa3d19080 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 15 May 2023 05:56:44 +0300 Subject: [PATCH 4/4] Fix keyboard buffer issues by @Willy-JL --- .../services/gui/modules/text_input.c | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/applications/services/gui/modules/text_input.c b/applications/services/gui/modules/text_input.c index e14639614..3e521c356 100644 --- a/applications/services/gui/modules/text_input.c +++ b/applications/services/gui/modules/text_input.c @@ -20,7 +20,6 @@ typedef struct { size_t text_buffer_size; size_t minimum_length; bool clear_default_text; - FuriString* temp_str; bool cursor_select; size_t cursor_pos; @@ -168,6 +167,7 @@ static void text_input_view_draw_callback(Canvas* canvas, void* _model) { uint8_t start_pos = 4; model->cursor_pos = model->cursor_pos > text_length ? text_length : model->cursor_pos; + size_t cursor_pos = model->cursor_pos; canvas_clear(canvas); canvas_set_color(canvas, ColorBlack); @@ -175,43 +175,44 @@ static void text_input_view_draw_callback(Canvas* canvas, void* _model) { canvas_draw_str(canvas, 2, 8, model->header); elements_slightly_rounded_frame(canvas, 1, 12, 126, 15); - FuriString* str = model->temp_str; + char buf[model->text_buffer_size + 1]; if(model->text_buffer) { - furi_string_set_str(str, model->text_buffer); - } else { - furi_string_reset(str); + strlcpy(buf, model->text_buffer, sizeof(buf)); } - const char* cstr = furi_string_get_cstr(str); + char* str = buf; if(model->clear_default_text) { elements_slightly_rounded_box( - canvas, start_pos - 1, 14, canvas_string_width(canvas, cstr) + 2, 10); + canvas, start_pos - 1, 14, canvas_string_width(canvas, str) + 2, 10); canvas_set_color(canvas, ColorWhite); } else { - furi_string_replace_at(str, model->cursor_pos, 0, "|"); + char* move = str + cursor_pos; + memmove(move + 1, move, strlen(move) + 1); + str[cursor_pos] = '|'; } - if(model->cursor_pos > 0 && canvas_string_width(canvas, cstr) > needed_string_width) { + if(cursor_pos > 0 && canvas_string_width(canvas, str) > needed_string_width) { canvas_draw_str(canvas, start_pos, 22, "..."); start_pos += 6; needed_string_width -= 8; for(uint32_t off = 0; - !furi_string_empty(str) && canvas_string_width(canvas, cstr) > needed_string_width && - off < model->cursor_pos; + strlen(str) && canvas_string_width(canvas, str) > needed_string_width && + off < cursor_pos; off++) { - furi_string_right(str, 1); + str++; } } - if(canvas_string_width(canvas, cstr) > needed_string_width) { + if(canvas_string_width(canvas, str) > needed_string_width) { needed_string_width -= 4; - while(!furi_string_empty(str) && canvas_string_width(canvas, cstr) > needed_string_width) { - furi_string_left(str, furi_string_size(str) - 1); + size_t len = strlen(str); + while(len && canvas_string_width(canvas, str) > needed_string_width) { + str[len--] = '\0'; } - furi_string_cat_str(str, "..."); + strcat(str, "..."); } - canvas_draw_str(canvas, start_pos, 22, cstr); + canvas_draw_str(canvas, start_pos, 22, str); canvas_set_font(canvas, FontKeyboard); @@ -507,7 +508,6 @@ TextInput* text_input_alloc() { TextInputModel * model, { model->validator_text = furi_string_alloc(); - model->temp_str = furi_string_alloc(); model->minimum_length = 1; model->cursor_pos = 0; model->cursor_select = false; @@ -524,10 +524,7 @@ void text_input_free(TextInput* text_input) { with_view_model( text_input->view, TextInputModel * model, - { - furi_string_free(model->validator_text); - furi_string_free(model->temp_str); - }, + { furi_string_free(model->validator_text); }, false); // Send stop command