nx_pe_compile_win_organ.nx
buildroot/runtime/nx_pe_compile_win_organ.nx
about
nx_pe_compile_win_organ.nx -- W3b-6: a realistic organ runs ENTIRELY native (mmap+write+exit).
The milestone: one nxc2-compiled organ that ALLOCATES a buffer (sys_mmap), FILLS it, PRINTS it
(sys_write), and EXITS (sys_exit) -- all three genuine nx_syscalls calls lowered to kernel32 by the
keystone-linker resolving a TABLE of three labels in one PE. 5 imports (GetProcessHeap, HeapAlloc,
GetStdHandle, WriteFile, ExitProcess). No compiler or assembler edits.
sys_mmap shim -> jmp HALLOC_THUNK (29B: GetProcessHeap+HeapAlloc; W3b-5a')
sys_write shim -> jmp WRITE_THUNK (66B: fd-routed GetStdHandle+WriteFile, returns; W3b-4)
sys_exit shim -> jmp EXIT_THUNK (13B: ExitProcess; W3b-2)
.text (raw 0x400) = [entry stub 18][compiled code][HALLOC 29][WRITE 66][EXIT 13]
NO-FALSE-GREEN: source allocates p=sys_mmap(4096), writes p[0..2]={78,88,10}='N','X','\n', then
sys_write(1,p,3), then sys_exit(88). stdout "NX\n" proves the bytes round-tripped through HeapAlloc
memory and WriteFile read them; exit 88 proves sys_exit reached ExitProcess (terminating before the
final `return w+e`). All three syscalls cooperate. Tamper any import -> 0xC0000139.
PIPELINE (build WSL sovereign, run native): src.nx -> nx_compile_x86_native.elf > /tmp/nxwin.s
-> nx_sov_build_run.elf nx_pe_compile_win_organ -> _offc/nx_win_compiled_organ.exe -> run native.
HONEST SCOPE: three syscalls hand-listed (not yet a fully data-driven N-from-spec table); sys_mmap
uses HeapAlloc (benign; VirtualAlloc is Defender-blocked). read/openat remain. This is the
"realistic organ runs native" milestone, not yet a full container-manager. Replicates keystone
assemble (reuses axc_pass; no shared edit). lineage_id: substrate_pe_compile_win_organ_v1
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnxasm_x86.nxnx_pe_writer.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
| 30 | const NXORG_CODE_CAP: i64 = 1048576 |
| 31 | const NXORG_FILE_SIZE: i64 = 0x800 // headers(0x200) + .text(0x400) + .idata(0x200) |
| 32 | const NXORG_STUB_LEN: i64 = 18 |
| 33 | const NXORG_HLEN: i64 = 29 // halloc thunk |
| 34 | const NXORG_WLEN: i64 = 66 // write thunk |
| 35 | const NXORG_ELEN: i64 = 13 // exit thunk |
| 36 | const NXORG_TEXT_CAP: i64 = 0x400 // .text raw region (file 0x200..0x600) |
| 37 | const NXORG_RVA_TEXT: i64 = 0x1000 |
| 38 | const NXORG_RVA_IDATA: i64 = 0x2000 // .text raw 0x400 -> virtual rounds to 0x1000 -> idata at 0x2000 |
| 39 | const NXORG_FOFF_TEXT: i64 = 0x200 |
| 40 | const NXORG_FOFF_IDATA:i64 = 0x600 |
| 41 | const NXORG_IAT_GPH: i64 = 0x2058 |
| 42 | const NXORG_IAT_HA: i64 = 0x2060 |
| 43 | const NXORG_IAT_GSH: i64 = 0x2068 |
| 44 | const NXORG_IAT_WF: i64 = 0x2070 |
| 45 | const NXORG_IAT_EXIT: i64 = 0x2078 |
functions
| 47 | func nxorg_assemble(src: *u8, n: i64, out: *u8, out_cap: i64, p_main: *i64, p_mm: *i64, p_sw: *i64, p_se: *i64) -> i64 |
| 90 | func nxorg_emit_pe(buf: *u8, code: *u8, code_len: i64, main_off: i64, mm_off: i64, sw_off: i64, se_off: i64) -> i64 |
| 247 | func main() -> i64 |