Update goodbyedpi.c
This commit is contained in:
parent
93b655b2f6
commit
ccd89695b5
|
@ -183,15 +183,13 @@ static void add_filter_str(int proto, int port) {
|
||||||
|
|
||||||
const size_t udp_length = strlen(udp);
|
const size_t udp_length = strlen(udp);
|
||||||
const size_t tcp_length = strlen(tcp);
|
const size_t tcp_length = strlen(tcp);
|
||||||
const size_t filter_string_length = strlen(filter_string);
|
|
||||||
|
|
||||||
size_t new_filter_size = filter_string_length + (proto == IPPROTO_UDP ? udp_length : tcp_length) + 16;
|
size_t new_filter_size = strlen(filter_string) + (proto == IPPROTO_UDP ? udp_length : tcp_length) + 16;
|
||||||
char *new_filter = malloc(new_filter_size);
|
char new_filter[new_filter_size];
|
||||||
|
|
||||||
sprintf(new_filter, proto == IPPROTO_UDP ? udp : tcp, port, port);
|
snprintf(new_filter, new_filter_size, proto == IPPROTO_UDP ? udp : tcp, port, port);
|
||||||
|
|
||||||
free(filter_string);
|
strcpy(filter_string, new_filter);
|
||||||
filter_string = new_filter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,8 +222,12 @@ static void add_maxpayloadsize_str(unsigned short maxpayload) {
|
||||||
|
|
||||||
|
|
||||||
static void finalize_filter_strings() {
|
static void finalize_filter_strings() {
|
||||||
char *newstr = repl_str(filter_string, IPID_TEMPLATE, "");
|
char *newstr, *newstr2;
|
||||||
|
|
||||||
|
newstr2 = repl_str(filter_string, IPID_TEMPLATE, "");
|
||||||
|
newstr = repl_str(newstr2, MAXPAYLOADSIZE_TEMPLATE, "");
|
||||||
free(filter_string);
|
free(filter_string);
|
||||||
|
free(newstr2);
|
||||||
filter_string = newstr;
|
filter_string = newstr;
|
||||||
|
|
||||||
newstr = repl_str(filter_passive_string, IPID_TEMPLATE, "");
|
newstr = repl_str(filter_passive_string, IPID_TEMPLATE, "");
|
||||||
|
@ -243,17 +245,10 @@ static char* dumb_memmem(const char* haystack, unsigned int hlen,
|
||||||
for (size_t i = 0; i < 256; ++i) skip[i] = nlen;
|
for (size_t i = 0; i < 256; ++i) skip[i] = nlen;
|
||||||
for (size_t i = 0; i < nlen - 1; ++i) skip[(unsigned char)needle[i]] = nlen - i - 1;
|
for (size_t i = 0; i < nlen - 1; ++i) skip[(unsigned char)needle[i]] = nlen - i - 1;
|
||||||
|
|
||||||
size_t i = nlen - 1;
|
for (size_t i = nlen - 1; i < hlen; i += skip[(unsigned char)haystack[i]]) {
|
||||||
while (i < hlen) {
|
if (memcmp(haystack + i - nlen + 1, needle, nlen) == 0) {
|
||||||
size_t j = nlen - 1;
|
return (char*)(haystack + i - nlen + 1);
|
||||||
while (j >= 0 && haystack[i] == needle[j]) {
|
|
||||||
--i;
|
|
||||||
--j;
|
|
||||||
}
|
}
|
||||||
if (j == (size_t)-1) {
|
|
||||||
return (char*)(haystack + i + 1);
|
|
||||||
}
|
|
||||||
i += skip[(unsigned char)haystack[i]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -395,15 +390,27 @@ static int extract_sni(const char *pktdata, unsigned int pktlen,
|
||||||
const unsigned char *hnaddr = NULL;
|
const unsigned char *hnaddr = NULL;
|
||||||
int hnlen = 0;
|
int hnlen = 0;
|
||||||
|
|
||||||
while (ptr + 8 < pktlen) {
|
const unsigned char *end = d + pktlen - 8;
|
||||||
if (d[ptr] == '\0' && d[ptr+1] == '\0' && d[ptr+2] == '\0' &&
|
|
||||||
d[ptr+4] == '\0' && d[ptr+6] == '\0' && d[ptr+7] == '\0' &&
|
|
||||||
d[ptr+3] - d[ptr+5] == 2 && d[ptr+5] - d[ptr+8] == 3)
|
|
||||||
{
|
|
||||||
hnaddr = &d[ptr+9];
|
|
||||||
hnlen = d[ptr+8];
|
|
||||||
|
|
||||||
if (ptr + 8 + hnlen > pktlen || hnlen < 3 || hnlen > HOST_MAXLEN) {
|
while (d + ptr < end) {
|
||||||
|
const unsigned char *current = d + ptr;
|
||||||
|
|
||||||
|
if (current[2] == '\0' &&
|
||||||
|
current[7] == '\0' &&
|
||||||
|
current[3] - current[5] == 2 &&
|
||||||
|
current[5] - current[8] == 3)
|
||||||
|
{
|
||||||
|
const unsigned char *nameStart = current + 9;
|
||||||
|
int nameLength = current[8];
|
||||||
|
|
||||||
|
if (current + 8 + nameLength > d + pktlen) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
hnaddr = nameStart;
|
||||||
|
hnlen = nameLength;
|
||||||
|
|
||||||
|
if (hnlen < 3 || hnlen > HOST_MAXLEN) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,13 +427,13 @@ static int extract_sni(const char *pktdata, unsigned int pktlen,
|
||||||
*hostnamelen = (unsigned int)hnlen;
|
*hostnamelen = (unsigned int)hnlen;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void change_window_size(const PWINDIVERT_TCPHDR ppTcpHdr, unsigned int size) {
|
static inline void change_window_size(const PWINDIVERT_TCPHDR ppTcpHdr, unsigned int size) {
|
||||||
if (size >= 1 && size <= 0xFFFFu) {
|
if (size >= 1 && size <= 0xFFFFu) {
|
||||||
ppTcpHdr->Window = htons((u_short)size);
|
ppTcpHdr->Window = htons((u_short)size);
|
||||||
|
|
Loading…
Reference in New Issue