code wiki / (root) / nx_shell_research_fetch.nx

nx_shell_research_fetch.nx source

↩ module page · 64 lines · 4209 B

1// nx_shell_research_fetch.nx -- SOVEREIGN researcher: GROUND the nx_shell benchmark in REAL fetched facts about 2// the shell competition (Rule 4). Sources: Bash, Unix shell, Zsh, Fish, PowerShell, the cross-shell comparison, 3// Shellshock (the bash security-surface lesson), GNU coreutils (the EXTERNAL binaries a unix shell depends on for 4// grep/sed/etc -- nx_shell has those IN-PROCESS), and the CLI overview. Mirrors the proven fetcher (sovereign 5// TLS-1.3 + Mozilla CA, idempotent skip-if-have), saves to knowledge/fetched/sh_*.raw. expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_x509_trust_store.nx" 8import "nx_trust_store_load_from_certdata.nx" 9import "nx_https_fetch_follow.nx" 10const K_MAGIC_4194304: i64 = 4194304 11const K_MAGIC_8388608: i64 = 8388608 12 13func df_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 14func df_putn(v: i64) -> i64 { 15 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 16 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 17 let d: *u8 = sys_mmap(24); var k: i64 = 0 18 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 19 var j: i64 = k - 1 20 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 21 return 0 22} 23func have_file(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 24func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 25 if have_file(opath) == 1 { df_puts(opath); df_puts(" [have-skip]\n"); return 1 } 26 let status: *i64 = sys_mmap(8) 27 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 28 df_puts(url); df_puts(" status="); df_putn(status[0]); df_puts(" bytes="); df_putn(n) 29 if n <= 0 { df_puts(" FETCH-FAIL\n"); return 0 } 30 var gz: i64 = 0 31 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 32 if gz == 1 { df_puts(" [GZIP-skip]\n"); return 0 } 33 let fd: i64 = sys_openat_wr(opath, 0x1a4) 34 if fd < 0 { df_puts(" SAVE-FAIL\n"); return 0 } 35 sys_write(fd, out, n); sys_close(fd); df_puts(" SAVED\n"); return 1 36} 37 38func main() -> i64 { 39 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 40 if r <= 0 { df_puts("SHELL: certdata load failed\n"); return 1 } 41 let store: *TrustStore = r as *TrustStore 42 df_puts("CA roots="); df_putn(trust_store_count(store)); df_puts("\n") 43 let cap: i64 = K_MAGIC_8388608 44 let out: *u8 = sys_mmap(cap) 45 var ok: i64 = 0 46 47 df_puts("== the incumbent unix shells (mature, feature-rich = the BENCHMARK) ==\n") 48 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Bash_(Unix_shell)" as *u8, "knowledge/fetched/sh_bash.raw" as *u8, store, out, cap) 49 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Unix_shell" as *u8, "knowledge/fetched/sh_unixshell.raw" as *u8, store, out, cap) 50 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Z_shell" as *u8, "knowledge/fetched/sh_zsh.raw" as *u8, store, out, cap) 51 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Fish_(Unix_shell)" as *u8, "knowledge/fetched/sh_fish.raw" as *u8, store, out, cap) 52 53 df_puts("== the object-shell + the cross-shell comparison ==\n") 54 ok = ok + fetch_save("https://en.wikipedia.org/wiki/PowerShell" as *u8, "knowledge/fetched/sh_powershell.raw" as *u8, store, out, cap) 55 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Comparison_of_command_shells" as *u8, "knowledge/fetched/sh_comparison.raw" as *u8, store, out, cap) 56 57 df_puts("== the SECURITY-SURFACE lesson + the EXTERNAL deps a unix shell needs (we have them in-process) ==\n") 58 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Shellshock_(software_bug)" as *u8, "knowledge/fetched/sh_shellshock.raw" as *u8, store, out, cap) 59 ok = ok + fetch_save("https://en.wikipedia.org/wiki/GNU_Core_Utilities" as *u8, "knowledge/fetched/sh_coreutils.raw" as *u8, store, out, cap) 60 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Command-line_interface" as *u8, "knowledge/fetched/sh_cli.raw" as *u8, store, out, cap) 61 62 df_puts("SHELL RESEARCH SOURCES SAVED: "); df_putn(ok); df_puts(" / 9\n") 63 return 0 64}