code wiki / (root) / nx_pe_compile_win_gui.nx

nx_pe_compile_win_gui.nx

buildroot/runtime/nx_pe_compile_win_gui.nx

24386 B375 linesdepth 4pulls 6 transitivereach 1 importersview sourcekind tooltopic pe
docsdependenciesstructsconstsfunctions

about

nx_pe_compile_win_gui.nx -- GUI-R0 keystone: emits nish_gui.nx as a native Windows PE with a sovereign Win32 FFI so NishiLang can drive user32/gdi32 (open a window, push a framebuffer). Imports (ONE contiguous IAT, indexed by FFI id = slot index; per-DLL counts come from each descriptor's OriginalFirstThunk/INT, so the IAT needs no inter-DLL null splits): kernel32 slots 0-6: ExitProcess GetProcessHeap HeapAlloc GetStdHandle WriteFile Sleep GetModuleHandleA user32 slots 7-17: RegisterClassExA CreateWindowExA ShowWindow PeekMessageA TranslateMessage DispatchMessageA DefWindowProcA GetDC ReleaseDC IsWindow LoadCursorA gdi32 slot 18: SetDIBitsToDevice Redirected shims: sys_mmap->HeapAlloc(zeroed), sys_write->WriteFile, sys_exit->ExitProcess, sys_sleep_ms->Sleep, win32->FFI-marshalled-call, win32addr->IAT-address-of. Same proven PE machinery as nx_pe_compile_win_nish.nx (writable .text for statics, RIP-relative code at the image base, MS-x64 thunks). lineage_id: substrate_pe_compile_win_gui_v1

dependencies 3 imports · 1 importers

nx_syscalls.nx nxasm_x86.nx nx_pe_writer.nx nx_pe_compile_win_gui.nx nx_pe_compile_win_game.nx

imports: nx_syscalls.nxnxasm_x86.nxnx_pe_writer.nx

imported by: nx_pe_compile_win_game.nx

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 gi_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 GI_CODE_CAP: i64 = 0x300000
21const GI_STUB_LEN: i64 = 18 // sub/call main/mov ecx/call exit/int3
22const GI_THUNK_SLACK: i64 = 0x1000
23const GI_FOFF_TEXT: i64 = 0x200
24const GI_RVA_TEXT: i64 = 0x1000
25const GI_IDATA_FSZ: i64 = 0x600
28const GI_DESC_K: i64 = 0x00 // kernel32 import descriptor (20)
29const GI_DESC_U: i64 = 0x14 // user32 (20)
30const GI_DESC_G: i64 = 0x28 // gdi32 (20)
31const GI_DESC_K2: i64 = 0x3C // 2nd kernel32 descriptor (ReadFile @ slot 19, additive)
32const GI_DESC_K3: i64 = 0x50 // 3rd kernel32 descriptor (CreateFileA/CreateProcessA/WaitForSingleObject/CloseHandle @ slots 20-23)
33const GI_DESC_U2: i64 = 0x64 // 2nd user32 descriptor (GetClientRect @ slot 24, additive for live resize)
34const GI_DESC_N: i64 = 0x78 // null (20)
35const GI_IAT: i64 = 0x8C // 25 slots contiguous (200B) -> ends 0x154
36const GI_INT_K: i64 = 0x154 // kernel32 INT: 7+null (64)
37const GI_INT_U: i64 = 0x194 // user32 INT: 11+null (96)
38const GI_INT_G: i64 = 0x1F4 // gdi32 INT: 1+null (16)
39const GI_INT_K2: i64 = 0x204 // kernel32#2 INT: 1+null (16)
40const GI_INT_K3: i64 = 0x214 // kernel32#3 INT: 4+null (40)
41const GI_INT_U2: i64 = 0x23C // user32#2 INT: 1+null (16)
42const GI_NAMES: i64 = 0x24C
44const GI_IMGBASE_LO: i64 = 0x40000000
45const GI_IMGBASE_HI: i64 = 0x1
46const GI_IMGBASE: i64 = 5368709120 // 0x1_4000_0000

functions

48func gi_align(x: i64, a: i64) -> i64 { return ((x + a - 1) / a) * a }
called by 2: mainmain
49func gi_rva(foff: i64) -> i64 { return GI_RVA_TEXT + (foff - GI_FOFF_TEXT) }
called by 2: gi_ecgi_emit_pe
50func gi_ec(buf: *u8, foff: i64, iat_rva: i64) -> i64
called by 1: gi_emit_pe calls 3: _w8_w32gi_rva
55func gi_redir(buf: *u8, shim_off: i64, thunk_rva: i64) -> i64
called by 1: gi_emit_pe calls 2: _w8_w32
62func gi_put_name(buf: *u8, foff: i64, s: *u8) -> i64
called by 1: gi_emit_pe calls 1: _w16
71func gi_put_str(buf: *u8, foff: i64, s: *u8) -> i64
called by 1: gi_emit_pe
77func gi_lbloff(src: *u8, lo: *i64, ll: *i64, la: *i64, n: i64, nm: *u8) -> i64
called by 1: gi_assemble calls 1: axc_tok_is
82func gi_assemble(src: *u8, n: i64, out: *u8, out_cap: i64, off: *i64) -> i64
115func gi_emit_pe(buf: *u8, code: *u8, code_len: i64, off: *i64, text_fsz: i64, rva_idata: i64) -> i64
350func main() -> i64