Skip to content

Mach-O Reference

LC_CODE_SIGNATURE

LC_CODE_SIGNATURE — the embedded signature

LC_CODE_SIGNATURE points at the Code Signing SuperBlob stored at the end of a Mach-O file: the CodeDirectory, the entitlements, the requirements and the CMS signature that together sign the image.

What it is

LC_CODE_SIGNATURE is a linkedit_data_command: two offsets that point at a blob of signing data appended to the file, inside __LINKEDIT.

FieldMeaning
cmdLC_CODE_SIGNATURE (0x1d).
cmdsize16 bytes.
dataoffFile offset of the signature blob.
datasizeIts length in bytes.

The SuperBlob

The data at dataoff is an embedded signature SuperBlob, and everything in it is big-endian. It begins with a magic (0xfade0cc0), a total length and a count, followed by an index. Each index entry pairs a slot type with the offset of a sub-blob:

SlotSub-blobMagic
CodeDirectoryHashes of every page of the image0xfade0c02
RequirementsThe designated requirement0xfade0c01
EntitlementsThe entitlements property list0xfade7171
DER EntitlementsThe same entitlements, DER-encoded0xfade7172
CMS SignatureThe PKCS#7 / CMS signature blob0xfade0b01

See code signing and entitlements for what the CodeDirectory and entitlements contain, and how the cdhash is formed.

How a parser reads it

Read the SuperBlob header, then walk its index. For each entry, jump to the sub-blob, read its own magic and length, and dispatch on the magic: parse the CodeDirectory for the signing identifier and hashes, read the entitlements plist as text, and note the presence of the CMS signature. A file can be unsigned (no LC_CODE_SIGNATURE), ad-hoc signed (a CodeDirectory but no CMS signature), or signed (a full CMS signature chaining to a certificate).