Mach-O Reference
LC_CODE_SIGNATURELC_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.
| Field | Meaning |
|---|---|
cmd | LC_CODE_SIGNATURE (0x1d). |
cmdsize | 16 bytes. |
dataoff | File offset of the signature blob. |
datasize | Its 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:
| Slot | Sub-blob | Magic |
|---|---|---|
| CodeDirectory | Hashes of every page of the image | 0xfade0c02 |
| Requirements | The designated requirement | 0xfade0c01 |
| Entitlements | The entitlements property list | 0xfade7171 |
| DER Entitlements | The same entitlements, DER-encoded | 0xfade7172 |
| CMS Signature | The PKCS#7 / CMS signature blob | 0xfade0b01 |
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).