#include <mach-o/fixup-chains.h>
mach-o/fixup-chains.h
#define LC_DYLD_EXPORTS_TRIE 0x80000033 // used with linkedit_data_command
structdyld_chained_fixups_header
header of the LC_DYLD_CHAINED_FIXUPS payload
| uint32_t | fixups_version | 0 |
| uint32_t | starts_offset | offset of dyld_chained_starts_in_image in chain_data |
| uint32_t | imports_offset | offset of imports table in chain_data |
| uint32_t | symbols_offset | offset of symbol strings in chain_data |
| uint32_t | imports_count | number of imported symbol names |
| uint32_t | imports_format | DYLD_CHAINED_IMPORT* |
| uint32_t | symbols_format | 0 => uncompressed, 1 => zlib compressed |
structdyld_chained_starts_in_image
This struct is embedded in LC_DYLD_CHAINED_FIXUPS payload
| uint32_t | seg_count | |
| uint32_t[1] | seg_info_offset | each entry is offset into this struct for that segment |
structdyld_chained_starts_in_segment
This struct is embedded in dyld_chain_starts_in_image
and passed down to the kernel for page-in linking
| uint32_t | size | size of this (amount kernel needs to copy) |
| uint16_t | page_size | 0x1000 or 0x4000 |
| uint16_t | pointer_format | DYLD_CHAINED_PTR_* |
| uint64_t | segment_offset | offset in memory to start of segment |
| uint32_t | max_valid_pointer | for 32-bit OS, any value beyond this is not a pointer |
| uint16_t | page_count | how many pages are in array |
| uint16_t[1] | page_start | each entry is offset in each page of first element in chain |
enum(anonymous)
| DYLD_CHAINED_PTR_START_NONE | 65535 | used in page_start[] to denote a page with no fixups |
| DYLD_CHAINED_PTR_START_MULTI | 32768 | used in page_start[] to denote a page which has multiple starts |
| DYLD_CHAINED_PTR_START_LAST | 32768 | used in chain_starts[] to denote last start in list for page |
enum(anonymous)
these values are set in the reserved1 field of the __chain_starts section
| DYLD_CHAINED_STARTS_USE_FILE_OFFSET | 1 | denotes chain starts linked with -fixup_chains_section |
| DYLD_CHAINED_STARTS_USE_VM_OFFSET | 2 | denotes chain starts linked with -fixup_chains_section_vm |
structdyld_chained_starts_offsets
This struct is embedded in __TEXT,__chain_starts section in firmware
| uint32_t | pointer_format | DYLD_CHAINED_PTR_32_FIRMWARE or DYLD_CHAINED_PTR_ARM64E_KERNEL |
| uint32_t | starts_count | number of starts in array |
| uint32_t[1] | chain_starts | array chain start offsets |
enum(anonymous)
values for dyld_chained_starts_in_segment.pointer_format
| DYLD_CHAINED_PTR_ARM64E | 1 | stride 8, unauth target is vmaddr |
| DYLD_CHAINED_PTR_64 | 2 | target is vmaddr |
| DYLD_CHAINED_PTR_32 | 3 | target is vmaddr |
| DYLD_CHAINED_PTR_32_CACHE | 4 | |
| DYLD_CHAINED_PTR_32_FIRMWARE | 5 | |
| DYLD_CHAINED_PTR_64_OFFSET | 6 | target is vm offset |
| DYLD_CHAINED_PTR_ARM64E_OFFSET | 7 | old name |
| DYLD_CHAINED_PTR_ARM64E_KERNEL | 7 | stride 4, unauth target is vm offset |
| DYLD_CHAINED_PTR_64_KERNEL_CACHE | 8 | |
| DYLD_CHAINED_PTR_ARM64E_USERLAND | 9 | stride 8, unauth target is vm offset |
| DYLD_CHAINED_PTR_ARM64E_FIRMWARE | 10 | stride 4, unauth target is vmaddr |
| DYLD_CHAINED_PTR_X86_64_KERNEL_CACHE | 11 | stride 1, x86_64 kernel caches |
| DYLD_CHAINED_PTR_ARM64E_USERLAND24 | 12 | stride 8, unauth target is vm offset, 24-bit bind |
| DYLD_CHAINED_PTR_ARM64E_SHARED_CACHE | 13 | stride 8, regular/auth targets both vm offsets. Only A keys supported |
| DYLD_CHAINED_PTR_ARM64E_SEGMENTED | 14 | stride 4, rebase offsets use segIndex and segOffset |
structdyld_chained_ptr_arm64e_rebase
| uint64_t:43 | target | |
| uint64_t:8 | high8 | |
| uint64_t:11 | next | 4 or 8-byte stide |
| uint64_t:1 | bind | == 0 |
| uint64_t:1 | auth | == 0 |
structdyld_chained_ptr_arm64e_bind
| uint64_t:16 | ordinal | |
| uint64_t:16 | zero | |
| uint64_t:19 | addend | +/-256K |
| uint64_t:11 | next | 4 or 8-byte stide |
| uint64_t:1 | bind | == 1 |
| uint64_t:1 | auth | == 0 |
structdyld_chained_ptr_arm64e_auth_rebase
| uint64_t:32 | target | runtimeOffset |
| uint64_t:16 | diversity | |
| uint64_t:1 | addrDiv | |
| uint64_t:2 | key | |
| uint64_t:11 | next | 4 or 8-byte stide |
| uint64_t:1 | bind | == 0 |
| uint64_t:1 | auth | == 1 |
structdyld_chained_ptr_arm64e_auth_bind
| uint64_t:16 | ordinal | |
| uint64_t:16 | zero | |
| uint64_t:16 | diversity | |
| uint64_t:1 | addrDiv | |
| uint64_t:2 | key | |
| uint64_t:11 | next | 4 or 8-byte stide |
| uint64_t:1 | bind | == 1 |
| uint64_t:1 | auth | == 1 |
structdyld_chained_ptr_64_rebase
| uint64_t:36 | target | 64GB max image size (DYLD_CHAINED_PTR_64 => vmAddr, DYLD_CHAINED_PTR_64_OFFSET => runtimeOffset) |
| uint64_t:8 | high8 | top 8 bits set to this (DYLD_CHAINED_PTR_64 => after slide added, DYLD_CHAINED_PTR_64_OFFSET => before slide added) |
| uint64_t:7 | reserved | all zeros |
| uint64_t:12 | next | 4-byte stride |
| uint64_t:1 | bind | == 0 |
structdyld_chained_ptr_arm64e_bind24
| uint64_t:24 | ordinal | |
| uint64_t:8 | zero | |
| uint64_t:19 | addend | +/-256K |
| uint64_t:11 | next | 8-byte stide |
| uint64_t:1 | bind | == 1 |
| uint64_t:1 | auth | == 0 |
structdyld_chained_ptr_arm64e_auth_bind24
| uint64_t:24 | ordinal | |
| uint64_t:8 | zero | |
| uint64_t:16 | diversity | |
| uint64_t:1 | addrDiv | |
| uint64_t:2 | key | |
| uint64_t:11 | next | 8-byte stide |
| uint64_t:1 | bind | == 1 |
| uint64_t:1 | auth | == 1 |
structdyld_chained_ptr_arm64e_segmented_rebase
| uint32_t:28 | targetSegOffset | offset in segment |
| uint32_t:4 | targetSegIndex | index into segment address table |
| uint32_t:19 | padding | |
| uint32_t:12 | next | 4-byte stide |
| uint32_t:1 | auth | == 0 |
structdyld_chained_ptr_arm64e_auth_segmented_rebase
| uint32_t:28 | targetSegOffset | offset in segment |
| uint32_t:4 | targetSegIndex | index into segment address table |
| uint32_t:16 | diversity | |
| uint32_t:1 | addrDiv | |
| uint32_t:2 | key | |
| uint32_t:12 | next | 4-byte stide |
| uint32_t:1 | auth | == 1 |
structdyld_chained_ptr_64_bind
| uint64_t:24 | ordinal | |
| uint64_t:8 | addend | 0 thru 255 |
| uint64_t:19 | reserved | all zeros |
| uint64_t:12 | next | 4-byte stride |
| uint64_t:1 | bind | == 1 |
structdyld_chained_ptr_64_kernel_cache_rebase
| uint64_t:30 | target | basePointers[cacheLevel] + target |
| uint64_t:2 | cacheLevel | what level of cache to bind to (indexes a mach_header array) |
| uint64_t:16 | diversity | |
| uint64_t:1 | addrDiv | |
| uint64_t:2 | key | |
| uint64_t:12 | next | 1 or 4-byte stide |
| uint64_t:1 | isAuth | 0 -> not authenticated. 1 -> authenticated |
structdyld_chained_ptr_32_rebase
DYLD_CHAINED_PTR_32
Note: for DYLD_CHAINED_PTR_32 some non-pointer values are co-opted into the chain
as out of range rebases. If an entry in the chain is > max_valid_pointer, then it
is not a pointer. To restore the value, subtract off the bias, which is
(64MB+max_valid_pointer)/2.
| uint32_t:26 | target | vmaddr, 64MB max image size |
| uint32_t:5 | next | 4-byte stride |
| uint32_t:1 | bind | == 0 |
structdyld_chained_ptr_32_bind
| uint32_t:20 | ordinal | |
| uint32_t:6 | addend | 0 thru 63 |
| uint32_t:5 | next | 4-byte stride |
| uint32_t:1 | bind | == 1 |
structdyld_chained_ptr_32_cache_rebase
| uint32_t:30 | target | 1GB max dyld cache TEXT and DATA |
| uint32_t:2 | next | 4-byte stride |
structdyld_chained_ptr_32_firmware_rebase
| uint32_t:26 | target | 64MB max firmware TEXT and DATA |
| uint32_t:6 | next | 4-byte stride |
enum(anonymous)
values for dyld_chained_fixups_header.imports_format
| DYLD_CHAINED_IMPORT | 1 | |
| DYLD_CHAINED_IMPORT_ADDEND | 2 | |
| DYLD_CHAINED_IMPORT_ADDEND64 | 3 |
structdyld_chained_import
| uint32_t:8 | lib_ordinal | -15 .. 240 (0xF1 .. 0xF0) |
| uint32_t:1 | weak_import | |
| uint32_t:23 | name_offset |
structdyld_chained_import_addend
| uint32_t:8 | lib_ordinal | -15 .. 240 (0xF1 .. 0xF0) |
| uint32_t:1 | weak_import | |
| uint32_t:23 | name_offset | |
| int32_t | addend |
structdyld_chained_import_addend64
| uint64_t:16 | lib_ordinal | -15 .. 65520 (0xFFF1 .. 0xFFF0) |
| uint64_t:1 | weak_import | |
| uint64_t:15 | reserved | |
| uint64_t:32 | name_offset | |
| uint64_t | addend |