nx_lib_pmc_fetch.nx source
↩ module page · 40 lines · 1846 B
1// nx_lib_pmc_fetch.nx -- pull the NCBI PoW interstitial + the pow.js algorithm
2// to disk (over sovereign TLS-1.3) so the challenge scheme can be reverse-
3// engineered and solved. Diagnostic step 1 of the PMC PoW solver.
4import "nx_syscalls.nx"
5import "nx_lib_fetch.nx"
6const K_MAGIC_16777216: i64 = 16777216
7
8func pf_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
9func pf_putn(v: i64) -> i64 {
10 let bb: *u8 = sys_mmap(28); var m: i64 = v
11 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) }
12 let t: *u8 = sys_mmap(28); var k: i64 = 0
13 if m == 0 { t[0] = 48 as u8; k = 1 }
14 while m > 0 { t[k] = (48 + (m - (m/10)*10)) as u8; m = m / 10; k = k + 1 }
15 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
16}
17
18func fetch_to_file(store: *TrustStore, url: *u8, path: *u8) -> i64 {
19 let cap: i64 = K_MAGIC_16777216
20 let buf: *u8 = sys_mmap(cap)
21 let gc: i64 = nx_lib_fetch(store, url, buf, cap)
22 if gc < 0 { return gc }
23 let fd: i64 = sys_openat_wr(path, 0x1A4)
24 if fd <= 0 { return 0 - 99 }
25 sys_write(fd, buf, gc)
26 sys_close(fd)
27 return gc
28}
29
30func main() -> i64 {
31 let store: *TrustStore = nx_lib_fetch_store()
32 if store == 0 as *TrustStore { pf_puts("no CA store\n"); return 1 }
33
34 let g1: i64 = fetch_to_file(store, "https://pmc.ncbi.nlm.nih.gov/articles/PMC7197042/pdf/CD004504.pdf\x00" as *u8, "knowledge/fetched/pmc_pow.html\x00" as *u8)
35 pf_puts("pmc interstitial bytes="); pf_putn(g1); pf_puts("\n")
36
37 let g2: i64 = fetch_to_file(store, "https://cdn.ncbi.nlm.nih.gov/pmc/pd-medc-pmc-cloudpmc-viewer/production/674d4f95/var/data/static/assets/pow-o51sQKbL.js\x00" as *u8, "knowledge/fetched/pow.js\x00" as *u8)
38 pf_puts("pow.js bytes="); pf_putn(g2); pf_puts("\n")
39 return 0
40}