Template
1
0
mirror of https://github.com/bol-van/zapret2.git synced 2026-03-14 06:13:09 +00:00

23 Commits

Author SHA1 Message Date
bol-van
d41151ef6f nfqws2: join fragments in quic CRYPTO reconstruction. allow intersections 2026-03-05 18:38:44 +03:00
bol-van
60ac3693fc nfqws2: optimize quic CRYPTO defrag 2026-03-05 09:41:41 +03:00
bol-van
766b60544f nfqws2: remove unused var 2026-03-04 22:50:31 +03:00
bol-van
e563f60153 AI fixes 2026-03-04 22:36:31 +03:00
bol-van
6d7f8efc49 nfqws2: optimize quic CRYPTO defrag 2026-03-04 19:33:49 +03:00
bol-van
e46cde8e6e nfqws2: optimize 2026-03-04 18:58:39 +03:00
bol-van
52072359f0 nfqws2: remove unneeded function 2026-03-04 18:54:38 +03:00
bol-van
cafacf35bc nfqws2: quic CRYPTO frag early dedup 2026-03-04 18:52:47 +03:00
bol-van
55dc47bae4 nfqws2: remove unneeded loop 2026-03-04 14:16:19 +03:00
bol-van
14a2548bf5 nfqws2: allow quic CRYPTO fragment intersection and dups 2026-03-04 12:31:40 +03:00
bol-van
f59ddbb645 github,linux-builder: revert to lj_alloc for arm64 and mips64 2026-03-03 19:25:33 +03:00
bol-van
96f58adc7a docs 2026-03-03 10:53:05 +03:00
bol-van
b20ee9adbe zapret-lib: prevent double apply_arg_prefix 2026-03-03 10:49:55 +03:00
bol-van
7bfb4066cd update docs 2026-03-02 20:24:45 +03:00
bol-van
a8a742f48c zapret-lib: call apply_arg_prefix right before instance execute 2026-03-02 20:21:38 +03:00
bol-van
03f1fc4788 init.d: warn if ipset/hostlist files inside zapret2 root 2026-03-02 14:18:57 +03:00
bol-van
3ae875f8aa AI fixes 2026-03-02 10:44:48 +03:00
bol-van
300084a654 github.linux-builder: move arm to armv6 2026-03-01 20:22:02 +03:00
bol-van
ccef4377df github: use thumb in android armv7 build 2026-03-01 18:30:54 +03:00
bol-van
3ebb24930e -DLUAJIT_USE_SYSMALLOC 2026-03-01 10:22:19 +03:00
bol-van
aff6fe3966 -DLUAJIT_USE_SYSMALLOC 2026-03-01 10:18:35 +03:00
bol-van
f43030c0b8 AI fix 2026-03-01 09:53:55 +03:00
bol-van
69e8bb3c7f AI fixes 2026-03-01 09:48:18 +03:00
16 changed files with 135 additions and 55 deletions

View File

@@ -25,7 +25,7 @@ jobs:
- arch: arm64
tool: aarch64-unknown-linux-musl
- arch: arm
tool: armv7-unknown-linux-musleabi
tool: armv6-unknown-linux-musleabi
- arch: mips64
tool: mips64-unknown-linux-musl
- arch: mipselsf
@@ -100,6 +100,7 @@ jobs:
export PKG_CONFIG_PATH=$DEPS_DIR/lib/pkgconfig
export STAGING_DIR=$RUNNER_TEMP
OPTIMIZE=-Oz
SYSMALLOC=-DLUAJIT_USE_SYSMALLOC
case "$ARCH" in
lexra)
OPTIMIZE=-Os
@@ -107,6 +108,10 @@ jobs:
arm)
CPU="-mcpu=cortex-a7 -mthumb"
;;
arm64|mips64)
# not safe without GC64
SYSMALLOC=
;;
esac
MINSIZE="$OPTIMIZE $MINSIZE"
@@ -131,9 +136,10 @@ jobs:
*)
HOSTCC="cc -m32"
esac
echo ARCH=$ARCH SYSMALLOC=$SYSMALLOC
(
cd luajit2-*
make BUILDMODE=static XCFLAGS="-DLUAJIT_DISABLE_FFI" HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$CPU $MINSIZE $CFLAGS" TARGET_LDFLAGS="$CPU $LDMINSIZE $LDFLAGS" -j$(nproc)
make BUILDMODE=static XCFLAGS="$SYSMALLOC -DLUAJIT_DISABLE_FFI" HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$CPU $MINSIZE $CFLAGS" TARGET_LDFLAGS="$CPU $LDMINSIZE $LDFLAGS" -j$(nproc)
make install PREFIX= DESTDIR=$DEPS_DIR
)
LJIT=1
@@ -236,6 +242,17 @@ jobs:
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
export PKG_CONFIG_PATH=$DEPS_DIR/lib/pkgconfig
SYSMALLOC=-DLUAJIT_USE_SYSMALLOC
case "$ABI" in
armeabi-v7a)
CPU="-mthumb"
;;
arm64-v8a)
# not safe without GC64
SYSMALLOC=
PAGESIZE="-Wl,-z,max-page-size=16384"
;;
esac
# luajit
wget -qO- https://github.com/openresty/luajit2/archive/refs/tags/v${LUAJIT_RELEASE}.tar.gz | tar -xz
@@ -248,7 +265,7 @@ jobs:
esac
(
cd luajit2-*
make BUILDMODE=static XCFLAGS=-DLUAJIT_DISABLE_FFI HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" -j$(nproc)
make BUILDMODE=static XCFLAGS="$SYSMALLOC -DLUAJIT_DISABLE_FFI" HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$CPU $MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" -j$(nproc)
make install PREFIX= DESTDIR=$DEPS_DIR
)
LJIT=1
@@ -264,7 +281,7 @@ jobs:
for i in libmnl libnfnetlink libnetfilter_queue ; do
(
cd $i-*
CFLAGS="$MINSIZE -Wno-implicit-function-declaration $CFLAGS" \
CFLAGS="$CPU $MINSIZE -Wno-implicit-function-declaration $CFLAGS" \
LDFLAGS="$LDMINSIZE $LDFLAGS" \
./configure --prefix= --host=$TARGET --enable-static --disable-shared --disable-dependency-tracking
make install -j$(nproc) DESTDIR=$DEPS_DIR
@@ -273,8 +290,8 @@ jobs:
done
# zapret2
CFLAGS="-DZAPRET_GH_VER=${{ github.ref_name }} -DZAPRET_GH_HASH=${{ github.sha }} -I$DEPS_DIR/include" \
LDFLAGS="-L$DEPS_DIR/lib" \
CFLAGS="-DZAPRET_GH_VER=${{ github.ref_name }} -DZAPRET_GH_HASH=${{ github.sha }} -I$DEPS_DIR/include $CPU" \
LDFLAGS="-L$DEPS_DIR/lib $PAGESIZE" \
make -C zapret2 LUA_JIT=$LJIT LUA_CFLAGS="$LCFLAGS" LUA_LIB="$LLIB" -j$(nproc) android
# strip unwanted ELF sections to prevent warnings on old Android versions
@@ -329,7 +346,7 @@ jobs:
wget -qO- https://github.com/openresty/luajit2/archive/refs/tags/v${LUAJIT_RELEASE}.tar.gz | tar -xz
(
cd luajit2-*
make BUILDMODE=static XCFLAGS="$PIC -DLUAJIT_DISABLE_FFI" HOST_CC=gcc CC=$CC TARGET_CFLAGS="$MINSIZE $CFLAGS $PIC" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS"
make BUILDMODE=static XCFLAGS="$PIC -DLUAJIT_USE_SYSMALLOC -DLUAJIT_DISABLE_FFI" HOST_CC=gcc CC=$CC TARGET_CFLAGS="$MINSIZE $CFLAGS $PIC" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS"
make install PREFIX= DESTDIR=$DEPS_DIR
)
@@ -442,7 +459,7 @@ jobs:
wget -q https://github.com/openresty/luajit2/archive/refs/tags/v${LUAJIT_RELEASE}.tar.gz &&
tar -xzf v${LUAJIT_RELEASE}.tar.gz &&
rm -f v${LUAJIT_RELEASE}.tar.gz &&
make -C luajit2-${LUAJIT_RELEASE} BUILDMODE=static XCFLAGS="-DLUAJIT_DISABLE_FFI -ffat-lto-objects" TARGET_CFLAGS="$MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" &&
make -C luajit2-${LUAJIT_RELEASE} BUILDMODE=static XCFLAGS="-DLUAJIT_USE_SYSMALLOC -DLUAJIT_DISABLE_FFI -ffat-lto-objects" TARGET_CFLAGS="$MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" &&
make -C luajit2-${LUAJIT_RELEASE} install
- name: Build winws

View File

@@ -438,6 +438,13 @@ has_bad_ws_options()
echo "Kernel ipsets should be used instead. Write custom scripts and filter IPs in kernel."
echo
}
contains "$1" "--ipset=$ZAPRET_BASE" || contains "$1" "--ipset-exclude=$ZAPRET_BASE" ||
contains "$1" "--hostlist=$ZAPRET_BASE" || contains "$1" "--hostlist-exclude=$ZAPRET_BASE" && {
echo
echo "WARNING !!! you store ipset or hostlist files inside '$ZAPRET_BASE'"
echo "It's not recommended. install_easy.sh will delete them during update."
echo
}
return 1
}

View File

@@ -264,3 +264,12 @@ v0.9.4.3
* winws2, dvtws2: ASLR
* github, linux-builder: reduce arm executable size by 20% - move to armv7+thumb
* init.d: warn if hostlist/ipset files are inside zapret2 root
* zapret-lib: do not call apply_arg_prefix in apply_execution_plan - call it right before instance execute
0.9.4.5
* github: rollback to lj_alloc in luajit for arm64 and mips64
* github: use 16K page size for android arm64 build
* nfqws2: join fragments in quic CRYPTO reconstruction. allow intersections.

View File

@@ -62,11 +62,20 @@ build_lua()
build_luajit()
{
local CFL="$CFLAGS"
local SYSMALLOC=
(
cd luajit2-*
CFLAGS="-Os"
make clean
make BUILDMODE=static XCFLAGS="-DLUAJIT_DISABLE_FFI $CFLAGS_PIC" HOST_CC="$HOST_CC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$OPTIMIZE $MINSIZE $CFL" TARGET_LDFLAGS="$CPU $LDMINSIZE $LDFLAGS"
case $TARGET in
aarch64*|mips64*)
# sysmalloc can cause troubles without GC64. GC64 slows down by 10-15%. better not to use sysmalloc and leave lj_alloc.
;;
*)
# save some exe size
SYSMALLOC=-DLUAJIT_USE_SYSMALLOC
esac
make BUILDMODE=static XCFLAGS="$SYSMALLOC -DLUAJIT_DISABLE_FFI $CFLAGS_PIC" HOST_CC="$HOST_CC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$OPTIMIZE $MINSIZE $CFL" TARGET_LDFLAGS="$CPU $LDMINSIZE $LDFLAGS"
make install PREFIX= DESTDIR="$STAGING_DIR"
)
}

View File

@@ -23,7 +23,7 @@ nproc=$(nproc)
TARGETS="\
aarch64-unknown-linux-musl \
armv7-unknown-linux-musleabi \
armv6-unknown-linux-musleabi \
i586-unknown-linux-musl \
x86_64-unknown-linux-musl \
mips-unknown-linux-muslsf \
@@ -38,7 +38,7 @@ target_has_luajit()
{
case "$1" in
aarch64-unknown-linux-musl| \
armv7-unknown-linux-musleabi| \
armv6-unknown-linux-musleabi| \
x86_64-unknown-linux-musl| \
mips-unknown-linux-muslsf| \
mips64-unknown-linux-musl| \
@@ -100,8 +100,8 @@ buildenv()
# not all archs support -static-pie. if does not support - it produces dynamic executable
# "-static -static-pie" causes segfaults
case $1 in
armv7-*)
CPU="-mcpu=cortex-a7 -mthumb -msoft-float"
armv6-*)
CPU="-mthumb -msoft-float"
CFLAGS="$CPU $CFLAGS"
;;
mips*)
@@ -273,7 +273,7 @@ translate_target()
aarch64-unknown-linux-musl)
ZBINTARGET=linux-arm64
;;
armv7-unknown-linux-musleabi)
armv6-unknown-linux-musleabi)
ZBINTARGET=linux-arm
;;
x86_64-unknown-linux-musl)

View File

@@ -3531,7 +3531,8 @@ Checks the [instance cutoff](#instance_cutoff) state for `desync.func_instance`
function apply_arg_prefix(desync)
```
Performs substitution of argument values from `desync.arg` that start with `%` and `#`.
Performs substitution of argument values from `desync.arg` that start with `%`, `#`, `\`.
Multiple calls are safe but do not update desync.arg if blobs were changed.
### apply_execution_plan
@@ -3540,6 +3541,8 @@ function apply_execution_plan(desync, instance)
```
Copies the instance identification and its arguments from an [execution plan](#execution_plan) `instance` into the desync object, thereby recreating the desync state as if the `instance` were called directly by C code.
With one exception : apply_arg_prefix is not applied because args can refer a blob created by previous conditionally executed instances.
The [execution plan](#execution_plan) is provided by the C function `execution_plan()` as an array of `instance` elements.
### verdict_aggregate
@@ -3558,6 +3561,7 @@ function plan_instance_execute_preapplied(desync, verdict, instance)
```
Executes an [execution plan](#execution_plan) `instance`, taking into account the [instance cutoff](#instance_cutoff) and standard [payload](#in-profile-filters) and [range](#in-profile-filters) filters.
Calls apply_arg_prefix right before calling the instance.
Returns the aggregation of the current verdict and the `instance` verdict.
The "preapplied" version does not apply execution plan, allowing the calling code to do so.
@@ -4479,6 +4483,7 @@ function cond_lua(desync)
```
Executes a Lua code from the "cond_code" argument. The code returns condition value. Direct addressing of the desync table is possible within the code.
desync.arg is passed without called "apply_arg_prefix" : `%`, `#`, `\` remain as is without substitution because can refer blobs created by previous conditionally executed instances.
# Auxiliary programs

View File

@@ -3709,7 +3709,8 @@ function cutoff_shim_check(desync)
function apply_arg_prefix(desync)
```
Выполняет подстановку значений аргументов из desync.arg, начинающихся с `%` и `#`.
Выполняет подстановку значений аргументов из desync.arg, начинающихся с `%` и `#`, `\`.
Функция ставит специальную метку в desync.arg , чтобы избежать двойного разименования. Повторные вызовы безопасны, но не обновляют desync.arg при изменении блобов.
### apply_execution_plan
@@ -3719,6 +3720,8 @@ function apply_execution_plan(desync, instance)
Копирует в desync идентификацию инстанса и его аргументы из элемента [execution plan](#execution_plan) `instance`,
тем самым воссоздает состояние desync, как если бы `instance` был вызван напрямую C кодом.
За одним исключением : apply_arg_prefix не применяется, поскольку может содержать несуществующие блоб, существование которого зависит от условного выполнения предыдущих истансов.
[execution plan](#execution_plan) выдается C функцией `execution_plan()` как массив, элементами которого являются `instance`.
### verdict_aggregate
@@ -3737,6 +3740,7 @@ function plan_instance_execute_preapplied(desync, verdict, instance)
```
Выполняет элемент [execution plan](#execution_plan) `instance` с учетом [instance cutoff](#instance_cutoff) и стандартных фильтров [payload](#внутрипрофильные-фильтры) и [range](#внутрипрофильные-фильтры).
При совпадении условий непосредственно перед вызовом выполняет apply_arg_prefix.
Возвращает агрегацию verdict и вердикта `instance`.
Вариант "preapplied" не выполняет apply_execution_plan, позволяя это сделат вызывающему коду.
@@ -4658,6 +4662,7 @@ function cond_lua(desync)
```
Выполняет Lua код из аргумента "cond_code". Код возвращает значение условия через return. Возможна прямая адресация таблицы desync.
desync.arg передаются с НЕ разименованными `%`, `#`, `\`, поскольку разименование может ссылаться на блобы, создаваемые предыдущими условно вызываемыми инстансами.
# Вспомогательные программы

View File

@@ -1210,8 +1210,8 @@ function udplen(ctx, desync)
else
desync.dis.payload = string.sub(desync.dis.payload,1,len+inc)
DLOG("udplen: "..len.." => "..#desync.dis.payload)
return VERDICT_MODIFY
end
return VERDICT_MODIFY
end
end
end

View File

@@ -149,6 +149,8 @@ end
-- applies # and $ prefixes. #var means var length, %var means var value
function apply_arg_prefix(desync)
-- prevent double apply
if desync.arg.__prefix_applied then return end
for a,v in pairs(desync.arg) do
local c = string.sub(v,1,1)
if c=='#' then
@@ -163,6 +165,7 @@ function apply_arg_prefix(desync)
end
end
end
desync.arg.__prefix_applied = true
end
-- copy instance identification and args from execution plan to desync table
-- NOTE : to not lose VERDICT_MODIFY dissect changes pass original desync table
@@ -173,7 +176,7 @@ function apply_execution_plan(desync, instance)
desync.func_n = instance.func_n
desync.func_instance = instance.func_instance
desync.arg = deepcopy(instance.arg)
apply_arg_prefix(desync)
-- no apply_arg_prefix here because it may refer non-existing blobs
end
-- produce resulting verdict from 2 verdicts
function verdict_aggregate(v1, v2)
@@ -200,6 +203,9 @@ function plan_instance_execute_preapplied(desync, verdict, instance)
elseif not pos_check_range(desync, instance.range) then
DLOG("plan_instance_execute: not calling '"..desync.func_instance.."' because pos "..pos_str(desync,instance.range.from).." "..pos_str(desync,instance.range.to).." is out of range '"..pos_range_str(instance.range).."'")
else
-- condition is satisfied. here blobs must be referenced
apply_arg_prefix(desync)
desync.arg.__prefix_applied = nil
DLOG("plan_instance_execute: calling '"..desync.func_instance.."'")
verdict = verdict_aggregate(verdict,_G[instance.func](nil, desync))
end
@@ -632,7 +638,7 @@ function tls_mod_shim(desync, blob, modlist, payload)
if not val then
error("tls_mod_shim: non-existent var '"..var.."'")
end
modlist = string.sub(modlist,1,p1+3)..val..string.sub(modlist,p2+1)
modlist = string.sub(modlist,1,p1+3)..tostring(val)..string.sub(modlist,p2+1)
end
return tls_mod(blob,modlist,payload)
end
@@ -962,7 +968,7 @@ function apply_fooling(desync, dis, fooling_options)
end
end
if fooling_options.tcp_ts_up then
move_ts_top(dis.tcp.options)
move_ts_top()
end
end
if dis.ip6 then

View File

@@ -780,6 +780,7 @@ function test_csum()
print( raw==udpb and "UDP RECONSTRUCT OK" or "UDP RECONSTRUCT FAILED" )
test_assert(raw==udpb)
ip.ip_p = IPPROTO_UDP
raw = reconstruct_dissect({ip=ip, udp=udp, payload=payload})
dis1 = dissect(raw)
ip.ip_p = IPPROTO_UDP

View File

@@ -50,7 +50,6 @@ void qsort_ssize_t(ssize_t *array, int ct)
qsort(array, ct, sizeof(*array), cmp_ssize_t);
}
int str_index(const char **strs, int count, const char *str)
{
for (int i = 0; i < count; i++)

View File

@@ -12,6 +12,9 @@
#include <fcntl.h>
#define UNARY_PLUS(v) (v>0 ? "+" : "")
//#define MIN(v1,v2) ((v1)<(v2) ? (v1) : (v2))
//#define MAX(v1,v2) ((v1)<(v2) ? (v2) : (v1))
// this saves memory. sockaddr_storage is larger than required. it can be 128 bytes. sockaddr_in6 is 28 bytes.
typedef union

View File

@@ -1868,7 +1868,7 @@ static bool lua_reconstruct_ip6exthdr(lua_State *L, int idx, struct ip6_hdr *ip6
{
LUA_STACK_GUARD_ENTER(L)
// proto = last header type
if (*len<sizeof(struct tcphdr)) return false;
if (*len<sizeof(struct ip6_hdr)) return false;
uint8_t *last_proto = &ip6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
size_t filled = sizeof(struct ip6_hdr);
@@ -2031,7 +2031,7 @@ bool lua_reconstruct_iphdr(lua_State *L, int idx, struct ip *ip, size_t *len)
LUA_STACK_GUARD_ENTER(L)
if (*len<sizeof(struct ip) || lua_type(L,-1)!=LUA_TTABLE) return false;
if (*len<sizeof(struct ip) || lua_type(L,idx)!=LUA_TTABLE) return false;
ip->ip_v = IPVERSION;
@@ -2201,7 +2201,7 @@ err:
}
bool lua_reconstruct_tcphdr(lua_State *L, int idx, struct tcphdr *tcp, size_t *len)
{
if (*len<sizeof(struct tcphdr) || lua_type(L,-1)!=LUA_TTABLE) return false;
if (*len<sizeof(struct tcphdr) || lua_type(L,idx)!=LUA_TTABLE) return false;
LUA_STACK_GUARD_ENTER(L)
@@ -2276,7 +2276,7 @@ static int luacall_reconstruct_tcphdr(lua_State *L)
bool lua_reconstruct_udphdr(lua_State *L, int idx, struct udphdr *udp)
{
if (lua_type(L,-1)!=LUA_TTABLE) return false;
if (lua_type(L,idx)!=LUA_TTABLE) return false;
LUA_STACK_GUARD_ENTER(L)
@@ -2320,7 +2320,7 @@ static int luacall_reconstruct_udphdr(lua_State *L)
bool lua_reconstruct_icmphdr(lua_State *L, int idx, struct icmp46 *icmp)
{
if (lua_type(L,-1)!=LUA_TTABLE) return false;
if (lua_type(L,idx)!=LUA_TTABLE) return false;
LUA_STACK_GUARD_ENTER(L)

View File

@@ -331,7 +331,7 @@ bool IsHttpReply(const uint8_t *data, size_t len)
data[10]>='0' && data[10]<='9' &&
data[11]>='0' && data[11]<='9';
}
int HttpReplyCode(const uint8_t *data, size_t len)
int HttpReplyCode(const uint8_t *data)
{
return (data[9]-'0')*100 + (data[10]-'0')*10 + (data[11]-'0');
}
@@ -370,7 +370,7 @@ bool HttpReplyLooksLikeDPIRedirect(const uint8_t *data, size_t len, const char *
if (!host || !*host || !IsHttpReply(data, len)) return false;
code = HttpReplyCode(data,len);
code = HttpReplyCode(data);
if ((code!=302 && code!=307) || !HttpExtractHeader(data,len,"\nLocation:",loc,sizeof(loc))) return false;
@@ -1252,6 +1252,13 @@ static int cmp_range64(const void * a, const void * b)
{
return (((struct range64*)a)->offset < ((struct range64*)b)->offset) ? -1 : (((struct range64*)a)->offset > ((struct range64*)b)->offset) ? 1 : 0;
}
/*
static bool intersected_u64(uint64_t l1, uint64_t r1, uint64_t l2, uint64_t r2)
{
return l1 <= r2 && l2 <= r1;
}
*/
bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,size_t *defrag_len, bool *bFull)
{
// Crypto frame can be split into multiple chunks
@@ -1265,7 +1272,7 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz
uint64_t offset,sz,szmax=0,zeropos=0,pos=0;
bool found=false;
struct range64 ranges[MAX_DEFRAG_PIECES];
int i,range=0;
int i,j,range=0;
while(pos<clean_len)
{
@@ -1287,24 +1294,54 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz
if ((pos+sz)>clean_len) return false;
if ((offset+sz)>defrag_data_len) return false; // defrag buf overflow
// remove exact duplicates early to save cpu
for(i=0;i<range;i++)
if (ranges[i].offset==offset && ranges[i].len==sz)
goto skip_range;
if (zeropos < offset)
// make sure no uninitialized gaps exist in case of not full fragment coverage
memset(defrag_data+zeropos,0,offset-zeropos);
if ((offset+sz) > zeropos)
zeropos=offset+sz;
memcpy(defrag_data+offset,clean+pos,sz);
if ((offset+sz) > szmax) szmax = offset+sz;
found=true;
pos+=sz;
if ((offset+sz) > szmax) szmax = offset+sz;
memcpy(defrag_data+offset,clean+pos,sz);
ranges[range].offset = offset;
ranges[range].len = sz;
range++;
skip_range:
pos+=sz;
}
}
if (found)
{
qsort(ranges, range, sizeof(*ranges), cmp_range64);
// for(i=0 ; i<range ; i++)
// printf("range1 %llu-%llu\n",ranges[i].offset,ranges[i].offset+ranges[i].len);
if (range>0)
{
for (j=0,i=1; i < range; i++)
{
uint64_t current_end = ranges[j].offset + ranges[j].len;
uint64_t next_start = ranges[i].offset;
uint64_t next_end = ranges[i].offset + ranges[i].len;
if (next_start <= current_end)
ranges[j].len = MAX(next_end,current_end) - ranges[j].offset;
else
ranges[++j] = ranges[i];
}
range = j+1;
}
// for(i=0 ; i<range ; i++)
// printf("range2 %llu-%llu\n",ranges[i].offset,ranges[i].offset+ranges[i].len);
defrag[0] = 6;
defrag[1] = 0; // offset
// 2..9 - length 64 bit
@@ -1313,21 +1350,7 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz
defrag[2] |= 0xC0; // 64 bit value
*defrag_len = (size_t)(szmax+10);
qsort(ranges, range, sizeof(*ranges), cmp_range64);
//for(i=0 ; i<range ; i++)
// printf("RANGE %zu len %zu\n",ranges[i].offset,ranges[i].len);
for(i=0,offset=0,*bFull=true ; i<range ; i++)
{
if (ranges[i].offset!=offset)
{
*bFull = false;
break;
}
offset += ranges[i].len;
}
*bFull = range==1 && !ranges[0].offset;
//printf("bFull=%u\n",*bFull);
}
return found;
@@ -1350,6 +1373,8 @@ bool IsQUICInitial(const uint8_t *data, size_t len)
if (data[offset] > QUIC_MAX_CID_LENGTH) return false;
offset += 1 + data[offset];
if (offset>=len) return false;
// SCID
if (data[offset] > QUIC_MAX_CID_LENGTH) return false;
offset += 1 + data[offset];

View File

@@ -104,7 +104,7 @@ bool HttpExtractHeader(const uint8_t *data, size_t len, const char *header, char
bool HttpExtractHost(const uint8_t *data, size_t len, char *host, size_t len_host);
bool IsHttpReply(const uint8_t *data, size_t len);
// must be pre-checked by IsHttpReply
int HttpReplyCode(const uint8_t *data, size_t len);
int HttpReplyCode(const uint8_t *data);
// must be pre-checked by IsHttpReply
bool HttpReplyLooksLikeDPIRedirect(const uint8_t *data, size_t len, const char *host);

View File

@@ -28,12 +28,6 @@ bool service_run(int argc, char *argv[])
return StartServiceCtrlDispatcherA(ServiceTable);
}
static void service_set_status(DWORD state)
{
ServiceStatus.dwCurrentState = state;
SetServiceStatus(hStatus, &ServiceStatus);
}
// Control handler function
void service_controlhandler(DWORD request)
{