Skip to content

Commit f28e785

Browse files
Merge pull request #11 from jaylikesbunda/main
v1.0.8
2 parents 9d3870d + 985867a commit f28e785

8 files changed

+252
-194
lines changed

callbacks.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,7 @@ void show_app_info(void* context) {
203203
FURI_LOG_D("AppInfo", "Show app info called, context: %p", app);
204204

205205
const char* info_text =
206-
"Ghost ESP v1.0.5\n\n"
207-
"Created by: Spooky\n"
208-
"Special Thanks:\n"
209-
"- Jay Candel\n"
210-
"Built with <3";
206+
"";
211207

212208
if(app && app->confirmation_view) {
213209
// Create a new context for the confirmation dialog

docs/changelog.md

+13
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@
6363
## v1.0.7a
6464
- Disable the expansion interface before trying to use UART
6565

66+
## v1.0.8
67+
68+
### 🔴 CRITICAL FIX - PCAP capture
69+
- Fixed PCAP file handling and storage system
70+
- Resolved PCAP file stream corruption issues
71+
- Added proper storage system initialization
72+
- Removed the line buffering logic for PCAP data
73+
74+
### Improvements
75+
- Added error checking for storage operations
76+
- Filtering majorly improved
77+
- Improved stop on back to be much more reliable by added type-specific stop commands with delays between operations
78+
6679
## TODO
6780
- Replaced select a utility text with prompt to show NEW Help Menu
6881
- IMPROVE optional filtering to UART output

menu.c

+45-16
Original file line numberDiff line numberDiff line change
@@ -816,18 +816,15 @@ void submenu_callback(void* context, uint32_t index) {
816816

817817
bool back_event_callback(void* context) {
818818
AppState* state = (AppState*)context;
819-
820-
// Get the current view ID
821819
uint32_t current_view = state->current_view;
822820

823-
// Do not consume the back button event if the current view is the confirmation view
824-
if(current_view == 7) { // 7 is the ID for the confirmation view
825-
// Allow the confirmation view's input callback to handle the back button
821+
// Allow confirmation view to handle its own back button
822+
if(current_view == 7) {
826823
return false;
827824
}
828825

829826
if(current_view == 5) { // Text box view
830-
FURI_LOG_D("Ghost ESP", "Stopping Thread");
827+
FURI_LOG_D("Ghost ESP", "Stopping Operations");
831828

832829
// Cleanup text buffer
833830
if(state->textBoxBuffer) {
@@ -839,28 +836,61 @@ bool back_event_callback(void* context) {
839836
state->buffer_length = 0;
840837
}
841838

842-
// Only send stop commands if enabled in settings
839+
// Send stop commands if enabled in settings
843840
if(state->settings.stop_on_back_index) {
844-
// Send all relevant stop commands
841+
// First stop any packet captures to ensure proper file saving
842+
send_uart_command("capture -stop\n", state);
843+
furi_delay_ms(100); // Give time for file operation
844+
845+
// Reset PCAP state if needed
846+
if(state->uart_context->pcap) {
847+
state->uart_context->pcap = false;
848+
furi_stream_buffer_reset(state->uart_context->pcap_stream);
849+
furi_delay_ms(50); // Allow buffer cleanup
850+
}
851+
852+
// Then stop various operations in a logical order
853+
send_uart_command("stopscan\n", state);
854+
furi_delay_ms(50);
855+
856+
send_uart_command("stopspam\n", state);
857+
furi_delay_ms(50);
858+
859+
send_uart_command("stopdeauth\n", state);
860+
furi_delay_ms(50);
861+
862+
send_uart_command("stopportal\n", state);
863+
furi_delay_ms(50);
864+
865+
send_uart_command("blescan -s\n", state);
866+
furi_delay_ms(50);
867+
868+
// Final general stop
845869
send_uart_command("stop\n", state);
870+
furi_delay_ms(50);
846871
}
847872

848-
// Close any open files
849-
if(state->uart_context->storageContext->current_file &&
850-
storage_file_is_open(state->uart_context->storageContext->current_file)) {
851-
state->uart_context->storageContext->HasOpenedFile = false;
852-
FURI_LOG_D("DEBUG", "Storage File Closed");
873+
// Close any open files with proper checking
874+
if(state->uart_context->storageContext) {
875+
if(state->uart_context->storageContext->current_file &&
876+
storage_file_is_open(state->uart_context->storageContext->current_file)) {
877+
// Give time for final writes
878+
furi_delay_ms(100);
879+
storage_file_close(state->uart_context->storageContext->current_file);
880+
state->uart_context->storageContext->HasOpenedFile = false;
881+
FURI_LOG_D("DEBUG", "Storage File Closed");
882+
}
853883
}
854884

855-
// Return to previous view
885+
// Return to appropriate previous view
856886
switch(state->previous_view) {
857887
case 1: show_wifi_menu(state); break;
858888
case 2: show_ble_menu(state); break;
859889
case 3: show_gps_menu(state); break;
860890
default: show_main_menu(state); break;
861891
}
862892
state->current_view = state->previous_view;
863-
} else if(current_view == 8) { // Settings actions menu
893+
} else if(current_view == 8) { // Settings menu
864894
show_main_menu(state);
865895
state->current_view = 0;
866896
} else if(current_view != 0) {
@@ -870,7 +900,6 @@ bool back_event_callback(void* context) {
870900
view_dispatcher_stop(state->view_dispatcher);
871901
}
872902

873-
// Consume the back button event for all views except the confirmation view
874903
return true;
875904
}
876905

settings_ui.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ bool settings_custom_event_callback(void* context, uint32_t event_id) {
391391
"Updated by: Jay Candel\n"
392392
"Built with <3";
393393

394-
confirmation_view_set_header(app_state->confirmation_view, "Ghost ESP v1.0.7a");
394+
confirmation_view_set_header(app_state->confirmation_view, "Ghost ESP v1.0.8");
395395
confirmation_view_set_text(app_state->confirmation_view, info_text);
396396

397397
// Save current view before switching

uart_storage.c

+78-37
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,64 @@
66
#include <storage/storage.h>
77
#include "sequential_file.h"
88

9-
109
#define COMMAND_BUFFER_SIZE 128
10+
#define PCAP_WRITE_CHUNK_SIZE 1024u
1111

1212
void uart_storage_rx_callback(uint8_t *buf, size_t len, void *context) {
1313
UartContext *app = context;
14-
if(app->storageContext->HasOpenedFile) {
15-
storage_file_write(app->storageContext->current_file, buf, len);
14+
15+
if(!app || !app->storageContext || !app->storageContext->storage_api) {
16+
FURI_LOG_E("Storage", "Invalid storage context");
17+
return;
18+
}
19+
20+
if(!app->storageContext->HasOpenedFile ||
21+
!app->storageContext->current_file ||
22+
!storage_file_is_open(app->storageContext->current_file)) {
23+
FURI_LOG_W("Storage", "No file open for writing");
24+
app->pcap = false; // Disable PCAP mode if file isn't ready
25+
return;
1626
}
17-
}
1827

19-
UartStorageContext *uart_storage_init(UartContext *parentContext) {
28+
// Write in chunks to avoid buffer overflow
29+
size_t written = 0;
30+
while(written < len) {
31+
size_t remaining = len - written;
32+
size_t chunk_size = (remaining < PCAP_WRITE_CHUNK_SIZE) ?
33+
remaining : PCAP_WRITE_CHUNK_SIZE;
34+
35+
uint16_t bytes_written = storage_file_write(
36+
app->storageContext->current_file,
37+
buf + written,
38+
chunk_size);
39+
40+
if(bytes_written != chunk_size) {
41+
FURI_LOG_E("Storage", "Write failed: %u/%zu bytes", bytes_written, chunk_size);
42+
app->pcap = false; // Disable PCAP mode on write failure
43+
break;
44+
}
45+
written += bytes_written;
46+
}
47+
}
48+
UartStorageContext* uart_storage_init(UartContext* parentContext) {
2049
uint32_t start_time = furi_get_tick();
2150
FURI_LOG_D("Storage", "Starting storage initialization");
2251

23-
UartStorageContext *ctx = malloc(sizeof(UartStorageContext));
52+
UartStorageContext* ctx = malloc(sizeof(UartStorageContext));
2453
if(!ctx) {
2554
FURI_LOG_E("Storage", "Failed to allocate context");
2655
return NULL;
2756
}
28-
2957
memset(ctx, 0, sizeof(UartStorageContext));
3058
ctx->parentContext = parentContext;
3159

32-
// Open storage API
33-
uint32_t storage_open_start = furi_get_tick();
3460
ctx->storage_api = furi_record_open(RECORD_STORAGE);
35-
FURI_LOG_D("Storage", "Storage API open took %lums", furi_get_tick() - storage_open_start);
36-
3761
if(!ctx->storage_api) {
3862
FURI_LOG_E("Storage", "Failed to open storage API");
3963
free(ctx);
4064
return NULL;
4165
}
4266

43-
// Allocate file handles
4467
ctx->current_file = storage_file_alloc(ctx->storage_api);
4568
ctx->log_file = storage_file_alloc(ctx->storage_api);
4669

@@ -53,69 +76,87 @@ UartStorageContext *uart_storage_init(UartContext *parentContext) {
5376
return NULL;
5477
}
5578

56-
// Create directories efficiently
57-
uint32_t dir_start = furi_get_tick();
58-
storage_simply_mkdir(ctx->storage_api, GHOST_ESP_APP_FOLDER);
59-
storage_simply_mkdir(ctx->storage_api, GHOST_ESP_APP_FOLDER_LOGS);
60-
storage_simply_mkdir(ctx->storage_api, GHOST_ESP_APP_FOLDER_PCAPS);
61-
storage_simply_mkdir(ctx->storage_api, GHOST_ESP_APP_FOLDER_WARDRIVE);
62-
FURI_LOG_D("Storage", "Directory creation took %lums", furi_get_tick() - dir_start);
79+
// Create directories with verification
80+
if(!storage_simply_mkdir(ctx->storage_api, GHOST_ESP_APP_FOLDER)) {
81+
FURI_LOG_W("Storage", "Failed to create app folder");
82+
}
83+
if(!storage_simply_mkdir(ctx->storage_api, GHOST_ESP_APP_FOLDER_PCAPS)) {
84+
FURI_LOG_W("Storage", "Failed to create PCAP folder");
85+
}
86+
if(!storage_simply_mkdir(ctx->storage_api, GHOST_ESP_APP_FOLDER_LOGS)) {
87+
FURI_LOG_W("Storage", "Failed to create logs folder");
88+
}
89+
if(!storage_simply_mkdir(ctx->storage_api, GHOST_ESP_APP_FOLDER_WARDRIVE)) {
90+
FURI_LOG_W("Storage", "Failed to create wardrive folder");
91+
}
92+
93+
// Verify PCAP directory exists and is writable
94+
File* test_dir = storage_file_alloc(ctx->storage_api);
95+
if(test_dir) {
96+
if(!storage_dir_open(test_dir, GHOST_ESP_APP_FOLDER_PCAPS)) {
97+
FURI_LOG_E("Storage", "PCAP directory not accessible");
98+
}
99+
storage_dir_close(test_dir);
100+
storage_file_free(test_dir);
101+
}
63102

64-
// Initialize log file efficiently
65-
uint32_t log_start = furi_get_tick();
103+
// Initialize log file
66104
bool log_ok = sequential_file_open(
67105
ctx->storage_api,
68106
ctx->log_file,
69107
GHOST_ESP_APP_FOLDER_LOGS,
70108
"ghost_logs",
71109
"txt");
72-
110+
73111
if(!log_ok) {
74-
FURI_LOG_W("Storage", "Failed to create initial log file");
112+
FURI_LOG_E("Storage", "Failed to open log file");
75113
}
76-
FURI_LOG_D("Storage", "Log file creation took %lums", furi_get_tick() - log_start);
77114

78115
ctx->HasOpenedFile = log_ok;
116+
ctx->IsWritingToFile = false;
79117

80118
FURI_LOG_I("Storage", "Storage initialization completed in %lums",
81119
furi_get_tick() - start_time);
82120
return ctx;
83121
}
122+
84123
void uart_storage_reset_logs(UartStorageContext *ctx) {
85124
if(!ctx || !ctx->storage_api) return;
86125

87-
FURI_LOG_D("Storage", "Resetting log files");
88-
89-
// Close existing log file if open
90126
if(ctx->log_file) {
91127
storage_file_close(ctx->log_file);
92128
storage_file_free(ctx->log_file);
93129
ctx->log_file = storage_file_alloc(ctx->storage_api);
94130
}
95131

96-
// Create new log file
97132
ctx->HasOpenedFile = sequential_file_open(
98133
ctx->storage_api,
99134
ctx->log_file,
100135
GHOST_ESP_APP_FOLDER_LOGS,
101136
"ghost_logs",
102137
"txt");
103-
138+
104139
if(!ctx->HasOpenedFile) {
105-
FURI_LOG_E("Storage", "Failed to create new log file during reset");
140+
FURI_LOG_E("Storage", "Failed to reset log file");
106141
}
107142
}
143+
108144
void uart_storage_free(UartStorageContext *ctx) {
109145
if(!ctx) return;
110146

111-
uint32_t start_time = furi_get_tick();
112-
FURI_LOG_D("Storage", "Starting storage cleanup");
147+
if(ctx->current_file) {
148+
storage_file_close(ctx->current_file);
149+
storage_file_free(ctx->current_file);
150+
}
113151

114-
if(ctx->current_file) storage_file_free(ctx->current_file);
115-
if(ctx->log_file) storage_file_free(ctx->log_file);
116-
if(ctx->storage_api) furi_record_close(RECORD_STORAGE);
152+
if(ctx->log_file) {
153+
storage_file_close(ctx->log_file);
154+
storage_file_free(ctx->log_file);
155+
}
156+
157+
if(ctx->storage_api) {
158+
furi_record_close(RECORD_STORAGE);
159+
}
117160

118161
free(ctx);
119-
FURI_LOG_D("Storage", "Storage cleanup completed in %lums",
120-
furi_get_tick() - start_time);
121162
}

uart_storage.h

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <furi.h>
55
#include <storage/storage.h>
66

7-
87
struct UartStorageContext {
98
Storage* storage_api;
109
File* current_file;

0 commit comments

Comments
 (0)