code wiki / _hdl_build / nx_mobi_book.nx
nx_mobi_book.nx
buildroot/runtime/_hdl_build/nx_mobi_book.nx
about
nx_mobi_book.nx -- SOVEREIGN MOBI/AZW (Kindle) -> Nishi format. Operator goal: read your OWN purchased books on
your OWN device, freed from the lock-in container. Parses the PDB database + PalmDOC-decompresses the text +
reads EXTH metadata, then reuses the SAME pipeline as the EPUB reader (nx_html_to_text -> book.json + chap.txt)
so the zero-JS reader renders it unchanged.
LEGAL LINE: this DECODES the FORMAT (interoperability). It DETECTS the MOBI encryptionType flag and DECLINES
DRM-encrypted files (exit 2) -- it does NOT circumvent DRM. DRM-FREE purchases/side-loads/library books decode.
Rung 1: whole book -> one chapter (readable); HUFF/CDIC compression + KF8/AZW3 + pagebreak chapter-splitting are
next rungs. Usage: nx_mobi_book <mobi-path> <slug>. expect_exit: 0 license_tier: ORIGINAL
dependencies 8 imports · 0 importers
imports: nx_syscalls.nxnx_itoa_lib.nxnx_palmdoc.nxnx_huffcdic.nxnx_html_to_text.nxnx_mobi_cover.nxnx_chapter_split.nxnx_charset.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 17 | const K_MAGIC_1252: i64 = 1252 |
| 18 | const K_MAGIC_17480: i64 = 17480 |
| 19 | const K_MAGIC_262144: i64 = 262144 |
| 20 | const K_MAGIC_1024: i64 = 1024 |
| 21 | const K_MAGIC_8192: i64 = 8192 |
| 131 | const MCAP: i64 = 16777216 |
functions
| 23 | func mb_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 24 | func mb_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, mb_slen(s)); return 0 } |
| 29 | func mb_n(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } |
| 30 | func mb_p(s: *u8) -> i64 { mb_w(1, s); return 0 } |
| 31 | func mb_pn(v: i64) -> i64 { mb_n(1, v); return 0 } |
| 32 | func ensure_dir(path: *u8) -> i64 { __syscall(258, 0-100, path, 0x1ed, 0, 0, 0); return 0 } called by 1: do_mobi |
| 34 | func be16(b: *u8, o: i64) -> i64 { return ((b[o] as i64) << 8) | (b[o+1] as i64) } called by 1: do_mobi |
| 35 | func be32(b: *u8, o: i64) -> i64 { return ((b[o] as i64) << 24) | ((b[o+1] as i64) << 16) | ((b[o+2] as i64) << 8) | (b[o+3] as i64) } called by 1: do_mobi |
| 37 | func find_sub(hay: *u8, hl: i64, needle: *u8) -> i64 |
| 44 | func extract_h1(html: *u8, hl: i64, out: *u8, cap: i64) -> i64 calls 1: find_sub |
| 64 | func er_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){dst[off+i]=s[i];i=i+1} return off+i } called by 1: do_mobi |
| 65 | func er_catn(dst: *u8, off: i64, v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; 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}; var i: i64=0; while i<k{dst[off+i]=t[k-1-i];i=i+1} return off+k } calls 1: sys_mmap |
| 68 | func er_wjson(fd: i64, s: *u8) -> i64 |
| 86 | func utf8_put(out: *u8, o: i64, cp: i64) -> i64 called by 1: decode_numeric_refs |
| 92 | func decode_numeric_refs(txt: *u8, n: i64, out: *u8, outcap: i64) -> i64 |
| 122 | func exth_copy(z: *u8, p: i64, rlen: i64, out: *u8, cap: i64) -> i64 called by 1: do_mobi |
| 133 | func do_mobi(path: *u8, slug: *u8) -> i64 |
| 298 | func main(argc: i64, argv: *i64) -> i64 |