code wiki / _hdl_build / nx_jq_locate.nx

nx_jq_locate.nx source

↩ module page · 38 lines · 2523 B

1// nx_jq_locate.nx -- find the EXACT construct where our parser rejects minified jQuery. Fetches jquery.min.js, 2// parses it RAW, and on PST_ERR prints the error token's source offset + the surrounding bytes -> identify+fix the 3// next parser gap directly (no guessing). Repeat (fix -> re-run) until "PARSED OK" -> then jQuery runs. 4import "nx_syscalls.nx" 5import "nx_x509_trust_store.nx" 6import "nx_trust_store_load_from_certdata.nx" 7import "nx_video_sniff.nx" 8import "nx_video_sniff_fetch.nx" 9const K_MAGIC_4194304: i64 = 4194304 10 11func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12func cn(v0: i64) -> i64 { let nb: *u8 = sys_mmap(32); var d: i64=0; var v: i64=v0; if v==0 { nb[0]=48; d=1 } else { let 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); return 0 } 13 14func main() -> i64 { 15 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 16 if r <= 0 { cw("certdata load failed\n" as *u8); sys_exit(1); return 1 } 17 let store: *TrustStore = r as *TrustStore 18 let status: *i64 = sys_mmap(8) as *i64 19 let jq: *u8 = sys_mmap(K_MAGIC_4194304) 20 let jn: i64 = nx_https_fetch_follow("https://code.jquery.com/jquery-3.7.1.min.js" as *u8, store, jq, K_MAGIC_4194304, 6, status) 21 cw("jquery bytes: " as *u8); cn(jn); cw("\n" as *u8) 22 if jn <= 0 { cw("(fetch failed)\n" as *u8); return 1 } 23 let ctxbox: *i64 = sys_mmap(16) as *i64 24 let prog: i64 = jp_parse_source(jq, jn, ctxbox) 25 let ctx: *i64 = (ctxbox[0]) as *i64 26 if (ctx as i64) == 0 { cw("ctx NULL (lex/parse aborted early)\n" as *u8); return 1 } 27 let pst: *i64 = jp_pst(ctx) 28 if pst[PST_ERR] != 1 { cw("PARSED OK (no PST_ERR) -- jQuery parses! next: run it.\n" as *u8); return 0 } 29 let off: i64 = jp_err_pos(ctx) // src offset recorded at the FIRST error (reliable; jp_cur advances during recovery) 30 cw("PARSE FAIL: src_offset=" as *u8); cn(off); cw(" of " as *u8); cn(jn); cw("\n" as *u8) 31 var s: i64 = off - 14; if s < 0 { s = 0 } 32 var e: i64 = off + 34; if e > jn { e = jn } 33 cw("[EXACT ERROR TOKEN starts right after the " as *u8); cn(off - s); cw("-char prefix]\n" as *u8) 34 cw("--- context [" as *u8); cn(s); cw(".." as *u8); cn(e); cw("] ---\n" as *u8) 35 sys_write(1, ((jq as i64) + s) as *u8, e - s) 36 cw("\n--- (^ the construct near src_offset is the next parser gap) ---\n" as *u8) 37 return 0 38}