wifi_marauder_pcap.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "wifi_marauder_app_i.h"
  2. #include "wifi_marauder_pcap.h"
  3. void wifi_marauder_get_prefix_from_sniff_cmd(char* dest, const char* command) {
  4. int start, end, delta;
  5. start = strlen("sniff");
  6. end = strcspn(command, " ");
  7. delta = end - start;
  8. strncpy(dest, command + start, end - start);
  9. dest[delta] = '\0';
  10. }
  11. void wifi_marauder_get_prefix_from_cmd(char* dest, const char* command) {
  12. int end;
  13. end = strcspn(command, " ");
  14. strncpy(dest, command, end);
  15. dest[end] = '\0';
  16. }
  17. void wifi_marauder_create_pcap_file(WifiMarauderApp* app) {
  18. char prefix[10];
  19. char capture_file_path[100];
  20. wifi_marauder_get_prefix_from_sniff_cmd(prefix, app->selected_tx_string);
  21. int i = 0;
  22. do {
  23. snprintf(
  24. capture_file_path,
  25. sizeof(capture_file_path),
  26. "%s/%s_%d.pcap",
  27. MARAUDER_APP_FOLDER_PCAPS,
  28. prefix,
  29. i);
  30. i++;
  31. } while(storage_file_exists(app->storage, capture_file_path));
  32. if(!storage_file_open(app->capture_file, capture_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
  33. dialog_message_show_storage_error(app->dialogs, "Cannot open pcap file");
  34. }
  35. }
  36. void wifi_marauder_create_log_file(WifiMarauderApp* app) {
  37. char prefix[10];
  38. char log_file_path[100];
  39. wifi_marauder_get_prefix_from_cmd(prefix, app->selected_tx_string);
  40. int i = 0;
  41. do {
  42. snprintf(
  43. log_file_path,
  44. sizeof(log_file_path),
  45. "%s/%s_%d.log",
  46. MARAUDER_APP_FOLDER_LOGS,
  47. prefix,
  48. i);
  49. i++;
  50. } while(storage_file_exists(app->storage, log_file_path));
  51. if(!storage_file_open(app->log_file, log_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
  52. dialog_message_show_storage_error(app->dialogs, "Cannot open log file");
  53. } else {
  54. strcpy(app->log_file_path, log_file_path);
  55. }
  56. }