code wiki / (root) / nx_pe_natbw.nx

nx_pe_natbw.nx

buildroot/runtime/nx_pe_natbw.nx

25575 B416 linesdepth 4pulls 6 transitivereach 0 importersview sourcekind tooltopic pe
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nxasm_x86.nx nx_pe_writer.nx nx_pe_natbw.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 nb_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

20const NB_CODE_CAP: i64 = 4194304 // 4MB assembled-code scratch
21const NB_BUF_CAP: i64 = 8388608 // 8MB emit buffer (covers a ~1.5MB forward .text)
22const NB_STUB_LEN: i64 = 18
23const NB_RVA_TEXT: i64 = 0x1000
24const NB_FOFF_TEXT: i64 = 0x200
26const NB_VALEN: i64 = 32 // VirtualAlloc (mmap)
27const NB_WLEN: i64 = 66 // GetStdHandle+WriteFile (write)
28const NB_ELEN: i64 = 13 // ExitProcess (exit)
29const NB_CTLEN: i64 = 47 // CreateThread
30const NB_TRLEN: i64 = 24 // trampoline
31const NB_CFLEN: i64 = 59 // CreateFileA (openat_rd)
32const NB_RFLEN: i64 = 55 // ReadFile (read) -- incl DWORD clamp of the count
33const NB_CHLEN: i64 = 18 // CloseHandle (close)
34const NB_MULEN: i64 = 3 // munmap -> no-op (xor eax,eax; ret); process exit frees all
35const NB_WALEN: i64 = 40 // sys_futex_wait -> WaitOnAddress(addr,&cmp,4,INFINITE)
36const NB_WKLEN: i64 = 18 // sys_futex_wake -> WakeByAddressAll(addr)
37const NB_NQLEN: i64 = 38 // sys_now_us -> QueryPerformanceCounter/10 (Win10/11 QPC = 10MHz = 10 ticks/us)

functions

40func nb_name(buf: *u8, base: i64, off: i64, s: *u8) -> i64
called by 1: nb_emit_pe calls 2: _w16_w8
50func nb_str(buf: *u8, base: i64, off: i64, s: *u8) -> i64
called by 1: nb_emit_pe calls 1: _w8
57func nb_assemble(src: *u8, n: i64, out: *u8, out_cap: i64, p: *i64) -> i64
103func nb_patch(buf: *u8, off: i64, thunk_off: i64) -> i64
called by 1: nb_emit_pe calls 2: _w8_w32
112func nb_emit_pe(buf: *u8, code: *u8, code_len: i64, p: *i64, p_fsize: *i64) -> i64
392func main() -> i64