mirror of
https://github.com/Waujito/youtubeUnblock.git
synced 2026-01-27 12:40:36 +03:00
25
src/args.c
25
src/args.c
@@ -62,14 +62,18 @@ static int read_file(const char* filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = fseek(fd, 0, SEEK_END);
|
ret = fseek(fd, 0, SEEK_END);
|
||||||
if (ret < 0) {
|
if (ret != 0) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
goto close_file;
|
goto close_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t fsize = ftell(fd);
|
long fsize = ftell(fd);
|
||||||
fseek(fd, 0, SEEK_SET);
|
if (fsize == -1L) {
|
||||||
if (ret < 0) {
|
ret = -errno;
|
||||||
|
goto close_file;
|
||||||
|
}
|
||||||
|
ret = fseek(fd, 0, SEEK_SET);
|
||||||
|
if (ret != 0) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
goto close_file;
|
goto close_file;
|
||||||
}
|
}
|
||||||
@@ -120,10 +124,10 @@ static int parse_sni_domains(struct domains_list **dlist, const char *domains_st
|
|||||||
unsigned int domain_len = (i - j);
|
unsigned int domain_len = (i - j);
|
||||||
const char *domain_startp = domains_str + j;
|
const char *domain_startp = domains_str + j;
|
||||||
struct domains_list *edomain = malloc(sizeof(struct domains_list));
|
struct domains_list *edomain = malloc(sizeof(struct domains_list));
|
||||||
*edomain = (struct domains_list){0};
|
|
||||||
if (edomain == NULL) {
|
if (edomain == NULL) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
*edomain = (struct domains_list){0};
|
||||||
|
|
||||||
edomain->domain_len = domain_len;
|
edomain->domain_len = domain_len;
|
||||||
edomain->domain_name = malloc(domain_len + 1);
|
edomain->domain_name = malloc(domain_len + 1);
|
||||||
@@ -285,6 +289,9 @@ static int parse_fake_custom_payload(
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
unsigned char *custom_buf = malloc(custom_len);
|
unsigned char *custom_buf = malloc(custom_len);
|
||||||
|
if (custom_buf == NULL) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < custom_len; i++) {
|
for (int i = 0; i < custom_len; i++) {
|
||||||
ret = sscanf(custom_hex_fake + (i << 1), "%2hhx", custom_buf + i);
|
ret = sscanf(custom_hex_fake + (i << 1), "%2hhx", custom_buf + i);
|
||||||
@@ -1242,11 +1249,11 @@ int init_section_config(struct section_config_t **section, struct section_config
|
|||||||
#else
|
#else
|
||||||
def_section = malloc(sizeof(struct section_config_t));
|
def_section = malloc(sizeof(struct section_config_t));
|
||||||
#endif
|
#endif
|
||||||
*def_section = (struct section_config_t)default_section_config;
|
if (def_section == NULL)
|
||||||
def_section->prev = prev;
|
|
||||||
|
|
||||||
if (def_section == NULL)
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
*def_section = (struct section_config_t)default_section_config;
|
||||||
|
|
||||||
|
def_section->prev = prev;
|
||||||
|
|
||||||
ret = parse_sni_domains(&def_section->sni_domains, default_snistr, sizeof(default_snistr));
|
ret = parse_sni_domains(&def_section->sni_domains, default_snistr, sizeof(default_snistr));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|||||||
22
src/mangle.c
22
src/mangle.c
@@ -502,18 +502,11 @@ drop:
|
|||||||
|
|
||||||
int send_ip4_frags(const struct section_config_t *section, const uint8_t *packet, size_t pktlen, const size_t *poses, size_t poses_sz, size_t dvs) {
|
int send_ip4_frags(const struct section_config_t *section, const uint8_t *packet, size_t pktlen, const size_t *poses, size_t poses_sz, size_t dvs) {
|
||||||
if (poses_sz == 0) {
|
if (poses_sz == 0) {
|
||||||
|
lgtrace_addp("raw send packet of %zu bytes with %zu dvs", pktlen, dvs);
|
||||||
if (section->seg2_delay && ((dvs > 0) ^ section->frag_sni_reverse)) {
|
if (section->seg2_delay && ((dvs > 0) ^ section->frag_sni_reverse)) {
|
||||||
if (!instance_config.send_delayed_packet) {
|
return instance_config.send_delayed_packet(
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
lgtrace_addp("Sent %zu delayed for %d", pktlen, section->seg2_delay);
|
|
||||||
instance_config.send_delayed_packet(
|
|
||||||
packet, pktlen, section->seg2_delay);
|
packet, pktlen, section->seg2_delay);
|
||||||
|
|
||||||
return 0;
|
|
||||||
} else {
|
} else {
|
||||||
lgtrace_addp("Sent %zu bytes", pktlen);
|
|
||||||
return instance_config.send_raw_packet(
|
return instance_config.send_raw_packet(
|
||||||
packet, pktlen);
|
packet, pktlen);
|
||||||
}
|
}
|
||||||
@@ -588,18 +581,11 @@ out:
|
|||||||
|
|
||||||
int send_tcp_frags(const struct section_config_t *section, const uint8_t *packet, size_t pktlen, const size_t *poses, size_t poses_sz, size_t dvs) {
|
int send_tcp_frags(const struct section_config_t *section, const uint8_t *packet, size_t pktlen, const size_t *poses, size_t poses_sz, size_t dvs) {
|
||||||
if (poses_sz == 0) {
|
if (poses_sz == 0) {
|
||||||
|
lgtrace_addp("raw send packet of %zu bytes with %zu dvs", pktlen, dvs);
|
||||||
if (section->seg2_delay && ((dvs > 0) ^ section->frag_sni_reverse)) {
|
if (section->seg2_delay && ((dvs > 0) ^ section->frag_sni_reverse)) {
|
||||||
if (!instance_config.send_delayed_packet) {
|
return instance_config.send_delayed_packet(
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
instance_config.send_delayed_packet(
|
|
||||||
packet, pktlen, section->seg2_delay);
|
packet, pktlen, section->seg2_delay);
|
||||||
|
|
||||||
return 0;
|
|
||||||
} else {
|
} else {
|
||||||
lgtrace_addp("raw send packet of %zu bytes with %zu dvs", pktlen, dvs);
|
|
||||||
|
|
||||||
return instance_config.send_raw_packet(
|
return instance_config.send_raw_packet(
|
||||||
packet, pktlen);
|
packet, pktlen);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ int quic_check_is_initial(const struct quic_lhdr *qch) {
|
|||||||
uint32_t qversion;
|
uint32_t qversion;
|
||||||
int ret;
|
int ret;
|
||||||
ret = quic_get_version(&qversion, qch);
|
ret = quic_get_version(&qversion, qch);
|
||||||
if (qversion < 0) return 0;
|
if (ret < 0) return 0;
|
||||||
|
|
||||||
uint8_t qtype = qch->type;
|
uint8_t qtype = qch->type;
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ int quic_parse_initial_message(
|
|||||||
ret = quic_parse_data(quic_payload, quic_plen,
|
ret = quic_parse_data(quic_payload, quic_plen,
|
||||||
&qch, &qch_len, &qci, &inpayload, &inplen
|
&qch, &qch_len, &qci, &inpayload, &inplen
|
||||||
);
|
);
|
||||||
|
if (ret < 0) {
|
||||||
|
lgerror(ret, "quic_parse_data");
|
||||||
|
goto error_nfr;
|
||||||
|
}
|
||||||
|
|
||||||
ret = quic_get_version(&qversion, qch);
|
ret = quic_get_version(&qversion, qch);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -117,10 +121,6 @@ int quic_parse_initial_message(
|
|||||||
}
|
}
|
||||||
|
|
||||||
quic_header_len = inpayload - quic_payload;
|
quic_header_len = inpayload - quic_payload;
|
||||||
if (ret < 0) {
|
|
||||||
lgerror(ret, "quic_parse_data");
|
|
||||||
goto error_nfr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = quic_parse_initial_header(inpayload, inplen, &qich);
|
ret = quic_parse_initial_header(inpayload, inplen, &qich);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|||||||
@@ -614,14 +614,33 @@ void *delay_packet_send_fn(void *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int delay_packet_send(const unsigned char *data, size_t data_len, unsigned int delay_ms) {
|
int delay_packet_send(const unsigned char *data, size_t data_len, unsigned int delay_ms) {
|
||||||
|
int ret;
|
||||||
|
|
||||||
struct dps_t *dpdt = malloc(sizeof(struct dps_t));
|
struct dps_t *dpdt = malloc(sizeof(struct dps_t));
|
||||||
|
if (dpdt == NULL) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
*dpdt = (struct dps_t){0};
|
||||||
|
|
||||||
dpdt->pkt = malloc(data_len);
|
dpdt->pkt = malloc(data_len);
|
||||||
|
if (dpdt->pkt == NULL) {
|
||||||
|
free(dpdt);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
memcpy(dpdt->pkt, data, data_len);
|
memcpy(dpdt->pkt, data, data_len);
|
||||||
|
|
||||||
dpdt->pktlen = data_len;
|
dpdt->pktlen = data_len;
|
||||||
dpdt->timer = delay_ms;
|
dpdt->timer = delay_ms;
|
||||||
pthread_t thr;
|
pthread_t thr = {0};
|
||||||
pthread_create(&thr, NULL, delay_packet_send_fn, dpdt);
|
ret = pthread_create(&thr, NULL, delay_packet_send_fn, dpdt);
|
||||||
pthread_detach(thr);
|
if (ret != 0) {
|
||||||
|
free(dpdt->pkt);
|
||||||
|
free(dpdt);
|
||||||
|
return -ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = pthread_detach(thr);
|
||||||
|
|
||||||
lgtrace_addp("Scheduled packet send after %d ms", delay_ms);
|
lgtrace_addp("Scheduled packet send after %d ms", delay_ms);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user