code wiki / (root) / nx_pe_compile_win_organ.nx

nx_pe_compile_win_organ.nx

buildroot/runtime/nx_pe_compile_win_organ.nx

16146 B284 linesdepth 4pulls 6 transitivereach 0 importersview sourcekind tooltopic pe
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nxasm_x86.nx nx_pe_writer.nx nx_pe_compile_win_organ.nx

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

main sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close nxorg_assemble sys_mmap ↻ axc_pass axc_is_space axc_is_ident axc_apply_section axc_tok_is axc_cstr_len axc_is_space ↻ axc_is_ident ↻ axc_tok_is ↻ axc_emit_bytes axc_is_digit axc_parse_int axc_is_digit ↻ axc_parse_operand axc_is_space ↻ axc_is_ident ↻ axc_reg_num axc_tok_is ↻ axc_parse_int ↻ axc_is_digit ↻ axc_tok_is ↻ axc_emit axc_tok_is ↻ axc_alu x86_alu_imm x86_rex_w x86_modrm x86_put_u32le x86_alu_rr x86_rex_w ↻

structs

none

consts

30const NXORG_CODE_CAP: i64 = 1048576
31const NXORG_FILE_SIZE: i64 = 0x800 // headers(0x200) + .text(0x400) + .idata(0x200)
32const NXORG_STUB_LEN: i64 = 18
33const NXORG_HLEN: i64 = 29 // halloc thunk
34const NXORG_WLEN: i64 = 66 // write thunk
35const NXORG_ELEN: i64 = 13 // exit thunk
36const NXORG_TEXT_CAP: i64 = 0x400 // .text raw region (file 0x200..0x600)
37const NXORG_RVA_TEXT: i64 = 0x1000
38const NXORG_RVA_IDATA: i64 = 0x2000 // .text raw 0x400 -> virtual rounds to 0x1000 -> idata at 0x2000
39const NXORG_FOFF_TEXT: i64 = 0x200
40const NXORG_FOFF_IDATA:i64 = 0x600
41const NXORG_IAT_GPH: i64 = 0x2058
42const NXORG_IAT_HA: i64 = 0x2060
43const NXORG_IAT_GSH: i64 = 0x2068
44const NXORG_IAT_WF: i64 = 0x2070
45const NXORG_IAT_EXIT: i64 = 0x2078

functions

47func nxorg_assemble(src: *u8, n: i64, out: *u8, out_cap: i64, p_main: *i64, p_mm: *i64, p_sw: *i64, p_se: *i64) -> i64
90func nxorg_emit_pe(buf: *u8, code: *u8, code_len: i64, main_off: i64, mm_off: i64, sw_off: i64, se_off: i64) -> i64
247func main() -> i64