code wiki / _hdl_build / nx_mobi_book_gate.nx

nx_mobi_book_gate.nx source

↩ module page · 87 lines · 5650 B

1// nx_mobi_book_gate.nx -- liar-kill gate for the sovereign MOBI/AZW reader. Builds the DRM-free fixture + 2// a DRM-flagged variant, then asserts: 3// DECODE : a DRM-FREE MOBI -> book.json (title+author from EXTH, format=mobi) + chap0.txt (PalmDOC-decompressed 4// real prose) -- i.e. a purchased book LIBERATED from the lock-in container into the Nishi format. 5// DECLINE: a DRM-flagged MOBI -> exit 2 (detected + DECLINED, NOT circumvented -- the legal line). 6// GREEN = we read DRM-free Kindle books on our own device, and refuse DRM rather than break it. expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_gate_verdict.nx" 9 10func xp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func xn(v0: i64) -> i64 { var v: i64=v0; if v<0 { sys_write(1,"-" as *u8,1); v=0-v } let b: *u8=sys_mmap(24); var k: i64=0; if v==0 {b[0]=48 as u8;k=1} while v>0 {b[k]=(48+(v%10)) as u8; v=v/10; k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k {o[j]=b[k-1-j];j=j+1} sys_write(1,o,k); return 0 } 12func xslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 13 14func spawn(path: *u8, a0: *u8, a1: *u8, redir: *u8) -> i64 { 15 let pid: i64 = sys_fork() 16 if pid == 0 { 17 let fd: i64 = sys_openat_wr(redir, 420) 18 if fd >= 0 { sys_dup3(fd, 1, 0); sys_dup3(fd, 2, 0) } 19 let argv: *i64 = sys_mmap(64) as *i64 20 var n: i64 = 0 21 argv[0] = path as i64; n = 1 22 if (a0 as i64) != 0 { argv[n] = a0 as i64; n = n + 1 } 23 if (a1 as i64) != 0 { argv[n] = a1 as i64; n = n + 1 } 24 argv[n] = 0 25 let envp: *i64 = sys_mmap(16) as *i64 26 envp[0] = "PATH=/usr/bin:/bin\x00" as *u8 as i64; envp[1] = 0 27 sys_execve(path, argv, envp) 28 sys_exit(127) 29 } 30 let st: *i64 = sys_mmap(16) as *i64 31 sys_wait4(pid, st, 0) 32 return (st[0] >> 8) & 0xff 33} 34 35func xfind(hay: *u8, hl: i64, needle: *u8) -> i64 { 36 let nl: i64 = xslen(needle); if nl == 0 { return 0-1 } 37 var i: i64 = 0 38 while i + nl <= hl { var k: i64=0; var hit: i64=1; while k<nl { if hay[i+k]!=needle[k]{hit=0;k=nl}else{k=k+1} } if hit==1 {return i} i=i+1 } 39 return 0-1 40} 41func xhas(hay: *u8, hl: i64, needle: *u8) -> i64 { if xfind(hay, hl, needle) >= 0 { return 1 } return 0 } 42 43func main() -> i64 { 44 xp("=== nx_mobi_book_gate: sovereign MOBI/AZW reader (decode DRM-free, DECLINE DRM) ===\n" as *u8) 45 let RUNNER: *u8 = "_offc/nx_sov_build_run.elf\x00" as *u8 46 let SCRATCH: *u8 = "knowledge/status/mobi_gate_scratch.log\x00" as *u8 47 48 spawn(RUNNER, "nx_mobi_fixture_build\x00" as *u8, 0 as *u8, SCRATCH) // build DRM-free + DRM-flagged fixtures 49 let rc_ok: i64 = spawn(RUNNER, "nx_mobi_book\x00" as *u8, 0 as *u8, SCRATCH) // rebuild+refresh _offc + decode the DRM-free default 50 51 let lj: *i64 = sys_mmap(8) as *i64; lj[0]=0 52 let bj: *u8 = sys_read_file("knowledge/staging/media/reader/nishi_mobi_fixture/book.json\x00" as *u8, lj) 53 let bn: i64 = lj[0] 54 let lc: *i64 = sys_mmap(8) as *i64; lc[0]=0 55 let ct: *u8 = sys_read_file("knowledge/staging/media/reader/nishi_mobi_fixture/chap0.txt\x00" as *u8, lc) 56 let cn: i64 = lc[0] 57 58 // DRM-flagged variant must be DECLINED (exit 2), never decoded 59 let rc_drm: i64 = spawn("_offc/nx_mobi_book.elf\x00" as *u8, "knowledge/fixtures/nishi_mobi_drm.mobi\x00" as *u8, "nishi_mobi_drm\x00" as *u8, SCRATCH) 60 61 if (bj as i64) == 0 { xp("MOBI-GATE verdict=RED reason=book.json-missing\n" as *u8); sys_exit(1); return 1 } 62 xp(" book.json (" as *u8); xn(bn); xp(" B): " as *u8); sys_write(1, bj, bn); xp("\n" as *u8) 63 xp(" rc_decode=" as *u8); xn(rc_ok); xp(" rc_drm=" as *u8); xn(rc_drm); xp(" chap0_bytes=" as *u8); xn(cn); xp("\n" as *u8) 64 65 var pass: i64 = 0; var fail: i64 = 0 66 if rc_ok == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL decode-nonzero-exit\n" as *u8) } 67 if xhas(bj, bn, "\"format\":\"mobi\"" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; xp(" FAIL not-mobi-format\n" as *u8) } 68 if xhas(bj, bn, "\"title\":\"The Liberation of Alice\"" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; xp(" FAIL title-not-from-EXTH\n" as *u8) } 69 if xhas(bj, bn, "\"author\":\"Lewis Carroll\"" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; xp(" FAIL author-not-from-EXTH\n" as *u8) } 70 // PalmDOC decompressed real prose into chap0.txt 71 if (ct as i64) != 0 { if xhas(ct, cn, "Alice was beginning to get very tired" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; xp(" FAIL prose-not-decompressed\n" as *u8) } } else { fail=fail+1; xp(" FAIL chap0-missing\n" as *u8) } 72 if xhas(ct, cn, "White Rabbit" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; xp(" FAIL prose-truncated\n" as *u8) } 73 if cn > 200 { pass=pass+1 } else { fail=fail+1; xp(" FAIL chap-too-short\n" as *u8) } 74 // THE legal line: DRM detected + declined (exit 2), not circumvented 75 if rc_drm == 2 { pass=pass+1 } else { fail=fail+1; xp(" FAIL drm-not-declined(rc=" as *u8); xn(rc_drm); xp(")\n" as *u8) } 76 77 xp("MOBI-GATE pass=" as *u8); xn(pass); xp(" fail=" as *u8); xn(fail) 78 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 79 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 80 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 81 let ctr__dry: *i64 = gv_ctr() 82 ctr__dry[0] = pass 83 ctr__dry[1] = pass + fail 84 let rc__dry: i64 = gv_verdict("MOBI-BOOK-GATE" as *u8, ctr__dry, "DRM-free MOBI liberated to Nishi format; DRM detected + declined, not circumvented)" as *u8) 85 sys_exit(rc__dry) 86 return rc__dry 87}