Skip to content

Commit 18a06fe

Browse files
committed
strip
1 parent 3406f9f commit 18a06fe

3 files changed

Lines changed: 75 additions & 75 deletions

File tree

Linux/cli/main.c

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void connection_callback(const char* process_name, uint32_t pid, const ch
3333
{
3434
if (verbose_level == 2 || verbose_level == 3)
3535
{
36-
printf("[CONN] %s (PID:%u) -> %s:%u via %s\n",
36+
printf("[CONN] %s (PID:%u) -> %s:%u via %s\n",
3737
process_name, pid, dest_ip, dest_port, proxy_info);
3838
}
3939
}
@@ -43,14 +43,14 @@ static void signal_handler(int sig)
4343
if (sig == SIGSEGV || sig == SIGABRT || sig == SIGBUS)
4444
{
4545
printf("\n\n=== CLI CRASH DETECTED ===\n");
46-
printf("Signal: %d (%s)\n", sig,
47-
sig == SIGSEGV ? "SEGFAULT" :
46+
printf("Signal: %d (%s)\n", sig,
47+
sig == SIGSEGV ? "SEGFAULT" :
4848
sig == SIGABRT ? "ABORT" : "BUS ERROR");
4949
printf("Calling emergency cleanup...\n");
5050
ProxyBridge_Stop();
5151
_exit(1);
5252
}
53-
53+
5454
if (keep_running)
5555
{
5656
printf("\n\nStopping ProxyBridge...\n");
@@ -80,14 +80,14 @@ static void show_help(const char* prog)
8080
show_banner();
8181
printf("USAGE:\n");
8282
printf(" %s [OPTIONS]\n\n", prog);
83-
83+
8484
printf("OPTIONS:\n");
8585
printf(" --proxy <url> Proxy server URL with optional authentication\n");
8686
printf(" Format: type://ip:port or type://ip:port:username:password\n");
8787
printf(" Examples: socks5://127.0.0.1:1080\n");
8888
printf(" http://proxy.com:8080:myuser:mypass\n");
8989
printf(" Default: socks5://127.0.0.1:4444\n\n");
90-
90+
9191
printf(" --rule <rule> Traffic routing rule (can be specified multiple times)\n");
9292
printf(" Format: process:hosts:ports:protocol:action\n");
9393
printf(" process - Process name(s): curl, cur*, *, or multiple separated by ;\n");
@@ -100,37 +100,37 @@ static void show_help(const char* prog)
100100
printf(" curl;wget:*:*:TCP:PROXY\n");
101101
printf(" *:*:53:UDP:PROXY\n");
102102
printf(" firefox:*:80;443:TCP:DIRECT\n\n");
103-
103+
104104
printf(" --dns-via-proxy <bool> Route DNS queries through proxy\n");
105105
printf(" Values: true, false, 1, 0\n");
106106
printf(" Default: true\n\n");
107-
107+
108108
printf(" --verbose <level> Logging verbosity level\n");
109109
printf(" 0 - No logs (default)\n");
110110
printf(" 1 - Show log messages only\n");
111111
printf(" 2 - Show connection events only\n");
112112
printf(" 3 - Show both logs and connections\n\n");
113-
113+
114114
printf(" --cleanup Cleanup resources (iptables, etc.) from crashed instance\n");
115115
printf(" Use if ProxyBridge crashed without proper cleanup\n\n");
116-
116+
117117
printf(" --help, -h Show this help message\n\n");
118-
118+
119119
printf("EXAMPLES:\n");
120120
printf(" # Basic usage with default proxy\n");
121121
printf(" sudo %s --rule curl:*:*:TCP:PROXY\n\n", prog);
122-
122+
123123
printf(" # Multiple rules with custom proxy\n");
124124
printf(" sudo %s --proxy socks5://192.168.1.10:1080 \\\n", prog);
125125
printf(" --rule curl:*:*:TCP:PROXY \\\n");
126126
printf(" --rule wget:*:*:TCP:PROXY \\\n");
127127
printf(" --verbose 2\n\n");
128-
128+
129129
printf(" # Route DNS through proxy with multiple apps\n");
130130
printf(" sudo %s --proxy socks5://127.0.0.1:1080 \\\n", prog);
131131
printf(" --rule \"curl;wget;firefox:*:*:BOTH:PROXY\" \\\n");
132132
printf(" --dns-via-proxy true --verbose 3\n\n");
133-
133+
134134
printf("NOTE:\n");
135135
printf(" ProxyBridge requires root privileges to use nfqueue.\n");
136136
printf(" Run with 'sudo' or as root user.\n\n");
@@ -142,7 +142,7 @@ static RuleProtocol parse_protocol(const char* str)
142142
for (size_t i = 0; str[i] && i < 15; i++)
143143
upper[i] = toupper(str[i]);
144144
upper[strlen(str) < 15 ? strlen(str) : 15] = '\0';
145-
145+
146146
if (strcmp(upper, "TCP") == 0)
147147
return RULE_PROTOCOL_TCP;
148148
else if (strcmp(upper, "UDP") == 0)
@@ -162,7 +162,7 @@ static RuleAction parse_action(const char* str)
162162
for (size_t i = 0; str[i] && i < 15; i++)
163163
upper[i] = toupper(str[i]);
164164
upper[strlen(str) < 15 ? strlen(str) : 15] = '\0';
165-
165+
166166
if (strcmp(upper, "PROXY") == 0)
167167
return RULE_ACTION_PROXY;
168168
else if (strcmp(upper, "DIRECT") == 0)
@@ -190,31 +190,31 @@ static bool parse_rule(const char* rule_str, ProxyRule* rule)
190190
char buffer[MAX_RULE_STR];
191191
strncpy(buffer, rule_str, sizeof(buffer) - 1);
192192
buffer[sizeof(buffer) - 1] = '\0';
193-
193+
194194
char* parts[5] = {NULL, NULL, NULL, NULL, NULL};
195195
int part_idx = 0;
196196
char* token = strtok(buffer, ":");
197-
197+
198198
while (token != NULL && part_idx < 5)
199199
{
200200
parts[part_idx++] = token;
201201
token = strtok(NULL, ":");
202202
}
203-
203+
204204
if (part_idx != 5)
205205
{
206206
fprintf(stderr, "ERROR: Invalid rule format '%s'\n", rule_str);
207207
fprintf(stderr, "Expected format: process:hosts:ports:protocol:action\n");
208208
return false;
209209
}
210-
210+
211211
default_if_empty(rule->process_name, parts[0], "*", sizeof(rule->process_name));
212212
default_if_empty(rule->target_hosts, parts[1], "*", sizeof(rule->target_hosts));
213213
default_if_empty(rule->target_ports, parts[2], "*", sizeof(rule->target_ports));
214-
214+
215215
rule->protocol = parse_protocol(parts[3]);
216216
rule->action = parse_action(parts[4]);
217-
217+
218218
return true;
219219
}
220220

@@ -223,27 +223,27 @@ static bool parse_proxy_url(const char* url, ProxyType* type, char* host, uint16
223223
char buffer[512];
224224
strncpy(buffer, url, sizeof(buffer) - 1);
225225
buffer[sizeof(buffer) - 1] = '\0';
226-
226+
227227
username[0] = '\0';
228228
password[0] = '\0';
229-
229+
230230
// parse type://
231231
char* scheme_end = strstr(buffer, "://");
232232
if (scheme_end == NULL)
233233
{
234234
fprintf(stderr, "ERROR: Invalid proxy URL format. Expected type://host:port\n");
235235
return false;
236236
}
237-
237+
238238
*scheme_end = '\0';
239239
char* scheme = buffer;
240240
char* rest = scheme_end + 3;
241-
241+
242242
char upper_scheme[16];
243243
for (size_t i = 0; scheme[i] && i < 15; i++)
244244
upper_scheme[i] = toupper(scheme[i]);
245245
upper_scheme[strlen(scheme) < 15 ? strlen(scheme) : 15] = '\0';
246-
246+
247247
if (strcmp(upper_scheme, "SOCKS5") == 0)
248248
*type = PROXY_TYPE_SOCKS5;
249249
else if (strcmp(upper_scheme, "HTTP") == 0)
@@ -253,7 +253,7 @@ static bool parse_proxy_url(const char* url, ProxyType* type, char* host, uint16
253253
fprintf(stderr, "ERROR: Invalid proxy type '%s'. Use 'socks5' or 'http'\n", scheme);
254254
return false;
255255
}
256-
256+
257257
// parse host:port[:user:pass]
258258
char* parts[4];
259259
int num_parts = 0;
@@ -263,31 +263,31 @@ static bool parse_proxy_url(const char* url, ProxyType* type, char* host, uint16
263263
parts[num_parts++] = token;
264264
token = strtok(NULL, ":");
265265
}
266-
266+
267267
if (num_parts < 2)
268268
{
269269
fprintf(stderr, "ERROR: Invalid proxy URL. Missing host or port\n");
270270
return false;
271271
}
272-
272+
273273
strncpy(host, parts[0], 255);
274274
host[255] = '\0';
275-
275+
276276
*port = atoi(parts[1]);
277277
if (*port == 0)
278278
{
279279
fprintf(stderr, "ERROR: Invalid proxy port '%s'\n", parts[1]);
280280
return false;
281281
}
282-
282+
283283
if (num_parts >= 4)
284284
{
285285
strncpy(username, parts[2], 255);
286286
username[255] = '\0';
287287
strncpy(password, parts[3], 255);
288288
password[255] = '\0';
289289
}
290-
290+
291291
return true;
292292
}
293293

@@ -309,12 +309,12 @@ int main(int argc, char *argv[])
309309
return 0;
310310
}
311311
}
312-
312+
313313
char proxy_url[512] = "socks5://127.0.0.1:4444";
314314
ProxyRule rules[MAX_RULES];
315315
int num_rules = 0;
316316
bool dns_via_proxy = true;
317-
317+
318318
// parse args
319319
for (int i = 1; i < argc; i++)
320320
{
@@ -368,64 +368,64 @@ int main(int argc, char *argv[])
368368
return 1;
369369
}
370370
}
371-
371+
372372
show_banner();
373-
373+
374374
// need root
375375
if (!is_root())
376376
{
377377
printf("\033[31m\nERROR: ProxyBridge requires root privileges!\033[0m\n");
378378
printf("Please run this application with sudo or as root.\n\n");
379379
return 1;
380380
}
381-
381+
382382
// parse proxy config
383383
ProxyType proxy_type;
384384
char proxy_host[256];
385385
uint16_t proxy_port;
386386
char proxy_username[256];
387387
char proxy_password[256];
388-
388+
389389
if (!parse_proxy_url(proxy_url, &proxy_type, proxy_host, &proxy_port, proxy_username, proxy_password))
390390
return 1;
391-
391+
392392
// setup callbacks based on verbose
393393
// 0=nothing 1=logs 2=connections 3=both
394-
394+
395395
if (verbose_level == 1 || verbose_level == 3)
396396
ProxyBridge_SetLogCallback(log_callback);
397397
else
398398
ProxyBridge_SetLogCallback(NULL); // Explicitly disable
399-
399+
400400
if (verbose_level == 2 || verbose_level == 3)
401401
ProxyBridge_SetConnectionCallback(connection_callback);
402402
else
403403
ProxyBridge_SetConnectionCallback(NULL); // Explicitly disable
404-
404+
405405
// turn on traffic logging when needed
406406
ProxyBridge_SetTrafficLoggingEnabled(verbose_level > 0);
407-
407+
408408
// show config
409-
printf("Proxy: %s://%s:%u\n",
409+
printf("Proxy: %s://%s:%u\n",
410410
proxy_type == PROXY_TYPE_HTTP ? "http" : "socks5",
411411
proxy_host, proxy_port);
412-
412+
413413
if (proxy_username[0] != '\0')
414414
printf("Proxy Auth: %s:***\n", proxy_username);
415-
415+
416416
printf("DNS via Proxy: %s\n", dns_via_proxy ? "Enabled" : "Disabled");
417-
417+
418418
// setup proxy
419-
if (!ProxyBridge_SetProxyConfig(proxy_type, proxy_host, proxy_port,
419+
if (!ProxyBridge_SetProxyConfig(proxy_type, proxy_host, proxy_port,
420420
proxy_username[0] ? proxy_username : "",
421421
proxy_password[0] ? proxy_password : ""))
422422
{
423423
fprintf(stderr, "ERROR: Failed to set proxy configuration\n");
424424
return 1;
425425
}
426-
426+
427427
ProxyBridge_SetDnsViaProxy(dns_via_proxy);
428-
428+
429429
// add rules
430430
if (num_rules > 0)
431431
{
@@ -436,17 +436,17 @@ int main(int argc, char *argv[])
436436
rules[i].protocol == RULE_PROTOCOL_UDP ? "UDP" : "BOTH";
437437
const char* action_str = rules[i].action == RULE_ACTION_PROXY ? "PROXY" :
438438
rules[i].action == RULE_ACTION_DIRECT ? "DIRECT" : "BLOCK";
439-
439+
440440
uint32_t rule_id = ProxyBridge_AddRule(
441441
rules[i].process_name,
442442
rules[i].target_hosts,
443443
rules[i].target_ports,
444444
rules[i].protocol,
445445
rules[i].action);
446-
446+
447447
if (rule_id > 0)
448448
{
449-
printf(" [%u] %s:%s:%s:%s -> %s\n",
449+
printf(" [%u] %s:%s:%s:%s -> %s\n",
450450
rule_id,
451451
rules[i].process_name,
452452
rules[i].target_hosts,
@@ -465,32 +465,32 @@ int main(int argc, char *argv[])
465465
printf("\033[33mWARNING: No rules specified. No traffic will be proxied.\033[0m\n");
466466
printf("Use --rule to add proxy rules. See --help for examples.\n");
467467
}
468-
468+
469469
// start proxybridge
470470
if (!ProxyBridge_Start())
471471
{
472472
fprintf(stderr, "ERROR: Failed to start ProxyBridge\n");
473473
return 1;
474474
}
475-
475+
476476
keep_running = true;
477477
printf("\nProxyBridge started. Press Ctrl+C to stop...\n\n");
478-
478+
479479
signal(SIGINT, signal_handler);
480480
signal(SIGTERM, signal_handler);
481481
signal(SIGSEGV, signal_handler); // Catch segfault
482482
signal(SIGABRT, signal_handler); // Catch abort
483483
signal(SIGBUS, signal_handler); // Catch bus error
484-
484+
485485
// main loop
486486
while (keep_running)
487487
{
488488
sleep(1);
489489
}
490-
490+
491491
// cleanup
492492
ProxyBridge_Stop();
493493
printf("ProxyBridge stopped.\n");
494-
494+
495495
return 0;
496496
}

0 commit comments

Comments
 (0)