code wiki / _hdl_build / nx_video_sniff_wire_gate.nx

nx_video_sniff_wire_gate.nx source

↩ module page · 80 lines · 5225 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_video_sniff_wire_gate.nx -- proves the LIVE-WIRE logic (minus the TLS GET): (a) extract every external 4// <script src> URL the wire must fetch; (b) assemble inline scripts + the fetched external bundle(s) and 5// guarded-sniff -> download plan. Covers the HARDENED-SPA shape (inline config + external bundle builds the 6// stream URL) and a hostile external bundle (guard-killed). license_tier: ORIGINAL expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_js_eval.nx" 9import "nx_media_jsexec.nx" 10import "nx_video_sniff.nx" 11import "nx_gate_verdict.nx" 12 13func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 14" as *u8); return ok } 15func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 16func plan_has(b: *u8, want: *u8) -> i64 { return mjx_contains(b, gsl(b), want, gsl(want)) } 17 18func run_ss(html: *u8, want_count: i64, want_url: *u8) -> i64 { 19 let out: *u8 = sys_mmap(4096) 20 let c: i64 = vs_extract_script_srcs(html, gsl(html), out, 4096) 21 if c != want_count { gw(" (count=" as *u8); gn(c); gw(" out=[" as *u8); gw(out); gw("])\n" as *u8); return 0 } 22 if want_count > 0 { if plan_has(out, want_url) == 0 { gw(" (url miss out=[" as *u8); gw(out); gw("])\n" as *u8); return 0 } } 23 return 1 24} 25func run_wb(html: *u8, extjs: *u8, want_kind: i64, want_sub: *u8) -> i64 { 26 let planbuf: *u8 = sys_mmap(2560) 27 let k: i64 = vs_sniff_page_bundled(html, gsl(html), extjs, gsl(extjs), planbuf, 2560, 2) 28 if k != want_kind { gw(" (kind=" as *u8); gn(k); gw(" plan=[" as *u8); gw(planbuf); gw("])\n" as *u8); return 0 } 29 if plan_has(planbuf, want_sub) == 0 { gw(" (plan=[" as *u8); gw(planbuf); gw("])\n" as *u8); return 0 } 30 return 1 31} 32 33func main() -> i64 { 34 gw("video-sniff WIRE gate (external <script src> extraction + inline+external bundle assembly -> plan)\n" as *u8) 35 var pass: i64 = 0 36 var ttl: i64 = 0 37 38 // --- external <script src> extraction (what the wire fetches) --- 39 ttl=ttl+1; pass=pass+grow("SS1 src=\"...\" -> 1 external url\x00" as *u8, 40 run_ss("<html><head><script src=\"https://cdn/bundle.js\"></script></head></html>" as *u8, 1, "https://cdn/bundle.js\x00" as *u8)) 41 ttl=ttl+1; pass=pass+grow("SS2 src='...' single-quote -> 1\x00" as *u8, 42 run_ss("<script src='https://cdn/app.js'></script>" as *u8, 1, "https://cdn/app.js\x00" as *u8)) 43 ttl=ttl+1; pass=pass+grow("SS3 inline-only -> 0 external\x00" as *u8, 44 run_ss("<script>var x=1;</script>" as *u8, 0, "-\x00" as *u8)) 45 ttl=ttl+1; pass=pass+grow("SS4 two external + one inline -> 2\x00" as *u8, 46 run_ss("<script src=\"https://cdn/a.js\"></script><script>z</script><script src=\"https://cdn/b.js\"></script>" as *u8, 2, "https://cdn/a.js\x00" as *u8)) 47 ttl=ttl+1; pass=pass+grow("SS5 <SCRIPT SRC> uppercase -> 1\x00" as *u8, 48 run_ss("<SCRIPT SRC=\"https://cdn/upper.js\"></SCRIPT>" as *u8, 1, "https://cdn/upper.js\x00" as *u8)) 49 ttl=ttl+1; pass=pass+grow("SS6 src after type= attr -> 1\x00" as *u8, 50 run_ss("<script type=\"module\" src=\"https://cdn/mod.js\"></script>" as *u8, 1, "https://cdn/mod.js\x00" as *u8)) 51 ttl=ttl+1; pass=pass+grow("SS7 &amp; entity decoded to & in src\x00" as *u8, 52 run_ss("<script src=\"https://cdn/load.php?a=1&amp;b=2\"></script>" as *u8, 1, "load.php?a=1&b=2\x00" as *u8)) 53 // --- inline + external bundle ASSEMBLY (the hardened-SPA shape) --- 54 // WB1: inline HTML sets the config; the EXTERNAL bundle builds the stream URL from it -> combined works. 55 ttl=ttl+1; pass=pass+grow("WB1 inline config + external bundle builds URL -> hls\x00" as *u8, 56 run_wb("<script>var cdn='https://c/'; var vid='WB1';</script>" as *u8, 57 "fetch(cdn+vid+'/master.m3u8');" as *u8, 58 VSK_HLS, "https://c/WB1/master.m3u8\x00" as *u8)) 59 // WB2: external bundle alone builds a direct URL (no inline). 60 ttl=ttl+1; pass=pass+grow("WB2 external bundle only -> direct\x00" as *u8, 61 run_wb("<html><body></body></html>" as *u8, 62 "fetch('https://c/direct/movie.mp4');" as *u8, 63 VSK_DIRECT, "https://c/direct/movie.mp4\x00" as *u8)) 64 // WB3: HOSTILE external bundle -> guard-killed (the guard covers external code, not just inline). 65 ttl=ttl+1; pass=pass+grow("WB3 hostile external bundle -> guard-killed\x00" as *u8, 66 run_wb("<script>var a=1;</script>" as *u8, 67 "while(true){a=a+1;}" as *u8, 68 VSK_KILLED, "guard-killed\x00" as *u8)) 69 70 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 71 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 72 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 73 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 74 let ctr__dry: *i64 = gv_ctr() 75 ctr__dry[0] = pass 76 ctr__dry[1] = ttl 77 let rc__dry: i64 = gv_verdict("VIDEO-SNIFF-WIRE-GATE" as *u8, ctr__dry, "wire logic: external src list + inline+external assembly + guard, all proven)" as *u8) 78 sys_exit(rc__dry) 79 return rc__dry 80}