remove --service arg and unnecessary argv copying

This commit is contained in:
ruti 2024-04-24 23:48:17 +03:00
parent 2c0ade1275
commit 15b9f50a5c
3 changed files with 16 additions and 38 deletions

View File

@ -10,9 +10,8 @@ pause
set svc_name="ByeDPI"
set svc_desc="Local SOCKS proxy server to bypass DPI (Deep Packet Inspection)."
:: Set up launch args (bypass methods) here. The "--service" arg is required;
:: without it, the program will not register itself as a Windows service!
set svc_bin="\"%cd%\ciadpi.exe\" --service --split 1+s --disorder 3+s --mod-http=h,d --auto --tlsrec 1+s"
:: Set up launch args (bypass methods) here.
set svc_bin="\"%cd%\ciadpi.exe\" --split 1+s --disorder 3+s --mod-http=h,d --auto --tlsrec 1+s"
sc stop %svc_name%
sc delete %svc_name%

27
main.c
View File

@ -140,9 +140,6 @@ const struct option options[] = {
#ifdef __linux__
{"md5sig", 0, 0, 'S'},
#endif
#ifdef _WIN32
{"service", 0, 0, 'B'},
#endif
{"fake-data", 1, 0, 'l'},
{"tls-sni", 1, 0, 'n'},
#endif
@ -437,8 +434,9 @@ int main(int argc, char **argv)
uniperror("WSAStartup");
return -1;
}
int as_winsvc = 0;
if (register_winsvc(argc, argv)) {
return 0;
}
#endif
struct sockaddr_ina s = {
.in = {
@ -465,7 +463,7 @@ int main(int argc, char **argv)
int rez;
int invalid = 0;
ssize_t val = 0;
long val = 0;
char *end = 0;
uint16_t port = htons(1080);
@ -481,12 +479,6 @@ int main(int argc, char **argv)
argc, argv, opt, options, 0)) != -1) {
switch (rez) {
#ifdef _WIN32
case 'B':
as_winsvc = 1;
break;
#endif
case 'N':
params.resolve = 0;
break;
@ -649,12 +641,13 @@ int main(int argc, char **argv)
break;
case 'H':;
char *data = ftob(optarg, &val);
ssize_t size;
char *data = ftob(optarg, &size);
if (!data) {
uniperror("read/parse");
invalid = 1;
}
dp->hosts = parse_hosts(data, val);
dp->hosts = parse_hosts(data, size);
if (!dp->hosts) {
perror("parse_hosts");
clear_params();
@ -815,12 +808,6 @@ int main(int argc, char **argv)
return -1;
}
}
#ifdef _WIN32
if (as_winsvc && register_winsvc(argc, argv))
return 0;
#endif
if (invalid) {
fprintf(stderr, "invalid value: -%c %s\n", rez, optarg);
clear_params();

View File

@ -6,6 +6,7 @@
static SERVICE_STATUS ServiceStatus;
static SERVICE_STATUS_HANDLE hStatus;
static int svc_argc = 0;
static char **svc_argv = NULL;
@ -60,20 +61,11 @@ int register_winsvc(int argc, char *argv[])
};
// Save args passed to the program to use instead of the service args.
if (!svc_argc && !svc_argv) {
svc_argc = argc;
svc_argv = calloc((size_t)(argc + 1), sizeof(void*));
for (int i = 0; i < argc; i++)
svc_argv[i] = strdup(argv[i]);
if (svc_argv) {
return 0;
}
int result = StartServiceCtrlDispatcher(ServiceTable);
if (svc_argc && svc_argv) {
for (int i = 0; i < svc_argc; i++)
free(svc_argv[i]);
free(svc_argv);
}
return result;
svc_argc = argc;
svc_argv = argv;
return StartServiceCtrlDispatcher(ServiceTable);
}