Update goodbyedpi.c
This commit is contained in:
parent
ccd89695b5
commit
1c1244efd2
|
|
@ -183,13 +183,15 @@ 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 = strlen(filter_string) + (proto == IPPROTO_UDP ? udp_length : tcp_length) + 16;
|
size_t new_filter_size = filter_string_length + (proto == IPPROTO_UDP ? udp_length : tcp_length) + 16;
|
||||||
char new_filter[new_filter_size];
|
char *new_filter = malloc(new_filter_size);
|
||||||
|
|
||||||
snprintf(new_filter, new_filter_size, proto == IPPROTO_UDP ? udp : tcp, port, port);
|
sprintf(new_filter, proto == IPPROTO_UDP ? udp : tcp, port, port);
|
||||||
|
|
||||||
strcpy(filter_string, new_filter);
|
free(filter_string);
|
||||||
|
filter_string = new_filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -222,12 +224,8 @@ static void add_maxpayloadsize_str(unsigned short maxpayload) {
|
||||||
|
|
||||||
|
|
||||||
static void finalize_filter_strings() {
|
static void finalize_filter_strings() {
|
||||||
char *newstr, *newstr2;
|
char *newstr = repl_str(filter_string, IPID_TEMPLATE, "");
|
||||||
|
|
||||||
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, "");
|
||||||
|
|
@ -236,7 +234,7 @@ static void finalize_filter_strings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* dumb_memmem(const char* haystack, unsigned int hlen,
|
static char* dumb_memmem(const char* haystack, unsigned int hlen,
|
||||||
const char* needle, unsigned int nlen)
|
const char* needle, unsigned int nlen)
|
||||||
{
|
{
|
||||||
if (nlen > hlen) return NULL;
|
if (nlen > hlen) return NULL;
|
||||||
if (nlen == 0) return (char*)haystack;
|
if (nlen == 0) return (char*)haystack;
|
||||||
|
|
@ -245,10 +243,17 @@ 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;
|
||||||
|
|
||||||
for (size_t i = nlen - 1; i < hlen; i += skip[(unsigned char)haystack[i]]) {
|
size_t i = nlen - 1;
|
||||||
if (memcmp(haystack + i - nlen + 1, needle, nlen) == 0) {
|
while (i < hlen) {
|
||||||
return (char*)(haystack + i - nlen + 1);
|
size_t j = 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;
|
||||||
|
|
@ -390,27 +395,15 @@ 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;
|
||||||
|
|
||||||
const unsigned char *end = d + pktlen - 8;
|
while (ptr + 8 < pktlen) {
|
||||||
|
if (d[ptr] == '\0' && d[ptr+1] == '\0' && d[ptr+2] == '\0' &&
|
||||||
while (d + ptr < end) {
|
d[ptr+4] == '\0' && d[ptr+6] == '\0' && d[ptr+7] == '\0' &&
|
||||||
const unsigned char *current = d + ptr;
|
d[ptr+3] - d[ptr+5] == 2 && d[ptr+5] - d[ptr+8] == 3)
|
||||||
|
|
||||||
if (current[2] == '\0' &&
|
|
||||||
current[7] == '\0' &&
|
|
||||||
current[3] - current[5] == 2 &&
|
|
||||||
current[5] - current[8] == 3)
|
|
||||||
{
|
{
|
||||||
const unsigned char *nameStart = current + 9;
|
hnaddr = &d[ptr+9];
|
||||||
int nameLength = current[8];
|
hnlen = d[ptr+8];
|
||||||
|
|
||||||
if (current + 8 + nameLength > d + pktlen) {
|
if (ptr + 8 + hnlen > pktlen || hnlen < 3 || hnlen > HOST_MAXLEN) {
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
hnaddr = nameStart;
|
|
||||||
hnlen = nameLength;
|
|
||||||
|
|
||||||
if (hnlen < 3 || hnlen > HOST_MAXLEN) {
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -427,13 +420,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