code wiki / _hdl_build / nx_jq_test.nx
nx_jq_test.nx source
↩ module page · 42 lines · 2661 B
1// nx_jq_test.nx -- THE decisive VM-compat probe: does nx_js_vm run REAL minified jQuery 3.7.1 to completion?
2// Fetches jquery.min.js, runs it inline FIRST, then a check script fetches https://s/jq-<typeof jQuery>.m3u8.
3// ROUTE=hls jq-function.m3u8 -> jQuery WORKS (javxxx's block is then XHR/ready/player-specific, not the VM)
4// ROUTE=hls jq-undefined.m3u8 -> jQuery ran but set no global (odd)
5// ROUTE=none -> jQuery's source THREW mid-eval (unsupported JS) = the fundamental VM gap
6import "nx_syscalls.nx"
7import "nx_x509_trust_store.nx"
8import "nx_trust_store_load_from_certdata.nx"
9import "nx_video_sniff.nx"
10import "nx_video_sniff_fetch.nx"
11import "nx_surrogate.nx"
12
13func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func tslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
15
16func main() -> i64 {
17 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, 4194304)
18 if r <= 0 { cw("certdata load failed\n" as *u8); sys_exit(1); return 1 }
19 let store: *TrustStore = r as *TrustStore
20 let status: *i64 = sys_mmap(8) as *i64
21 let jq: *u8 = sys_mmap(4194304)
22 let jn: i64 = nx_https_fetch_follow("https://code.jquery.com/jquery-3.7.1.min.js" as *u8, store, jq, 4194304, 6, status)
23 cw("jquery bytes: " as *u8); let nb: *u8 = sys_mmap(32); var d: i64 = 0; var v: i64 = jn; if v==0 { nb[0]=48; d=1 } else { var tmp: *u8 = sys_mmap(32); var t: i64=0; while v>0 { tmp[t]=(48+(v%10)) as u8; v=v/10; t=t+1 } while t>0 { t=t-1; nb[d]=tmp[t]; d=d+1 } } nb[d]=0 as u8; cw(nb); cw("\n" as *u8)
24 if jn <= 0 { cw("(jquery fetch failed)\n" as *u8); return 1 }
25 // html = <script>JQUERY</script><script>CHECK</script>
26 let hcap: i64 = jn + 4096
27 let html: *u8 = sys_mmap(hcap)
28 var o: i64 = 0
29 let s1: *u8 = "<script>fetch('https://s/before.mp4');</script><script>" as *u8; var a: i64=0; while s1[a]!=(0 as u8){html[o]=s1[a];o=o+1;a=a+1}
30 var j: i64 = 0; while j < jn { html[o]=jq[j]; o=o+1; j=j+1 }
31 let s2: *u8 = "</script><script>try{fetch('https://s/jq-'+(typeof jQuery)+'.m3u8');}catch(e){fetch('https://s/jq-threw.m3u8');}</script>" as *u8
32 var b: i64=0; while s2[b]!=(0 as u8){html[o]=s2[b];o=o+1;b=b+1}
33 html[o]=0 as u8
34 let sgt: *i64 = sg_new(); sg_seed(sgt)
35 let preamble: *u8 = sys_mmap(16384)
36 let pre_len: i64 = sg_build_preamble(sgt, preamble, 16384)
37 let empty: *u8 = "" as *u8
38 let plan: *u8 = sys_mmap(2560)
39 vs_sniff_net_bundled(preamble, pre_len, html, o, empty, 0, store, plan, 2560, 3)
40 cw("JQ PLAN: " as *u8); cw(plan); cw("\n" as *u8)
41 return 0
42}