code wiki / (root) / nx_pe_compile_win_sw.nx

nx_pe_compile_win_sw.nx

buildroot/runtime/nx_pe_compile_win_sw.nx

12579 B229 linesdepth 4pulls 6 transitivereach 0 importersview sourcekind tooltopic pe
docsdependenciesstructsconstsfunctions

about

nx_pe_compile_win_sw.nx -- W3b-4: an organ's REAL sys_write reaches WriteFile, fd-routed. W3b-3 (nx_pe_compile_win_write) proved a CUSTOM shim (nx_win_write) reaches WriteFile. This rung redirects the GENUINE nx_syscalls name `sys_write` -- VERIFIED the compiler emits a direct `call sys_write` (SysV rdi=fd, rsi=buf, rdx=n), the same redirectable label as any function. So an organ that calls the real `sys_write(fd, buf, n)` prints natively on Windows, with fd routed to the correct console handle (1->STD_OUTPUT, 2->STD_ERROR). No compiler or assembler edits. thunk (SysV in: rdi=fd, rsi=buf, rdx=n): sub rsp, 0x38 mov [rsp+0x30], rdx ; save n (rdx MS-x64 VOLATILE) mov ecx, -11 ; default STD_OUTPUT_HANDLE cmp edi, 2 / jne +5 / mov ecx, -12 ; fd==2 -> STD_ERROR_HANDLE call [rip+GetStdHandle] ; rax=handle; rsi(buf) survives (MS-x64 non-volatile) mov rcx, rax / mov rdx, rsi / mov r8,[rsp+0x30] / lea r9,[rsp+0x28] / mov qword[rsp+0x20],0 call [rip+WriteFile] add rsp, 0x38 / ret NO-FALSE-GREEN: an organ defining the canonical `sys_write` (body = __syscall(64,...), overwritten) and calling sys_write(FD, "...", N). FD=1 -> the bytes land on STDOUT (stderr empty); FD=2 -> on STDERR (stdout empty). Capturing the two streams separately proves the fd arg routes the handle (a hardcoded-stdout thunk would fail FD=2). Tamper (corrupt WriteFile import) -> 0xC0000139. PIPELINE (build WSL sovereign, run native): src.nx -> ./_offc/nx_compile_x86_native.elf <src> > /tmp/nxwin.s -> ./_offc/nx_sov_build_run.elf nx_pe_compile_win_sw (reads /tmp/nxwin.s) -> _offc/nx_win_compiled_sw.exe -> run native on Windows 11. HONEST SCOPE: redirecting sys_write makes WRITE-to-console work for an organ's genuine sys_write call. A full I/O organ also calls sys_mmap/sys_exit/sys_read/etc. -- those still emit Linux `syscall` (dead on Windows) and need the same label-redirect (if bodied) or a syscall-dispatch layer. So this is NOT yet "any organ runs"; it is "the real sys_write name lowers to WriteFile, fd-routed". Proven with a local sys_write definition; the imported nx_syscalls.sys_write is the SAME label -> same redirect. Replicates keystone assemble (reuses axc_pass; no shared-assembler edit). lineage_id: substrate_pe_compile_win_sw_v1

dependencies 3 imports · 0 importers

nx_syscalls.nx nxasm_x86.nx nx_pe_writer.nx nx_pe_compile_win_sw.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 nxsw_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

41const NXSW_CODE_CAP: i64 = 1048576
42const NXSW_FILE_SIZE: i64 = 0x800
43const NXSW_STUB_LEN: i64 = 18
44const NXSW_THUNK_LEN: i64 = 66 // fd-routed GetStdHandle+WriteFile returning thunk
45const NXSW_TEXT_CAP: i64 = 0x200
46const NXSW_RVA_TEXT: i64 = 0x1000
47const NXSW_RVA_RDATA: i64 = 0x2000
48const NXSW_RVA_IDATA: i64 = 0x3000
49const NXSW_FOFF_TEXT: i64 = 0x200
50const NXSW_FOFF_RDATA:i64 = 0x400
51const NXSW_FOFF_IDATA:i64 = 0x600
52const NXSW_IAT_GSH: i64 = 0x3048
53const NXSW_IAT_WF: i64 = 0x3050
54const NXSW_IAT_EXIT: i64 = 0x3058

functions

57func nxsw_assemble(src: *u8, n: i64, out: *u8, out_cap: i64, p_main: *i64, p_sw: *i64) -> i64
94func nxsw_emit_pe(buf: *u8, code: *u8, code_len: i64, main_off: i64, sw_off: i64) -> i64
200func main() -> i64