code wiki / _hdl_build / nx_elara_ref_fetch.nx

nx_elara_ref_fetch.nx source

↩ module page · 47 lines · 2446 B

1// nx_elara_ref_fetch.nx -- pull the operator's TARGET Elara reference (nishi gallery) over OUR TLS client, 2// save the raw image bytes to knowledge/elara_ref.dat, and print status + size + magic so we know the codec. 3// The critic's grounding: score OUR render against THIS real target, not just abstract axes. expect_exit: 0 4import "nx_syscalls.nx" 5import "nx_x509_trust_store.nx" 6import "nx_trust_store_load_from_certdata.nx" 7import "nx_https_fetch_follow.nx" 8const K_MAGIC_4194304: i64 = 4194304 9const K_MAGIC_8388608: i64 = 8388608 10 11func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 12func wn(v: i64) -> i64 { 13 let b: *u8 = sys_mmap(28); var m: i64 = v 14 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } 15 let t: *u8 = sys_mmap(28); var k: i64 = 0 16 if m == 0 { t[0] = 48 as u8; k = 1 } 17 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 18 var i: i64 = 0; while i < k { b[i] = t[k - 1 - i]; i = i + 1 } 19 sys_write(1, b, k); return 0 20} 21func whex(v: i64) -> i64 { 22 let d: *u8 = "0123456789abcdef" as *u8 23 let o: *u8 = sys_mmap(4) 24 o[0] = d[(v / 16) % 16]; o[1] = d[v % 16] 25 sys_write(1, o, 2); return 0 26} 27 28func main() -> i64 { 29 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 30 if r <= 0 { w("STORE-FAIL (need data/mozilla_certdata.txt)\n" as *u8); return 1 } 31 let store: *TrustStore = r as *TrustStore 32 let cap: i64 = K_MAGIC_8388608 33 let raw: *u8 = sys_mmap(cap) 34 let st: *i64 = (sys_mmap(8)) as *i64 35 let n: i64 = nx_https_fetch_follow("https://nishifamily.com/gallery/img/nxc1-269974504bacf259fd06601cbb50cda0e13500987569bb2f4b9d443d8e50a6cc" as *u8, store, raw, cap, 6, st) 36 w("status=" as *u8); wn(st[0]); w(" body_bytes=" as *u8); wn(n); w(" magic=" as *u8) 37 if n >= 4 { whex(raw[0] as i64); whex(raw[1] as i64); whex(raw[2] as i64); whex(raw[3] as i64) } 38 w("\n" as *u8) 39 if n <= 0 { w("FETCH-EMPTY (auth-gated? status above)\n" as *u8); return 1 } 40 let fd: i64 = sys_openat_wr("/mnt/c/Users/elder/nishi-core/nxc2/knowledge/elara_ref.dat" as *u8, 420) 41 if fd < 0 { w("OPEN-FAIL\n" as *u8); return 1 } 42 var wr: i64 = 0 43 while wr < n { let c: i64 = sys_write(fd, raw + wr, n - wr); if c <= 0 { break } wr = wr + c } 44 sys_close(fd) 45 w("wrote " as *u8); wn(wr); w(" bytes -> knowledge/elara_ref.dat\n" as *u8) 46 return 0 47}