code wiki / _hdl_build / nx_bf_live.nx

nx_bf_live.nx source

↩ module page · 35 lines · 2271 B

1// nx_bf_live.nx -- proves the render-front fetch (browser headers + redirect follow) actually pulls media where 2// the single-mode fetches failed: samplelib 301-redirects (broke the spoof) and Google 403s on UA (broke plain). 3// Run from nxc2 root. argv[1]=url (default = samplelib mp4 that 301'd). license_tier: ORIGINAL 4import "nx_syscalls.nx" 5import "nx_x509_trust_store.nx" 6import "nx_trust_store_load_from_certdata.nx" 7import "nx_csprng.nx" 8import "nx_browser_fetch.nx" 9const K_MAGIC_4194304: i64 = 4194304 10const K_MAGIC_8388608: i64 = 8388608 11const K_MAGIC_100000: i64 = 100000 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://download.samplelib.com/mp4/sample-5s.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("BF-LIVE: certdata load failed\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_bf_live (browser headers + redirect follow) ==\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 = bf_fetch_follow(url, store, cr, pk, sys_now_realtime_sec(), resp, cap, 5) 28 let st: i64 = bf_status(resp, n) 29 let boff: i64 = bf_body_off(resp, n) 30 pw("final status=" as *u8); pn(st); pw(" total bytes=" as *u8); pn(n); pw(" body bytes=" as *u8); pn(n - boff); pw("\n" as *u8) 31 if st == 200 { if (n - boff) > K_MAGIC_100000 { pw("verdict=GREEN (render-front fetch followed the redirect + pulled the media with browser headers)\n" as *u8); sys_exit(0); return 0 } } 32 pw("verdict=RED (did not land media -- may be a hard host needing full browser render)\n" as *u8) 33 sys_exit(0) 34 return 0 35}