|
|
@@ -1,5 +1,28 @@
|
|
|
#include "../wifi_marauder_app_i.h"
|
|
|
|
|
|
+char* _wifi_marauder_get_prefix_from_cmd(const char* command) {
|
|
|
+ int end = strcspn(command, " ");
|
|
|
+ char* prefix = (char*) malloc(sizeof(char) * (end + 1));
|
|
|
+ strncpy(prefix, command, end);
|
|
|
+ prefix[end] = '\0';
|
|
|
+ return prefix;
|
|
|
+}
|
|
|
+
|
|
|
+bool _wifi_marauder_is_save_pcaps_enabled(WifiMarauderApp* app) {
|
|
|
+ if (!app->ok_to_save_pcaps) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // If it is a script that contains a sniff function
|
|
|
+ if (app->script != NULL) {
|
|
|
+ WifiMarauderScriptStage* sniff_pmkid_stage = wifi_marauder_script_get_stage(app->script, WifiMarauderScriptStageTypeSniffPmkid);
|
|
|
+ if (sniff_pmkid_stage != NULL) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // If it is a sniff function
|
|
|
+ return app->is_command && app->selected_tx_string && strncmp("sniff", app->selected_tx_string, strlen("sniff")) == 0;
|
|
|
+}
|
|
|
+
|
|
|
void wifi_marauder_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
|
|
|
furi_assert(context);
|
|
|
WifiMarauderApp* app = context;
|
|
|
@@ -27,30 +50,36 @@ void wifi_marauder_console_output_handle_rx_packets_cb(uint8_t* buf, size_t len,
|
|
|
WifiMarauderApp* app = context;
|
|
|
|
|
|
if(app->is_writing_pcap) {
|
|
|
- storage_file_write(app->capture_file, buf, len);
|
|
|
+ sequential_file_write(app->capture_file, buf, len);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void wifi_marauder_scene_console_output_on_enter(void* context) {
|
|
|
WifiMarauderApp* app = context;
|
|
|
|
|
|
+ // Reset text box and set font
|
|
|
TextBox* text_box = app->text_box;
|
|
|
- text_box_reset(app->text_box);
|
|
|
+ text_box_reset(text_box);
|
|
|
text_box_set_font(text_box, TextBoxFontText);
|
|
|
+
|
|
|
+ // Set focus on start or end
|
|
|
if(app->focus_console_start) {
|
|
|
text_box_set_focus(text_box, TextBoxFocusStart);
|
|
|
} else {
|
|
|
text_box_set_focus(text_box, TextBoxFocusEnd);
|
|
|
}
|
|
|
+
|
|
|
+ // Set command-related messages
|
|
|
if(app->is_command) {
|
|
|
furi_string_reset(app->text_box_store);
|
|
|
app->text_box_store_strlen = 0;
|
|
|
+ // Help message
|
|
|
if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
|
|
|
const char* help_msg = "Marauder companion " WIFI_MARAUDER_APP_VERSION "\n";
|
|
|
furi_string_cat_str(app->text_box_store, help_msg);
|
|
|
app->text_box_store_strlen += strlen(help_msg);
|
|
|
}
|
|
|
-
|
|
|
+ // Stopscan message
|
|
|
if(app->show_stopscan_tip) {
|
|
|
const char* help_msg = "Press BACK to send stopscan\n";
|
|
|
furi_string_cat_str(app->text_box_store, help_msg);
|
|
|
@@ -58,47 +87,57 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Set starting text - for "View Log from end", this will just be what was already in the text box store
|
|
|
+ // Set starting text
|
|
|
text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
|
|
|
|
|
|
+ // Set scene state and switch view
|
|
|
scene_manager_set_scene_state(app->scene_manager, WifiMarauderSceneConsoleOutput, 0);
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewConsoleOutput);
|
|
|
|
|
|
- // Register callback to receive data
|
|
|
- wifi_marauder_uart_set_handle_rx_data_cb(
|
|
|
- app->uart,
|
|
|
- wifi_marauder_console_output_handle_rx_data_cb); // setup callback for general log rx thread
|
|
|
- wifi_marauder_uart_set_handle_rx_data_cb(
|
|
|
- app->lp_uart,
|
|
|
- wifi_marauder_console_output_handle_rx_packets_cb); // setup callback for packets rx thread
|
|
|
+ // Register callbacks to receive data
|
|
|
+ wifi_marauder_uart_set_handle_rx_data_cb(app->uart, wifi_marauder_console_output_handle_rx_data_cb); // setup callback for general log rx thread
|
|
|
+ wifi_marauder_uart_set_handle_rx_data_cb(app->lp_uart, wifi_marauder_console_output_handle_rx_packets_cb); // setup callback for packets rx thread
|
|
|
|
|
|
- // Run the script if the file with the script has been opened
|
|
|
- if(app->script != NULL) {
|
|
|
- furi_string_reset(app->text_box_store);
|
|
|
- app->text_box_store_strlen = 0;
|
|
|
- app->script_worker = wifi_marauder_script_worker_alloc();
|
|
|
- wifi_marauder_script_worker_start(app->script_worker, app->script, wifi_marauder_script_execute_stage, app->script_worker);
|
|
|
- }
|
|
|
-
|
|
|
// Get ready to send command
|
|
|
- if(app->is_command && app->selected_tx_string) {
|
|
|
+ if((app->is_command && app->selected_tx_string) || app->script) {
|
|
|
+ const char* prefix = strlen(app->selected_tx_string) > 0 ?
|
|
|
+ _wifi_marauder_get_prefix_from_cmd(app->selected_tx_string) : // Function name
|
|
|
+ app->script->name; // Script name
|
|
|
+
|
|
|
// Create files *before* sending command
|
|
|
// (it takes time to iterate through the directory)
|
|
|
if(app->ok_to_save_logs) {
|
|
|
app->is_writing_log = true;
|
|
|
- wifi_marauder_create_log_file(app);
|
|
|
+ app->sequential_log_file = sequential_file_create(app->storage, MARAUDER_APP_FOLDER_LOGS, prefix, "log");
|
|
|
+ if (app->sequential_log_file) {
|
|
|
+ app->log_file = app->sequential_log_file->file;
|
|
|
+ strcpy(app->log_file_path, app->sequential_log_file->path);
|
|
|
+ } else {
|
|
|
+ dialog_message_show_storage_error(app->dialogs, "Cannot open log file");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // If it is a sniff function, open the pcap file for recording
|
|
|
- if(app->ok_to_save_pcaps && strncmp("sniff", app->selected_tx_string, strlen("sniff")) == 0) {
|
|
|
+ // If it is a sniff function or script, open the pcap file for recording
|
|
|
+ if (_wifi_marauder_is_save_pcaps_enabled(app)) {
|
|
|
app->is_writing_pcap = true;
|
|
|
- wifi_marauder_create_pcap_file(app);
|
|
|
+ app->capture_file = sequential_file_create(app->storage, MARAUDER_APP_FOLDER_PCAPS, prefix, "pcap");
|
|
|
+ if (app->capture_file == NULL) {
|
|
|
+ dialog_message_show_storage_error(app->dialogs, "Cannot open pcap file");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Send command with newline '\n'
|
|
|
- wifi_marauder_uart_tx(
|
|
|
- (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
|
|
|
- wifi_marauder_uart_tx((uint8_t*)("\n"), 1);
|
|
|
+ if (app->selected_tx_string) {
|
|
|
+ wifi_marauder_uart_tx(
|
|
|
+ (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
|
|
|
+ wifi_marauder_uart_tx((uint8_t*)("\n"), 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Run the script if the file with the script has been opened
|
|
|
+ if(app->script) {
|
|
|
+ app->script_worker = wifi_marauder_script_worker_alloc();
|
|
|
+ wifi_marauder_script_worker_start(app->script_worker, app->script, wifi_marauder_script_execute_stage, app->script_worker);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -120,31 +159,22 @@ bool wifi_marauder_scene_console_output_on_event(void* context, SceneManagerEven
|
|
|
void wifi_marauder_scene_console_output_on_exit(void* context) {
|
|
|
WifiMarauderApp* app = context;
|
|
|
|
|
|
- // Unregister rx callback
|
|
|
- wifi_marauder_uart_set_handle_rx_data_cb(app->uart, NULL);
|
|
|
- wifi_marauder_uart_set_handle_rx_data_cb(app->lp_uart, NULL);
|
|
|
-
|
|
|
- if (app->script_worker) {
|
|
|
- wifi_marauder_script_worker_free(app->script_worker);
|
|
|
- }
|
|
|
-
|
|
|
- if (app->script) {
|
|
|
- wifi_marauder_script_free(app->script);
|
|
|
- }
|
|
|
-
|
|
|
// Automatically stop the scan when exiting view
|
|
|
if(app->is_command) {
|
|
|
wifi_marauder_uart_tx((uint8_t*)("stopscan\n"), strlen("stopscan\n"));
|
|
|
+ furi_delay_ms(50);
|
|
|
}
|
|
|
|
|
|
+ // Unregister rx callback
|
|
|
+ wifi_marauder_uart_set_handle_rx_data_cb(app->uart, NULL);
|
|
|
+ wifi_marauder_uart_set_handle_rx_data_cb(app->lp_uart, NULL);
|
|
|
+
|
|
|
+ wifi_marauder_script_worker_free(app->script_worker);
|
|
|
+ wifi_marauder_script_free(app->script);
|
|
|
+
|
|
|
app->is_writing_pcap = false;
|
|
|
- if(app->capture_file && storage_file_is_open(app->capture_file)) {
|
|
|
- storage_file_close(app->capture_file);
|
|
|
- }
|
|
|
+ sequential_file_free_destroy_file(app->capture_file);
|
|
|
|
|
|
app->is_writing_log = false;
|
|
|
- if(app->log_file && storage_file_is_open(app->log_file)) {
|
|
|
- storage_file_close(app->log_file);
|
|
|
- }
|
|
|
-
|
|
|
+ sequential_file_free_close_file(app->sequential_log_file);
|
|
|
}
|