1
1
#include "../wifi_marauder_app_i.h"
2
2
3
+ char * _wifi_marauder_get_prefix_from_cmd (const char * command ) {
4
+ int end = strcspn (command , " " );
5
+ char * prefix = (char * ) malloc (sizeof (char ) * (end + 1 ));
6
+ strncpy (prefix , command , end );
7
+ prefix [end ] = '\0' ;
8
+ return prefix ;
9
+ }
10
+
11
+ bool _wifi_marauder_is_save_pcaps_enabled (WifiMarauderApp * app ) {
12
+ if (!app -> ok_to_save_pcaps ) {
13
+ return false;
14
+ }
15
+ // If it is a script that contains a sniff function
16
+ if (app -> script != NULL ) {
17
+ return wifi_marauder_script_has_stage (app -> script , WifiMarauderScriptStageTypeSniffRaw ) ||
18
+ wifi_marauder_script_has_stage (app -> script , WifiMarauderScriptStageTypeSniffBeacon ) ||
19
+ wifi_marauder_script_has_stage (app -> script , WifiMarauderScriptStageTypeSniffDeauth ) ||
20
+ wifi_marauder_script_has_stage (app -> script , WifiMarauderScriptStageTypeSniffEsp ) ||
21
+ wifi_marauder_script_has_stage (app -> script , WifiMarauderScriptStageTypeSniffPmkid ) ||
22
+ wifi_marauder_script_has_stage (app -> script , WifiMarauderScriptStageTypeSniffPwn );
23
+ }
24
+ // If it is a sniff function
25
+ return app -> is_command && app -> selected_tx_string && strncmp ("sniff" , app -> selected_tx_string , strlen ("sniff" )) == 0 ;
26
+ }
27
+
3
28
void wifi_marauder_console_output_handle_rx_data_cb (uint8_t * buf , size_t len , void * context ) {
4
29
furi_assert (context );
5
30
WifiMarauderApp * app = context ;
@@ -34,63 +59,89 @@ void wifi_marauder_console_output_handle_rx_packets_cb(uint8_t* buf, size_t len,
34
59
void wifi_marauder_scene_console_output_on_enter (void * context ) {
35
60
WifiMarauderApp * app = context ;
36
61
62
+ // Reset text box and set font
37
63
TextBox * text_box = app -> text_box ;
38
- text_box_reset (app -> text_box );
64
+ text_box_reset (text_box );
39
65
text_box_set_font (text_box , TextBoxFontText );
66
+
67
+ // Set focus on start or end
40
68
if (app -> focus_console_start ) {
41
69
text_box_set_focus (text_box , TextBoxFocusStart );
42
70
} else {
43
71
text_box_set_focus (text_box , TextBoxFocusEnd );
44
72
}
73
+
74
+ // Set command-related messages
45
75
if (app -> is_command ) {
46
76
furi_string_reset (app -> text_box_store );
47
77
app -> text_box_store_strlen = 0 ;
78
+ // Help message
48
79
if (0 == strncmp ("help" , app -> selected_tx_string , strlen ("help" ))) {
49
80
const char * help_msg = "Marauder companion " WIFI_MARAUDER_APP_VERSION "\n" ;
50
81
furi_string_cat_str (app -> text_box_store , help_msg );
51
82
app -> text_box_store_strlen += strlen (help_msg );
52
83
}
53
-
84
+ // Stopscan message
54
85
if (app -> show_stopscan_tip ) {
55
86
const char * help_msg = "Press BACK to send stopscan\n" ;
56
87
furi_string_cat_str (app -> text_box_store , help_msg );
57
88
app -> text_box_store_strlen += strlen (help_msg );
58
89
}
59
90
}
60
91
61
- // Set starting text - for "View Log from end", this will just be what was already in the text box store
92
+ // Set starting text
62
93
text_box_set_text (app -> text_box , furi_string_get_cstr (app -> text_box_store ));
63
94
95
+ // Set scene state and switch view
64
96
scene_manager_set_scene_state (app -> scene_manager , WifiMarauderSceneConsoleOutput , 0 );
65
97
view_dispatcher_switch_to_view (app -> view_dispatcher , WifiMarauderAppViewConsoleOutput );
66
98
67
- // Register callback to receive data
68
- wifi_marauder_uart_set_handle_rx_data_cb (
69
- app -> uart ,
70
- wifi_marauder_console_output_handle_rx_data_cb ); // setup callback for general log rx thread
71
- wifi_marauder_uart_set_handle_rx_data_cb (
72
- app -> lp_uart ,
73
- wifi_marauder_console_output_handle_rx_packets_cb ); // setup callback for packets rx thread
74
-
99
+ // Register callbacks to receive data
100
+ 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
101
+ 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
102
+
75
103
// Get ready to send command
76
- if (app -> is_command && app -> selected_tx_string ) {
104
+ if ((app -> is_command && app -> selected_tx_string ) || app -> script ) {
105
+ const char * prefix = strlen (app -> selected_tx_string ) > 0 ?
106
+ _wifi_marauder_get_prefix_from_cmd (app -> selected_tx_string ) : // Function name
107
+ app -> script -> name ; // Script name
108
+
77
109
// Create files *before* sending command
78
110
// (it takes time to iterate through the directory)
79
111
if (app -> ok_to_save_logs ) {
80
- app -> is_writing_log = true;
81
- wifi_marauder_create_log_file (app );
112
+ strcpy (app -> log_file_path , sequential_file_resolve_path (app -> storage , MARAUDER_APP_FOLDER_LOGS , prefix , "log" ));
113
+ if (app -> log_file_path != NULL ) {
114
+ if (storage_file_open (app -> log_file , app -> log_file_path , FSAM_WRITE , FSOM_CREATE_ALWAYS )) {
115
+ app -> is_writing_log = true;
116
+ } else {
117
+ dialog_message_show_storage_error (app -> dialogs , "Cannot open log file" );
118
+ }
119
+ } else {
120
+ dialog_message_show_storage_error (app -> dialogs , "Cannot resolve log path" );
121
+ }
82
122
}
83
123
84
- // If it is a sniff function, open the pcap file for recording
85
- if (app -> ok_to_save_pcaps && strncmp ("sniff" , app -> selected_tx_string , strlen ("sniff" )) == 0 ) {
86
- app -> is_writing_pcap = true;
87
- wifi_marauder_create_pcap_file (app );
124
+ // If it is a sniff function or script, open the pcap file for recording
125
+ if (_wifi_marauder_is_save_pcaps_enabled (app )) {
126
+ if (sequential_file_open (app -> storage , app -> capture_file , MARAUDER_APP_FOLDER_PCAPS , prefix , "pcap" )) {
127
+ app -> is_writing_pcap = true;
128
+ } else {
129
+ dialog_message_show_storage_error (app -> dialogs , "Cannot open pcap file" );
130
+ }
88
131
}
89
132
90
133
// Send command with newline '\n'
91
- wifi_marauder_uart_tx (
92
- (uint8_t * )(app -> selected_tx_string ), strlen (app -> selected_tx_string ));
93
- wifi_marauder_uart_tx ((uint8_t * )("\n" ), 1 );
134
+ if (app -> selected_tx_string ) {
135
+ wifi_marauder_uart_tx (
136
+ (uint8_t * )(app -> selected_tx_string ), strlen (app -> selected_tx_string ));
137
+ wifi_marauder_uart_tx ((uint8_t * )("\n" ), 1 );
138
+ }
139
+
140
+ // Run the script if the file with the script has been opened
141
+ if (app -> script != NULL ) {
142
+ app -> script_worker = wifi_marauder_script_worker_alloc ();
143
+ wifi_marauder_script_worker_start (app -> script_worker , app -> script );
144
+ }
94
145
}
95
146
}
96
147
@@ -112,15 +163,19 @@ bool wifi_marauder_scene_console_output_on_event(void* context, SceneManagerEven
112
163
void wifi_marauder_scene_console_output_on_exit (void * context ) {
113
164
WifiMarauderApp * app = context ;
114
165
115
- // Unregister rx callback
116
- wifi_marauder_uart_set_handle_rx_data_cb (app -> uart , NULL );
117
- wifi_marauder_uart_set_handle_rx_data_cb (app -> lp_uart , NULL );
118
-
119
166
// Automatically stop the scan when exiting view
120
167
if (app -> is_command ) {
121
168
wifi_marauder_uart_tx ((uint8_t * )("stopscan\n" ), strlen ("stopscan\n" ));
169
+ furi_delay_ms (50 );
122
170
}
123
171
172
+ // Unregister rx callback
173
+ wifi_marauder_uart_set_handle_rx_data_cb (app -> uart , NULL );
174
+ wifi_marauder_uart_set_handle_rx_data_cb (app -> lp_uart , NULL );
175
+
176
+ wifi_marauder_script_worker_free (app -> script_worker );
177
+ app -> script_worker = NULL ;
178
+
124
179
app -> is_writing_pcap = false;
125
180
if (app -> capture_file && storage_file_is_open (app -> capture_file )) {
126
181
storage_file_close (app -> capture_file );
0 commit comments