code wiki / _hdl_build / nx_video_sniff_wire_gate.nx

nx_video_sniff_wire_gate.nx source

↩ module page · 72 lines · 4838 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" 11 12func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 13" as *u8); return ok } 14func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 15func plan_has(b: *u8, want: *u8) -> i64 { return mjx_contains(b, gsl(b), want, gsl(want)) } 16 17func run_ss(html: *u8, want_count: i64, want_url: *u8) -> i64 { 18 let out: *u8 = sys_mmap(4096) 19 let c: i64 = vs_extract_script_srcs(html, gsl(html), out, 4096) 20 if c != want_count { gw(" (count=" as *u8); gn(c); gw(" out=[" as *u8); gw(out); gw("])\n" as *u8); return 0 } 21 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 } } 22 return 1 23} 24func run_wb(html: *u8, extjs: *u8, want_kind: i64, want_sub: *u8) -> i64 { 25 let planbuf: *u8 = sys_mmap(2560) 26 let k: i64 = vs_sniff_page_bundled(html, gsl(html), extjs, gsl(extjs), planbuf, 2560, 2) 27 if k != want_kind { gw(" (kind=" as *u8); gn(k); gw(" plan=[" as *u8); gw(planbuf); gw("])\n" as *u8); return 0 } 28 if plan_has(planbuf, want_sub) == 0 { gw(" (plan=[" as *u8); gw(planbuf); gw("])\n" as *u8); return 0 } 29 return 1 30} 31 32func main() -> i64 { 33 gw("video-sniff WIRE gate (external <script src> extraction + inline+external bundle assembly -> plan)\n" as *u8) 34 var pass: i64 = 0 35 var ttl: i64 = 0 36 37 // --- external <script src> extraction (what the wire fetches) --- 38 ttl=ttl+1; pass=pass+grow("SS1 src=\"...\" -> 1 external url\x00" as *u8, 39 run_ss("<html><head><script src=\"https://cdn/bundle.js\"></script></head></html>" as *u8, 1, "https://cdn/bundle.js\x00" as *u8)) 40 ttl=ttl+1; pass=pass+grow("SS2 src='...' single-quote -> 1\x00" as *u8, 41 run_ss("<script src='https://cdn/app.js'></script>" as *u8, 1, "https://cdn/app.js\x00" as *u8)) 42 ttl=ttl+1; pass=pass+grow("SS3 inline-only -> 0 external\x00" as *u8, 43 run_ss("<script>var x=1;</script>" as *u8, 0, "-\x00" as *u8)) 44 ttl=ttl+1; pass=pass+grow("SS4 two external + one inline -> 2\x00" as *u8, 45 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)) 46 ttl=ttl+1; pass=pass+grow("SS5 <SCRIPT SRC> uppercase -> 1\x00" as *u8, 47 run_ss("<SCRIPT SRC=\"https://cdn/upper.js\"></SCRIPT>" as *u8, 1, "https://cdn/upper.js\x00" as *u8)) 48 ttl=ttl+1; pass=pass+grow("SS6 src after type= attr -> 1\x00" as *u8, 49 run_ss("<script type=\"module\" src=\"https://cdn/mod.js\"></script>" as *u8, 1, "https://cdn/mod.js\x00" as *u8)) 50 ttl=ttl+1; pass=pass+grow("SS7 &amp; entity decoded to & in src\x00" as *u8, 51 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)) 52 // --- inline + external bundle ASSEMBLY (the hardened-SPA shape) --- 53 // WB1: inline HTML sets the config; the EXTERNAL bundle builds the stream URL from it -> combined works. 54 ttl=ttl+1; pass=pass+grow("WB1 inline config + external bundle builds URL -> hls\x00" as *u8, 55 run_wb("<script>var cdn='https://c/'; var vid='WB1';</script>" as *u8, 56 "fetch(cdn+vid+'/master.m3u8');" as *u8, 57 VSK_HLS, "https://c/WB1/master.m3u8\x00" as *u8)) 58 // WB2: external bundle alone builds a direct URL (no inline). 59 ttl=ttl+1; pass=pass+grow("WB2 external bundle only -> direct\x00" as *u8, 60 run_wb("<html><body></body></html>" as *u8, 61 "fetch('https://c/direct/movie.mp4');" as *u8, 62 VSK_DIRECT, "https://c/direct/movie.mp4\x00" as *u8)) 63 // WB3: HOSTILE external bundle -> guard-killed (the guard covers external code, not just inline). 64 ttl=ttl+1; pass=pass+grow("WB3 hostile external bundle -> guard-killed\x00" as *u8, 65 run_wb("<script>var a=1;</script>" as *u8, 66 "while(true){a=a+1;}" as *u8, 67 VSK_KILLED, "guard-killed\x00" as *u8)) 68 69 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 70 if pass == ttl { gw("verdict=GREEN (wire logic: external src list + inline+external assembly + guard, all proven)\n" as *u8); sys_exit(0); return 0 } 71 gw("verdict=RED\n" as *u8); sys_exit(1); return 1 72}