Просмотр исходного кода

Now a file is created for each capture with its respective prefix

tcpassos 2 лет назад
Родитель
Сommit
0fcad0e254

+ 40 - 13
applications/plugins/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c

@@ -1,5 +1,43 @@
 #include "../wifi_marauder_app_i.h"
 #include "../wifi_marauder_app_i.h"
 
 
+void wifi_marauder_print_message(uint8_t* buf, size_t len, WifiMarauderApp* app) {
+    // If text box store gets too big, then truncate it
+    app->text_box_store_strlen += len;
+    if(app->text_box_store_strlen >= WIFI_MARAUDER_TEXT_BOX_STORE_SIZE - 1) {
+        furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
+        app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
+    }
+    // Null-terminate buf and append to text box store
+    buf[len] = '\0';
+    furi_string_cat_printf(app->text_box_store, "%s", buf);
+}
+
+void wifi_marauder_get_prefix_from_cmd(char* dest, const char* command) {
+    int start, end, delta;
+    start = strlen("sniff");
+    end = strcspn(command, " ");
+    delta = end - start;
+    strncpy(dest, command + start, end - start);
+    dest[delta] = '\0';    
+}
+
+void wifi_marauder_create_pcap_file(WifiMarauderApp* app) {
+    char prefix[10];
+    char capture_file_path[100];
+    wifi_marauder_get_prefix_from_cmd(prefix, app->selected_tx_string);
+
+    app->capture_file = storage_file_alloc(app->storage);
+    int i=0;
+    do{
+        snprintf(capture_file_path, sizeof(capture_file_path), "%s/%s_%d.pcap", MARAUDER_APP_FOLDER, prefix, i);
+        i++;
+    } while(storage_file_exists(app->storage, capture_file_path));
+
+    if (!storage_file_open(app->capture_file, capture_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
+        dialog_message_show_storage_error(app->dialogs, "Cannot open pcap file");
+    }
+}
+
 void wifi_marauder_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
 void wifi_marauder_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
     furi_assert(context);
     furi_assert(context);
     WifiMarauderApp* app = context;
     WifiMarauderApp* app = context;
@@ -8,25 +46,14 @@ void wifi_marauder_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, vo
     if (strncmp("sniff", app->selected_tx_string, strlen("sniff")) == 0 && !app->is_writing) {
     if (strncmp("sniff", app->selected_tx_string, strlen("sniff")) == 0 && !app->is_writing) {
         app->is_writing = true;
         app->is_writing = true;
         if (!app->capture_file || !storage_file_is_open(app->capture_file)) {
         if (!app->capture_file || !storage_file_is_open(app->capture_file)) {
-            app->capture_file = storage_file_alloc(app->storage);
-            if (!storage_file_open(app->capture_file, MARAUDER_CAPTURE_FILE_PREFIX, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
-                dialog_message_show_storage_error(app->dialogs, "Cannot open pcap file");
-            }
+            wifi_marauder_create_pcap_file(app);
         }
         }
     }
     }
 
 
     if (app->is_writing) {
     if (app->is_writing) {
         storage_file_write(app->capture_file, buf, len);
         storage_file_write(app->capture_file, buf, len);
     } else {
     } else {
-        // If text box store gets too big, then truncate it
-        app->text_box_store_strlen += len;
-        if(app->text_box_store_strlen >= WIFI_MARAUDER_TEXT_BOX_STORE_SIZE - 1) {
-            furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
-            app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
-        }
-        // Null-terminate buf and append to text box store
-        buf[len] = '\0';
-        furi_string_cat_printf(app->text_box_store, "%s", buf);
+        wifi_marauder_print_message(buf, len, app);
     }
     }
 
 
     view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshConsoleOutput);
     view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshConsoleOutput);

+ 0 - 1
applications/plugins/wifi_marauder_companion/wifi_marauder_app_i.h

@@ -23,7 +23,6 @@
 #define WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE (512)
 #define WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE (512)
 
 
 #define MARAUDER_APP_FOLDER ANY_PATH("apps_data/marauder")
 #define MARAUDER_APP_FOLDER ANY_PATH("apps_data/marauder")
-#define MARAUDER_CAPTURE_FILE_PREFIX MARAUDER_APP_FOLDER "/capture.pcap"
 
 
 struct WifiMarauderApp {
 struct WifiMarauderApp {
     Gui* gui;
     Gui* gui;