code wiki / _hdl_build / nx_video_sniff_cli.nx
nx_video_sniff_cli.nx source
↩ module page · 43 lines · 2633 B
1// nx_video_sniff_cli.nx -- the LIVE peak: `nx_video_sniff <page-url>`. Fetches a video page over sovereign
2// TLS-1.3 (Mozilla CA), pulls its inline scripts + fetches its external <script src> bundles (relative
3// resolved), then runs the whole thing through the GUARDED sniff (CPU/mem-capped child -> hostile JS can't
4// hang) and prints a DOWNLOAD PLAN that routes the runtime-discovered stream URL to the X-DLP engine
5// (.m3u8 -> nx_hls_get incl AES-128; .mp4 -> nx_video_get). Reuses the proven research-fetch TLS stack +
6// nx_hls_resolve_uri + the gated nx_video_sniff logic. Smoke-test on LEGAL content only. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_x509_trust_store.nx"
9import "nx_trust_store_load_from_certdata.nx"
10import "nx_video_sniff.nx"
11import "nx_video_sniff_fetch.nx"
12const K_MAGIC_4194304: i64 = 4194304
13const K_MAGIC_2560: i64 = 2560
14
15func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
16func cslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
17
18func main(argc: i64, argv: *i64) -> i64 {
19 if argc < 2 { cw("usage: nx_video_sniff <page-url>\n" as *u8); sys_exit(2); return 2 }
20 let url: *u8 = argv[1] as *u8
21 let ulen: i64 = cslen(url)
22
23 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
24 if r <= 0 { cw("SNIFF: certdata load failed (run from nxc2 root)\n" as *u8); sys_exit(1); return 1 }
25 let store: *TrustStore = r as *TrustStore
26
27 cw("== nx_video_sniff ==\npage: " as *u8); cw(url); cw("\n" as *u8)
28
29 // fetch page + external bundles + guarded sniff -- SHARED with the API daemon (vsf_sniff_url).
30 let planbuf: *u8 = sys_mmap(K_MAGIC_2560)
31 let kind: i64 = vsf_sniff_url(url, ulen, store, planbuf, K_MAGIC_2560, 5)
32 cw("\n--- DOWNLOAD PLAN ---\n" as *u8)
33 cw(planbuf); cw("\n" as *u8)
34 let jbuf: *u8 = sys_mmap(K_MAGIC_2560) // API-shaped result (what a /media/sniff route returns)
35 vs_result_json(kind, planbuf, jbuf, K_MAGIC_2560)
36 cw("json: " as *u8); cw(jbuf); cw("\n" as *u8)
37 if kind == VSK_KILLED { cw("(the page's JS was runaway/hostile -- guard killed it; no stream captured)\n" as *u8) }
38 if kind == VSK_HLS { cw("route: nx_hls_get <URL> out.ts (master/variant + #EXT-X-KEY AES-128 + TS->fMP4)\n" as *u8) }
39 if kind == VSK_DIRECT { cw("route: nx_video_get <URL> out.mp4\n" as *u8) }
40 if kind == VSK_NONE { cw("(no stream URL surfaced from the page's runtime JS -- may need multi-round real-network capture, or the URL is server-signed/DRM'd)\n" as *u8) }
41 sys_exit(0)
42 return 0
43}