Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
updated GUI
anof-cyberc1c99d94b927
diff --git a/Linux/gui/gui.h b/Linux/gui/gui.hindex d0e57de..777f2bf 100644--- a/Linux/gui/gui.h+++ b/Linux/gui/gui.h@@ -13,9 +13,6 @@#include <sys/stat.h>#include <sys/wait.h>#include "ProxyBridge.h"--// --- Data Structures ----typedef struct {char *process_name;uint32_t pid;@@ -53,7 +50,6 @@ typedef struct {bool selected;} RuleData;-// --- Thread Communication ---struct TestRunnerData {char *host;uint16_t port;@@ -66,7 +62,6 @@ typedef struct {GtkWidget *btn;} TestResultData;-// --- Globals (External) ---extern GtkWidget *window;extern GtkTextBuffer *conn_buffer;extern GtkTextBuffer *log_buffer;@@ -81,9 +76,6 @@ extern char g_proxy_pass[256];extern GList *g_rules_list;-// --- Function Prototypes -----// Utilslong safe_strtol(const char *nptr);void show_message(GtkWindow *parent, GtkMessageType type, const char *format, ...);void trim_buffer_lines(GtkTextBuffer *buffer, int max_lines);@@ -92,10 +84,10 @@ char *escape_json_string(const char *src);char *extract_sub_json_str(const char *json, const char *key);bool extract_sub_json_bool(const char *json, const char *key);-// Settings+// settingsvoid on_proxy_configure(GtkWidget *widget, gpointer data);-// Rules+// rules sectionvoid on_proxy_rules_clicked(GtkWidget *widget, gpointer data);// Logs@@ -106,4 +98,4 @@ void on_search_log_changed(GtkSearchEntry *entry, gpointer user_data);void on_clear_conn_clicked(GtkButton *button, gpointer user_data);void on_clear_log_clicked(GtkButton *button, gpointer user_data);-#endif // PROXYBRIDGE_GUI_H+#endifdiff --git a/Linux/gui/gui_logs.c b/Linux/gui/gui_logs.cindex 8803348..3410269 100644--- a/Linux/gui/gui_logs.c+++ b/Linux/gui/gui_logs.c@@ -1,6 +1,6 @@#include "gui.h"-// Filter Function for TextView+// filter the text view based on user imputstatic void filter_text_view(GtkTextBuffer *buffer, const char *text) {if (!buffer) return;@@ -18,7 +18,7 @@ static void filter_text_view(GtkTextBuffer *buffer, const char *text) {char *line_text = gtk_text_buffer_get_text(buffer, &line_start, &line_end, FALSE);- // Case-insensitive search+ // case insensitive searchchar *lower_line = g_utf8_strdown(line_text, -1);char *lower_search = g_utf8_strdown(text, -1);@@ -64,7 +64,7 @@ static void free_connection_data(ConnectionData *data) {}}-// Thread-safe idle callback for Log+// update logs safely from main threadstatic gboolean update_log_gui(gpointer user_data) {LogData *data = (LogData *)user_data;if (!data) return FALSE;@@ -83,10 +83,10 @@ static gboolean update_log_gui(gpointer user_data) {free(data->message);free(data);- return FALSE; // Remove source+ return FALSE; // done}-// Thread-safe idle callback for Connection+// update connection info safelystatic gboolean update_connection_gui_append(gpointer user_data) {ConnectionData *data = (ConnectionData *)user_data;if (!data) return FALSE;diff --git a/Linux/gui/gui_rules.c b/Linux/gui/gui_rules.cindex 52b1718..2beca0f 100644--- a/Linux/gui/gui_rules.c+++ b/Linux/gui/gui_rules.c@@ -3,7 +3,7 @@static GtkWidget *rules_list_box = NULL;static GtkWidget *btn_select_all_header = NULL;-// Forward declaration+// forward declstatic void refresh_rules_ui();static void free_rule_data(RuleData *rule) {@@ -33,7 +33,7 @@ static void on_rule_toggle(GtkToggleButton *btn, gpointer data) {static void on_save_rule(GtkWidget *widget, gpointer data) {GtkWidget **widgets = (GtkWidget **)data;GtkWidget *dialog = widgets[0];- RuleData *edit_rule = (RuleData *)widgets[6]; // If not null, we are editing+ RuleData *edit_rule = (RuleData *)widgets[6]; // existing rule if presentconst char *proc = gtk_entry_get_text(GTK_ENTRY(widgets[1]));const char *hosts = gtk_entry_get_text(GTK_ENTRY(widgets[2]));@@ -41,16 +41,19 @@ static void on_save_rule(GtkWidget *widget, gpointer data) {RuleProtocol proto = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets[4]));RuleAction action = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets[5]));- if (strlen(proc) == 0) return; // Error+ if (strlen(proc) == 0) return; // need process nameif (edit_rule) {+ // update backendProxyBridge_EditRule(edit_rule->id, proc, hosts, ports, proto, action);+ // update localfree(edit_rule->process_name); edit_rule->process_name = strdup(proc);free(edit_rule->target_hosts); edit_rule->target_hosts = strdup(hosts);free(edit_rule->target_ports); edit_rule->target_ports = strdup(ports);edit_rule->protocol = proto;edit_rule->action = action;} else {+ // new ruleuint32_t new_id = ProxyBridge_AddRule(proc, hosts, ports, proto, action);RuleData *new_rule = malloc(sizeof(RuleData));new_rule->id = new_id;@@ -99,7 +102,7 @@ static void open_rule_dialog(RuleData *rule) {gtk_grid_set_column_spacing(GTK_GRID(grid), 10);gtk_container_set_border_width(GTK_CONTAINER(grid), 15);- // Process+ // process inputGtkWidget *proc_entry = gtk_entry_new();GtkWidget *browse_btn = gtk_button_new_with_label("Browse...");g_signal_connect(browse_btn, "clicked", G_CALLBACK(on_browse_clicked), proc_entry);@@ -110,13 +113,13 @@ static void open_rule_dialog(RuleData *rule) {GtkWidget *host_entry = gtk_entry_new();GtkWidget *port_entry = gtk_entry_new();- // Protocol+ // protocol listGtkWidget *proto_combo = gtk_combo_box_text_new();gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(proto_combo), "TCP");gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(proto_combo), "UDP");gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(proto_combo), "BOTH");- // Action+ // action listGtkWidget *action_combo = gtk_combo_box_text_new();gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(action_combo), "PROXY");gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(action_combo), "DIRECT");@@ -131,8 +134,8 @@ static void open_rule_dialog(RuleData *rule) {} else {gtk_entry_set_text(GTK_ENTRY(port_entry), "*");gtk_entry_set_text(GTK_ENTRY(host_entry), "*");- gtk_combo_box_set_active(GTK_COMBO_BOX(proto_combo), 2); // BOTH- gtk_combo_box_set_active(GTK_COMBO_BOX(action_combo), 0); // PROXY+ gtk_combo_box_set_active(GTK_COMBO_BOX(proto_combo), 2); // BOTH default+ gtk_combo_box_set_active(GTK_COMBO_BOX(action_combo), 0); // PROXY default}int row = 0;diff --git a/Linux/gui/gui_settings.c b/Linux/gui/gui_settings.cindex 9a13d48..2cad586 100644--- a/Linux/gui/gui_settings.c+++ b/Linux/gui/gui_settings.c@@ -1,6 +1,6 @@#include "gui.h"-// --- Settings Dialog ---+// settings view logicstatic gboolean on_test_done(gpointer user_data) {TestResultData *data = (TestResultData *)user_data;@@ -18,7 +18,7 @@ static gpointer run_test_thread(gpointer user_data) {char *buffer = malloc(4096);memset(buffer, 0, 4096);- // Check callback if needed, but TestConnection usually returns result in buffer+ // run the testProxyBridge_TestConnection(req->host, req->port, buffer, 4096);TestResultData *res = malloc(sizeof(TestResultData));@@ -36,7 +36,7 @@ static gpointer run_test_thread(gpointer user_data) {static void on_start_test_clicked(GtkWidget *widget, gpointer data) {ConfigInfo *info = (ConfigInfo *)data;- // 1. Validate Proxy Config+ // validate inputsconst char *ip_text = gtk_entry_get_text(GTK_ENTRY(info->ip_entry));const char *port_text = gtk_entry_get_text(GTK_ENTRY(info->port_entry));@@ -45,7 +45,7 @@ static void on_start_test_clicked(GtkWidget *widget, gpointer data) {return;}- // 2. Set Proxy Config+ // save configProxyType type = (gtk_combo_box_get_active(GTK_COMBO_BOX(info->type_combo)) == 0) ? PROXY_TYPE_HTTP : PROXY_TYPE_SOCKS5;int port = (int)safe_strtol(port_text);const char *user = gtk_entry_get_text(GTK_ENTRY(info->user_entry));@@ -53,7 +53,7 @@ static void on_start_test_clicked(GtkWidget *widget, gpointer data) {ProxyBridge_SetProxyConfig(type, ip_text, port, user, pass);- // 3. Get Test Target+ // get targetconst char *t_host = gtk_entry_get_text(GTK_ENTRY(info->test_host));const char *t_port_s = gtk_entry_get_text(GTK_ENTRY(info->test_port));@@ -61,11 +61,11 @@ static void on_start_test_clicked(GtkWidget *widget, gpointer data) {int t_port = (int)safe_strtol(t_port_s);if (t_port <= 0) t_port = 80;- // 4. Update UI+ // update guigtk_text_buffer_set_text(info->output_buffer, "Testing connection... Please wait...", -1);gtk_widget_set_sensitive(info->test_btn, FALSE);- // 5. Run Thread+ // start threadstruct TestRunnerData *req = malloc(sizeof(struct TestRunnerData));req->host = strdup(t_host);req->port = t_port;@@ -87,7 +87,7 @@ void on_proxy_configure(GtkWidget *widget, gpointer data) {"Cancel", GTK_RESPONSE_CANCEL,"Save", GTK_RESPONSE_ACCEPT,NULL);- // Increase width for log+ // make it widergtk_window_set_default_size(GTK_WINDOW(info.dialog), 600, 500);content_area = gtk_dialog_get_content_area(GTK_DIALOG(info.dialog));@@ -97,22 +97,22 @@ void on_proxy_configure(GtkWidget *widget, gpointer data) {gtk_container_set_border_width(GTK_CONTAINER(grid), 10);gtk_box_pack_start(GTK_BOX(content_area), grid, TRUE, TRUE, 0);- // Type+ // type selectiongtk_grid_attach(GTK_GRID(grid), gtk_label_new("Type:"), 0, 0, 1, 1);info.type_combo = gtk_combo_box_text_new();gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(info.type_combo), "HTTP");gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(info.type_combo), "SOCKS5");gtk_combo_box_set_active(GTK_COMBO_BOX(info.type_combo), g_proxy_type == PROXY_TYPE_HTTP ? 0 : 1);- gtk_grid_attach(GTK_GRID(grid), info.type_combo, 1, 0, 3, 1); // Span 3+ gtk_grid_attach(GTK_GRID(grid), info.type_combo, 1, 0, 3, 1);- // IP+ // ip addressgtk_grid_attach(GTK_GRID(grid), gtk_label_new("Host:"), 0, 1, 1, 1);info.ip_entry = gtk_entry_new();gtk_entry_set_text(GTK_ENTRY(info.ip_entry), g_proxy_ip);gtk_widget_set_hexpand(info.ip_entry, TRUE);gtk_grid_attach(GTK_GRID(grid), info.ip_entry, 1, 1, 3, 1);- // Port+ // port numbergtk_grid_attach(GTK_GRID(grid), gtk_label_new("Port:"), 0, 2, 1, 1);info.port_entry = gtk_entry_new();if (g_proxy_port != 0) {@@ -122,20 +122,20 @@ void on_proxy_configure(GtkWidget *widget, gpointer data) {}gtk_grid_attach(GTK_GRID(grid), info.port_entry, 1, 2, 3, 1);- // User+ // usernamegtk_grid_attach(GTK_GRID(grid), gtk_label_new("Username:"), 0, 3, 1, 1);info.user_entry = gtk_entry_new();gtk_entry_set_text(GTK_ENTRY(info.user_entry), g_proxy_user);gtk_grid_attach(GTK_GRID(grid), info.user_entry, 1, 3, 3, 1);- // Pass+ // passwordgtk_grid_attach(GTK_GRID(grid), gtk_label_new("Password:"), 0, 4, 1, 1);info.pass_entry = gtk_entry_new();gtk_entry_set_visibility(GTK_ENTRY(info.pass_entry), FALSE);gtk_entry_set_text(GTK_ENTRY(info.pass_entry), g_proxy_pass);gtk_grid_attach(GTK_GRID(grid), info.pass_entry, 1, 4, 3, 1);- // --- Test Section ---+ // test connection sectiongtk_grid_attach(GTK_GRID(grid), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), 0, 5, 4, 1);GtkWidget *test_label = gtk_label_new("<b>Test Connection</b>");@@ -143,7 +143,7 @@ void on_proxy_configure(GtkWidget *widget, gpointer data) {gtk_widget_set_halign(test_label, GTK_ALIGN_START);gtk_grid_attach(GTK_GRID(grid), test_label, 0, 6, 4, 1);- // Target Host+ // target hostgtk_grid_attach(GTK_GRID(grid), gtk_label_new("Target:"), 0, 7, 1, 1);info.test_host = gtk_entry_new();gtk_entry_set_text(GTK_ENTRY(info.test_host), "google.com");diff --git a/Linux/gui/gui_utils.c b/Linux/gui/gui_utils.cindex a1f6931..59e0821 100644--- a/Linux/gui/gui_utils.c+++ b/Linux/gui/gui_utils.c@@ -1,15 +1,15 @@#include "gui.h"-// Helper for safe integer conversion+// safer way to turn string to intlong safe_strtol(const char *nptr) {- if (!nptr) return 0; // Handle NULL+ if (!nptr) return 0; // null checkchar *endptr;long val = strtol(nptr, &endptr, 10);- if (endptr == nptr) return 0; // No digits found+ if (endptr == nptr) return 0; // bad inputreturn val;}-// Helper for quick message dialogs+// show simple popupvoid show_message(GtkWindow *parent, GtkMessageType type, const char *format, ...) {va_list args;va_start(args, format);@@ -26,7 +26,7 @@ void show_message(GtkWindow *parent, GtkMessageType type, const char *format, ..g_free(msg);}-// Helper to limit buffer lines+// limit log size so it doesnt eat ramvoid trim_buffer_lines(GtkTextBuffer *buffer, int max_lines) {if (gtk_text_buffer_get_line_count(buffer) > max_lines) {GtkTextIter start, next;@@ -47,7 +47,7 @@ char* get_current_time_str() {return buffer;}-// --- JSON Helpers ---+// json stuffchar *escape_json_string(const char *src) {if (!src) return strdup("");GString *str = g_string_new("");@@ -60,7 +60,7 @@ char *escape_json_string(const char *src) {return g_string_free(str, FALSE);}-// Very basic JSON parser for valid input+// basic parser, good enough for valid inputschar *extract_sub_json_str(const char *json, const char *key) {char search_key[256];snprintf(search_key, sizeof(search_key), "\"%s\"", key);@@ -83,7 +83,7 @@ bool extract_sub_json_bool(const char *json, const char *key) {if (!k) return false;char *colon = strchr(k, ':');if (!colon) return false;- // Skip spaces+ // skip whitespacechar *v = colon + 1;while(*v == ' ' || *v == '\t') v++;if (strncmp(v, "true", 4) == 0) return true;diff --git a/Linux/gui/main.c b/Linux/gui/main.cindex aaa3294..da7efb9 100644--- a/Linux/gui/main.c+++ b/Linux/gui/main.c@@ -1,6 +1,6 @@#include "gui.h"-// --- Global UI Widgets ---+// ui widgetsGtkWidget *window;GtkTextView *conn_view;GtkTextBuffer *conn_buffer;@@ -9,7 +9,7 @@ GtkTextBuffer *log_buffer;GtkWidget *status_bar;guint status_context_id;-// --- Config Globals (Defaults) ---+// default configchar g_proxy_ip[256] = "";uint16_t g_proxy_port = 0;ProxyType g_proxy_type = PROXY_TYPE_SOCKS5;@@ -132,7 +132,7 @@ int main(int argc, char *argv[]) {GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);gtk_container_add(GTK_CONTAINER(window), vbox);- // Menu+ // menu setupGtkWidget *menubar = gtk_menu_bar_new();GtkWidget *proxy_menu_item = gtk_menu_item_new_with_label("Proxy");GtkWidget *proxy_menu = gtk_menu_new();@@ -176,11 +176,11 @@ int main(int argc, char *argv[]) {gtk_menu_shell_append(GTK_MENU_SHELL(menubar), about_menu_item);gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);- // Tabs+ // tabsGtkWidget *notebook = gtk_notebook_new();gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);- // Tab 1: Connections+ // active connections tabGtkWidget *conn_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);gtk_container_set_border_width(GTK_CONTAINER(conn_vbox), 5);GtkWidget *conn_toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);@@ -202,7 +202,7 @@ int main(int argc, char *argv[]) {gtk_box_pack_start(GTK_BOX(conn_vbox), scrolled_window, TRUE, TRUE, 0);gtk_notebook_append_page(GTK_NOTEBOOK(notebook), conn_vbox, gtk_label_new("Connections"));- // Tab 2: Logs+ // logs tabGtkWidget *log_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);gtk_container_set_border_width(GTK_CONTAINER(log_vbox), 5);GtkWidget *log_toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);@@ -224,12 +224,12 @@ int main(int argc, char *argv[]) {gtk_box_pack_start(GTK_BOX(log_vbox), log_scroll, TRUE, TRUE, 0);gtk_notebook_append_page(GTK_NOTEBOOK(notebook), log_vbox, gtk_label_new("Activity Logs"));- // Status Bar+ // status barstatus_bar = gtk_statusbar_new();status_context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(status_bar), "Status");gtk_box_pack_start(GTK_BOX(vbox), status_bar, FALSE, FALSE, 0);- // Initial Config+ // start it upProxyBridge_SetLogCallback(lib_log_callback);ProxyBridge_SetConnectionCallback(lib_connection_callback);ProxyBridge_SetTrafficLoggingEnabled(true);