A MoonBit library for parsing and analyzing binary debugging formats, with comprehensive support for Mach-O binary files (macOS/iOS executables, libraries, and object files). This library is inspired by and maintains API compatibility with Go's debug/macho
package while leveraging MoonBit's strong type system for safer binary parsing.
The project implements three main MoonBit packages:
- Primary focus: Complete port of Go's
debug/macho
package - Functionality: Parses Mach-O binary files (macOS/iOS executables, libraries, object files)
- Features:
- 32-bit and 64-bit Mach-O support
- Cross-architecture parsing (x86, x86_64, ARM, ARM64, PowerPC)
- Load command parsing (segments, symbol tables, dynamic libraries)
- Symbol table analysis and extraction
- Fat/Universal binary support
- DWARF debug information extraction with ZLIB decompression
- Section and segment data access
- Purpose: DWARF debugging format support
- Integration: Works with Mach-O parser to extract debug information
- Purpose: Common I/O operations for binary parsing
- Integration: Provides shared functionality across parsers
- Complete Mach-O Support: Parse 32-bit and 64-bit Mach-O files with full cross-architecture support
- Type Safety: Leverages MoonBit's strong type system for safe binary parsing with comprehensive error handling
- DWARF Debug Information: Extract and analyze debugging information with automatic ZLIB decompression
- Universal Binary Support: Handle Fat/Universal binaries with multiple architectures
- Symbol Analysis: Extract symbol tables, dynamic symbols, and library dependencies
- High-Level API: Convenient functions for common binary analysis tasks
According to the documentation, the project is ~85-90% complete for the Mach-O library:
✅ Completed Features:
- Complete Mach-O file parsing (32-bit/64-bit)
- Fat/Universal binary support
- Symbol table extraction and analysis
- Load command parsing
- Section/segment data access
- DWARF debug information extraction
- File I/O integration
- High-level query functions
🚧 Remaining Work:
- Complete relocation processing
- Architecture-specific relocation types
- Advanced data access methods
- Thread state/register parsing
- Enhanced error context
- Comprehensive testing with real binaries
- Language: MoonBit (a modern functional programming language)
- Build System: Moon (MoonBit's package manager)
- Dependencies:
moonbitlang/x
(MoonBit extended library)gmlewis/zlib
(compression support for DWARF)
- Error Handling: Uses MoonBit's structured error system with
suberror
types - Binary Data: Proper handling of raw bytes (avoiding string conversion issues)
This library enables MoonBit applications to:
- Analyze macOS/iOS application binaries
- Extract debugging information from executables
- Parse dynamic library dependencies
- Examine code signatures and load commands
- Support reverse engineering and binary analysis tools
- Enable development tools that work with Apple platform binaries
Add the library to your MoonBit project:
moon add tonyfettes/debugo
// Parse a Mach-O file
let file_data = @fs.read_file_to_bytes("example.dylib")
let file = @macho.File::new(file_data)
// Examine file properties
println("Architecture: \{file.header.cpu}")
println("File Type: \{file.header.type_}")
// Extract DWARF debug information
match file.dwarf(file_data) {
Some(dwarf_data) => {
let sections = dwarf_data.get_section_names()
println("DWARF sections: \{sections}")
}
None => println("No debug information found")
}
For detailed usage examples and API documentation, see src/macho/README.mbt.md
.
This project welcomes contributions! Key areas for contribution:
- Complete remaining features: See the roadmap in
src/macho/README.mbt.md
- Add comprehensive tests: Especially with real-world binary files
- Improve documentation: Add more usage examples and API docs
- Port additional debug formats: Consider porting
debug/elf
,debug/pe
, etc.
Apache-2.0 - See LICENSE file for details.
This library's API design is inspired by Go's debug/macho
package, adapted for MoonBit's type system and functional programming paradigms.