Mach-O

Mach-O, für Mach Object, beschreibt das Standard-Binärformat ausführbarer Programme, Bibliotheken und von Speicherauszügen unter vielen MACH-basierten UNIX-Betriebssystemen wie beispielsweise OPENSTEP (ursprünglich NeXTStep), FreeBSD oder macOS (ursprünglich unter dem Namen Mac OS X).

Es wurde ab 1985 an der Carnegie Mellon University, kurz CMU, für das MACH-Betriebssystem entwickelt. Große Verbreitung hat es vor allem unter NeXTStep und dessen Weiterentwicklung macOS und darauf basierenden Apple-Systemen, wie iOS und iPadOS. Mit Universal Binaries, unter NeXTStep Multi-Architecture Binaries, wurde das Format zudem um Multi-Prozessorarchitektur-Fähigkeit erweitert.

Aufbau

Eine Mach-O-Datei besteht im Wesentlichen aus drei Teilen:[1]

  • Kopfinformationen, englisch header
    • Magic
    • diverse Flags
    • Anzahl und Größe der Load commands
  • Load commands
    • Metadaten
    • Offset-Addressen der Segmente
  • Segmente, segments
    • bis zu 255 Sektionen, sections

Der Mach-Header ist ein 32 Bytes großer Bereich am Anfang einer 64-Bit-Mach-O-Binärdatei bzw. 28 Bytes bei 32-Bit-Mach-O. Der folgende Quelltext stammt aus osfmk/mach-o/loader.h von XNU, dem Kernel von macOS.[2]

struct mach_header_64 {
	uint32_t	    magic;		    /* mach magic number identifier */
	cpu_type_t	    cputype;	    /* cpu specifier */
	cpu_subtype_t	cpusubtype;	    /* machine specifier */
	uint32_t	    filetype;	    /* type of file */
	uint32_t	    ncmds;  		/* number of load commands */
	uint32_t	    sizeofcmds; 	/* the size of all the load commands */
	uint32_t	    flags;	    	/* flags */
	uint32_t	    reserved;   	/* reserved (64-Bit only) */
};

Ein Beispiel für einen Mach-Header aus einer beliebigen Programmdatei:[3]

Offset
(hex)
Länge
(dec)
Inhalt Beispiel
00 4 mach magic number identifier 0xfeedfacfMH_MAGIC_64
04 4 CPU type 0x01000007CPU_TYPE_X86_64 = CPU_TYPE_I386 | CPU_ARCH_ABI64
08 4 CPU subtype, machine specifier 0x80000003CPU_SUBTYPE_X86_ALL | CPU_SUBTYPE_LIB64
12 4 Dateityp 0x00000002MH_EXECUTE
16 4 Anzahl der load commands 0x00000010
20 4 Größe aller load commands 0x00000510 bytes
24 4 Flags 0x00200085 → u. a. MH_DYLDLINK | MH_NOUNDEFS
28 4 reserviert (fehlt bei 32-Bit-Mach-O) 0x00000000

Siehe auch

  • Harry Moulton: Mach-O File Format: Introduction. 3. Januar 2020, archiviert vom Original am 22. November 2021; (englisch).

Einzelnachweise

  1. William Woodruff: Mach-O Internals. (PDF; 307 KB) 10. Februar 2016, S. 10; (englisch).
  2. Apple, Inc.: XNU Kernel Source. Archiviert vom Original am 22. November 2021; abgerufen am 22. November 2021 (englisch).
  3. How to read Mach-O header from object file?

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.