code wiki / _hdl_build / _h2_probe_imgsearch.nx

_h2_probe_imgsearch.nx source

↩ module page · 58 lines · 3985 B

1// _h2_probe_imgsearch.nx -- MEASUREMENT PROBE (ten-second-tool, NOT a deliverable; 2// mirrors _h2_fetch_google). The cookieless /search?tbm=isch GET returns 200 but 3// google's "enable JavaScript" interstitial (/httpservice/retry/enablejs) -- so the 4// results are JS-rendered, NOT a cookie/consent wall. This probe now measures the 5// NO-JS google endpoints (gbv=1 basic HTML, asearch=ichunk async image fragment, 6// udm=2 modern vertical) to see which, if any, yields PARSEABLE image results 7// without a JS engine. Fresh TLS+ALPN-h2 connection per path. No nghttp2/curl/python. 8import "nx_x509_trust_store.nx" 9import "nx_trust_store_load_from_certdata.nx" 10import "nx_tls13_client_validate_certificate.nx" 11import "nx_tls13_client_h2run.nx" 12import "nx_https_url_for_fetch.nx" 13import "nx_https_url_connect.nx" 14import "nx_h2_client_over_tls.nx" 15 16func _pi_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 17func _pi_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 } 18func _pi_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 19 20// One full connect -> TLS1.3+ALPN-h2 -> GET path -> report :status/body sample. 21func pi_fetch(store: *TrustStore, label: *u8, path: *u8) -> i64 { 22 _pi_puts("\n--- " as *u8); _pi_puts(label); _pi_puts(" : GET " as *u8); _pi_puts(path); _pi_puts("\n" as *u8) 23 let url_p: *NxUrl = nx_url_new() 24 let target_raw: *u8 = sys_mmap(64); let target: *NxHttpsTarget = target_raw as *NxHttpsTarget 25 target.url = url_p; target.port = 0 26 let urlbuf: *u8 = sys_mmap(256) 27 nx_str_cpy(urlbuf, "https://www.google.com/" as *u8) 28 if nx_https_url_for_fetch(urlbuf, target) != NX_HTTPS_URL_OK { _pi_puts(" url parse FAIL\n" as *u8); return 0-3 } 29 let fd_p: *i64 = sys_mmap(16) as *i64 30 if nx_https_url_connect(target, urlbuf, sys_now_realtime_sec(), fd_p) != NX_HTTPS_CONNECT_OK { _pi_puts(" connect FAIL\n" as *u8); return 0-4 } 31 let cfd: i64 = fd_p[0] 32 let vc_raw: *u8 = sys_mmap(64); let vc: *TlsValidationContext = vc_raw as *TlsValidationContext 33 vc.store = store; vc.sni_host = urlbuf + target.url.host_off; vc.sni_host_len = target.url.host_len; vc.now_epoch = sys_now_realtime_sec() 34 let cr2: *u8 = sys_mmap(32); var ei: i64=0; while ei<32 { cr2[ei]=(0xC0+ei) as u8; ei=ei+1 } 35 let priv2: *u8 = sys_mmap(32); ei=0; while ei<32 { priv2[ei]=(0xA0+ei) as u8; ei=ei+1 } 36 let sr: i64 = nx_tls13_client_session_run_h2(cfd, urlbuf + target.url.host_off, target.url.host_len, cr2, priv2, vc) 37 if sr <= 0 { _pi_puts(" h2 handshake FAIL rc=" as *u8); _pi_num(sr); _pi_puts("\n" as *u8); sys_close(cfd); return 0-5 } 38 let session: *Tls13ClientSession = sr as *Tls13ClientSession 39 let pl: i64 = _pi_strlen(path) 40 let body: *u8 = sys_mmap(1048576) 41 let st: *i64 = sys_mmap(16) as *i64 42 let bl: i64 = h2_tls_get(session, cfd, urlbuf + target.url.host_off, target.url.host_len, path, pl, body, 1048576, st) 43 sys_close(cfd) 44 _pi_puts(" :status=" as *u8); _pi_num(st[0]); _pi_puts(" total_body=" as *u8); _pi_num(bl); _pi_puts("\n" as *u8) 45 var show: i64 = bl 46 if show > 16000 { show = 16000 } 47 if show > 0 { _pi_puts(" body[0:" as *u8); _pi_num(show); _pi_puts("]=" as *u8); sys_write(1, body, show); _pi_puts("\n" as *u8) } 48 return st[0] 49} 50 51func main() -> i64 { 52 _pi_puts("=== h2 imgsearch NO-JS endpoint probe (cookieless) ===\n" as *u8) 53 let r: i64 = nx_trust_store_load_from_certdata("/tmp/mozilla_certdata.txt" as *u8, 512, 4194304) 54 if r <= 0 { _pi_puts(" trust store FAIL\n" as *u8); sys_exit(2); return 2 } 55 let store: *TrustStore = r as *TrustStore 56 pi_fetch(store, "gbv1-isch-full" as *u8, "/search?q=kitten&tbm=isch&hl=en&gl=us&gbv=1\x00" as *u8) 57 sys_exit(0); return 0 58}