code wiki / _hdl_build / nx_video_sniff_gate.nx
nx_video_sniff_gate.nx source
↩ module page · 64 lines · 4527 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_video_sniff_gate.nx -- proves the discovery->download bridge: run a JS-hardened video page, capture the
4// stream URLs its obfuscated code builds, rank them, and emit the right X-DLP download route. license_tier: ORIGINAL expect_exit: 0
5import "nx_syscalls.nx"
6import "nx_js_eval.nx"
7import "nx_media_jsexec.nx"
8import "nx_video_sniff.nx"
9
10func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
11" as *u8); return ok }
12func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
13func plan_has(planbuf: *u8, want: *u8) -> i64 { return mjx_contains(planbuf, gsl(planbuf), want, gsl(want)) }
14
15// run vs_sniff on `js`; pass iff returned kind == want_kind AND the plan contains both want_route and want_url.
16func run_vs(js: *u8, want_kind: i64, want_route: *u8, want_url: *u8) -> i64 {
17 let listbuf: *u8 = sys_mmap(4096)
18 let planbuf: *u8 = sys_mmap(2560)
19 let k: i64 = vs_sniff(js, gsl(js), listbuf, 4096, planbuf, 2560)
20 if k != want_kind { gw(" (kind=" as *u8); gn(k); gw(" plan=[" as *u8); gw(planbuf); gw("])\n" as *u8); return 0 }
21 if plan_has(planbuf, want_route) == 0 { gw(" (route miss, plan=[" as *u8); gw(planbuf); gw("])\n" as *u8); return 0 }
22 if plan_has(planbuf, want_url) == 0 { gw(" (url miss, plan=[" as *u8); gw(planbuf); gw("])\n" as *u8); return 0 }
23 return 1
24}
25
26func main() -> i64 {
27 gw("video-sniff SOVEREIGN gate (run hardened page JS -> capture stream URL -> rank -> X-DLP route)\n" as *u8)
28 var pass: i64 = 0
29 var ttl: i64 = 0
30
31 // VS1: obfuscated page builds the HLS master at runtime + also fetches a segment + a poster; the MASTER
32 // must win (a manifest gets all qualities+segments; the lone .ts and the image are not the target).
33 ttl=ttl+1; pass=pass+grow("VS1 runtime master.m3u8 beats segment+poster -> route=hls\x00" as *u8,
34 run_vs("function m(id){return 'https://cdn/'+id+'/master.m3u8';} var v='X7'; fetch(m(v)); fetch('https://cdn/X7/seg1.ts'); fetch('https://cdn/X7/poster.jpg');" as *u8,
35 VSK_HLS, "ROUTE=hls\x00" as *u8, "https://cdn/X7/master.m3u8\x00" as *u8))
36 // VS2: only a direct file -> route=direct (nx_video_get).
37 ttl=ttl+1; pass=pass+grow("VS2 direct .mp4 -> route=direct\x00" as *u8,
38 run_vs("var u='https://cdn/'+'movie'+'.mp4'; fetch(u);" as *u8,
39 VSK_DIRECT, "ROUTE=direct\x00" as *u8, "https://cdn/movie.mp4\x00" as *u8))
40 // VS3: manifest AND direct present -> manifest wins (all qualities).
41 ttl=ttl+1; pass=pass+grow("VS3 .m3u8 present beats .mp4 -> route=hls\x00" as *u8,
42 run_vs("fetch('https://c/index.m3u8'); fetch('https://c/fallback.mp4');" as *u8,
43 VSK_HLS, "ROUTE=hls\x00" as *u8, "https://c/index.m3u8\x00" as *u8))
44 // VS4: DASH manifest -> honestly routed dash-todo (nx_hls_get is HLS-only).
45 ttl=ttl+1; pass=pass+grow("VS4 .mpd -> route=dash-todo (honest: not yet downloadable)\x00" as *u8,
46 run_vs("fetch('https://c/manifest.mpd');" as *u8,
47 VSK_DASH, "ROUTE=dash-todo\x00" as *u8, "https://c/manifest.mpd\x00" as *u8))
48 // VS5: images only, no video -> no target (route=none). The sniffer is video-focused, not noisy.
49 ttl=ttl+1; pass=pass+grow("VS5 images only -> route=none\x00" as *u8,
50 run_vs("fetch('https://c/thumb.jpg'); fetch('https://c/logo.png');" as *u8,
51 VSK_NONE, "ROUTE=none\x00" as *u8, "URL=-\x00" as *u8))
52 // VS6: SIGNED/tokened manifest built at runtime -> captured WITH its token, routed hls.
53 ttl=ttl+1; pass=pass+grow("VS6 signed ?token m3u8 -> route=hls, token preserved\x00" as *u8,
54 run_vs("var t='?token=abc123&e=999'; fetch('https://cdn/vid/master.m3u8'+t);" as *u8,
55 VSK_HLS, "ROUTE=hls\x00" as *u8, "master.m3u8?token=abc123\x00" as *u8))
56 // VS7: a bare segment with NO manifest -> honestly flagged segment-only (can't stitch without the playlist).
57 ttl=ttl+1; pass=pass+grow("VS7 bare .ts, no manifest -> route=segment-only\x00" as *u8,
58 run_vs("fetch('https://cdn/only_seg.ts');" as *u8,
59 VSK_SEGMENT, "ROUTE=segment-only\x00" as *u8, "https://cdn/only_seg.ts\x00" as *u8))
60
61 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8)
62 if pass == ttl { gw("verdict=GREEN (hardened page -> sniff runtime stream URL -> ranked X-DLP download route)\n" as *u8); sys_exit(0); return 0 }
63 gw("verdict=RED\n" as *u8); sys_exit(1); return 1
64}