nx_pe_hello_test.nx source
↩ module page · 47 lines · 1820 B
1// nx_pe_hello_test.nx -- substrate emits Hello World PE, writes to disk.
2
3import "nx_syscalls.nx"
4import "nx_hal.nx"
5import "nx_pe_writer.nx"
6
7func main() -> i64 {
8 let buf: *u8 = nx_hal_alloc_pages(PE_HELLO_FILE_SIZE)
9 if (buf as i64) == 0 { return 1 }
10
11 let rc: i64 = nx_pe_emit_hello(buf)
12 if rc != NX_PE_OK { return 2 }
13
14 // Spot-checks: substrate verifies its own emission.
15 if buf[0] != 0x4D { return 10 } // 'M'
16 if buf[1] != 0x5A { return 11 } // 'Z'
17 if buf[0x80] != 0x50 { return 12 } // 'P' (PE sig)
18 // 3 sections
19 if buf[0x86] != 0x03 { return 13 }
20 // .text starts: sub rsp, 0x38 (48 83 EC 38)
21 if buf[0x200] != 0x48 { return 14 }
22 if buf[0x203] != 0x38 { return 15 } // 0x38 stack adjust
23 // mov ecx, -11 (B9 F5 FF FF FF)
24 if buf[0x204] != 0xB9 { return 16 }
25 if buf[0x205] != 0xF5 { return 17 }
26 // Message at .rdata file 0x400: "Hello..."
27 if buf[0x400] != 0x48 { return 18 } // 'H'
28 if buf[0x401] != 0x65 { return 19 } // 'e'
29 if buf[0x402] != 0x6C { return 20 } // 'l'
30 if buf[0x40B] != 0x4E { return 21 } // 'N' (Nishi)
31 if buf[0x414] != 0x0A { return 22 } // newline at end
32 // .idata: GetStdHandle name at file 0x668
33 if buf[0x66A] != 0x47 { return 23 } // 'G'
34 if buf[0x66B] != 0x65 { return 24 } // 'e'
35 if buf[0x66C] != 0x74 { return 25 } // 't'
36 // "kernel32.dll" at file 0x692
37 if buf[0x692] != 0x6B { return 26 } // 'k'
38
39 // Flush to disk.
40 let out_path: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/_offc/nx_pe_hello.exe" as *u8
41 let wrc: i64 = nx_pe_write_to_file(out_path, buf, PE_HELLO_FILE_SIZE)
42 if wrc != NX_PE_OK { return 70 }
43
44 let msg: *u8 = "[substrate] Hello World PE32+ written (2048 bytes)\n" as *u8
45 sys_write(1, msg, 51)
46 return 0
47}