code wiki / _hdl_build / nx_roku_emit_gate.nx
nx_roku_emit_gate.nx source
↩ module page · 97 lines · 6293 B
1// nx_roku_emit_gate.nx -- SOVEREIGN liar-kill gate for nx_roku_emit (R0 of the Roku media-app arc). Drives the
2// REAL /tmp/nx_roku_emit.sov.elf to emit a channel zip to a test path, then re-proves it ENTIRELY within Nishi
3// (no python) via our own opc_read_part / raw-zip inspection:
4// STRUCTURE : valid ZIP (PK\x03\x04) carrying all 4 channel parts (manifest, source/main.brs,
5// components/MainScene.xml, images/icon.png)
6// CONTENT : manifest is the real Roku manifest (title=Nishi + ui_resolutions=hd); main.brs is the SceneGraph
7// entry (roSGScreen); icon.png carries a valid PNG signature
8// LIAR-KILL : reading a part that does NOT exist returns <0 (the reader can't false-positive)
9// GREEN iff 10/10. Requires /tmp/nx_roku_emit.sov.elf (build nx_roku_emit first). Durable
10// knowledge/status/roku_emit_gate.log. license_tier: ORIGINAL
11import "nx_syscalls.nx"
12import "nx_gate_emit_lib.nx"
13import "nx_opc.nx"
14
15func g_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); 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{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
16func g_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
17func g_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; let t: *u8=sys_mmap(28); 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{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 }
18func g_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
19func g_read(path: *u8, buf: *u8, cap: i64) -> i64 {
20 let fd: i64=sys_openat_rd(path); if fd<0 { return 0 }
21 var total: i64=0; var nrd: i64=sys_read(fd, buf, cap)
22 while nrd>0 { total=total+nrd; if total>=cap { nrd=0 } else { nrd=sys_read(fd, ((buf as i64)+total) as *u8, cap-total) } }
23 sys_close(fd); return total
24}
25func g_contains(hay: *u8, n: i64, needle: *u8) -> i64 {
26 let nl: i64=g_strlen(needle); if nl==0 { return 0 }
27 var i: i64=0
28 while i+nl<=n { var j: i64=0; var hit: i64=1; while j<nl { if hay[i+j]!=needle[j] { hit=0; j=nl } else { j=j+1 } } if hit==1 { return 1 } i=i+1 }
29 return 0
30}
31func g_check(label: *u8, ok: i64) -> i64 { g_puts(label); if ok==1 { g_puts(" PASS\n" as *u8); return 1 } g_puts(" FAIL\n" as *u8); return 0 }
32func g_run(elf: *u8, args: *i64, nargs: i64, out_path: *u8) -> i64 {
33 let pid: i64=sys_fork()
34 if pid==0 {
35 let o: i64=sys_openat_wr(out_path, 0x1a4); if o>=0 { sys_dup3(o,1,0) }
36 let argv: *i64=sys_mmap(8*16) as *i64
37 argv[0]=elf as i64
38 var i: i64=0; while i<nargs { argv[1+i]=args[i]; i=i+1 } argv[1+nargs]=0
39 let envp: *i64=sys_mmap(16) as *i64; envp[0]="PATH=/usr/bin:/bin" as *u8 as i64; envp[1]=0
40 sys_execve(elf, argv, envp); sys_exit(127)
41 }
42 let st: *i64=sys_mmap(16) as *i64; sys_wait4(pid, st, 0); return (st[0]>>8)&0xff
43}
44
45func main() -> i64 {
46 g_puts("=== ROKU EMIT GATE: sovereign re-proof of the channel package (no python) ===\n" as *u8)
47 let EMIT: *u8="/tmp/nx_roku_emit.sov.elf" as *u8
48 let ZIP: *u8="/tmp/roku_gate.zip" as *u8
49 let scr: *u8="/tmp/roku_gate_scratch.txt" as *u8
50 let a: *i64=sys_mmap(8*8) as *i64
51
52 // drive the real emit organ to a test path
53 a[0]=ZIP as i64
54 g_run(EMIT, a, 1, scr)
55
56 // raw zip bytes for structure + part-name presence
57 let zbuf: *u8=sys_mmap(262144)
58 let zn: i64=g_read(ZIP, zbuf, 262144)
59
60 var zmagic: i64=0
61 if zn>=4 { if zbuf[0]==(0x50 as u8) { if zbuf[1]==(0x4b as u8) { if zbuf[2]==(0x03 as u8) { if zbuf[3]==(0x04 as u8) { zmagic=1 } } } } }
62
63 // materialize parts via our own sovereign reader
64 let mbuf: *u8=sys_mmap(8192)
65 let mn: i64=opc_read_part(ZIP, "manifest" as *u8, mbuf, 8192)
66 let bbuf: *u8=sys_mmap(8192)
67 let bn: i64=opc_read_part(ZIP, "source/main.brs" as *u8, bbuf, 8192)
68 let pbuf: *u8=sys_mmap(262144)
69 let pn: i64=opc_read_part(ZIP, "images/icon.png" as *u8, pbuf, 262144)
70 let xbuf: *u8=sys_mmap(64)
71 let xn: i64=opc_read_part(ZIP, "does/not/exist" as *u8, xbuf, 64)
72
73 var pngsig: i64=0
74 if pn>=8 { if pbuf[0]==(0x89 as u8) { if pbuf[1]==(0x50 as u8) { if pbuf[2]==(0x4e as u8) { if pbuf[3]==(0x47 as u8) { pngsig=1 } } } } }
75
76 var pass: i64=0; let rows: i64=10
77 pass=pass+g_check(" R1 valid ZIP (PK\\x03\\x04)" as *u8, zmagic)
78 pass=pass+g_check(" R2 part: manifest" as *u8, g_contains(zbuf,zn,"manifest" as *u8))
79 pass=pass+g_check(" R3 part: source/main.brs" as *u8, g_contains(zbuf,zn,"source/main.brs" as *u8))
80 pass=pass+g_check(" R4 part: components/MainScene.xml" as *u8, g_contains(zbuf,zn,"components/MainScene.xml" as *u8))
81 pass=pass+g_check(" R5 part: images/icon.png" as *u8, g_contains(zbuf,zn,"images/icon.png" as *u8))
82 var m_title: i64=0; if mn>0 { m_title=g_contains(mbuf,mn,"title=Nishi" as *u8) }
83 pass=pass+g_check(" R6 manifest -> title=Nishi" as *u8, m_title)
84 var m_res: i64=0; if mn>0 { m_res=g_contains(mbuf,mn,"ui_resolutions=hd" as *u8) }
85 pass=pass+g_check(" R7 manifest -> ui_resolutions=hd" as *u8, m_res)
86 var b_sg: i64=0; if bn>0 { b_sg=g_contains(bbuf,bn,"roSGScreen" as *u8) }
87 pass=pass+g_check(" R8 main.brs -> SceneGraph entry (roSGScreen)" as *u8, b_sg)
88 pass=pass+g_check(" R9 icon.png -> valid PNG signature" as *u8, pngsig)
89 var negok: i64=0; if xn<0 { negok=1 }
90 pass=pass+g_check(" R10 liar-kill: unknown part returns <0" as *u8, negok)
91
92 g_puts("----\nROKU-EMIT rows=" as *u8); g_num(rows); g_puts(" pass=" as *u8); g_num(pass); g_puts(" zipbytes=" as *u8); g_num(zn); g_puts("\n" as *u8)
93 let lg: i64=sys_openat_append("knowledge/status/roku_emit_gate.log" as *u8, 0x1a4)
94 if lg>=0 { g_w(lg, "ROKU-EMIT rows=" as *u8); g_wn(lg, rows); g_w(lg, " pass=" as *u8); g_wn(lg, pass); if pass==rows { g_w(lg, " verdict=GREEN\n" as *u8) } else { g_w(lg, " verdict=RED\n" as *u8) } sys_close(lg) }
95 if pass==rows { g_puts("ROKU-EMIT GREEN (sovereign channel package proven without python)\n" as *u8); sys_exit(0); return 0 }
96 g_puts("ROKU-EMIT RED\n" as *u8); sys_exit(1); return 1
97}