nx_pe_natbw.nx
buildroot/runtime/nx_pe_natbw.nx
about
nx_pe_natbw.nx -- GENERAL sovereign native-Windows PE emitter.
Wraps a /tmp/nxwin.s (from the FULL compiler _offc/nx_compile_x86.elf, which
supports func types/pointers) into a native .exe, bridging Linux syscalls to
kernel32 by PATCHING the shim entries (jmp -> thunk). Dynamic linker-style
layout (.text raw = roundup(VirtualSize,0x1000) so .idata is contiguous).
HAL bridged (8 kernel32 imports):
sys_mmap -> VirtualAlloc(NULL,size,MEM_COMMIT|MEM_RESERVE,PAGE_RW) [lazy/large-alloc safe]
sys_write -> GetStdHandle + WriteFile (fd 1/2 routed)
sys_exit -> ExitProcess
sys_thread_create -> CreateThread + MS-ABI->SysV trampoline (reads {fn,ctx})
sys_openat_rd -> CreateFileA (GENERIC_READ, OPEN_EXISTING)
sys_read -> ReadFile (returns bytesRead)
sys_close -> CloseHandle
license_tier: ORIGINAL
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
| 20 | const NB_CODE_CAP: i64 = 4194304 // 4MB assembled-code scratch |
| 21 | const NB_BUF_CAP: i64 = 8388608 // 8MB emit buffer (covers a ~1.5MB forward .text) |
| 22 | const NB_STUB_LEN: i64 = 18 |
| 23 | const NB_RVA_TEXT: i64 = 0x1000 |
| 24 | const NB_FOFF_TEXT: i64 = 0x200 |
| 26 | const NB_VALEN: i64 = 32 // VirtualAlloc (mmap) |
| 27 | const NB_WLEN: i64 = 66 // GetStdHandle+WriteFile (write) |
| 28 | const NB_ELEN: i64 = 13 // ExitProcess (exit) |
| 29 | const NB_CTLEN: i64 = 47 // CreateThread |
| 30 | const NB_TRLEN: i64 = 24 // trampoline |
| 31 | const NB_CFLEN: i64 = 59 // CreateFileA (openat_rd) |
| 32 | const NB_RFLEN: i64 = 55 // ReadFile (read) -- incl DWORD clamp of the count |
| 33 | const NB_CHLEN: i64 = 18 // CloseHandle (close) |
| 34 | const NB_MULEN: i64 = 3 // munmap -> no-op (xor eax,eax; ret); process exit frees all |
| 35 | const NB_WALEN: i64 = 40 // sys_futex_wait -> WaitOnAddress(addr,&cmp,4,INFINITE) |
| 36 | const NB_WKLEN: i64 = 18 // sys_futex_wake -> WakeByAddressAll(addr) |
| 37 | const NB_NQLEN: i64 = 38 // sys_now_us -> QueryPerformanceCounter/10 (Win10/11 QPC = 10MHz = 10 ticks/us) |
functions
| 40 | func nb_name(buf: *u8, base: i64, off: i64, s: *u8) -> i64 |
| 50 | func nb_str(buf: *u8, base: i64, off: i64, s: *u8) -> i64 |
| 57 | func nb_assemble(src: *u8, n: i64, out: *u8, out_cap: i64, p: *i64) -> i64 |
| 103 | func nb_patch(buf: *u8, off: i64, thunk_off: i64) -> i64 |
| 112 | func nb_emit_pe(buf: *u8, code: *u8, code_len: i64, p: *i64, p_fsize: *i64) -> i64 |
| 392 | func main() -> i64 |