From bceb754e656305e153ec553e6f933979bf2c3ed5 Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 27 Oct 2026 00:04:21 +0300 Subject: [PATCH] windows: zapret2 on winws2 with nfqws2-keenetic's strategies ps-core::zapret2 reads nfqws2-keenetic's nfqws2.conf and patches it as upstream's sources.nix does, expands the hostlist markers as zapret2's list.sh does (autohostlist with its detector settings, the configured domains), fills circular's unset detector settings from autoHostlist, merges the extra ports into the profiles that tell traffic by protocol, and gives winws2 WinDivert port filters in place of the queue's rules. The service runs it with the learned list in a directory labelled Low integrity, where winws2 can still write once it drops to Low. winws2 verifies the whole command line under Wine. detect.lua, z2k and the cutoff probe are not there yet. Co-Authored-By: Claude Opus 5.5 --- .../crates/ps-core/examples/zapret2_args.rs | 22 + windows/crates/ps-core/src/lib.rs | 1 + windows/crates/ps-core/src/zapret2.rs | 395 ++++++++++++++++++ windows/crates/ps-service/src/service.rs | 12 +- windows/crates/ps-service/src/zapret.rs | 75 ++++ windows/tools/winws-dry-run.sh | 15 +- 6 files changed, 516 insertions(+), 4 deletions(-) create mode 100644 windows/crates/ps-core/examples/zapret2_args.rs create mode 100644 windows/crates/ps-core/src/zapret2.rs diff --git a/windows/crates/ps-core/examples/zapret2_args.rs b/windows/crates/ps-core/examples/zapret2_args.rs new file mode 100644 index 0000000..150fb7f --- /dev/null +++ b/windows/crates/ps-core/examples/zapret2_args.rs @@ -0,0 +1,22 @@ +//! For tools/winws-dry-run.sh: winws2's arguments as the service builds them, one per line. +//! `zapret2_args ` + +use ps_core::config::Zapret2; +use ps_core::zapret2::{Paths, args, keenetic}; + +fn main() { + let a: Vec = std::env::args().collect(); + let conf = std::fs::read_to_string(std::path::Path::new(&a[1]).join("keenetic").join("nfqws2.conf")).unwrap(); + let (comp, state) = (&a[2], &a[3]); + let source = keenetic(&conf, &format!("{comp}keenetic\\")).unwrap(); + let paths = Paths { + lua: format!("{comp}lua\\"), + user: format!("{state}zapret-hosts-user.txt"), + exclude: format!("{state}zapret-hosts-user-exclude.txt"), + auto: format!("{state}learned\\zapret-hosts-auto.txt"), + }; + let z = Zapret2 { domains: vec!["rutracker.org".into()], ..Default::default() }; + for arg in args(&z, &source, &paths, false).unwrap() { + println!("{arg}"); + } +} diff --git a/windows/crates/ps-core/src/lib.rs b/windows/crates/ps-core/src/lib.rs index 8f1c8be..97c31e0 100644 --- a/windows/crates/ps-core/src/lib.rs +++ b/windows/crates/ps-core/src/lib.rs @@ -12,3 +12,4 @@ pub mod links; pub mod render; pub mod wg; pub mod zapret; +pub mod zapret2; diff --git a/windows/crates/ps-core/src/zapret2.rs b/windows/crates/ps-core/src/zapret2.rs new file mode 100644 index 0000000..bcbe76f --- /dev/null +++ b/windows/crates/ps-core/src/zapret2.rs @@ -0,0 +1,395 @@ +//! zapret2 on Windows: winws2 (WinDivert) with the strategies upstream's module gives nfqws2 +//! (NFQUEUE). The strategy source is nfqws2-keenetic, read and patched as upstream's +//! `zapret2/sources.nix` does; the profiles, markers, circular defaults and ports follow +//! upstream's `zapret2/runtime.nix` and zapret2's own `common/list.sh`. +//! +//! What differs on Windows: WinDivert's port filters (`--wf-tcp-out`, `--wf-udp-out`) take +//! the place of the queue's rules, and there are no marks. winws2 drops to Low integrity once +//! it runs, so the learned list lives in a directory the service labels Low for it (winws2's +//! own `--writable` insists on making the directory, which must already hold the list). +//! Learning is nfqws2's own autohostlist; upstream's detector (`detect.lua`, +//! `extendedDetection`) and z2k come later. + +use crate::config::{StrategySource, Zapret2}; + +fn words(s: &str) -> Vec<&str> { + s.split_whitespace().collect() +} + +/// The text between `start` and the next `stop`; exactly one `start`, or the pinned file +/// changed shape. +fn between<'a>(what: &str, start: &str, stop: &str, text: &'a str) -> Result<&'a str, String> { + let mut parts = text.split(start); + let (_, Some(after), None) = (parts.next(), parts.next(), parts.next()) else { + return Err(format!("expected one `{}` in {what}", start.trim())); + }; + Ok(after.split(stop).next().unwrap_or("")) +} + +fn patch(what: &str, from: &str, to: &str, text: &str) -> Result { + if text.contains(from) { + Ok(text.replacen(from, to, 1)) + } else { + Err(format!("expected `{from}` in {what}")) + } +} + +/// nfqws2-keenetic's strategies, as upstream's sources.nix takes them. +#[derive(Debug, Clone, PartialEq)] +pub struct Source { + /// In nfqws2's order: UDP, QUIC, TCP. Hostlist markers still in. + pub profiles: Vec, + pub blob_args: Vec, + pub tcp_ports: String, + pub udp_ports: String, +} + +/// `conf`: its `etc/nfqws2/nfqws2.conf`; `dir`: where its `etc/nfqws2/` is (as winws2 will +/// read it, with a trailing separator). +pub fn keenetic(conf: &str, dir: &str) -> Result { + let quoted = |name: &str| between("nfqws2.conf", &format!("\n{name}=\""), "\"", conf); + let bare = |name: &str| between("nfqws2.conf", &format!("\n{name}="), "\n", conf); + let args = |name: &str| -> Result { + let body = quoted(name)?; + let kept: Vec<&str> = body.lines().filter(|l| !l.trim().starts_with('#')).collect(); + Ok(words(&kept.join("\n")).join(" ")) + }; + let sep = if dir.contains('\\') { "\\" } else { "/" }; + let lists = format!( + "--hostlist={dir}lists{sep}user.list --hostlist-exclude={dir}lists{sep}exclude.list" + ); + let circular = "--lua-desync=circular:fails=2:time=300:retrans=3:nld=2"; + let tcp_payload = "--payload=tls_client_hello,mtproto_initial"; + let udp_payload = "--payload=wireguard_initiation,wireguard_response,wireguard_cookie,stun,discord_ip_discovery,mtproto_initial,unknown"; + + // Its first UDP strategy's fake has no blob, which zapret2 rejects on every packet; + // circular is handed the replies, as in zapret2's manual. + let udp = args("NFQWS_ARGS_UDP")?; + let udp = patch("NFQWS_ARGS_UDP", "--lua-desync=fake:repeats=6:strategy=1", &format!("--lua-desync=fake:blob=0x{}:repeats=6:strategy=1", "0".repeat(128)), &udp)?; + let udp = patch( + "NFQWS_ARGS_UDP", + &format!("--out-range= {lists}", args("NFQWS_ARGS_QUIC")?); + let tcp = patch( + "NFQWS_ARGS", + &format!("{tcp_payload} {circular}"), + &format!(" --in-range=-s5556 {tcp_payload},tls_server_hello,empty,unknown {circular}:key=circular_3_1 --in-range=x {tcp_payload}"), + &args("NFQWS_ARGS")?, + )?; + let tcp = format!("{tcp} {lists}"); + + let blob_args = words(quoted("NFQWS_BASE_ARGS")?) + .into_iter() + .filter(|w| w.starts_with("--blob=")) + .map(|w| { + let w = w.replace("@/opt/etc/nfqws2/", &format!("@{dir}")); + if sep == "\\" { w.replace("blobs/", "blobs\\") } else { w } + }) + .collect(); + Ok(Source { + profiles: vec![udp, quic, tcp], + blob_args, + tcp_ports: bare("TCP_PORTS")?.trim().to_owned(), + udp_ports: bare("UDP_PORTS")?.trim().replace(':', "-"), + }) +} + +/// Where winws2's lists are, as it reads them. +#[derive(Debug, Clone)] +pub struct Paths { + /// The component's `lua\`, with a trailing separator. + pub lua: String, + /// `zapret-hosts-user.txt`: `zapret.zapret2.domains` and `proxy-ctl zapret auto add`. + pub user: String, + /// `zapret-hosts-user-exclude.txt`. + pub exclude: String, + /// `zapret-hosts-auto.txt`, in a directory labelled Low integrity. + pub auto: String, +} + +/// What `` and `` expand to (zapret2's filter_apply_hostlist_target). +fn hostlist_args(z: &Zapret2, p: &Paths) -> (String, String) { + let a = &z.auto_hostlist; + let base = format!("--hostlist={} --hostlist-exclude={}", p.user, p.exclude); + let (with_auto, no_auto) = if a.enable { + ( + format!( + "{base} --hostlist-auto={} --hostlist-auto-fail-threshold={} --hostlist-auto-fail-time={} \ + --hostlist-auto-retrans-threshold={} --hostlist-auto-retrans-reset={} \ + --hostlist-auto-retrans-maxseq={} --hostlist-auto-incoming-maxseq={} \ + --hostlist-auto-udp-in={} --hostlist-auto-udp-out={}", + p.auto, + a.fail_threshold, + a.fail_time, + a.retrans_threshold, + u8::from(a.retrans_reset), + a.retrans_maxseq, + a.incoming_maxseq, + a.udp_in, + a.udp_out + ), + format!("{base} --hostlist={}", p.auto), + ) + } else { + (base.clone(), base) + }; + // The configuration's domains join every profile that takes a list. + let mut statics = String::new(); + if !z.domains.is_empty() { + statics.push_str(&format!(" --hostlist-domains={}", z.domains.join(","))); + } + if !z.exclude_domains.is_empty() { + statics.push_str(&format!(" --hostlist-exclude-domains={}", z.exclude_domains.join(","))); + } + (with_auto + &statics, no_auto + &statics) +} + +/// Detector settings a circular instance leaves unset come from autoHostlist. +fn circular_fill(z: &Zapret2, token: &str) -> String { + let a = &z.auto_hostlist; + let mut fill = vec![ + format!("retrans={}", a.retrans_threshold), + format!("maxseq={}", a.retrans_maxseq), + format!("inseq={}", a.incoming_maxseq), + format!("udp_out={}", a.udp_out), + format!("udp_in={}", a.udp_in), + ]; + if a.retrans_reset { + fill.push("reset".into()); + } + let mut t = token.to_owned(); + for f in fill { + let key = f.split('=').next().unwrap(); + let has = t.split(':').skip(1).any(|part| part == key || part.starts_with(&format!("{key}="))); + if !has { + t.push(':'); + t.push_str(&f); + } + } + t +} + +fn port_list(values: &[serde_json::Value]) -> String { + values + .iter() + .map(|v| match v { + serde_json::Value::String(s) => s.clone(), + other => other.to_string(), + }) + .collect::>() + .join(",") +} + +/// Ports as ranges, merged: upstream's ports.awk. +fn merge_ports(lists: &[&str]) -> String { + let mut on = vec![false; 65537]; + for list in lists { + for p in list.split(',') { + let p = p.trim(); + let Some((lo, hi)) = (match p.split_once('-') { + Some((a, b)) => a.parse::().ok().zip(b.parse::().ok()), + None => p.parse::().ok().map(|n| (n, n)), + }) else { + continue; + }; + for port in lo.max(1)..=hi.min(65535) { + on[port as usize] = true; + } + } + } + let mut out = Vec::new(); + let mut start = 0; + for port in 1..=65536usize { + if port <= 65535 && on[port] { + if start == 0 { + start = port; + } + } else if start != 0 { + out.push(if start == port - 1 { start.to_string() } else { format!("{start}-{}", port - 1) }); + start = 0; + } + } + out.join(",") +} + +/// winws2's whole command line. +pub fn args(z: &Zapret2, source: &Source, p: &Paths, debug_packets: bool) -> Result, String> { + if z.strategy_source != StrategySource::Nfqws2Keenetic && z.profiles.is_none() { + return Err("only the nfqws2-keenetic strategies are there on Windows yet (zapret.zapret2.strategySource)".into()); + } + let (with_auto, no_auto) = hostlist_args(z, p); + let render = |profile: &str| { + profile + .replace("", &no_auto) + .replace("", &with_auto) + .replace(" ", "") + .replace("", "") + }; + let profiles: Vec = match &z.profiles { + Some(own) => own.iter().map(|x| render(x)).collect(), + None => source.profiles.iter().map(|x| render(x)).collect(), + }; + + let mut opt: Vec = Vec::new(); + if debug_packets { + opt.push("--debug=1".into()); + } + for lua in ["zapret-lib.lua", "zapret-antidpi.lua", "zapret-auto.lua"] { + opt.push(format!("--lua-init=@{}{lua}", p.lua)); + } + for (name, file) in &z.blobs { + opt.push(format!("--blob={name}:@{file}")); + } + if z.profiles.is_none() { + opt.extend(source.blob_args.iter().cloned()); + } + let mut body: Vec = Vec::new(); + for (i, profile) in profiles.iter().enumerate() { + if i > 0 { + body.push("--new".into()); + } + body.extend(words(profile).into_iter().map(str::to_owned)); + } + let body: Vec = body + .into_iter() + .map(|t| if t.starts_with("--lua-desync=circular") { circular_fill(z, &t) } else { t }) + .collect(); + + // Extra ports join every profile that tells its traffic by protocol; the WinDivert + // filter takes the base lists, the extras and every port a profile filters on. + let xtcp = port_list(&z.ports.extra_tcp); + let xudp = port_list(&z.ports.extra_udp); + let mut l7 = std::collections::BTreeSet::new(); + let mut prof = 0; + for t in &body { + if t == "--new" { + prof += 1; + } else if t.starts_with("--filter-l7=") { + l7.insert(prof); + } + } + let (mut tcp_ports, mut udp_ports): (Vec, Vec) = (Vec::new(), Vec::new()); + let mut prof = 0; + let body: Vec = body + .into_iter() + .map(|t| { + if t == "--new" { + prof += 1; + return t; + } + for (key, extra, list) in [("--filter-tcp=", &xtcp, &mut tcp_ports), ("--filter-udp=", &xudp, &mut udp_ports)] { + if let Some(ports) = t.strip_prefix(key) { + let t = if l7.contains(&prof) && !extra.is_empty() { format!("{t},{extra}") } else { t.clone() }; + list.push(t[key.len()..].to_owned()); + let _ = ports; + return t; + } + } + t + }) + .collect(); + let base_tcp = z.ports.tcp.clone().unwrap_or_else(|| source.tcp_ports.clone()); + let base_udp = z.ports.udp.clone().unwrap_or_else(|| source.udp_ports.clone()); + let mut tcp_all: Vec<&str> = vec![&base_tcp, &xtcp]; + tcp_all.extend(tcp_ports.iter().map(String::as_str)); + let mut udp_all: Vec<&str> = vec![&base_udp, &xudp]; + udp_all.extend(udp_ports.iter().map(String::as_str)); + let (wf_tcp, wf_udp) = (merge_ports(&tcp_all), merge_ports(&udp_all)); + if !wf_tcp.is_empty() { + opt.push(format!("--wf-tcp-out={wf_tcp}")); + } + if !wf_udp.is_empty() { + opt.push(format!("--wf-udp-out={wf_udp}")); + // UDP has no handshake for the filter to catch: circular judges a flow by its replies. + opt.push(format!("--wf-udp-in={wf_udp}")); + } + if !z.ipv6 { + opt.push("--wf-l3=ipv4".into()); + } + opt.extend(body); + Ok(opt) +} + +#[cfg(test)] +mod tests { + use super::*; + + const CONF: &str = r#"# x +NFQWS_BASE_ARGS="--lua-init=@/opt/etc/nfqws2/lua/zapret-lib.lua + --blob=quic_initial:@/opt/etc/nfqws2/blobs/quic_initial.bin + --blob=tls_clienthello:@/opt/etc/nfqws2/blobs/tls_clienthello.bin" + +NFQWS_ARGS="--filter-tcp=443,80 --filter-l7=http,tls + # HTTPS + --payload=tls_client_hello,mtproto_initial + --lua-desync=circular:fails=2:time=300:retrans=3:nld=2 + # Strategy 1 + --lua-desync=fake:blob=tls_clienthello:strategy=1" + +NFQWS_ARGS_QUIC="--filter-udp=443 --filter-l7=quic + --payload=quic_initial + --lua-desync=fake:blob=quic_initial:repeats=11" + +NFQWS_ARGS_UDP="--filter-udp=590-600,3478-3481 + --filter-l7=stun + --out-range= Paths { + Paths { + lua: r"C:\z2\lua\".into(), + user: r"C:\s\user.txt".into(), + exclude: r"C:\s\exclude.txt".into(), + auto: r"C:\s\learned\auto.txt".into(), + } + } + + #[test] + fn keenetic_is_read_and_patched_as_upstream_does() { + let s = keenetic(CONF, r"C:\z2\keenetic\").unwrap(); + assert!(s.profiles[0].contains(&format!("blob=0x{}", "0".repeat(128)))); + assert!(s.profiles[0].contains("--out-range=a --in-range=a")); + assert!(s.profiles[1].ends_with(r" --hostlist=C:\z2\keenetic\lists\user.list --hostlist-exclude=C:\z2\keenetic\lists\exclude.list")); + assert!(s.profiles[2].contains(":key=circular_3_1 --in-range=x")); + assert!(!s.profiles[2].contains("# Strategy")); + assert_eq!(s.blob_args[0], r"--blob=quic_initial:@C:\z2\keenetic\blobs\quic_initial.bin"); + assert_eq!((s.tcp_ports.as_str(), s.udp_ports.as_str()), ("80,443,1984", "443,590-600")); + } + + #[test] + fn a_whole_command_line() { + let s = keenetic(CONF, r"C:\z2\keenetic\").unwrap(); + let mut z = Zapret2 { domains: vec!["rutracker.org".into()], ..Default::default() }; + z.ports.extra_tcp = vec![serde_json::json!(8444)]; + let a = args(&z, &s, &paths(), false).unwrap(); + let line = a.join(" "); + assert!(line.starts_with(r"--lua-init=@C:\z2\lua\zapret-lib.lua")); + assert!(line.contains(r"--hostlist-auto=C:\s\learned\auto.txt --hostlist-auto-fail-threshold=3")); + assert!(line.contains(r"--hostlist=C:\s\learned\auto.txt --hostlist-domains=rutracker.org")); + assert!(line.contains("--filter-tcp=443,80,8444")); + assert!(line.contains("--wf-tcp-out=80,443,1984,8444")); + assert!(line.contains("--wf-udp-out=443,590-600,3478-3481")); + assert!(line.contains("--wf-l3=ipv4")); + // circular got the detector's defaults it left unset. + let circ = a.iter().find(|t| t.starts_with("--lua-desync=circular") && t.contains("key=")).unwrap(); + assert!(circ.contains(":maxseq=32768") && circ.contains(":reset") && circ.contains(":retrans=3")); + assert_eq!(circ.matches("retrans=").count(), 1); + assert_eq!(a.iter().filter(|t| *t == "--new").count(), 2); + assert!(!line.contains(" { - self.sup.stop(crate::zapret::UNIT).await; - anyhow::bail!("zapret2 is not supported on Windows yet; use engine \"zapret-discord-youtube\"") + let program = self.comps.program("zapret2", "winws2")?; + let spec = crate::zapret::zapret2_unit(&cfg, self.paths(), program)?; + if cfg.zapret.tcp_timestamps && !self.tcp_timestamps_on { + match crate::zapret::enable_tcp_timestamps().await { + Ok(()) => self.tcp_timestamps_on = true, + Err(e) => self.sup.note(crate::zapret::UNIT, format!("proxy-suite: warning: {e}")), + } + } + self.sup.ensure(spec); + Ok(()) } } } diff --git a/windows/crates/ps-service/src/zapret.rs b/windows/crates/ps-service/src/zapret.rs index f657083..e4079da 100644 --- a/windows/crates/ps-service/src/zapret.rs +++ b/windows/crates/ps-service/src/zapret.rs @@ -125,3 +125,78 @@ pub async fn enable_tcp_timestamps() -> Result<()> { } Ok(()) } + +/// The unit for zapret2: winws2 with nfqws2-keenetic's strategies (ps_core::zapret2), its +/// lists in the service's `zapret2\\` directory, the learned one where winws2 can still write +/// once it runs at Low integrity. +pub fn zapret2_unit(cfg: &Config, paths: &Paths, program: PathBuf) -> Result { + use ps_core::zapret2; + let z = &cfg.zapret.zapret2; + let component = paths.bin().join("zapret2"); + let conf = std::fs::read_to_string(component.join("keenetic").join("nfqws2.conf")).context("reading nfqws2-keenetic's nfqws2.conf")?; + let source = zapret2::keenetic(&conf, &with_sep(&component.join("keenetic"))).map_err(anyhow::Error::msg)?; + + let state = paths.root.join("zapret2"); + let learned = state.join("learned"); + std::fs::create_dir_all(&learned)?; + #[cfg(windows)] + low_integrity(&learned)?; + let user = state.join("zapret-hosts-user.txt"); + let exclude = state.join("zapret-hosts-user-exclude.txt"); + let auto = learned.join("zapret-hosts-auto.txt"); + // nfqws2 refuses a list it cannot open; an empty one is fine. + for f in [&user, &exclude, &auto] { + if !f.exists() { + std::fs::write(f, b"")?; + } + } + let p = zapret2::Paths { + lua: with_sep(&component.join("lua")), + user: user.to_string_lossy().into_owned(), + exclude: exclude.to_string_lossy().into_owned(), + auto: auto.to_string_lossy().into_owned(), + }; + let argv = zapret2::args(z, &source, &p, cfg.debug.zapret2.packets).map_err(anyhow::Error::msg)?; + let generation = { + use sha2::{Digest, Sha256}; + let mut h = Sha256::new(); + for a in &argv { + h.update(a.as_bytes()); + h.update(b"\n"); + } + h.finalize().iter().map(|b| format!("{b:02x}")).collect() + }; + Ok(UnitSpec { name: UNIT.into(), program, args: argv, env: Vec::new(), cwd: Some(component), generation }) +} + +/// A Low mandatory label on `dir`, inherited below it: what a Low-integrity process (winws2, +/// once it runs) may still write to. Its DACL stays as it is. +#[cfg(windows)] +fn low_integrity(dir: &Path) -> Result<()> { + use std::ffi::c_void; + use std::os::windows::ffi::OsStrExt; + use std::ptr::null_mut; + use windows_sys::Win32::Foundation::{ERROR_SUCCESS, LocalFree}; + use windows_sys::Win32::Security::Authorization::{ + ConvertStringSecurityDescriptorToSecurityDescriptorW, SDDL_REVISION_1, SE_FILE_OBJECT, SetNamedSecurityInfoW, + }; + use windows_sys::Win32::Security::{ACL, GetSecurityDescriptorSacl, LABEL_SECURITY_INFORMATION}; + let sddl: Vec = "S:(ML;OICI;NW;;;LW)".encode_utf16().chain(Some(0)).collect(); + let path: Vec = dir.as_os_str().encode_wide().chain(Some(0)).collect(); + let mut sd: *mut c_void = null_mut(); + // SAFETY: NUL-terminated inputs; the SACL points into sd, freed below. + unsafe { + if ConvertStringSecurityDescriptorToSecurityDescriptorW(sddl.as_ptr(), SDDL_REVISION_1, &mut sd, null_mut()) == 0 { + return Err(std::io::Error::last_os_error().into()); + } + let (mut present, mut defaulted) = (0, 0); + let mut sacl: *mut ACL = null_mut(); + GetSecurityDescriptorSacl(sd, &mut present, &mut sacl, &mut defaulted); + let rc = SetNamedSecurityInfoW(path.as_ptr() as *mut u16, SE_FILE_OBJECT, LABEL_SECURITY_INFORMATION, null_mut(), null_mut(), null_mut(), sacl); + LocalFree(sd); + if rc != ERROR_SUCCESS { + return Err(std::io::Error::from_raw_os_error(rc as i32).into()); + } + } + Ok(()) +} diff --git a/windows/tools/winws-dry-run.sh b/windows/tools/winws-dry-run.sh index 6deef09..6f29434 100755 --- a/windows/tools/winws-dry-run.sh +++ b/windows/tools/winws-dry-run.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # Every preset of Flowseal's release, with the arguments and lists the service builds, -# checked by its own winws.exe (`--dry-run`) under Wine. +# checked by its own winws.exe (`--dry-run`) under Wine; then zapret2's command line, by +# winws2.exe. # # nix develop --command nix shell nixpkgs#wineWow64Packages.stable -c tools/winws-dry-run.sh STAGE_DIR set -euo pipefail @@ -10,7 +11,7 @@ REL="$STAGE/zapret" WORK=$(mktemp -d) export WINEPREFIX=${WINEPREFIX:-$WORK/prefix} WINEDEBUG=-all trap 'wineserver -k 2>/dev/null || true; rm -rf "$WORK"' EXIT -cargo build -q -p ps-core --example zapret_args +cargo build -q -p ps-core --example zapret_args --example zapret2_args win() { echo "Z:$(realpath "$1" | sed 's|/|\\|g')\\"; } # The lists as the service writes them: the release's, and the user's placeholders. mkdir -p "$WORK/lists" && cp "$REL"/lists/*.txt "$WORK/lists/" @@ -30,4 +31,14 @@ while IFS= read -r preset; do done done < <(ls "$REL"/*.bat | xargs -n1 -d '\n' basename | grep -vi '^service' | sed 's/\.bat$//') echo "$((n - fail))/$n preset runs verified by winws.exe" + +# zapret2: nfqws2-keenetic's strategies as the service renders them, its lists in place. +Z2="$STAGE/zapret2" +mkdir -p "$WORK/z2/learned" && : > "$WORK/z2/zapret-hosts-user.txt" && : > "$WORK/z2/zapret-hosts-user-exclude.txt" && : > "$WORK/z2/learned/zapret-hosts-auto.txt" +mapfile -t args < <(target/debug/examples/zapret2_args "$Z2" "$(win "$Z2")" "$(win "$WORK/z2")") +if out=$(cd "$Z2" && wine ./winws2.exe --dry-run "${args[@]}" 2>&1) && grep -q "parameters verified" <<<"$out"; then + echo "zapret2: verified by winws2.exe" +else + fail=$((fail + 1)); echo "FAIL: zapret2"; grep -v -i cygwin <<<"$out" | tail -4 +fi [ "$fail" = 0 ]