code wiki / _hdl_build / _h2_probe_imgsearch_ua.nx

_h2_probe_imgsearch_ua.nx source

↩ module page · 84 lines · 5247 B

1// _h2_probe_imgsearch_ua.nx -- MEASUREMENT PROBE (no-wave): does a REAL desktop 2// User-Agent on the sovereign h2 GET get past google image-search's JS wall to the 3// results HTML (which embeds the first image batch as JSON in <script>)? The prior 4// probe sent NO UA and hit the "enable JavaScript / update your browser" interstitial. 5// This sends an identified Chrome UA via h2_tls_get_ua (HPACK static idx 58) and 6// reports :status + body sample so we can SEE results-vs-wall. No nghttp2/curl/python. 7import "nx_x509_trust_store.nx" 8import "nx_trust_store_load_from_certdata.nx" 9import "nx_tls13_client_validate_certificate.nx" 10import "nx_tls13_client_h2run.nx" 11import "nx_https_url_for_fetch.nx" 12import "nx_https_url_connect.nx" 13import "nx_h2_client_over_tls.nx" 14 15func _pu_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 16func _pu_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 } 17func _pu_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 18 19// count non-overlapping occurrences of a needle in buf[0:len]. 20func _pu_count(buf: *u8, len: i64, needle: *u8) -> i64 { 21 let nl: i64 = _pu_strlen(needle) 22 if nl == 0 { return 0 } 23 var c: i64 = 0 24 var i: i64 = 0 25 while i + nl <= len { 26 var j: i64 = 0 27 var hit: i64 = 1 28 while j < nl { if (buf[i + j] & 0xff) != (needle[j] & 0xff) { hit = 0; j = nl } else { j = j + 1 } } 29 if hit == 1 { c = c + 1; i = i + nl } else { i = i + 1 } 30 } 31 return c 32} 33 34func pu_fetch_ua(store: *TrustStore, path: *u8, ua: *u8) -> i64 { 35 _pu_puts("\n--- GET " as *u8); _pu_puts(path); _pu_puts(" (with desktop UA)\n" as *u8) 36 let url_p: *NxUrl = nx_url_new() 37 let target_raw: *u8 = sys_mmap(64); let target: *NxHttpsTarget = target_raw as *NxHttpsTarget 38 target.url = url_p; target.port = 0 39 let urlbuf: *u8 = sys_mmap(256) 40 nx_str_cpy(urlbuf, "https://www.google.com/" as *u8) 41 if nx_https_url_for_fetch(urlbuf, target) != NX_HTTPS_URL_OK { _pu_puts(" url parse FAIL\n" as *u8); return 0-3 } 42 let fd_p: *i64 = sys_mmap(16) as *i64 43 if nx_https_url_connect(target, urlbuf, sys_now_realtime_sec(), fd_p) != NX_HTTPS_CONNECT_OK { _pu_puts(" connect FAIL\n" as *u8); return 0-4 } 44 let cfd: i64 = fd_p[0] 45 let vc_raw: *u8 = sys_mmap(64); let vc: *TlsValidationContext = vc_raw as *TlsValidationContext 46 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() 47 let cr2: *u8 = sys_mmap(32); var ei: i64=0; while ei<32 { cr2[ei]=(0xC0+ei) as u8; ei=ei+1 } 48 let priv2: *u8 = sys_mmap(32); ei=0; while ei<32 { priv2[ei]=(0xA0+ei) as u8; ei=ei+1 } 49 let sr: i64 = nx_tls13_client_session_run_h2(cfd, urlbuf + target.url.host_off, target.url.host_len, cr2, priv2, vc) 50 if sr <= 0 { _pu_puts(" h2 handshake FAIL rc=" as *u8); _pu_num(sr); _pu_puts("\n" as *u8); sys_close(cfd); return 0-5 } 51 let session: *Tls13ClientSession = sr as *Tls13ClientSession 52 let pl: i64 = _pu_strlen(path) 53 let ual: i64 = _pu_strlen(ua) 54 let body: *u8 = sys_mmap(1048576) 55 let st: *i64 = sys_mmap(16) as *i64 56 let bl: i64 = h2_tls_get_ua(session, cfd, urlbuf + target.url.host_off, target.url.host_len, path, pl, ua, ual, body, 1048576, st) 57 sys_close(cfd) 58 _pu_puts(" :status=" as *u8); _pu_num(st[0]); _pu_puts(" total_body=" as *u8); _pu_num(bl); _pu_puts("\n" as *u8) 59 var cap: i64 = bl 60 if cap > 1048576 { cap = 1048576 } 61 // SIGNAL DETECTORS: wall markers vs real image-result markers. 62 _pu_puts(" signals: enablejs=" as *u8); _pu_num(_pu_count(body, cap, "enablejs\x00" as *u8)) 63 _pu_puts(" 'not supported'=" as *u8); _pu_num(_pu_count(body, cap, "supported\x00" as *u8)) 64 _pu_puts(" 'https://encrypted-tbn'=" as *u8); _pu_num(_pu_count(body, cap, "encrypted-tbn\x00" as *u8)) 65 _pu_puts(" 'data:image'=" as *u8); _pu_num(_pu_count(body, cap, "data:image\x00" as *u8)) 66 _pu_puts(" '\"ou\":'(img-json)=" as *u8); _pu_num(_pu_count(body, cap, "[\"http\x00" as *u8)) 67 _pu_puts("\n" as *u8) 68 var show: i64 = cap 69 if show > 1200 { show = 1200 } 70 if show > 0 { _pu_puts(" body[0:" as *u8); _pu_num(show); _pu_puts("]=" as *u8); sys_write(1, body, show); _pu_puts("\n" as *u8) } 71 return st[0] 72} 73 74func main() -> i64 { 75 _pu_puts("=== h2 imgsearch probe WITH desktop User-Agent (no-wave measure) ===\n" as *u8) 76 let r: i64 = nx_trust_store_load_from_certdata("/tmp/mozilla_certdata.txt" as *u8, 512, 4194304) 77 if r <= 0 { _pu_puts(" trust store FAIL\n" as *u8); sys_exit(2); return 2 } 78 let store: *TrustStore = r as *TrustStore 79 let ua: *u8 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36\x00" 80 // legacy tbm=isch 302-redirects (with a UA) to the modern udm=2 image vertical; 81 // fetch the redirect target directly. 82 pu_fetch_ua(store, "/search?q=kitten&hl=en&gl=us&udm=2\x00" as *u8, ua) 83 sys_exit(0); return 0 84}