Pure-MoonBit reader for Windows PE/COFF images: headers, section table, imports and exports, with precise byte-offset errors instead of panics.
| Layer | Status |
|---|---|
| DOS header (MZ, e_lfanew) | ✅ |
| NT signature (PE\0\0) | ✅ |
| COFF header (machine, sections, timestamp, characteristics) | ✅ |
| Optional header, PE32 and PE32+ | ✅ |
| Data directories (up to 16) | ✅ |
| Section table (name, sizes, addresses, permissions) | ✅ |
| RVA → file offset (with zero-filled tail detection) | ✅ |
| Import directory, by name and by ordinal | ✅ |
| Export directory, named and ordinal-only | ✅ |
| CLI: info, sections, imports, exports, all | ✅ |
moon add Rz-coder8848/moonpeimport { "Rz-coder8848/moonpe" @pe }let pe = @pe.Pe::parse(bytes)
pe.bits() // 64
pe.machine() // "AMD64"
pe.subsystem() // "windows-console"
pe.optional.entry_point // 0x2c5d0
pe.optional.image_base // 0x180000000
for section in pe.sections {
println(section.name + " " + section.permissions()) // ".text r-x"
}
for library in pe.imports() {
println(library.name) // "KERNEL32.dll"
for entry in library.entries {
match entry.name {
Some(name) => println(" " + name)
None => println(" ordinal " + entry.ordinal.unwrap())
}
}
}moon run cmd/moonpe --target js -- info C:/Windows/System32/kernel32.dllfile: C:/Windows/System32/kernel32.dll
format: PE64 at offset 0x80
machine: AMD64
subsystem: windows-console (3)
image: base 0x180000000
size 0xcb000
entry: 0x2c5d0
sections: 8
imports: 104 libraries
exports: 1697 symbolsmoon run cmd/moonpe --target js -- sections C:/Windows/System32/kernel32.dllNAME VADDR VSIZE RAWPTR RAWSIZE PERM
.text 0x1000 0x85014 0x1000 0x86000 r-x
.rdata 0x88000 0x385b0 0x88000 0x39000 r--
.data 0xc1000 0x16b8 0xc1000 0x1000 rw-
...moon test --target wasm-gc| Reference | Used for | License |
|---|---|---|
| PE format specification | header, section, import and export layouts | Microsoft documentation |
| goblin → pe module | behaviour cross-check (documentation only) | MIT |
| pefile | behaviour cross-check (documentation only) | MIT |
pub(all) suberror PeError {
OutOfBounds(Int, Int, Int)
BadMagic(String, Int)
Malformed(String, Int)
Unsupported(String)
}pub(all) struct CoffHeader {
machine : Int
number_of_sections : Int
timestamp : Int
characteristics : Int
} derive(Debug)pub(all) struct OptionalHeader {
kind : PeKind
entry_point : Int
image_base : Int64
section_alignment : Int
file_alignment : Int
size_of_image : Int
size_of_headers : Int
subsystem : Int
dll_characteristics : Int
directories : Array[DataDirectory]
} derive(Debug)pub(all) struct Pe {
bytes : Bytes
coff : CoffHeader
optional : OptionalHeader
sections : Array[Section]
}pub(all) struct Section {
name : String
virtual_size : Int
virtual_address : Int
raw_size : Int
raw_pointer : Int
characteristics : Int
} derive(Debug)fn has_flag(flags : Int, mask : Int) -> Boolfn hex(value : Int) -> Stringfn hex64(value : Int64) -> Stringfn hex_upper(value : Int) -> StringInstall
Download zipPure-MoonBit reader for Windows PE/COFF images: headers, section table, imports and exports, with precise byte-offset errors instead of panics.