Page
Library
Module
Module type
Parameter
Class
Class type
Source
MachoSourceMacOS Mach-O parser based on /usr/include/mach-o/* headers
type magic = | MAGIC32| MAGIC64| CIGAM32| CIGAM64Magic numbers identifying the endianness and architecture of Mach-O files.
MAGIC32: 32-bit Mach-O file, native endiannessMAGIC64: 64-bit Mach-O file, native endiannessCIGAM32: 32-bit Mach-O file, swapped endiannessCIGAM64: 64-bit Mach-O file, swapped endiannessstring_of_magic magic returns a human-readable string representation of the magic number for debugging and display purposes.
Represents unknown or unrecognized values with their raw integer representation.
CPU architectures supported by Mach-O binaries. Includes Intel x86/x64, ARM variants, PowerPC architectures, and a catch-all for unknown types.
type cpu_subtype = [ | `Intel| `I386_ALL| `I386| `I486| `I486SX| `PENT| `PENTPRO| `PENTII_M3| `PENTII_M5| `CELERON| `CELERON_MOBILE| `PENTIUM_3| `PENTIUM_3_M| `PENTIUM_3_XEON| `PENTIUM_M| `PENTIUM_4| `PENTIUM_4_M| `ITANIUM| `ITANIUM_2| `XEON| `XEON_MP| `INTEL_FAMILY| `INTEL_FAMILY_MAX| `INTEL_MODEL| `INTEL_MODEL_ALL| `X86_ALL| `X86_64_ALL| `X86_ARCH1| `POWERPC_ALL| `POWERPC_601| `POWERPC_602| `POWERPC_603| `POWERPC_603e| `POWERPC_603ev| `POWERPC_604| `POWERPC_604e| `POWERPC_620| `POWERPC_750| `POWERPC_7400| `POWERPC_7450| `POWERPC_970| `ARM_ALL| `ARM_V4T| `ARM_V6| `ARM_V5TEJ| `ARM_XSCALE| `ARM_V7| `ARM_V7F| `ARM_V7S| `ARM_V7K| `ARM_V8| unknown ]CPU subtypes providing more specific processor identification within a CPU family. Includes various Intel processors, PowerPC variants, ARM versions, and unknown types.
cpu_type_to_int cpu_type converts a CPU type to its integer representation.
cpu_type_to_string cpu_type converts a CPU type to its string representation (e.g., "i386", "x86_64", "arm64").
cpu_subtype_to_int cpu_type cpu_subtype converts a CPU subtype to its integer representation. The cpu_type is needed for context-dependent subtype values.
type file_type = [ | `OBJECT| `EXECUTE| `FVMLIB| `CORE| `PRELOAD| `DYLIB| `DYLINKER| `BUNDLE| `DYLIB_STUB| `DSYM| `KEXT_BUNDLE| `FILESET| `GPU_EXECUTE| `GPU_DYLIB| unknown ]Types of Mach-O files, from relocatable object files to executables, dynamic libraries, bundles, and specialized types like GPU executables and file sets.
type header_flag = [ | `NOUNDEFS| `INCRLINK| `DYLDLINK| `BINDATLOAD| `PREBOUND| `SPLIT_SEGS| `TWOLEVEL| `FORCE_FLAT| `NOMULTIDEFS| `NOFIXPREBINDING| `PREBINDABLE| `ALLMODSBOUND| `SUBSECTIONS_VIA_SYMBOLS| `CANONICAL| `WEAK_DEFINES| `BINDS_TO_WEAK| `ALLOW_STACK_EXECUTION| `ROOT_SAFE| `SETUID_SAFE| `NO_REEXPORTED_DYLIBS| `PIE ]Flags in the Mach-O header indicating various linking and loading behaviors, such as undefined references, dynamic linking, prebinding, and security features.
type header = {magic : magic;cpu_type : cpu_type;cpu_subtype : cpu_subtype;file_type : file_type;flags : header_flag list;}The Mach-O header containing essential information about the binary including endianness, architecture, file type, and various flags controlling linking behavior.
type reloc_type = [ | `GENERIC_RELOC_VANILLA| `GENERIC_RELOC_PAIR| `GENERIC_RELOC_SECTDIFF| `GENERIC_RELOC_LOCAL_SECTDIFF| `GENERIC_RELOC_PB_LA_PTR| `X86_64_RELOC_BRANCH| `X86_64_RELOC_GOT_LOAD| `X86_64_RELOC_GOT| `X86_64_RELOC_SIGNED| `X86_64_RELOC_UNSIGNED| `X86_64_RELOC_SUBTRACTOR| `X86_64_RELOC_SIGNED_1| `X86_64_RELOC_SIGNED_2| `X86_64_RELOC_SIGNED_4| `PPC_RELOC_VANILLA| `PPC_RELOC_PAIR| `PPC_RELOC_BR14| `PPC_RELOC_BR24| `PPC_RELOC_HI16| `PPC_RELOC_LO16| `PPC_RELOC_HA16| `PPC_RELOC_LO14| `PPC_RELOC_SECTDIFF| `PPC_RELOC_LOCAL_SECTDIFF| `PPC_RELOC_PB_LA_PTR| `PPC_RELOC_HI16_SECTDIFF| `PPC_RELOC_LO16_SECTDIFF| `PPC_RELOC_HA16_SECTDIFF| `PPC_RELOC_JBSR| `PPC_RELOC_LO14_SECTDIFF| unknown ]Relocation types for different architectures (generic, x86-64, PowerPC) indicating how addresses should be modified during linking and loading.
type relocation_info = {ri_address : int;Offset from start of section to place to be relocated
*)ri_symbolnum : Object_types.u32;Index into symbol or section table
*)ri_pcrel : bool;Indicates if the item to be relocated is part of an instruction containing PC-relative addressing
*)ri_length : Object_types.u32;Length of item containing address to be relocated (literal form (4) instead of power of two (2))
*)ri_extern : bool;Indicates whether symbolnum is an index into the symbol table (true) or section table (false)
*)ri_type : reloc_type;Relocation type
*)}Information needed to relocate addresses during linking. Contains the location to be relocated, the symbol or section it references, and how the relocation should be performed.
type scattered_relocation_info = {rs_pcrel : bool;Indicates if the item to be relocated is part of an instruction containing PC-relative addressing
*)rs_length : Object_types.u32;Length of item containing address to be relocated (literal form (4) instead of power of two (2))
*)rs_type : reloc_type;Relocation type
*)rs_address : Object_types.u32;Offset from start of section to place to be relocated
*)rs_value : Object_types.s32;Address of the relocatable expression for the item in the file that needs to be updated if the address is changed
*)}Scattered relocation information used when the relocation cannot be described by a simple symbol or section reference. Contains the actual address value and relocation details.
type relocation = [ | `Relocation_info of relocation_info| `Scattered_relocation_info of scattered_relocation_info ]Union type representing either a standard or scattered relocation entry. Standard relocations reference symbols or sections by index, while scattered relocations contain literal addresses.
type sec_type = [ | `S_REGULARRegular section
*)| `S_ZEROFILLZero fill on demand section
*)| `S_CSTRING_LITERALSSection with only literal C strings
*)| `S_4BYTE_LITERALSSection with only 4 byte literals
*)| `S_8BYTE_LITERALSSection with only 8 byte literals
*)| `S_LITERAL_POINTERSSection with only pointers to literals
*)| `S_NON_LAZY_SYMBOL_POINTERSSection with only non-lazy symbol pointers
*)| `S_LAZY_SYMBOL_POINTERSSection with only lazy symbol pointers
*)| `S_SYMBOL_STUBSSection with only symbol stubs, byte size of stub in the reserved2 field
*)| `S_MOD_INIT_FUNC_POINTERSSection with only function pointers for initialization
*)| `S_MOD_TERM_FUNC_POINTERSSection with only function pointers for termination
*)| `S_COALESCEDSection contains symbols that are to be coalesced
*)| `S_GB_ZEROFILLZero fill on demand section (that can be larger than 4 gigabytes)
*)| `S_INTERPOSINGSection with only pairs of function pointers for interposing
*)| `S_16BYTE_LITERALSSection with only 16 byte literals
*)| `S_DTRACE_DOFSection contains DTrace Object Format
*)| `S_LAZY_DYLIB_SYMBOL_POINTERSSection with only lazy symbol pointers to lazy loaded dylibs
*)| unknown ]Section types indicating the content and purpose of a section within a segment. Each type defines how the section data should be interpreted and used by the linker and loader.
type sec_user_attr = [ | `PURE_INSTRUCTIONSSection contains only true machine instructions
*)| `NO_TOCSection contains coalesced symbols that are not to be in a ranlib table of contents
*)| `STRIP_STATIC_SYMSOK to strip static symbols in this section in files with the MH_DYLDLINK flag
*)| `NO_DEAD_STRIPNo dead stripping
*)| `LIVE_SUPPORTBlocks are live if they reference live blocks
*)| `SELF_MODIFYING_CODEUsed with i386 code stubs written on by dyld
*)| `DEBUGA debug section
*) ]User-defined section attributes controlling how sections are treated during linking and optimization processes.
type sec_sys_attr = [ | `SOME_INSTRUCTIONSSection contains some machine instructions
*)| `EXT_RELOCSection has external relocation entries
*)| `LOC_RELOCSection has local relocation entries
*) ]System-defined section attributes indicating relocation and instruction content.
type section = {sec_sectname : string;Name of section
*)sec_segname : string;Name of segment that should own this section
*)sec_addr : Object_types.u64;Virtual memory address for section
*)sec_size : Object_types.u64;Size of section
*)sec_offset : Object_types.u32;File offset of section
*)sec_align : int;Alignment required by section (literal form, not power of two, e.g. 8 not 3)
*)sec_relocs : relocation array;Relocations for this section
*)sec_type : sec_type;Type of section
*)sec_user_attrs : sec_user_attr list;User attributes of section
*)sec_sys_attrs : sec_sys_attr list;System attributes of section
*)sec_reserved1 : Object_types.u32;Reserved field 1
*)sec_reserved2 : Object_types.u32;Reserved field 2
*)}A section within a segment, containing code or data with specific attributes and relocations. Sections are the finest granularity of organization within Mach-O files.
sec_type_to_int sec_type converts a section type to its integer representation as used in Mach-O section headers.
sec_user_attrs_to_int attrs converts section user attributes to their combined integer representation.
sec_sys_attrs_to_int attrs converts section system attributes to their combined integer representation.
Virtual memory protection flags controlling access permissions for segments and sections.
Segment flags controlling special handling of segment contents and relocations.
type segment = {seg_segname : string;Segment name
*)seg_vmaddr : Object_types.u64;Virtual address where the segment is loaded
*)seg_vmsize : Object_types.u64;Size of segment at runtime
*)seg_fileoff : Object_types.u64;File offset of the segment
*)seg_filesize : Object_types.u64;Size of segment in file
*)seg_maxprot : vm_prot list;Maximum virtual memory protection
*)seg_initprot : vm_prot list;Initial virtual memory protection
*)seg_flags : seg_flag list;Segment flags
*)seg_sections : section array;Sections owned by this segment
*)}A segment containing one or more sections, representing a contiguous range of virtual memory that is mapped from the file during loading. Segments define memory protection and layout.
vm_prot_to_int prots converts virtual memory protection flags to their combined integer representation.
seg_flags_to_int flags converts segment flags to their combined integer representation.
type sym_type = [ | `UNDF| `ABS| `SECT| `PBUD| `INDR| `GSYM| `FNAME| `FUN| `STSYM| `LCSYM| `BNSYM| `OPT| `RSYM| `SLINE| `ENSYM| `SSYM| `SO| `OSO| `LSYM| `BINCL| `SOL| `PARAMS| `VERSION| `OLEVEL| `PSYM| `EINCL| `ENTRY| `LBRAC| `EXCL| `RBRAC| `BCOMM| `ECOMM| `ECOML| `LENG| `PC| unknown ]Symbol types including regular symbols (UNDF, ABS, SECT) and STAB debug symbols. STAB symbols provide debugging information like source file names, line numbers, and local variable information used by debuggers.
type reference_flag = [ | `UNDEFINED_NON_LAZY| `UNDEFINED_LAZY| `DEFINED| `PRIVATE_DEFINED| `PRIVATE_UNDEFINED_NON_LAZY| `PRIVATE_UNDEFINED_LAZY| `REFERENCED_DYNAMICALLY| `SYM_WEAK_REF| `SYM_WEAK_DEF| `LIBRARY_ORDINAL of Object_types.u16| unknown ]Reference flags indicating how symbols are bound and resolved during linking. Controls symbol visibility, weak binding, and library ordinals for two-level namespaces.
type symbol = {sym_name : string;Symbol name
*)sym_type : sym_type;Symbol type
*)sym_pext : bool;True if limited global scope
*)sym_ext : bool;True if external symbol
*)sym_sect : Object_types.u8;Section index where the symbol can be found
*)sym_flags : [ `Uninterpreted of Object_types.u16
| `Flags of reference_flag list ];For stab entries, uninterpreted flags field; otherwise reference flags
*)sym_value : Object_types.u64;Symbol value, 32-bit symbol values are promoted to 64-bit for simplicity
*)}A symbol table entry representing a named location in code or data. Symbols can be functions, variables, or debugging information, and may reference external libraries.
type dylib_module = {dylib_module_name_offset : Object_types.u32;Module name string table offset
*)dylib_ext_def_sym : Object_types.u32 * Object_types.u32;(initial, count) pair of symbol table indices for externally defined symbols
*)dylib_ref_sym : Object_types.u32 * Object_types.u32;(initial, count) pair of symbol table indices for referenced symbols
*)dylib_local_sym : Object_types.u32 * Object_types.u32;(initial, count) pair of symbol table indices for local symbols
*)dylib_ext_rel : Object_types.u32 * Object_types.u32;(initial, count) pair of symbol table indices for externally referenced symbols
*)dylib_init : Object_types.u32 * Object_types.u32;(initial, count) pair of symbol table indices for the index of the module init section and the number of init pointers
*)dylib_term : Object_types.u32 * Object_types.u32;(initial, count) pair of symbol table indices for the index of the module term section and the number of term pointers
*)dylib_objc_module_info_addr : Object_types.u32;Statically linked address of the start of the data for this module in the __module_info section in the __OBJC segment
*)dylib_objc_module_info_size : Object_types.u64;Number of bytes of data for this module that are used in the __module_info section in the __OBJC segment
*)}Module information for dynamic libraries, containing indices into various symbol tables and initialization/termination routines.
type toc_entry = {symbol_index : Object_types.u32;Index into symbol table
*)module_index : Object_types.u32;Index into module table
*)}Table of contents entry mapping symbols to their defining modules.
type symbol_table = {symoff : Object_types.u32;Symbol table offset
*)nsyms : Object_types.u32;Number of symbols
*)stroff : Object_types.u32;String table offset
*)strsize : Object_types.u32;String table size
*)symbols : symbol array;Parsed symbols
*)strings : Buffer.t;String table buffer
*)}Symbol table command containing symbol and string table information.
type dynamic_symbol_table = {ilocalsym : Object_types.u32;Index of first local symbol
*)nlocalsym : Object_types.u32;Number of local symbols
*)iextdefsym : Object_types.u32;Index of first external defined symbol
*)nextdefsym : Object_types.u32;Number of external defined symbols
*)iundefsym : Object_types.u32;Index of first undefined symbol
*)nundefsym : Object_types.u32;Number of undefined symbols
*)tocoff : Object_types.u32;Table of contents offset
*)ntoc : Object_types.u32;Number of table of contents entries
*)modtaboff : Object_types.u32;Module table offset
*)nmodtab : Object_types.u32;Number of module table entries
*)extrefsymoff : Object_types.u32;External reference symbol table offset
*)nextrefsyms : Object_types.u32;Number of external reference symbols
*)indirectsymoff : Object_types.u32;Indirect symbol table offset
*)nindirectsyms : Object_types.u32;Number of indirect symbols
*)extreloff : Object_types.u32;External relocation table offset
*)nextrel : Object_types.u32;Number of external relocations
*)locreloff : Object_types.u32;Local relocation table offset
*)nlocrel : Object_types.u32;Number of local relocations
*)toc_entries : toc_entry array;Parsed table of contents entries
*)modules : dylib_module array;Parsed modules
*)ext_ref_syms : Object_types.u32 array;Parsed external reference symbols
*)indirect_syms : Object_types.u32 array;Parsed indirect symbols
*)ext_rels : relocation array;Parsed external relocations
*)loc_rels : relocation array;Parsed local relocations
*)}Dynamic symbol table containing information needed for dynamic linking, including symbol organization and relocation data.
type dylib = {dylib_name : string;Name of the dynamic library
*)dylib_timestamp : Object_types.u32;Time when the library was built
*)dylib_current_version : Object_types.u32;Current version of the library
*)dylib_compatibility_version : Object_types.u32;Oldest version this library is compatible with
*)}Dynamic library information including name and version details.
Build tool information including tool type and version.
type build_version_info = {platform : Object_types.u32;Target platform
*)minos : Object_types.u32;Minimum OS version
*)sdk : Object_types.u32;SDK version used to build
*)tools : build_tool array;Build tools used
*)}Build version information for the binary.
type command = | LC_SEGMENT_32 of segment lazy_t| LC_SYMTAB of symbol_table lazy_t| LC_THREAD of (Object_types.u32 * Object_types.u32 array) list lazy_t| LC_UNIXTHREAD of (Object_types.u32 * Object_types.u32 array) list lazy_t| LC_DYSYMTAB of dynamic_symbol_table lazy_t| LC_LOAD_DYLIB of dylib lazy_t| LC_ID_DYLIB of dylib lazy_t| LC_LOAD_DYLINKER of string| LC_ID_DYLINKER of string| LC_PREBOUND_DYLIB of (string * Object_types.u8 array) lazy_t| LC_ROUTINES_32 of Object_types.u32 * Object_types.u32| LC_SUB_FRAMEWORK of string| LC_SUB_UMBRELLA of string| LC_SUB_CLIENT of string| LC_SUB_LIBRARY of string| LC_TWOLEVEL_HINTS of (Object_types.u32 * Object_types.u32) array lazy_t| LC_PREBIND_CKSUM of Object_types.u32| LC_LOAD_WEAK_DYLIB of dylib lazy_t| LC_SEGMENT_64 of segment lazy_t| LC_ROUTINES_64 of Object_types.u64 * Object_types.u64| LC_UUID of string| LC_RPATH of string| LC_CODE_SIGNATURE of Object_types.u32 * Object_types.u32| LC_SEGMENT_SPLIT_INFO of Object_types.u32 * Object_types.u32| LC_MAIN of Object_types.u64 * Object_types.u64| LC_SOURCE_VERSION of Object_types.u64| LC_BUILD_VERSION of build_version_info lazy_t| LC_FUNCTION_STARTS of Object_types.u32 * Object_types.u32| LC_DATA_IN_CODE of Object_types.u32 * Object_types.u32| LC_DYLD_EXPORTS_TRIE of Object_types.u32 * Object_types.u32| LC_DYLD_CHAINED_FIXUPS of Object_types.u32 * Object_types.u32| LC_UNHANDLED of int * Buffer.tLoad commands instruct the dynamic linker how to set up the process from the Mach-O file. Commands specify segments to load, libraries to link, symbols to resolve, and other setup tasks. Each command contains specific data relevant to its operation.
command_name cmd returns the load command name as a string (e.g., "LC_SEGMENT_64", "LC_SYMTAB").
read_symbol_table header buffer cursor reads the symbol table from a Mach-O LC_SYMTAB load command. Returns a symbol_table record with all symbol and string table buffer. The cursor should be positioned at the start of the symbol table command data (after the standard load command header).
read_load_command header buffer cursor reads a single load command from the Mach-O file. The cursor should be positioned at the start of a load command (at the cmd field).
read_load_commands header buffer cursor reads all remaining load commands from the current cursor position until the end of the load commands region.
read decodes the header and load command list, from a Buffer.t pointing to a MachO image
section_body macho section returns a sub-buffer with the contents of the section of the MachO image in Buffer.t.
get_section_contents buffer section_name searches for a section with the given section_name in the Mach-O file and returns its contents as a buffer. Returns None if the section is not found.
type fat_magic = | FAT_MAGIC| FAT_CIGAM| FAT_MAGIC_64| FAT_CIGAM_64Magic numbers for FAT/Universal binaries.
FAT_MAGIC: 32-bit FAT binary, big-endian (0xcafebabe)FAT_CIGAM: 32-bit FAT binary, byte-swapped (0xbebafeca)FAT_MAGIC_64: 64-bit FAT binary, big-endian (0xcafebabf)FAT_CIGAM_64: 64-bit FAT binary, byte-swapped (0xbfbafeca)Convert a fat_magic value to its integer representation.
type fat_arch = {fa_cputype : cpu_type;CPU type
*)fa_cpusubtype : cpu_subtype;CPU subtype
*)fa_offset : Object_types.u32;File offset to this architecture's Mach-O
*)fa_size : Object_types.u32;Size of this architecture's Mach-O
*)fa_align : Object_types.u32;Alignment as a power of 2
*)}Architecture descriptor for 32-bit FAT binaries. Describes the location and size of a single architecture's Mach-O binary within the FAT file.
type fat_arch_64 = {fa64_cputype : cpu_type;CPU type
*)fa64_cpusubtype : cpu_subtype;CPU subtype
*)fa64_offset : Object_types.u64;File offset to this architecture's Mach-O
*)fa64_size : Object_types.u64;Size of this architecture's Mach-O
*)fa64_align : Object_types.u32;Alignment as a power of 2
*)fa64_reserved : Object_types.u32;Reserved, must be 0
*)}Architecture descriptor for 64-bit FAT binaries. Used when offsets or sizes exceed 4GB (2^32 bytes).
Union type for either 32-bit or 64-bit FAT architecture descriptor.
type fat_header = {fat_magic : fat_magic;Magic number identifying FAT format
*)fat_archs : fat_arch_any array;Array of architecture descriptors
*)}FAT binary header containing magic number and all architecture descriptors. FAT binaries are always stored in big-endian format.
is_fat buffer checks if the buffer contains a FAT/Universal binary by examining the magic number at the beginning of the buffer.
read_fat buffer parses a FAT binary header from the buffer. The buffer must point to the start of a FAT binary. Handles both 32-bit and 64-bit FAT formats and performs byte-swapping if needed (FAT is always big-endian).
extract_arch buffer arch extracts a single architecture's Mach-O binary from a FAT binary as a sub-buffer. The returned buffer can be passed to read to parse the Mach-O contents.
arch_name arch returns the architecture name as a string (e.g. "x86_64", "arm64", "arm64e"). Handles special cases like ARM64E (subtype 2).
find_arch fat_header arch_name searches for an architecture by name in the FAT header.
extract_arch_by_name buffer arch_name extracts a single architecture's Mach-O binary by name from a FAT binary. Convenience function combining read_fat, find_arch, and extract_arch.
type fat_validation_error = | Overlap of int * int * int * intArchitecture overlap: (offset1, size1, offset2, size2)
*)| Invalid_alignment of string * int * intInvalid alignment: (arch_name, offset, align)
*)| Out_of_bounds of string * int * int * intOut of bounds: (arch_name, offset, size, buffer_size)
*)| Invalid_arch_count of intInvalid architecture count
*)validate_fat buffer validates a FAT binary for correctness. Checks for overlapping architectures, proper alignment, and bounds.