From 5160c70608318503ba8eca8d22334e112d2921da Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 20 Nov 2023 19:41:51 +0000 Subject: [PATCH 1/3] Fix html set delay --- .../evil_portal/scenes/evil_portal_scene_console_output.c | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/external/evil_portal/scenes/evil_portal_scene_console_output.c b/applications/external/evil_portal/scenes/evil_portal_scene_console_output.c index 2574da3f7..64332eeac 100644 --- a/applications/external/evil_portal/scenes/evil_portal_scene_console_output.c +++ b/applications/external/evil_portal/scenes/evil_portal_scene_console_output.c @@ -151,6 +151,7 @@ void evil_portal_scene_console_output_on_enter(void* context) { evil_portal_uart_tx((uint8_t*)("\n"), 1); for(uint8_t t = 0; t < 15 && !captured(app, "html set"); t++) furi_delay_ms(100); + furi_delay_ms(100); evil_portal_uart_tx( (uint8_t*)("evilportal -c start\n"), strlen("evilportal -c start\n")); } From ffd61fa56f59ce8c1d8c5ae48e0eea41adf16bfb Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 20 Nov 2023 20:06:09 +0000 Subject: [PATCH 2/3] Fix console disable on evil portal uart --- applications/external/evil_portal/evil_portal_uart.c | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/external/evil_portal/evil_portal_uart.c b/applications/external/evil_portal/evil_portal_uart.c index 9e639aa24..78a01ed0a 100644 --- a/applications/external/evil_portal/evil_portal_uart.c +++ b/applications/external/evil_portal/evil_portal_uart.c @@ -100,7 +100,6 @@ Evil_PortalUart* evil_portal_uart_init(Evil_PortalApp* app) { furi_hal_uart_init(UART_CH, app->BAUDRATE); } - furi_hal_console_disable(); if(app->BAUDRATE == 0) { app->BAUDRATE = 115200; } From 8700b7ebc155366cc82d1dfa9ea708b141c86001 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 20 Nov 2023 20:18:27 +0000 Subject: [PATCH 3/3] Fix evil portal log hang and crash --- .../external/evil_portal/evil_portal_app.c | 20 +++++++++++-------- .../external/evil_portal/evil_portal_app_i.h | 1 + .../external/evil_portal/evil_portal_uart.c | 8 ++++++-- .../evil_portal/helpers/evil_portal_storage.c | 3 +-- .../scenes/evil_portal_scene_console_output.c | 2 ++ 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/applications/external/evil_portal/evil_portal_app.c b/applications/external/evil_portal/evil_portal_app.c index 903ef5087..8bfc828d9 100644 --- a/applications/external/evil_portal/evil_portal_app.c +++ b/applications/external/evil_portal/evil_portal_app.c @@ -27,6 +27,7 @@ Evil_PortalApp* evil_portal_app_alloc() { app->sent_reset = false; app->portal_logs = furi_string_alloc(); + app->portal_logs_mutex = furi_mutex_alloc(FuriMutexTypeRecursive); app->capture_line = false; app->captured_line = furi_string_alloc(); @@ -81,14 +82,6 @@ Evil_PortalApp* evil_portal_app_alloc() { } void evil_portal_app_free(Evil_PortalApp* app) { - // save latest logs - if(furi_string_utf8_length(app->portal_logs) > 0) { - write_logs(app->portal_logs); - furi_string_free(app->portal_logs); - } - - furi_string_free(app->captured_line); - // Send reset event to dev board evil_portal_uart_tx((uint8_t*)(RESET_CMD), strlen(RESET_CMD)); evil_portal_uart_tx((uint8_t*)("\n"), 1); @@ -112,6 +105,17 @@ void evil_portal_app_free(Evil_PortalApp* app) { evil_portal_uart_free(app->uart); + // save latest logs + furi_mutex_acquire(app->portal_logs_mutex, FuriWaitForever); + if(furi_string_size(app->portal_logs) > 0) { + write_logs(app->portal_logs); + furi_string_free(app->portal_logs); + } + furi_mutex_release(app->portal_logs_mutex); + furi_mutex_free(app->portal_logs_mutex); + + furi_string_free(app->captured_line); + // Close records furi_record_close(RECORD_GUI); diff --git a/applications/external/evil_portal/evil_portal_app_i.h b/applications/external/evil_portal/evil_portal_app_i.h index fe4103a38..871c1cefa 100644 --- a/applications/external/evil_portal/evil_portal_app_i.h +++ b/applications/external/evil_portal/evil_portal_app_i.h @@ -34,6 +34,7 @@ struct Evil_PortalApp { SceneManager* scene_manager; FuriString* portal_logs; + FuriMutex* portal_logs_mutex; FuriString* text_box_store; size_t text_box_store_strlen; diff --git a/applications/external/evil_portal/evil_portal_uart.c b/applications/external/evil_portal/evil_portal_uart.c index 78a01ed0a..6437e8e8b 100644 --- a/applications/external/evil_portal/evil_portal_uart.c +++ b/applications/external/evil_portal/evil_portal_uart.c @@ -48,24 +48,28 @@ static int32_t uart_worker(void* context) { if(uart->handle_rx_data_cb) { uart->handle_rx_data_cb(uart->rx_buf, len, uart->app); + furi_mutex_acquire(uart->app->portal_logs_mutex, FuriWaitForever); if(uart->app->sent_reset == false) { furi_string_cat(uart->app->portal_logs, (char*)uart->rx_buf); } - if(furi_string_utf8_length(uart->app->portal_logs) > 4000) { + if(furi_string_size(uart->app->portal_logs) > 4000) { write_logs(uart->app->portal_logs); furi_string_reset(uart->app->portal_logs); } + furi_mutex_release(uart->app->portal_logs_mutex); } else { uart->rx_buf[len] = '\0'; + furi_mutex_acquire(uart->app->portal_logs_mutex, FuriWaitForever); if(uart->app->sent_reset == false) { furi_string_cat(uart->app->portal_logs, (char*)uart->rx_buf); } - if(furi_string_utf8_length(uart->app->portal_logs) > 4000) { + if(furi_string_size(uart->app->portal_logs) > 4000) { write_logs(uart->app->portal_logs); furi_string_reset(uart->app->portal_logs); } + furi_mutex_release(uart->app->portal_logs_mutex); } } } diff --git a/applications/external/evil_portal/helpers/evil_portal_storage.c b/applications/external/evil_portal/helpers/evil_portal_storage.c index 33bef3eab..b9704c96b 100644 --- a/applications/external/evil_portal/helpers/evil_portal_storage.c +++ b/applications/external/evil_portal/helpers/evil_portal_storage.c @@ -156,8 +156,7 @@ void write_logs(FuriString* portal_logs) { File* file = storage_file_alloc(storage); if(storage_file_open(file, seq_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) { - storage_file_write( - file, furi_string_get_cstr(portal_logs), furi_string_utf8_length(portal_logs)); + storage_file_write(file, furi_string_get_cstr(portal_logs), furi_string_size(portal_logs)); } storage_file_close(file); storage_file_free(file); diff --git a/applications/external/evil_portal/scenes/evil_portal_scene_console_output.c b/applications/external/evil_portal/scenes/evil_portal_scene_console_output.c index 64332eeac..70f2443fe 100644 --- a/applications/external/evil_portal/scenes/evil_portal_scene_console_output.c +++ b/applications/external/evil_portal/scenes/evil_portal_scene_console_output.c @@ -62,8 +62,10 @@ void evil_portal_scene_console_output_on_enter(void* context) { const char* help_msg = "Logs saved.\n\n"; furi_string_cat_str(app->text_box_store, help_msg); app->text_box_store_strlen += strlen(help_msg); + furi_mutex_acquire(app->portal_logs_mutex, FuriWaitForever); write_logs(app->portal_logs); furi_string_reset(app->portal_logs); + furi_mutex_release(app->portal_logs_mutex); if(app->show_stopscan_tip) { const char* msg = "Press BACK to return\n"; furi_string_cat_str(app->text_box_store, msg);