Chameleon

Chameleon Commit Details

Date:2010-09-28 01:44:47 (8 years 10 months ago)
Author:Evan Lojewski
Commit:565
Parents: 564
Message:Added missing file
Changes:
A/branches/meklort/i386/modules/KextPatcher/mkext.h

File differences

branches/meklort/i386/modules/KextPatcher/mkext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
* Copyright (c) 2008 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
#ifndef _MKEXT_H_
#define _MKEXT_H_ 1
#include <sys/cdefs.h>
#include <sys/types.h>
#include <mach/machine.h>
/*********************************************************************
* Mkext File Format
*
* ALL BINARY VALUES ARE BIG-ENDIAN.
*********************************************************************/
#if PRAGMA_MARK
#pragma mark Constants
#endif
#define MKEXT_MAGIC 0x4D4B5854 /* 'MKXT' */
#define MKEXT_SIGN 0x4D4F5358 /* 'MOSX' */
#define MKEXT_EXTN ".mkext"
#define MKEXT_VERS_1 (0x01008000)
// Used during development/bringup: v 2.0d1
#define MKEXT_VERS_2 (0x02002001)
// xxx - Will use this when format is final
// #define MKEXT_VERS_2 (0x02008000)
#if PRAGMA_MARK
#pragma mark Core Header
#endif
/*********************************************************************
* Core Header
*
* All versions of mkext files have this basic header:
*
* - magic & signature - always 'MKXT' and 'MOSX' as defined above.
* - length - the length of the whole file
* - adler32 - checksum from &version to end of file
* - version - a 'vers' style value
* - numkexts - how many kexts are in the archive (only needed in v.1)
* - cputype & cpusubtype - in version 1 could be CPU_TYPE_ANY
* and CPU_SUBTYPE_MULTIPLE if the archive contained fat kexts;
* version 2 does not allow this and all kexts must be of a single
* arch. For either version, mkexts of specific arches can be
* embedded in a fat Mach-O file to combine them.
*********************************************************************/
#define MKEXT_HEADER_CORE \
uint32_t magic; \
uint32_t signature; \
uint32_t length; \
uint32_t adler32; \
uint32_t version; \
uint32_t numkexts; \
cpu_type_t cputype; \
cpu_subtype_t cpusubtype;
typedef struct mkext_basic_header {
MKEXT_HEADER_CORE
} mkext_basic_header;
#define MKEXT_HDR_CAST(hdr) ((mkext_basic_header *)(hdr))
#define MKEXT_SWAP(num) OSSwapBigToHostInt32((uint32_t)(num))
#define MKEXT_GET_MAGIC(hdr) (MKEXT_SWAP(MKEXT_HDR_CAST(hdr)->magic))
#define MKEXT_GET_SIGNATURE(hdr) (MKEXT_SWAP(MKEXT_HDR_CAST(hdr)->signature))
#define MKEXT_GET_LENGTH(hdr) (MKEXT_SWAP(MKEXT_HDR_CAST(hdr)->length))
#define MKEXT_GET_CHECKSUM(hdr) (MKEXT_SWAP(MKEXT_HDR_CAST(hdr)->adler32))
#define MKEXT_GET_VERSION(hdr) (MKEXT_SWAP(MKEXT_HDR_CAST(hdr)->version))
#define MKEXT_GET_COUNT(hdr) (MKEXT_SWAP(MKEXT_HDR_CAST(hdr)->numkexts))
#define MKEXT_GET_CPUTYPE(hdr) (MKEXT_SWAP(MKEXT_HDR_CAST(hdr)->cputype))
#define MKEXT_GET_CPUSUBTYPE(hdr) (MKEXT_SWAP(MKEXT_HDR_CAST(hdr)->cpusubtype))
#if PRAGMA_MARK
#pragma mark Mkext Version 2 Format Definitions
#endif
/*********************************************************************
* Mkext Version 2 Format Definitions
*
* The version field here will be some variant of 0x0200....; that is
* the major version byte will be 0x02.
*
* Version 2 uses zlib for compression, not the lzss compressor used
* by version 1.
*
* In version 2, all executable & resource files are stored in sequence
* followed by the combined info dictionaries of all kexts at the end.
* This XML plist should be nul-terminated and stored at a page-aligned
* offset in the file so that kernel code can unmap it as soon as it's
* parsed.
*
* The info dict for each kext will have inserted into it these
* additional properties:
*
* - _MKEXTBundlePath (string) - full path to the original bundle,
* relative to volume.
* - _MKEXTExecutable (integer) - offset to the executable entry.
* - _MKEXTResources (dict) - keyed by filename, values integer offsets
* to file entries.
*
* Mkext2 buffers are used to send load requests to the kernel. When
* this is done, the plist will contain an _MKEXTLoadRequest dictionary
* whose keys are the bundle IDs to load, and whose values are
* dictionaries of flags:
*
* - "Load Kext" - boolean, whether to load the kext or not (default true).
* May be used to send just personalities for already-loaded kexts,
* but we do have a mechanism to do that from userland already.
* - "Start Kext" - boolean, whether to start the kext or not
* (used when debugging). Defaults to true.
* - "Add Personalities" - boolean, whether to send personalities to
* the IOCatalogue (used when debugging). Defaults to true.
* - "Disable Autounload" - boolean, whether to prevent the reaper
* thread from unloading the kext, so the dev. has time to set up
* the debug session. (Predefined window, or maybe this will be a
* number of seconds to wait.) Defaults to false.
*********************************************************************/
#define kMKEXTInfoDictionariesKey "_MKEXTInfoDictionaries"
#define kMKEXTBundlePathKey "_MKEXTBundlePath"
#define kMKEXTExecutableKey "_MKEXTExecutable"
#define kMKEXTLoadRequestKey "_MKEXTLoadRequest"
#define kMKEXTLoadRequestLoadKey "Load Kext"
#define kMKEXTLoadRequestStartKey "Start Kext"
#define kMKEXTLoadRequestAddPersonalitiesKey "Add Personalities"
#define kMKEXTLoadRequestDisableAutounloadKey "Disable Autounload"
typedef struct mkext2_file_entry {
uint32_t compressed_size; // if zero, file is not compressed
uint32_t full_size; // full size of data w/o this struct
uint8_t data[0]; // data is inline to this struct
} mkext2_file_entry;
typedef struct mkext2_header {
MKEXT_HEADER_CORE
uint32_t plist_offset;
uint32_t plist_compressed_size;
uint32_t plist_full_size;
} mkext2_header;
#define MKEXT2_GET_ENTRY_COMPSIZE(ptr) MKEXT_SWAP((ptr)->compressed_size)
#define MKEXT2_GET_ENTRY_FULLSIZE(ptr) MKEXT_SWAP((ptr)->full_size)
#define MKEXT2_GET_ENTRY_DATA(ptr) ((ptr)->data)
#define MKEXT2_HDR_CAST(hdr) ((mkext2_header *)(hdr))
#define MKEXT2_GET_PLIST(hdr) MKEXT_SWAP(MKEXT2_HDR_CAST(hdr)->plist_offset)
#define MKEXT2_GET_PLIST_COMPSIZE(hdr) MKEXT_SWAP(MKEXT2_HDR_CAST(hdr)->plist_compressed_size)
#define MKEXT2_GET_PLIST_FULLSIZE(hdr) MKEXT_SWAP(MKEXT2_HDR_CAST(hdr)->plist_full_size)
#if PRAGMA_MARK
#pragma mark Mkext Version 1 Format Definitions
#endif
/*********************************************************************
* Mkext Version 1 Format Definitions
*
* The original mkext format has version 0x01008000 ("1.0").
*
* In version 1, plists were not nul-terminated, so it's up to the
* reader to add that '\0' on the end if it's needed.
*
* Original bad names preserved for source compatibility.
*********************************************************************/
// If all fields are 0 then this file slot is empty
// If compsize is zero then the file isn't compressed.
typedef struct mkext_file {
uint32_t offset; // 4 bytes
uint32_t compsize; // 4 bytes
uint32_t realsize; // 4 bytes
uint32_t modifiedsecs; // 4 bytes; cast to time_t to use
} mkext_file;
// The plist file entry is mandatory, but module may be empty
typedef struct mkext_kext {
mkext_file plist; // 16 bytes
mkext_file module; // 16 bytes
} mkext_kext;
typedef struct mkext_header {
MKEXT_HEADER_CORE
mkext_kext kext[1]; // 32 bytes/entry
} mkext_header;
typedef mkext_header mkext1_header;
#define MKEXT1_ENTRY_CAST(ptr) ((mkext_file *)(ptr))
#define MKEXT1_GET_ENTRY_OFFSET(ptr) (MKEXT_SWAP(MKEXT1_ENTRY_CAST(ptr)->offset))
#define MKEXT1_GET_ENTRY_COMPSIZE(ptr) (MKEXT_SWAP(MKEXT1_ENTRY_CAST(ptr)->compsize))
#define MKEXT1_GET_ENTRY_FULLSIZE(ptr) (MKEXT_SWAP(MKEXT1_ENTRY_CAST(ptr)->realsize))
#define MKEXT1_GET_ENTRY_MODTIME(ptr) ((time_t)MKEXT_SWAP(MKEXT1_ENTRY_CAST(ptr)->modifiedsecs))
#define MKEXT1_ENTRY_EXISTS(ptr) (MKEXT1_GET_ENTRY_OFFSET(ptr) || \
MKEXT1_GET_ENTRY_FULLSIZE(ptr) || \
MKEXT_GET_ENTRY_COMPSIZE(ptr) || \
MKEXT_GET_ENTRY_COMPSIZE(ptr))
#define MKEXT1_GET_KEXT(hdr, i) ((mkext_kext *)&(MKEXT1_HDR_CAST(hdr)->kext[(i)]))
#define MKEXT1_GET_KEXT_PLIST(hdr, i) (MKEXT1_ENTRY_CAST(&(MKEXT1_GET_KEXT((hdr), (i))->plist)))
#define MKEXT1_GET_KEXT_EXEC(hdr, i) (MKEXT1_ENTRY_CAST(&(MKEXT1_GET_KEXT((hdr), (i))->module)
#define MKEXT1_HDR_CAST(hdr) ((mkext1_header *)(hdr))
#endif /* _MKEXT_H_ */

Archive Download the corresponding diff file

Revision: 565