code wiki / (root) / nx_fetch_dump.nx

nx_fetch_dump.nx source

↩ module page · 28 lines · 1796 B

1// nx_fetch_dump.nx -- diagnostic: fetch a URL over validated TLS and dump the raw body to a file, 2// so we can see WHAT a Cloudflare-protected site (javdb) actually returns (challenge vs real page). 3// argv[1]=url argv[2]=outpath. license_tier: ORIGINAL 4import "nx_https_get.nx" 5import "nx_x509_trust_store.nx" 6import "nx_pem_loader.nx" 7import "nx_csprng.nx" 8import "nx_syscalls.nx" 9const K_MAGIC_16777216: i64 = 16777216 10 11func fd_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 12func fd_wn(fd: i64, v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; if m<0 { sys_write(fd,"-" as *u8,1); m=0-m } 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} let b: *u8=sys_mmap(28); var i: i64=0; while i<k {b[i]=t[k-1-i];i=i+1} sys_write(fd,b,k); return 0 } 13 14func main(argc: i64, argv: *i64) -> i64 { 15 var url: *u8 = "https://example.com/" as *u8 16 if argc >= 2 { url = argv[1] as *u8 } 17 var outpath: *u8 = "/mnt/c/Users/elder/Downloads/nishi-torrents/_dump.html" as *u8 18 if argc >= 3 { outpath = argv[2] as *u8 } 19 let store: *TrustStore = trust_store_alloc(400) 20 let nroots: i64 = nx_pem_trust_load_file("/etc/ssl/certs/ca-certificates.crt\x00", store) 21 if nroots <= 0 { fd_w(1, "no-ca\n" as *u8); sys_exit(1); return 1 } 22 let cr: *u8 = sys_mmap(32); let pk: *u8 = sys_mmap(32); nx_csprng_fill(cr, 32); nx_csprng_fill(pk, 32) 23 let cap: i64 = K_MAGIC_16777216; let resp: *u8 = sys_mmap(cap) 24 let n: i64 = nx_https_get(url, cr, pk, store, sys_now_realtime_sec(), resp, cap) 25 fd_w(1, "FETCH n=" as *u8); fd_wn(1, n); fd_w(1, "\n" as *u8) 26 if n > 0 { let fd: i64 = sys_openat_wr(outpath, 0x1a4); if fd>=0 { sys_write(fd, resp, n); sys_close(fd) } } 27 sys_exit(0); return 0 28}