code wiki / _hdl_build / nx_mobi_book.nx

nx_mobi_book.nx

buildroot/runtime/_hdl_build/nx_mobi_book.nx

16854 B305 linesdepth 5pulls 10 transitivereach 0 importersview sourcekind tooltopic mobi
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_itoa_lib.nx nx_palmdoc.nx nx_huffcdic.nx nx_html_to_text.nx nx_mobi_cover.nx nx_chapter_split.nx nx_charset.nx nx_mobi_book.nx

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

main do_mobi sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close mb_p mb_w sys_write mb_slen be16 be32 mb_pn mb_n nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap sys_exit huff_load hc_be32 cdic_load hc_be32 ↻ hc_be16 palmdoc_decompress hc_unpack sys_mmap ↻ hc_be64 hc_unpack ↻ find_sub mb_slen ↻ exth_copy nx_html_to_text nx_html_to_text_x h2t_state_new sys_mmap ↻

structs

none

consts

17const K_MAGIC_1252: i64 = 1252
18const K_MAGIC_17480: i64 = 17480
19const K_MAGIC_262144: i64 = 262144
20const K_MAGIC_1024: i64 = 1024
21const K_MAGIC_8192: i64 = 8192
131const MCAP: i64 = 16777216

functions

23func mb_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 3: mb_wfind_subdo_mobi
24func mb_w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, mb_slen(s)); return 0 }
called by 2: mb_pdo_mobi calls 2: sys_writemb_slen
29func mb_n(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: mb_pn calls 1: nxi_fd
30func mb_p(s: *u8) -> i64 { mb_w(1, s); return 0 }
called by 2: do_mobimain calls 1: mb_w
31func mb_pn(v: i64) -> i64 { mb_n(1, v); return 0 }
called by 1: do_mobi calls 1: mb_n
32func ensure_dir(path: *u8) -> i64 { __syscall(258, 0-100, path, 0x1ed, 0, 0, 0); return 0 }
called by 1: do_mobi
34func be16(b: *u8, o: i64) -> i64 { return ((b[o] as i64) << 8) | (b[o+1] as i64) }
called by 1: do_mobi
35func 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
37func find_sub(hay: *u8, hl: i64, needle: *u8) -> i64
called by 2: extract_h1do_mobi calls 1: mb_slen
44func extract_h1(html: *u8, hl: i64, out: *u8, cap: i64) -> i64
calls 1: find_sub
64func 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
65func 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
68func er_wjson(fd: i64, s: *u8) -> i64
86func utf8_put(out: *u8, o: i64, cp: i64) -> i64
called by 1: decode_numeric_refs
92func decode_numeric_refs(txt: *u8, n: i64, out: *u8, outcap: i64) -> i64
called by 1: do_mobi calls 1: utf8_put
122func exth_copy(z: *u8, p: i64, rlen: i64, out: *u8, cap: i64) -> i64
called by 1: do_mobi
133func do_mobi(path: *u8, slug: *u8) -> i64
298func main(argc: i64, argv: *i64) -> i64