]> git.saurik.com Git - apple/dyld.git/blob - launch-cache/CacheFileAbstraction.hpp
dyld-195.5.tar.gz
[apple/dyld.git] / launch-cache / CacheFileAbstraction.hpp
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
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
12 * file.
13 *
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.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 #ifndef __DYLD_CACHE_ABSTRACTION__
25 #define __DYLD_CACHE_ABSTRACTION__
26
27 #include "dyld_cache_format.h"
28
29 #include "FileAbstraction.hpp"
30 #include "Architectures.hpp"
31
32 template <typename E>
33 class dyldCacheHeader {
34 public:
35 const char* magic() const INLINE { return fields.magic; }
36 void set_magic(const char* value) INLINE { memcpy(fields.magic, value, 16); }
37
38 uint32_t mappingOffset() const INLINE { return E::get32(fields.mappingOffset); }
39 void set_mappingOffset(uint32_t value) INLINE { E::set32(fields.mappingOffset, value); }
40
41 uint32_t mappingCount() const INLINE { return E::get32(fields.mappingCount); }
42 void set_mappingCount(uint32_t value) INLINE { E::set32(fields.mappingCount, value); }
43
44 uint32_t imagesOffset() const INLINE { return E::get32(fields.imagesOffset); }
45 void set_imagesOffset(uint32_t value) INLINE { E::set32(fields.imagesOffset, value); }
46
47 uint32_t imagesCount() const INLINE { return E::get32(fields.imagesCount); }
48 void set_imagesCount(uint32_t value) INLINE { E::set32(fields.imagesCount, value); }
49
50 uint64_t dyldBaseAddress() const INLINE { return E::get64(fields.dyldBaseAddress); }
51 void set_dyldBaseAddress(uint64_t value) INLINE { E::set64(fields.dyldBaseAddress, value); }
52
53 uint64_t codeSignatureOffset() const INLINE { return E::get64(fields.codeSignatureOffset); }
54 void set_codeSignatureOffset(uint64_t value) INLINE { E::set64(fields.codeSignatureOffset, value); }
55
56 uint64_t codeSignatureSize() const INLINE { return E::get64(fields.codeSignatureSize); }
57 void set_codeSignatureSize(uint64_t value) INLINE { E::set64(fields.codeSignatureSize, value); }
58
59 uint64_t slideInfoOffset() const INLINE { return E::get64(fields.slideInfoOffset); }
60 void set_slideInfoOffset(uint64_t value) INLINE { E::set64(fields.slideInfoOffset, value); }
61
62 uint64_t slideInfoSize() const INLINE { return E::get64(fields.slideInfoSize); }
63 void set_slideInfoSize(uint64_t value) INLINE { E::set64(fields.slideInfoSize, value); }
64
65 private:
66 dyld_cache_header fields;
67 };
68
69
70 template <typename E>
71 class dyldCacheFileMapping {
72 public:
73 uint64_t address() const INLINE { return E::get64(fields.address); }
74 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
75
76 uint64_t size() const INLINE { return E::get64(fields.size); }
77 void set_size(uint64_t value) INLINE { E::set64(fields.size, value); }
78
79 uint64_t file_offset() const INLINE { return E::get64(fields.fileOffset); }
80 void set_file_offset(uint64_t value) INLINE { E::set64(fields.fileOffset, value); }
81
82 uint32_t max_prot() const INLINE { return E::get32(fields.maxProt); }
83 void set_max_prot(uint32_t value) INLINE { E::set32((uint32_t&)fields.maxProt, value); }
84
85 uint32_t init_prot() const INLINE { return E::get32(fields.initProt); }
86 void set_init_prot(uint32_t value) INLINE { E::set32((uint32_t&)fields.initProt, value); }
87
88 private:
89 dyld_cache_mapping_info fields;
90 };
91
92
93 template <typename E>
94 class dyldCacheImageInfo {
95 public:
96 uint64_t address() const INLINE { return E::get64(fields.address); }
97 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
98
99 uint64_t modTime() const INLINE { return E::get64(fields.modTime); }
100 void set_modTime(uint64_t value) INLINE { E::set64(fields.modTime, value); }
101
102 uint64_t inode() const INLINE { return E::get64(fields.inode); }
103 void set_inode(uint64_t value) INLINE { E::set64(fields.inode, value); }
104
105 uint32_t pathFileOffset() const INLINE { return E::get32(fields.pathFileOffset); }
106 void set_pathFileOffset(uint32_t value) INLINE { E::set32(fields.pathFileOffset, value); fields.pad=0; }
107
108 private:
109 dyld_cache_image_info fields;
110 };
111
112 template <typename E>
113 class dyldCacheSlideInfo {
114 public:
115 uint32_t version() const INLINE { return E::get32(fields.version); }
116 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
117
118 uint32_t toc_offset() const INLINE { return E::get32(fields.toc_offset); }
119 void set_toc_offset(uint32_t value) INLINE { E::set32(fields.toc_offset, value); }
120
121 uint32_t toc_count() const INLINE { return E::get32(fields.toc_count); }
122 void set_toc_count(uint32_t value) INLINE { E::set32(fields.toc_count, value); }
123
124 uint32_t entries_offset() const INLINE { return E::get32(fields.entries_offset); }
125 void set_entries_offset(uint32_t value) INLINE { E::set32(fields.entries_offset, value); }
126
127 uint32_t entries_count() const INLINE { return E::get32(fields.entries_count); }
128 void set_entries_count(uint32_t value) INLINE { E::set32(fields.entries_count, value); }
129
130 uint32_t entries_size() const INLINE { return E::get32(fields.entries_size); }
131 void set_entries_size(uint32_t value) INLINE { E::set32(fields.entries_size, value); }
132
133 uint16_t toc(unsigned index) const INLINE { return E::get16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.toc_offset)))[index]); }
134 void set_toc(unsigned index, uint16_t value) INLINE { return E::set16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.toc_offset)))[index], value); }
135
136 private:
137 dyld_cache_slide_info fields;
138 };
139
140
141 struct dyldCacheSlideInfoEntry {
142 uint8_t bits[4096/(8*4)]; // 128-byte bitmap
143 };
144
145
146
147 #endif // __DYLD_CACHE_ABSTRACTION__
148
149