Safe PE/COFF inspection, import/export extraction, and security metadata auditing for MoonBit.
moon add 404-32/moon-pe-inspect@0.6.3git clone https://github.com/404-32/byc001.git
cd byc001
moon test --target wasmmoon run cmd/main -- inspect examples/minimal-pe32.exemoon run cmd/main -- imports examples/minimal-pe32.exe
moon run cmd/main -- exports examples/minimal-pe32.exemoon run cmd/main -- inspect examples/minimal-pe32plus.exe --json
moon run cmd/main -- security examples/minimal-pe32plus.exe --jsonmoon run cmd/main -- directories examples/minimal-pe32.exe
moon run cmd/main -- resources examples/minimal-pe32.exe
moon run cmd/main -- delay-imports examples/minimal-pe32.exe
moon run cmd/main -- load-config examples/minimal-pe32.exe
moon run cmd/main -- bound-imports examples/minimal-pe32.exe
moon run cmd/main -- clr examples/minimal-pe32.exe
moon run cmd/main -- certificates examples/minimal-pe32.exe
moon run cmd/main -- overlay examples/minimal-pe32.exe
moon run cmd/main -- checksum examples/minimal-pe32.exe
moon run cmd/main -- rich examples/rich-pe32.exe
moon run cmd/main -- diff examples/minimal-pe32.exe examples/minimal-pe32plus.exe
moon run cmd/main -- coff examples/minimal-coff.objmoon run cmd/main -- lint examples/minimal-pe32.exe --json
moon run cmd/main -- security examples/minimal-pe32.exe --sarifmoon run cmd/main -- sections C:\Windows\System32\notepad.exe///|
let image = @pe.PEImage::parse(file_bytes)
///|
let sections = image.sections
///|
let imports = image.imports()
///|
let exports = image.exports()
///|
let resources = image.resources()
///|
let relocations = image.base_relocations()
///|
let delay_imports = image.delay_imports()
///|
let tls = image.tls()
///|
let debug_entries = image.debug_entries()
///|
let load_config = image.load_config()
///|
let exceptions = image.exception_entries()
///|
let bound_imports = image.bound_imports()
///|
let clr_header = image.clr_header()
///|
let certificates = image.certificates()
///|
let overlay = image.overlay()
///|
let checksum = image.checksum_info()
///|
let rich = image.rich_header()
///|
let entropies = image.section_entropies()
///|
let diagnostics = image.security_diagnostics()
///|
let offset = image.rva_to_offset(0x1000UL)
///|
let object = @pe.CoffObject::parse(coff_bytes)python scripts/generate_fixtures.py
moon check --target all --deny-warn
moon test --target wasm --deny-warn
moon test --target wasm-gc --deny-warn
moon test --target js --deny-warn
moon fmt --check
moon package
moon run cmd/main -- inspect examples/minimal-pe32.exepub(all) struct CertificateRecord {
length : Int
revision : Int
certificate_type : Int
}pub(all) struct ChecksumInfo {
stored : Int
computed : Int
present : Bool
valid : Bool
}pub(all) struct ClrHeaderInfo {
header_size : Int
major_runtime_version : Int
minor_runtime_version : Int
metadata_rva : UInt64
metadata_size : Int
flags : Int
entry_point_token : Int
resources_rva : UInt64
resources_size : Int
strong_name_rva : UInt64
strong_name_size : Int
}pub(all) struct CoffObject {
machine : Int
section_count : Int
timestamp : Int
symbol_table_pointer : Int
symbol_count : Int
optional_header_size : Int
characteristics : Int
sections : Array[CoffSection]
symbols : Array[CoffSymbol]
}pub(all) struct CoffSection {
name : String
virtual_size : Int
virtual_address : UInt64
raw_size : Int
raw_offset : Int
relocation_offset : Int
line_number_offset : Int
relocation_count : Int
line_number_count : Int
characteristics : UInt64
}pub(all) struct CoffSymbol {
name : String
value : UInt64
section_number : Int
symbol_type : Int
storage_class : Int
}pub(all) struct DataDirectory {
index : Int
name : String
virtual_address : UInt64
size : Int
}pub(all) struct DebugEntry {
debug_type : Int
type_name : String
timestamp : Int
size_of_data : Int
address_of_raw_data : UInt64
pointer_to_raw_data : Int
pdb_path : String?
pdb_age : Int?
pdb_guid : String?
}pub(all) struct DelayImportLibrary {
name : String
attributes : Int
timestamp : Int
symbols : Array[ImportSymbol]
}pub(all) struct ExceptionEntry {
begin_rva : UInt64
end_rva : UInt64
unwind_info_rva : UInt64
}pub(all) struct ExportSymbol {
name : String
ordinal : Int
rva : UInt64
forwarder : String?
}pub(all) struct LoadConfigInfo {
structure_size : Int
timestamp : Int
global_flags_clear : Int?
global_flags_set : Int?
security_cookie : UInt64?
se_handler_table : UInt64?
se_handler_count : Int?
guard_cf_check_pointer : UInt64?
guard_cf_dispatch_pointer : UInt64?
guard_cf_function_table : UInt64?
guard_cf_function_count : Int?
guard_flags : Int?
}pub(all) struct PEImage {
data : Bytes
pe_offset : Int
format : PEFormat
machine : Int
number_of_sections : Int
timestamp : UInt64
symbol_table_pointer : UInt64
number_of_symbols : UInt64
size_of_optional_header : Int
characteristics : Int
entry_point : UInt64
image_base : UInt64
section_alignment : Int
file_alignment : Int
size_of_image : Int
size_of_headers : Int
checksum : UInt64
subsystem : Int
dll_characteristics : Int
sections : Array[Section]
directories : Array[DataDirectory]
}pub(all) struct RelocationEntry {
relocation_type : Int
offset : Int
target_rva : UInt64
}pub(all) struct ResourceEntry {
path : String
type_id : Int?
name_id : Int?
language_id : Int?
data_rva : UInt64
file_offset : Int?
size : Int
code_page : Int
}pub(all) struct Section {
name : String
virtual_size : Int
virtual_address : UInt64
raw_size : Int
raw_offset : Int
characteristics : UInt64
}pub(all) struct SectionEntropy {
section_name : String
entropy : Double
raw_size : Int
}pub(all) struct TlsInfo {
raw_data_start : UInt64
raw_data_end : UInt64
index_address : UInt64
callbacks_address : UInt64
size_of_zero_fill : Int
characteristics : Int
callbacks : Array[UInt64]
}Install
Download zipSafe PE/COFF inspection, import/export extraction, and security metadata auditing for MoonBit.