code wiki / (root) / nx_pe_compile_win_halloc.nx

nx_pe_compile_win_halloc.nx

buildroot/runtime/nx_pe_compile_win_halloc.nx

11012 B214 linesdepth 4pulls 6 transitivereach 0 importersview sourcekind tooltopic pe
docsdependenciesstructsconstsfunctions

about

nx_pe_compile_win_halloc.nx -- W3b-5a' : sys_mmap reaches a BENIGN allocator (HeapAlloc). W3b-5a redirected sys_mmap -> VirtualAlloc, which Windows Defender quarantined (a minimal hand-PE importing VirtualAlloc matches the shellcode-loader heuristic; see pe_compile_win_mmap_gate.log). This rung uses the recommended benign alternative: sys_mmap -> HeapAlloc(GetProcessHeap(), 0, size), the allocation pattern of ordinary programs, which should not trip the heuristic. No compiler/asm edits. thunk (SysV in: rdi=size): sub rsp, 0x28 ; shadow + 16-byte align call [rip+GetProcessHeap] ; rax = default heap handle; rdi(size) survives (MS-x64 non-volatile) mov rcx, rax ; arg1 hHeap xor edx, edx ; arg2 dwFlags = 0 mov r8, rdi ; arg3 dwBytes = size call [rip+HeapAlloc] ; rax = pointer add rsp, 0x28 / ret ; rax = base pointer (SysV return) NO-FALSE-GREEN: source `{ let p = sys_mmap(4096); p[0]=77; p[1]=22; return p[0]+p[1] }`. Exit 99 proves HeapAlloc returned a VALID, WRITABLE region the compiled code wrote+read back; a NULL/bad pointer faults (0xC0000005). Tamper (corrupt HeapAlloc import name) -> 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_halloc -> _offc/nx_win_compiled_halloc.exe -> run native. HONEST SCOPE: single redirect (sys_mmap) via HeapAlloc; combine with the W3b-5b table for a full multi-syscall organ. 3 imports (GetProcessHeap, HeapAlloc, ExitProcess). Replicates keystone assemble (reuses axc_pass; no shared edit). lineage_id: substrate_pe_compile_win_halloc_v1

dependencies 3 imports · 0 importers

nx_syscalls.nx nxasm_x86.nx nx_pe_writer.nx nx_pe_compile_win_halloc.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 nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close nxh_assemble sys_mmap ↻ nxh_emit_pe _w16 _w32 _w8 _w64 _w32 ↻ _emit_section_header _w8 ↻ _w32 ↻ _w16 ↻ nx_pe_write_to_file sys_openat_wr sys_write ↻ sys_close ↻ sys_write ↻

structs

none

consts

32const NXH_CODE_CAP: i64 = 1048576
33const NXH_FILE_SIZE: i64 = 0x600 // headers + .text + .idata
34const NXH_STUB_LEN: i64 = 18
35const NXH_THUNK_LEN: i64 = 29
36const NXH_TEXT_CAP: i64 = 0x200
37const NXH_RVA_TEXT: i64 = 0x1000
38const NXH_RVA_IDATA: i64 = 0x2000
39const NXH_FOFF_TEXT: i64 = 0x200
40const NXH_FOFF_IDATA:i64 = 0x400
41const NXH_IAT_GPH: i64 = 0x2048 // IAT GetProcessHeap RVA
42const NXH_IAT_HA: i64 = 0x2050 // IAT HeapAlloc RVA
43const NXH_IAT_EXIT: i64 = 0x2058 // IAT ExitProcess RVA

functions

45func nxh_assemble(src: *u8, n: i64, out: *u8, out_cap: i64, p_main: *i64, p_mm: *i64) -> i64
called by 1: main calls 1: sys_mmap
82func nxh_emit_pe(buf: *u8, code: *u8, code_len: i64, main_off: i64, mm_off: i64) -> i64
185func main() -> i64