code wiki / _hdl_build / nx_browser_fetch_probe.nx
nx_browser_fetch_probe.nx source
↩ module page · 38 lines · 2320 B
1// nx_browser_fetch_probe.nx -- proves the render-front header fix: fetch a URL that bot-blocked our plain client
2// (Google's video bucket 403'd nx_https_fetch_follow) using nx_https_get_spoof (real Firefox UA + browser Accept
3// headers). If it now returns 200 + the media bytes, presenting as a browser is what beats the block -- the
4// keystone for capturing media from hosts that reject non-browser clients. Run from nxc2 root. ORIGINAL
5import "nx_syscalls.nx"
6import "nx_x509_trust_store.nx"
7import "nx_trust_store_load_from_certdata.nx"
8import "nx_csprng.nx"
9import "nx_https_get_spoof.nx"
10const K_MAGIC_4194304: i64 = 4194304
11const K_MAGIC_8388608: i64 = 8388608
12
13func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func pn(v: i64) -> i64 { let b: *u8=sys_mmap(24); var m: i64=v; if m<0{pw("-" as *u8);m=0-m} let t: *u8=sys_mmap(24); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
15
16func main(argc: i64, argv: *i64) -> i64 {
17 var url: *u8 = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4" as *u8
18 if argc >= 2 { url = argv[1] as *u8 }
19 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
20 if r <= 0 { pw("BFP: certdata load failed (run from nxc2 root)\n" as *u8); sys_exit(1); return 1 }
21 let store: *TrustStore = r as *TrustStore
22 let cr: *u8 = sys_mmap(32); let pk: *u8 = sys_mmap(32); nx_csprng_fill(cr, 32); nx_csprng_fill(pk, 32)
23
24 pw("== nx_browser_fetch_probe (browser-spoof GET) ==\nurl: " as *u8); pw(url); pw("\n" as *u8)
25 let cap: i64 = K_MAGIC_8388608
26 let resp: *u8 = sys_mmap(cap)
27 let n: i64 = nx_https_get_spoof(url, cr, pk, store, sys_now_realtime_sec(), "" as *u8, 0, resp, cap)
28 pw("bytes=" as *u8); pn(n); pw("\n" as *u8)
29 if n > 0 {
30 pw("status line: " as *u8)
31 var i: i64 = 0
32 while i < 40 { if i < n { if (resp[i]&0xff) == 13 { i = 40 } else { sys_write(1, ((resp as i64)+i) as *u8, 1); i = i + 1 } } else { i = 40 } }
33 pw("\n" as *u8)
34 }
35 pw("== 200 + megabytes = browser-spoof beat the 403 (render front unblocks media) ==\n" as *u8)
36 sys_exit(0)
37 return 0
38}