1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
24 #ifndef __DYLD_CACHE_ABSTRACTION__
25 #define __DYLD_CACHE_ABSTRACTION__
27 #include "dyld_cache_format.h"
29 #include "FileAbstraction.hpp"
30 #include "Architectures.hpp"
33 class dyldCacheHeader {
35 const char* magic() const INLINE { return fields.magic; }
36 void set_magic(const char* value) INLINE { memcpy(fields.magic, value, 16); }
38 uint32_t mappingOffset() const INLINE { return E::get32(fields.mappingOffset); }
39 void set_mappingOffset(uint32_t value) INLINE { E::set32(fields.mappingOffset, value); }
41 uint32_t mappingCount() const INLINE { return E::get32(fields.mappingCount); }
42 void set_mappingCount(uint32_t value) INLINE { E::set32(fields.mappingCount, value); }
44 uint32_t imagesOffset() const INLINE { return E::get32(fields.imagesOffset); }
45 void set_imagesOffset(uint32_t value) INLINE { E::set32(fields.imagesOffset, value); }
47 uint32_t imagesCount() const INLINE { return E::get32(fields.imagesCount); }
48 void set_imagesCount(uint32_t value) INLINE { E::set32(fields.imagesCount, value); }
50 uint64_t dyldBaseAddress() const INLINE { return E::get64(fields.dyldBaseAddress); }
51 void set_dyldBaseAddress(uint64_t value) INLINE { E::set64(fields.dyldBaseAddress, value); }
53 uint64_t codeSignatureOffset() const INLINE { return E::get64(fields.codeSignatureOffset); }
54 void set_codeSignatureOffset(uint64_t value) INLINE { E::set64(fields.codeSignatureOffset, value); }
56 uint64_t codeSignatureSize() const INLINE { return E::get64(fields.codeSignatureSize); }
57 void set_codeSignatureSize(uint64_t value) INLINE { E::set64(fields.codeSignatureSize, value); }
59 uint64_t slideInfoOffset() const INLINE { return E::get64(fields.slideInfoOffset); }
60 void set_slideInfoOffset(uint64_t value) INLINE { E::set64(fields.slideInfoOffset, value); }
62 uint64_t slideInfoSize() const INLINE { return E::get64(fields.slideInfoSize); }
63 void set_slideInfoSize(uint64_t value) INLINE { E::set64(fields.slideInfoSize, value); }
65 uint64_t localSymbolsOffset() const INLINE { return E::get64(fields.localSymbolsOffset); }
66 void set_localSymbolsOffset(uint64_t value) INLINE { E::set64(fields.localSymbolsOffset, value); }
68 uint64_t localSymbolsSize() const INLINE { return E::get64(fields.localSymbolsSize); }
69 void set_localSymbolsSize(uint64_t value) INLINE { E::set64(fields.localSymbolsSize, value); }
71 const uint8_t* uuid() const INLINE { return fields.uuid; }
72 void set_uuid(const uint8_t value[16]) INLINE { memcpy(fields.uuid, value, 16); }
74 uint64_t cacheType() const INLINE { return E::get64(fields.cacheType); }
75 void set_cacheType(uint64_t value) INLINE { E::set64(fields.cacheType, value); }
78 dyld_cache_header fields;
83 class dyldCacheFileMapping {
85 uint64_t address() const INLINE { return E::get64(fields.address); }
86 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
88 uint64_t size() const INLINE { return E::get64(fields.size); }
89 void set_size(uint64_t value) INLINE { E::set64(fields.size, value); }
91 uint64_t file_offset() const INLINE { return E::get64(fields.fileOffset); }
92 void set_file_offset(uint64_t value) INLINE { E::set64(fields.fileOffset, value); }
94 uint32_t max_prot() const INLINE { return E::get32(fields.maxProt); }
95 void set_max_prot(uint32_t value) INLINE { E::set32((uint32_t&)fields.maxProt, value); }
97 uint32_t init_prot() const INLINE { return E::get32(fields.initProt); }
98 void set_init_prot(uint32_t value) INLINE { E::set32((uint32_t&)fields.initProt, value); }
101 dyld_cache_mapping_info fields;
105 template <typename E>
106 class dyldCacheImageInfo {
108 uint64_t address() const INLINE { return E::get64(fields.address); }
109 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
111 uint64_t modTime() const INLINE { return E::get64(fields.modTime); }
112 void set_modTime(uint64_t value) INLINE { E::set64(fields.modTime, value); }
114 uint64_t inode() const INLINE { return E::get64(fields.inode); }
115 void set_inode(uint64_t value) INLINE { E::set64(fields.inode, value); }
117 uint32_t pathFileOffset() const INLINE { return E::get32(fields.pathFileOffset); }
118 void set_pathFileOffset(uint32_t value) INLINE { E::set32(fields.pathFileOffset, value); fields.pad=0; }
121 dyld_cache_image_info fields;
124 template <typename E>
125 class dyldCacheSlideInfo {
127 uint32_t version() const INLINE { return E::get32(fields.version); }
128 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
130 uint32_t toc_offset() const INLINE { return E::get32(fields.toc_offset); }
131 void set_toc_offset(uint32_t value) INLINE { E::set32(fields.toc_offset, value); }
133 uint32_t toc_count() const INLINE { return E::get32(fields.toc_count); }
134 void set_toc_count(uint32_t value) INLINE { E::set32(fields.toc_count, value); }
136 uint32_t entries_offset() const INLINE { return E::get32(fields.entries_offset); }
137 void set_entries_offset(uint32_t value) INLINE { E::set32(fields.entries_offset, value); }
139 uint32_t entries_count() const INLINE { return E::get32(fields.entries_count); }
140 void set_entries_count(uint32_t value) INLINE { E::set32(fields.entries_count, value); }
142 uint32_t entries_size() const INLINE { return E::get32(fields.entries_size); }
143 void set_entries_size(uint32_t value) INLINE { E::set32(fields.entries_size, value); }
145 uint16_t toc(unsigned index) const INLINE { return E::get16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.toc_offset)))[index]); }
146 void set_toc(unsigned index, uint16_t value) INLINE { return E::set16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.toc_offset)))[index], value); }
149 dyld_cache_slide_info fields;
153 struct dyldCacheSlideInfoEntry {
154 uint8_t bits[4096/(8*4)]; // 128-byte bitmap
159 template <typename E>
160 class dyldCacheLocalSymbolsInfo {
162 uint32_t nlistOffset() const INLINE { return E::get32(fields.nlistOffset); }
163 void set_nlistOffset(uint32_t value) INLINE { E::set32(fields.nlistOffset, value); }
165 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
166 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
168 uint32_t stringsOffset() const INLINE { return E::get32(fields.stringsOffset); }
169 void set_stringsOffset(uint32_t value) INLINE { E::set32(fields.stringsOffset, value); }
171 uint32_t stringsSize() const INLINE { return E::get32(fields.stringsSize); }
172 void set_stringsSize(uint32_t value) INLINE { E::set32(fields.stringsSize, value); }
174 uint32_t entriesOffset() const INLINE { return E::get32(fields.entriesOffset); }
175 void set_entriesOffset(uint32_t value) INLINE { E::set32(fields.entriesOffset, value); }
177 uint32_t entriesCount() const INLINE { return E::get32(fields.entriesCount); }
178 void set_entriesCount(uint32_t value) INLINE { E::set32(fields.entriesCount, value); }
181 dyld_cache_local_symbols_info fields;
185 template <typename E>
186 class dyldCacheLocalSymbolEntry {
188 uint32_t dylibOffset() const INLINE { return E::get32(fields.dylibOffset); }
189 void set_dylibOffset(uint32_t value) INLINE { E::set32(fields.dylibOffset, value); }
191 uint32_t nlistStartIndex() const INLINE { return E::get32(fields.nlistStartIndex); }
192 void set_nlistStartIndex(uint32_t value) INLINE { E::set32(fields.nlistStartIndex, value); }
194 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
195 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
198 dyld_cache_local_symbols_entry fields;
204 #endif // __DYLD_CACHE_ABSTRACTION__