From fd1eac2ef11eff525a82868c17d3692646958fc3 Mon Sep 17 00:00:00 2001 From: bol-van Date: Fri, 5 Dec 2025 22:31:51 +0300 Subject: [PATCH] zapret-lib: fix seq number substraction --- lua/zapret-antidpi.lua | 2 +- lua/zapret-lib.lua | 9 +++++++-- lua/zapret-tests.lua | 26 +++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lua/zapret-antidpi.lua b/lua/zapret-antidpi.lua index c367004..1e63496 100644 --- a/lua/zapret-antidpi.lua +++ b/lua/zapret-antidpi.lua @@ -290,7 +290,7 @@ end -- nfqws1 : "--dpi-desync=syndata" -- standard args : fooling, rawsend, reconstruct, ipfrag -- arg : blob= - fake payload. must fit to single packet. no segmentation possible. default - 16 zero bytes. --- arg : tls_mod= - comma separated list of tls mods : rnd,rndsni,sni=,dupsid,padencap +-- arg : tls_mod= - comma separated list of tls mods : rnd,rndsni,sni= function syndata(ctx, desync) if desync.dis.tcp then if bitand(desync.dis.tcp.th_flags, TH_SYN + TH_ACK)==TH_SYN then diff --git a/lua/zapret-lib.lua b/lua/zapret-lib.lua index fb033b1..ea4945e 100644 --- a/lua/zapret-lib.lua +++ b/lua/zapret-lib.lua @@ -85,7 +85,7 @@ function apply_execution_plan(desync, plan) desync.arg = deepcopy(plan.arg) apply_arg_prefix(desync.arg) end --- produce resulting verdict from 2 verdict +-- produce resulting verdict from 2 verdicts function verdict_aggregate(v1, v2) local v v1 = v1 or VERDICT_PASS @@ -142,7 +142,7 @@ function pos_get(desync, mode) elseif mode=='b' then return desync.outgoing and desync.track.pbcounter_orig or desync.track.pbcounter_reply elseif mode=='s' and desync.track.tcp then - return desync.outgoing and (desync.track.tcp.seq - desync.track.tcp.seq0) or (desync.track.tcp.ack - desync.track.tcp.ack0) + return desync.outgoing and u32add(desync.track.tcp.seq, -desync.track.tcp.seq0) or u32add(desync.track.tcp.ack, -desync.track.tcp.ack0) end end return 0 @@ -1032,6 +1032,11 @@ function genhost(len, template) end end +-- return hostname if present or ip address in text form otherwise +function host_or_ip(desync) + return desync.hostname or (desync.dis.ip and ntop(desync.dis.ip) or desync.dis.ip6 and ntop(desync.dis.ip6)) +end + function is_absolute_path(path) if string.sub(path,1,1)=='/' then return true end local un = uname() diff --git a/lua/zapret-tests.lua b/lua/zapret-tests.lua index 7224906..6a549a2 100644 --- a/lua/zapret-tests.lua +++ b/lua/zapret-tests.lua @@ -299,8 +299,32 @@ function test_bit() test_assert(v2==v3) end +function test_ux() + local v1, v2, v3, usum, sum + for k,test in pairs({ + { add=u8add, fname="u8add", max = 0xFF }, + { add=u16add, fname="u16add", max = 0xFFFF }, + { add=u24add, fname="u24add", max = 0xFFFFFF }, + { add=u32add, fname="u32add", max = 0xFFFFFFFF } + }) do + io.write(test.fname.." : ") + for i=1,1000 do + v1=math.random(-test.max,test.max) + v2=math.random(-test.max,test.max) + v3=math.random(-test.max,test.max) + usum = test.add(v1,v2,v3) + sum = bitand(v1+v2+v3,test.max) + if sum~=usum then + print("FAIL") + end + test_assert(sum==usum) + end + print("OK") + end +end + function test_bin(...) - test_run({test_ub, test_bit},...) + test_run({test_ub, test_bit, test_ux},...) end