1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the 'License'). You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this 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 OR NON-INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | /*␊ |
25 | * drivers.c - Driver Loading Functions.␊ |
26 | *␊ |
27 | * Copyright (c) 2000 Apple Computer, Inc.␊ |
28 | *␊ |
29 | * DRI: Josh de Cesare␊ |
30 | */␊ |
31 | ␊ |
32 | #include <mach-o/fat.h>␊ |
33 | #include <libkern/OSByteOrder.h>␊ |
34 | #include <mach/machine.h>␊ |
35 | ␊ |
36 | #include "sl.h"␊ |
37 | #include "boot.h"␊ |
38 | #include "bootstruct.h"␊ |
39 | #include "xml.h"␊ |
40 | #include "ramdisk.h"␊ |
41 | #include "modules.h"␊ |
42 | ␊ |
43 | #if DEBUG␊ |
44 | #define DBG(x...)␉printf(x)␊ |
45 | #else␊ |
46 | #define DBG(x...)␉msglog(x)␊ |
47 | #endif␊ |
48 | ␊ |
49 | // extern char gMacOSVersion[8];␊ |
50 | ␊ |
51 | struct Module { ␊ |
52 | ␉struct Module *nextModule;␊ |
53 | ␉long willLoad;␊ |
54 | ␉TagPtr dict;␊ |
55 | ␉char *plistAddr;␊ |
56 | ␉long plistLength;␊ |
57 | ␉char *executablePath;␊ |
58 | ␉char *bundlePath;␊ |
59 | ␉long bundlePathLength;␊ |
60 | };␊ |
61 | typedef struct Module Module, *ModulePtr;␊ |
62 | ␊ |
63 | struct DriverInfo {␊ |
64 | ␉char *plistAddr;␊ |
65 | ␉long plistLength;␊ |
66 | ␉void *executableAddr;␊ |
67 | ␉long executableLength;␊ |
68 | ␉void *bundlePathAddr;␊ |
69 | ␉long bundlePathLength;␊ |
70 | };␊ |
71 | typedef struct DriverInfo DriverInfo, *DriverInfoPtr;␊ |
72 | ␊ |
73 | #define kDriverPackageSignature1 'MKXT'␊ |
74 | #define kDriverPackageSignature2 'MOSX'␊ |
75 | ␊ |
76 | struct DriversPackage {␊ |
77 | ␉unsigned long signature1;␊ |
78 | ␉unsigned long signature2;␊ |
79 | ␉unsigned long length;␊ |
80 | ␉unsigned long adler32;␊ |
81 | ␉unsigned long version;␊ |
82 | ␉unsigned long numDrivers;␊ |
83 | ␉unsigned long reserved1;␊ |
84 | ␉unsigned long reserved2;␊ |
85 | };␊ |
86 | typedef struct DriversPackage DriversPackage;␊ |
87 | ␊ |
88 | enum {␊ |
89 | ␉kCFBundleType2,␊ |
90 | ␉kCFBundleType3␊ |
91 | };␊ |
92 | ␊ |
93 | long (*LoadExtraDrivers_p)(FileLoadDrivers_t FileLoadDrivers_p);␊ |
94 | ␊ |
95 | /*static*/ unsigned long Adler32( unsigned char * buffer, long length );␊ |
96 | ␊ |
97 | long FileLoadDrivers(char *dirSpec, long plugin);␊ |
98 | long NetLoadDrivers(char *dirSpec);␊ |
99 | long LoadDriverMKext(char *fileSpec);␊ |
100 | long LoadDriverPList(char *dirSpec, char *name, long bundleType);␊ |
101 | long LoadMatchedModules(void);␊ |
102 | ␊ |
103 | static long MatchPersonalities(void);␊ |
104 | static long MatchLibraries(void);␊ |
105 | #ifdef NOTDEF␊ |
106 | ␉static ModulePtr FindModule(char *name);␊ |
107 | ␉static void ThinFatFile(void **loadAddrP, unsigned long *lengthP);␊ |
108 | #endif␊ |
109 | static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities);␊ |
110 | static long InitDriverSupport(void);␊ |
111 | ␊ |
112 | ModulePtr gModuleHead, gModuleTail;␊ |
113 | static TagPtr gPersonalityHead, gPersonalityTail;␊ |
114 | static char * gExtensionsSpec;␊ |
115 | static char * gDriverSpec;␊ |
116 | static char * gFileSpec;␊ |
117 | static char * gTempSpec;␊ |
118 | static char * gFileName;␊ |
119 | ␊ |
120 | /*static*/ unsigned long␊ |
121 | Adler32( unsigned char * buffer, long length )␊ |
122 | {␊ |
123 | ␉long cnt;␊ |
124 | ␉unsigned long result, lowHalf, highHalf;␊ |
125 | ␊ |
126 | ␉lowHalf = 1;␊ |
127 | ␉highHalf = 0;␊ |
128 | ␊ |
129 | ␉for (cnt = 0; cnt < length; cnt++)␊ |
130 | ␉{␊ |
131 | ␉␉if ((cnt % 5000) == 0)␊ |
132 | ␉␉{␊ |
133 | ␉␉␉lowHalf %= 65521L;␊ |
134 | ␉␉␉highHalf %= 65521L;␊ |
135 | ␉␉}␊ |
136 | ␊ |
137 | ␉␉lowHalf += buffer[cnt];␊ |
138 | ␉␉highHalf += lowHalf;␊ |
139 | ␉}␊ |
140 | ␊ |
141 | ␉lowHalf %= 65521L;␊ |
142 | ␉highHalf %= 65521L;␊ |
143 | ␊ |
144 | ␉result = (highHalf << 16) | lowHalf;␊ |
145 | ␊ |
146 | ␉return result;␊ |
147 | }␊ |
148 | ␊ |
149 | //==========================================================================␊ |
150 | // InitDriverSupport␊ |
151 | ␊ |
152 | static long InitDriverSupport( void )␊ |
153 | {␊ |
154 | ␉gExtensionsSpec = malloc( 4096 );␊ |
155 | ␉gDriverSpec = malloc( 4096 );␊ |
156 | ␉gFileSpec = malloc( 4096 );␊ |
157 | ␉gTempSpec = malloc( 4096 );␊ |
158 | ␉gFileName = malloc( 4096 );␊ |
159 | ␊ |
160 | ␉if ( !gExtensionsSpec || !gDriverSpec || !gFileSpec || !gTempSpec || !gFileName ) {␊ |
161 | ␉␉stop("InitDriverSupport error");␊ |
162 | ␉}␊ |
163 | ␊ |
164 | ␉return 0;␊ |
165 | }␊ |
166 | ␊ |
167 | //==========================================================================␊ |
168 | // LoadDrivers␊ |
169 | ␊ |
170 | long LoadDrivers( char * dirSpec )␊ |
171 | {␊ |
172 | ␉char dirSpecExtra[1024];␊ |
173 | ␊ |
174 | ␉if ( InitDriverSupport() != 0 ) {␊ |
175 | ␉␉return 0;␊ |
176 | ␉}␊ |
177 | ␊ |
178 | ␉// Load extra drivers if a hook has been installed.␊ |
179 | ␉if (LoadExtraDrivers_p != NULL)␊ |
180 | ␉{␊ |
181 | ␉␉(*LoadExtraDrivers_p)(&FileLoadDrivers);␊ |
182 | ␉}␊ |
183 | ␊ |
184 | ␉if ( gBootFileType == kNetworkDeviceType )␊ |
185 | ␉{␊ |
186 | ␉␉if (NetLoadDrivers(dirSpec) != 0)␊ |
187 | ␉␉{␊ |
188 | ␉␉␉error("Could not load drivers from the network\n");␊ |
189 | ␉␉␉return -1;␊ |
190 | ␉␉}␊ |
191 | ␉}␊ |
192 | ␉else if ( gBootFileType == kBlockDeviceType )␊ |
193 | ␉{␊ |
194 | ␉␉// First try to load Extra extensions from the ramdisk if isn't aliased as bt(0,0).␊ |
195 | ␉␉if (gRAMDiskVolume && !gRAMDiskBTAliased)␊ |
196 | ␉␉{␊ |
197 | ␉␉␉strcpy(dirSpecExtra, "rd(0,0)/Extra/");␊ |
198 | ␉␉␉FileLoadDrivers(dirSpecExtra, 0);␊ |
199 | ␉␉}␊ |
200 | ␊ |
201 | ␉␉// Next try to load Extra extensions from the selected root partition.␊ |
202 | ␉␉strcpy(dirSpecExtra, "/Extra/");␊ |
203 | ␉␉if (FileLoadDrivers(dirSpecExtra, 0) != 0) {␊ |
204 | ␉␉␉// If failed, then try to load Extra extensions from the boot partition␊ |
205 | ␉␉␉// in case we have a separate booter partition or a bt(0,0) aliased ramdisk.␊ |
206 | ␉␉␉if ( !(gBIOSBootVolume->biosdev == gBootVolume->biosdev && gBIOSBootVolume->part_no == gBootVolume->part_no)␊ |
207 | ␉␉␉␉|| (gRAMDiskVolume && gRAMDiskBTAliased) ) {␊ |
208 | ␉␉␉␉// Next try a specfic OS version folder ie 10.5␊ |
209 | ␉␉␉␉sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", &gMacOSVersion);␊ |
210 | ␉␉␉␉if (FileLoadDrivers(dirSpecExtra, 0) != 0) {␊ |
211 | ␉␉␉␉␉// Next we'll try the base␊ |
212 | ␉␉␉␉␉strcpy(dirSpecExtra, "bt(0,0)/Extra/");␊ |
213 | ␉␉␉␉␉FileLoadDrivers(dirSpecExtra, 0);␊ |
214 | ␉␉␉␉}␊ |
215 | ␉␉␉}␊ |
216 | ␉␉}␊ |
217 | ␉␉if(!gHaveKernelCache) {␊ |
218 | ␉␉␉// Don't load main driver (from /System/Library/Extentions) if gHaveKernelCache is set.␊ |
219 | ␉␉␉// since these drivers will already be in the kernel cache.␊ |
220 | ␉␉␉// NOTE: when gHaveKernelCache, xnu cannot (by default) load *any* extra kexts from the bootloader.␊ |
221 | ␉␉␉// The /Extra code is not disabled in this case due to a kernel patch that allows for this to happen.␊ |
222 | ␊ |
223 | ␉␉␉// Also try to load Extensions from boot helper partitions.␊ |
224 | ␉␉␉if (gBootVolume->flags & kBVFlagBooter) {␊ |
225 | ␉␉␉␉strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");␊ |
226 | ␉␉␉␉if (FileLoadDrivers(dirSpecExtra, 0) != 0) {␊ |
227 | ␉␉␉␉␉strcpy(dirSpecExtra, "/com.apple.boot.R/System/Library/");␊ |
228 | ␉␉␉␉␉if (FileLoadDrivers(dirSpecExtra, 0) != 0) {␊ |
229 | ␉␉␉␉␉␉strcpy(dirSpecExtra, "/com.apple.boot.S/System/Library/");␊ |
230 | ␉␉␉␉␉␉FileLoadDrivers(dirSpecExtra, 0);␊ |
231 | ␉␉␉␉␉}␊ |
232 | ␉␉␉␉}␊ |
233 | ␉␉␉}␊ |
234 | ␊ |
235 | ␉␉␉if (gMKextName[0] != '\0') {␊ |
236 | ␉␉␉␉verbose("LoadDrivers: Loading from [%s]\n", gMKextName);␊ |
237 | ␉␉␉␉if ( LoadDriverMKext(gMKextName) != 0 ) {␊ |
238 | ␉␉␉␉␉error("Could not load %s\n", gMKextName);␊ |
239 | ␉␉␉␉␉return -1;␊ |
240 | ␉␉␉␉}␊ |
241 | ␉␉␉}␊ |
242 | ␉␉␉else␊ |
243 | ␉␉␉{␊ |
244 | ␉␉␉␉if ( MAVERICKS || YOSEMITE ) // issue 352␊ |
245 | ␉␉␉␉{␊ |
246 | ␉␉␉␉␉strlcpy(gExtensionsSpec, dirSpec, 4087); /* 4096 - sizeof("Library/") */␊ |
247 | ␉␉␉␉␉strcat(gExtensionsSpec, "Library/");␊ |
248 | ␉␉␉␉␉FileLoadDrivers(gExtensionsSpec, 0);␊ |
249 | ␉␉␉␉}␊ |
250 | ␉␉␉␉strlcpy(gExtensionsSpec, dirSpec, 4080); /* 4096 - sizeof("System/Library/") */␊ |
251 | ␉␉␉␉strcat(gExtensionsSpec, "System/Library/");␊ |
252 | ␉␉␉␉FileLoadDrivers(gExtensionsSpec, 0);␊ |
253 | ␉␉␉}␊ |
254 | ␊ |
255 | ␉␉}␊ |
256 | ␉} else {␊ |
257 | ␉␉return 0;␊ |
258 | ␉}␊ |
259 | ␊ |
260 | ␉MatchPersonalities();␊ |
261 | ␊ |
262 | ␉MatchLibraries();␊ |
263 | ␊ |
264 | ␉LoadMatchedModules();␊ |
265 | ␊ |
266 | ␉return 0;␊ |
267 | }␊ |
268 | ␊ |
269 | //==========================================================================␊ |
270 | // FileLoadMKext␊ |
271 | ␊ |
272 | static long␊ |
273 | FileLoadMKext( const char * dirSpec, const char * extDirSpec )␊ |
274 | {␊ |
275 | ␉long␉ret, flags, time, time2;␊ |
276 | ␉char␉altDirSpec[512];␊ |
277 | ␉␊ |
278 | ␉snprintf(altDirSpec, sizeof(altDirSpec), "%s%s", dirSpec, extDirSpec);␊ |
279 | ␉ret = GetFileInfo(altDirSpec, "Extensions.mkext", &flags, &time);␊ |
280 | ␊ |
281 | ␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat))␊ |
282 | ␉{␊ |
283 | ␉␉ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2);␊ |
284 | ␊ |
285 | ␉␉if ((ret != 0)␊ |
286 | ␉␉␉|| ((flags & kFileTypeMask) != kFileTypeDirectory)␊ |
287 | ␉␉␉|| (((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1))))␊ |
288 | ␉␉{␊ |
289 | ␉␉␉snprintf(gDriverSpec, sizeof(altDirSpec) + 18, "%sExtensions.mkext", altDirSpec);␊ |
290 | ␉␉␉verbose("LoadDrivers: Loading from [%s]\n", gDriverSpec);␊ |
291 | ␊ |
292 | ␉␉␉if (LoadDriverMKext(gDriverSpec) == 0) {␊ |
293 | ␉␉␉␉return 0;␊ |
294 | ␉␉␉}␊ |
295 | ␉␉}␊ |
296 | ␉}␊ |
297 | ␉return -1;␊ |
298 | }␊ |
299 | ␊ |
300 | //==========================================================================␊ |
301 | // FileLoadDrivers␊ |
302 | ␊ |
303 | long␊ |
304 | FileLoadDrivers( char * dirSpec, long plugin )␊ |
305 | {␊ |
306 | ␉long ret, length, flags, time, bundleType;␊ |
307 | ␉long long␉ index;␊ |
308 | ␉long result = -1;␊ |
309 | ␉const char * name;␊ |
310 | ␊ |
311 | ␉if ( !plugin )␊ |
312 | ␉{␊ |
313 | ␉␉// First try 10.6's path for loading Extensions.mkext.␊ |
314 | ␉␉if (FileLoadMKext(dirSpec, "Caches/com.apple.kext.caches/Startup/") == 0) {␊ |
315 | ␉␉␉return 0;␊ |
316 | ␉␉}␊ |
317 | ␊ |
318 | ␉␉// Next try the legacy path.␊ |
319 | ␉␉else if (FileLoadMKext(dirSpec, "") == 0) {␊ |
320 | ␉␉␉return 0;␊ |
321 | ␉␉}␊ |
322 | ␊ |
323 | ␉␉strcat(dirSpec, "Extensions");␊ |
324 | ␉}␊ |
325 | ␊ |
326 | ␉index = 0;␊ |
327 | ␉while (1)␊ |
328 | ␉{␊ |
329 | ␉␉ret = GetDirEntry(dirSpec, &index, &name, &flags, &time);␊ |
330 | ␉␉if (ret == -1) {␊ |
331 | ␉␉␉break;␊ |
332 | ␉␉}␊ |
333 | ␊ |
334 | ␉␉// Make sure this is a directory.␊ |
335 | ␉␉if ((flags & kFileTypeMask) != kFileTypeDirectory) {␊ |
336 | ␉␉␉continue;␊ |
337 | ␉␉}␊ |
338 | ␊ |
339 | ␉␉// Make sure this is a kext.␊ |
340 | ␉␉length = strlen(name);␊ |
341 | ␉␉if (strcmp(name + length - 5, ".kext")) {␊ |
342 | ␉␉␉continue;␊ |
343 | ␉␉}␊ |
344 | ␊ |
345 | ␉␉// Save the file name.␊ |
346 | ␉␉strlcpy(gFileName, name, 4096);␊ |
347 | ␊ |
348 | ␉␉// Determine the bundle type.␊ |
349 | ␉␉snprintf(gTempSpec, 4096, "%s/%s", dirSpec, gFileName);␊ |
350 | ␉␉ret = GetFileInfo(gTempSpec, "Contents", &flags, &time);␊ |
351 | ␉␉if (ret == 0) {␊ |
352 | ␉␉␉bundleType = kCFBundleType2;␊ |
353 | ␉␉} else {␊ |
354 | ␉␉␉bundleType = kCFBundleType3;␊ |
355 | ␉␉}␊ |
356 | ␊ |
357 | ␉␉if (!plugin) {␊ |
358 | ␉␉␉snprintf(gDriverSpec, 4096, "%s/%s/%sPlugIns", dirSpec, gFileName, (bundleType == kCFBundleType2) ? "Contents/" : "");␊ |
359 | ␉␉}␊ |
360 | ␊ |
361 | ␉␉ret = LoadDriverPList(dirSpec, gFileName, bundleType);␊ |
362 | ␊ |
363 | ␉␉if (result != 0) {␊ |
364 | ␉␉␉result = ret;␊ |
365 | ␉␉}␊ |
366 | ␊ |
367 | ␉␉if (!plugin) {␊ |
368 | ␉␉␉FileLoadDrivers(gDriverSpec, 1);␊ |
369 | ␉␉}␊ |
370 | ␉}␊ |
371 | ␊ |
372 | ␉return result;␊ |
373 | }␊ |
374 | ␊ |
375 | ␊ |
376 | //==========================================================================␊ |
377 | // ␊ |
378 | ␊ |
379 | long NetLoadDrivers( char * dirSpec )␊ |
380 | {␊ |
381 | ␉long tries;␊ |
382 | ␊ |
383 | #if NODEF␊ |
384 | ␉long cnt;␊ |
385 | ␊ |
386 | ␉// Get the name of the kernel␊ |
387 | ␉cnt = strlen(gBootFile);␊ |
388 | ␉while (cnt--) {␊ |
389 | ␉␉if ((gBootFile[cnt] == '\\') || (gBootFile[cnt] == ',')) {␊ |
390 | ␉␉␉cnt++;␊ |
391 | ␉␉␉break;␊ |
392 | ␉␉}␊ |
393 | ␉}␊ |
394 | #endif␊ |
395 | ␊ |
396 | ␉// INTEL modification␊ |
397 | ␉snprintf(gDriverSpec, 4096, "%s%s.mkext", dirSpec, bootInfo->bootFile);␊ |
398 | ␊ |
399 | ␉verbose("NetLoadDrivers: Loading from [%s]\n", gDriverSpec);␊ |
400 | ␊ |
401 | ␉tries = 3;␊ |
402 | ␉while (tries--)␊ |
403 | ␉{␊ |
404 | ␉␉if (LoadDriverMKext(gDriverSpec) == 0) {␊ |
405 | ␉␉␉break;␊ |
406 | ␉␉}␊ |
407 | ␉}␊ |
408 | ␉if (tries == -1) {␊ |
409 | ␉␉return -1;␊ |
410 | ␉}␊ |
411 | ␊ |
412 | ␉return 0;␊ |
413 | }␊ |
414 | ␊ |
415 | //==========================================================================␊ |
416 | // loadDriverMKext␊ |
417 | ␊ |
418 | long LoadDriverMKext( char * fileSpec )␊ |
419 | {␊ |
420 | ␉unsigned long driversAddr, driversLength;␊ |
421 | ␉long length;␊ |
422 | ␉char segName[32];␊ |
423 | ␉DriversPackage * package;␊ |
424 | ␊ |
425 | #define GetPackageElement(e) OSSwapBigToHostInt32(package->e)␊ |
426 | ␊ |
427 | ␉// Load the MKext.␊ |
428 | ␉length = LoadThinFatFile(fileSpec, (void **)&package);␊ |
429 | ␉if (length < sizeof (DriversPackage)) {␊ |
430 | ␉␉return -1;␊ |
431 | ␉}␊ |
432 | ␊ |
433 | ␉// call hook to notify modules that the mkext has been loaded␊ |
434 | ␉execute_hook("LoadDriverMKext", (void*)fileSpec, (void*)package, (void*) &length, NULL);␊ |
435 | ␊ |
436 | ␉␊ |
437 | ␉// Verify the MKext.␊ |
438 | ␉if (( GetPackageElement(signature1) != kDriverPackageSignature1) ||␊ |
439 | ␉␉( GetPackageElement(signature2) != kDriverPackageSignature2) ||␊ |
440 | ␉␉( GetPackageElement(length) > kLoadSize ) ||␊ |
441 | ␉␉( GetPackageElement(adler32) !=␊ |
442 | ␉␉Adler32((unsigned char *)&package->version, GetPackageElement(length) - 0x10) ) )␊ |
443 | ␉{␊ |
444 | ␉␉return -1;␊ |
445 | ␉}␊ |
446 | ␊ |
447 | ␉// Make space for the MKext.␊ |
448 | ␉driversLength = GetPackageElement(length);␊ |
449 | ␉driversAddr = AllocateKernelMemory(driversLength);␊ |
450 | ␊ |
451 | ␉// Copy the MKext.␊ |
452 | ␉memcpy((void *)driversAddr, (void *)package, driversLength);␊ |
453 | ␊ |
454 | ␉// Add the MKext to the memory map.␊ |
455 | ␉snprintf(segName, sizeof(segName), "DriversPackage-%lx", driversAddr);␊ |
456 | ␉AllocateMemoryRange(segName, driversAddr, driversLength, kBootDriverTypeMKEXT);␊ |
457 | ␊ |
458 | ␉return 0;␊ |
459 | }␊ |
460 | ␊ |
461 | //==========================================================================␊ |
462 | // LoadDriverPList␊ |
463 | ␊ |
464 | long␊ |
465 | LoadDriverPList( char * dirSpec, char * name, long bundleType )␊ |
466 | {␊ |
467 | ␉long length, executablePathLength, bundlePathLength;␊ |
468 | ␉ModulePtr module;␊ |
469 | ␉TagPtr personalities;␊ |
470 | ␉char * buffer = 0;␊ |
471 | ␉char * tmpExecutablePath = 0;␊ |
472 | ␉char * tmpBundlePath = 0;␊ |
473 | ␉long ret = -1;␊ |
474 | ␊ |
475 | ␉do{␊ |
476 | ␉// Save the driver path.␊ |
477 | ␊ |
478 | ␉if(name) {␊ |
479 | ␉␉snprintf(gFileSpec, 4096, "%s/%s/%s", dirSpec, name, (bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");␊ |
480 | ␉} else {␊ |
481 | ␉␉snprintf(gFileSpec, 4096, "%s/%s", dirSpec, (bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");␊ |
482 | ␉}␊ |
483 | ␉executablePathLength = strlen(gFileSpec) + 1;␊ |
484 | ␊ |
485 | ␉tmpExecutablePath = malloc(executablePathLength);␊ |
486 | ␉if (tmpExecutablePath == 0) {␊ |
487 | ␉␉break;␊ |
488 | ␉}␊ |
489 | ␉strcpy(tmpExecutablePath, gFileSpec);␊ |
490 | ␊ |
491 | ␉if(name) {␊ |
492 | ␉␉snprintf(gFileSpec, 4096, "%s/%s", dirSpec, name);␊ |
493 | ␉} else ␉{␊ |
494 | ␉␉snprintf(gFileSpec, 4096, "%s", dirSpec);␊ |
495 | ␉}␊ |
496 | ␉bundlePathLength = strlen(gFileSpec) + 1;␊ |
497 | ␊ |
498 | ␉tmpBundlePath = malloc(bundlePathLength);␊ |
499 | ␉if (tmpBundlePath == 0) {␊ |
500 | ␉␉break;␊ |
501 | ␉}␊ |
502 | ␊ |
503 | ␉strcpy(tmpBundlePath, gFileSpec);␊ |
504 | ␊ |
505 | ␉// Construct the file spec to the plist, then load it.␊ |
506 | ␊ |
507 | ␉if(name) {␊ |
508 | ␉␉snprintf(gFileSpec, 4096, "%s/%s/%sInfo.plist", dirSpec, name, (bundleType == kCFBundleType2) ? "Contents/" : "");␊ |
509 | ␉} else {␊ |
510 | ␉␉snprintf(gFileSpec, 4096, "%s/%sInfo.plist", dirSpec, (bundleType == kCFBundleType2) ? "Contents/" : "");␊ |
511 | ␉}␊ |
512 | ␊ |
513 | ␉length = LoadFile(gFileSpec);␊ |
514 | ␉if (length == -1) {␊ |
515 | ␉␉break;␊ |
516 | ␉}␊ |
517 | ␉length = length + 1;␊ |
518 | ␉buffer = malloc(length);␊ |
519 | ␉if (buffer == 0) {␊ |
520 | ␉␉break;␊ |
521 | ␉}␊ |
522 | ␉strlcpy(buffer, (char *)kLoadAddr, length);␊ |
523 | ␊ |
524 | ␉// Parse the plist.␊ |
525 | ␊ |
526 | ␉ret = ParseXML(buffer, &module, &personalities);␊ |
527 | ␊ |
528 | ␉if (ret != 0) {␊ |
529 | ␉␉break;␊ |
530 | ␉}␊ |
531 | ␊ |
532 | ␉if (!module) // cparm␊ |
533 | ␉{␊ |
534 | ␉␉ret = -1;␊ |
535 | ␉␉break;␊ |
536 | ␉} // Should never happen but it will make the compiler happy␊ |
537 | ␊ |
538 | ␉// Allocate memory for the driver path and the plist.␊ |
539 | ␊ |
540 | ␉module->executablePath = tmpExecutablePath;␊ |
541 | ␉module->bundlePath = tmpBundlePath;␊ |
542 | ␉module->bundlePathLength = bundlePathLength;␊ |
543 | ␉module->plistAddr = malloc(length);␊ |
544 | ␊ |
545 | ␉if ((module->executablePath == 0) || (module->bundlePath == 0) || (module->plistAddr == 0)) {␊ |
546 | ␉␉break;␊ |
547 | ␉}␊ |
548 | ␊ |
549 | ␉// Save the driver path in the module.␊ |
550 | ␉//strcpy(module->driverPath, tmpDriverPath);␊ |
551 | ␉tmpExecutablePath = 0;␊ |
552 | ␉tmpBundlePath = 0;␊ |
553 | ␊ |
554 | ␉// Add the plist to the module.␊ |
555 | ␊ |
556 | ␉strlcpy(module->plistAddr, (char *)kLoadAddr, length);␊ |
557 | ␉module->plistLength = length;␊ |
558 | ␊ |
559 | ␉// Add the module to the end of the module list.␊ |
560 | ␊ |
561 | ␉if (gModuleHead == 0) {␊ |
562 | ␉␉gModuleHead = module;␊ |
563 | ␉} else ␉{␊ |
564 | ␉␉gModuleTail->nextModule = module;␊ |
565 | ␉}␊ |
566 | ␉gModuleTail = module;␊ |
567 | ␊ |
568 | ␉// Add the persionalities to the personality list.␊ |
569 | ␊ |
570 | ␉if (personalities) {␊ |
571 | ␉␉personalities = personalities->tag;␊ |
572 | ␉}␊ |
573 | ␉while (personalities != 0)␊ |
574 | ␉{␊ |
575 | ␉␉if (gPersonalityHead == 0) {␊ |
576 | ␉␉␉gPersonalityHead = personalities->tag;␊ |
577 | ␉␉} else {␊ |
578 | ␉␉␉gPersonalityTail->tagNext = personalities->tag;␊ |
579 | ␉␉}␊ |
580 | ␊ |
581 | ␉␉gPersonalityTail = personalities->tag;␊ |
582 | ␉␉personalities = personalities->tagNext;␊ |
583 | ␉}␊ |
584 | ␊ |
585 | ␉ret = 0;␊ |
586 | ␉}␊ |
587 | ␉while (0);␊ |
588 | ␊ |
589 | ␉if ( buffer ) {␊ |
590 | ␉␉free( buffer );␊ |
591 | ␉}␊ |
592 | ␉if ( tmpExecutablePath ) {␊ |
593 | ␉␉free( tmpExecutablePath );␊ |
594 | ␉}␊ |
595 | ␉if ( tmpBundlePath ) {␊ |
596 | ␉␉free( tmpBundlePath );␊ |
597 | ␉}␊ |
598 | ␉return ret;␊ |
599 | }␊ |
600 | ␊ |
601 | ␊ |
602 | //==========================================================================␊ |
603 | // LoadMatchedModules␊ |
604 | ␊ |
605 | long␊ |
606 | LoadMatchedModules( void )␊ |
607 | {␊ |
608 | ␉TagPtr␉␉ prop;␊ |
609 | ␉ModulePtr␉ module;␊ |
610 | ␉char␉␉ *fileName, segName[32];␊ |
611 | ␉DriverInfoPtr driver;␊ |
612 | ␉long␉␉ length, driverAddr, driverLength;␊ |
613 | ␉void␉␉ *executableAddr = 0;␊ |
614 | ␊ |
615 | ␉module = gModuleHead;␊ |
616 | ␊ |
617 | ␉while (module != 0)␊ |
618 | ␉{␊ |
619 | ␉␉if (module->willLoad)␊ |
620 | ␉␉{␊ |
621 | ␉␉␉prop = XMLGetProperty(module->dict, kPropCFBundleExecutable);␊ |
622 | ␊ |
623 | ␉␉␉if (prop != 0)␊ |
624 | ␉␉␉{␊ |
625 | ␉␉␉␉fileName = prop->string;␊ |
626 | ␉␉␉␉snprintf(gFileSpec, 4096, "%s%s", module->executablePath, fileName);␊ |
627 | ␉␉␉␉length = LoadThinFatFile(gFileSpec, &executableAddr);␊ |
628 | ␉␉␉␉if (length == 0)␊ |
629 | ␉␉␉␉{␊ |
630 | ␉␉␉␉␉length = LoadFile(gFileSpec);␊ |
631 | ␉␉␉␉␉executableAddr = (void *)kLoadAddr;␊ |
632 | ␉␉␉␉}␊ |
633 | //␉␉␉␉printf("%s length = %d addr = 0x%x\n", gFileSpec, length, driverModuleAddr); getchar();␊ |
634 | ␉␉␉}␊ |
635 | ␉␉␉else␊ |
636 | ␉␉␉␉length = 0;␊ |
637 | ␊ |
638 | ␉␉␉if (length != -1)␊ |
639 | ␉␉␉{␊ |
640 | //␉␉␉␉driverModuleAddr = (void *)kLoadAddr;␊ |
641 | //␉␉␉␉if (length != 0)␊ |
642 | //␉␉␉␉{␊ |
643 | //␉␉␉␉␉ThinFatFile(&driverModuleAddr, &length);␊ |
644 | //␉␉␉␉}␊ |
645 | ␊ |
646 | ␉␉␉␉// Make make in the image area.␊ |
647 | ␊ |
648 | ␉␉␉␉execute_hook("LoadMatchedModules", module, &length, executableAddr, NULL);␊ |
649 | ␊ |
650 | ␉␉␉␉driverLength = sizeof(DriverInfo) + module->plistLength + length + module->bundlePathLength;␊ |
651 | ␉␉␉␉driverAddr = AllocateKernelMemory(driverLength);␊ |
652 | ␊ |
653 | ␉␉␉␉// Set up the DriverInfo.␊ |
654 | ␉␉␉␉driver = (DriverInfoPtr)driverAddr;␊ |
655 | ␉␉␉␉driver->plistAddr = (char *)(driverAddr + sizeof(DriverInfo));␊ |
656 | ␉␉␉␉driver->plistLength = module->plistLength;␊ |
657 | ␉␉␉␉if (length != 0)␊ |
658 | ␉␉␉␉{␊ |
659 | ␉␉␉␉␉driver->executableAddr = (void *)(driverAddr + sizeof(DriverInfo) +␊ |
660 | ␉␉␉␉␉␉␉␉␉␉ module->plistLength);␊ |
661 | ␉␉␉␉␉driver->executableLength = length;␊ |
662 | ␉␉␉␉}␊ |
663 | ␉␉␉␉else␊ |
664 | ␉␉␉␉{␊ |
665 | ␉␉␉␉␉driver->executableAddr␉ = 0;␊ |
666 | ␉␉␉␉␉driver->executableLength = 0;␊ |
667 | ␉␉␉␉}␊ |
668 | ␉␉␉␉driver->bundlePathAddr = (void *)(driverAddr + sizeof(DriverInfo) +␊ |
669 | ␉␉␉␉␉␉␉␉␉ module->plistLength + driver->executableLength);␊ |
670 | ␉␉␉␉driver->bundlePathLength = module->bundlePathLength;␊ |
671 | ␊ |
672 | ␉␉␉␉// Save the plist, module and bundle.␊ |
673 | ␉␉␉␉strcpy(driver->plistAddr, module->plistAddr);␊ |
674 | ␉␉␉␉if (length != 0)␊ |
675 | ␉␉␉␉{␊ |
676 | ␉␉␉␉␉memcpy(driver->executableAddr, executableAddr, length);␊ |
677 | ␉␉␉␉}␊ |
678 | ␉␉␉␉strcpy(driver->bundlePathAddr, module->bundlePath);␊ |
679 | ␊ |
680 | ␉␉␉␉// Add an entry to the memory map.␊ |
681 | ␉␉␉␉snprintf(segName, sizeof(segName), "Driver-%lx", (unsigned long)driver);␊ |
682 | ␉␉␉␉AllocateMemoryRange(segName, driverAddr, driverLength,␊ |
683 | ␉␉␉␉␉␉␉␉␉kBootDriverTypeKEXT);␊ |
684 | ␉␉␉}␊ |
685 | ␉␉}␊ |
686 | ␉␉module = module->nextModule;␊ |
687 | ␉}␊ |
688 | ␊ |
689 | ␉return 0;␊ |
690 | }␊ |
691 | ␊ |
692 | //==========================================================================␊ |
693 | // MatchPersonalities␊ |
694 | ␊ |
695 | static long␊ |
696 | MatchPersonalities( void )␊ |
697 | {␊ |
698 | ␉/* IONameMatch support not implemented */␊ |
699 | ␉return 0;␊ |
700 | }␊ |
701 | ␊ |
702 | //==========================================================================␊ |
703 | // MatchLibraries␊ |
704 | ␊ |
705 | static long␊ |
706 | MatchLibraries( void )␊ |
707 | {␊ |
708 | ␉TagPtr prop, prop2;␊ |
709 | ␉ModulePtr module, module2;␊ |
710 | ␉long done;␊ |
711 | ␊ |
712 | ␉do {␊ |
713 | ␉␉done = 1;␊ |
714 | ␉␉module = gModuleHead;␊ |
715 | ␊ |
716 | ␉␉while (module != 0)␊ |
717 | ␉␉{␊ |
718 | ␉␉␉if (module->willLoad == 1)␊ |
719 | ␉␉␉{␊ |
720 | ␉␉␉␉prop = XMLGetProperty(module->dict, kPropOSBundleLibraries);␊ |
721 | ␊ |
722 | ␉␉␉␉if (prop != 0)␊ |
723 | ␉␉␉␉{␊ |
724 | ␉␉␉␉␉prop = prop->tag;␊ |
725 | ␊ |
726 | ␉␉␉␉␉while (prop != 0)␊ |
727 | ␉␉␉␉␉{␊ |
728 | ␉␉␉␉␉␉module2 = gModuleHead;␊ |
729 | ␊ |
730 | ␉␉␉␉␉␉while (module2 != 0)␊ |
731 | ␉␉␉␉␉␉{␊ |
732 | ␉␉␉␉␉␉␉prop2 = XMLGetProperty(module2->dict, kPropCFBundleIdentifier);␊ |
733 | ␊ |
734 | ␉␉␉␉␉␉␉if ((prop2 != 0) && (!strcmp(prop->string, prop2->string)))␊ |
735 | ␉␉␉␉␉␉␉{␊ |
736 | ␉␉␉␉␉␉␉␉if (module2->willLoad == 0)␊ |
737 | ␉␉␉␉␉␉␉␉{␊ |
738 | ␉␉␉␉␉␉␉␉␉module2->willLoad = 1;␊ |
739 | ␉␉␉␉␉␉␉␉}␊ |
740 | ␉␉␉␉␉␉␉␉break;␊ |
741 | ␉␉␉␉␉␉␉}␊ |
742 | ␉␉␉␉␉␉␉module2 = module2->nextModule;␊ |
743 | ␉␉␉␉␉␉}␊ |
744 | ␉␉␉␉␉␉prop = prop->tagNext;␊ |
745 | ␉␉␉␉␉}␊ |
746 | ␉␉␉␉}␊ |
747 | ␉␉␉␉module->willLoad = 2;␊ |
748 | ␉␉␉␉done = 0;␊ |
749 | ␉␉␉}␊ |
750 | ␉␉␉module = module->nextModule;␊ |
751 | ␉␉}␊ |
752 | ␉}␊ |
753 | ␉while (!done);␊ |
754 | ␊ |
755 | ␉return 0;␊ |
756 | }␊ |
757 | ␊ |
758 | ␊ |
759 | //==========================================================================␊ |
760 | // FindModule␊ |
761 | ␊ |
762 | #if NOTDEF␊ |
763 | static ModulePtr␊ |
764 | FindModule( char * name )␊ |
765 | {␊ |
766 | ␉ModulePtr module;␊ |
767 | ␉TagPtr prop;␊ |
768 | ␊ |
769 | ␉module = gModuleHead;␊ |
770 | ␊ |
771 | ␉while (module != 0)␊ |
772 | ␉{␊ |
773 | ␉␉prop = GetProperty(module->dict, kPropCFBundleIdentifier);␊ |
774 | ␊ |
775 | ␉␉if ((prop != 0) && !strcmp(name, prop->string)) {␊ |
776 | ␉␉␉break;␊ |
777 | ␉␉}␊ |
778 | ␊ |
779 | ␉␉module = module->nextModule;␊ |
780 | ␉}␊ |
781 | ␊ |
782 | ␉return module;␊ |
783 | }␊ |
784 | #endif /* NOTDEF */␊ |
785 | ␊ |
786 | //==========================================================================␊ |
787 | // ParseXML␊ |
788 | ␊ |
789 | static long␊ |
790 | ParseXML( char * buffer, ModulePtr * module, TagPtr * personalities )␊ |
791 | {␊ |
792 | ␉long length, pos;␊ |
793 | ␉TagPtr moduleDict, required;␊ |
794 | ␉ModulePtr tmpModule;␊ |
795 | ␊ |
796 | ␉pos = 0;␊ |
797 | ␊ |
798 | ␉while (1)␊ |
799 | ␉{␊ |
800 | ␉␉length = XMLParseNextTag(buffer + pos, &moduleDict);␊ |
801 | ␉␉if (length == -1) {␊ |
802 | ␉␉␉break;␊ |
803 | ␉␉}␊ |
804 | ␊ |
805 | ␉␉pos += length;␊ |
806 | ␊ |
807 | ␉␉if (moduleDict == 0) {␊ |
808 | ␉␉␉continue;␊ |
809 | ␉␉}␊ |
810 | ␉␉if (moduleDict->type == kTagTypeDict) {␊ |
811 | ␉␉␉break;␊ |
812 | ␉␉}␊ |
813 | ␉␉XMLFreeTag(moduleDict);␊ |
814 | ␉}␊ |
815 | ␊ |
816 | ␉if (length == -1) {␊ |
817 | ␉␉return -1;␊ |
818 | ␉}␊ |
819 | ␊ |
820 | ␉required = XMLGetProperty(moduleDict, kPropOSBundleRequired);␊ |
821 | ␊ |
822 | ␉if ( (required == 0) || (required->type != kTagTypeString) || !strcmp(required->string, "Safe Boot"))␊ |
823 | ␉{␊ |
824 | ␉␉XMLFreeTag(moduleDict);␊ |
825 | ␉␉return -2;␊ |
826 | ␉}␊ |
827 | ␊ |
828 | ␉tmpModule = malloc(sizeof(Module));␊ |
829 | ␉if (tmpModule == 0) {␊ |
830 | ␉␉XMLFreeTag(moduleDict);␊ |
831 | ␉␉return -1;␊ |
832 | ␉}␊ |
833 | ␉tmpModule->dict = moduleDict;␊ |
834 | ␊ |
835 | ␉// For now, load any module that has OSBundleRequired != "Safe Boot".␊ |
836 | ␊ |
837 | ␉tmpModule->willLoad = 1;␊ |
838 | ␊ |
839 | ␉*module = tmpModule;␊ |
840 | ␊ |
841 | ␉// Get the personalities.␊ |
842 | ␊ |
843 | ␉*personalities = XMLGetProperty(moduleDict, kPropIOKitPersonalities);␊ |
844 | ␊ |
845 | ␉return 0;␊ |
846 | }␊ |
847 | ␊ |
848 | #if NOTDEF␊ |
849 | static char gPlatformName[64];␊ |
850 | #endif␊ |
851 | ␊ |
852 | char *gDarwinBuildVerStr = "Darwin Kernel Version"; // Bungo␊ |
853 | ␊ |
854 | long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize)␊ |
855 | {␊ |
856 | ␉long ret = 0;␊ |
857 | ␉compressed_kernel_header *kernel_header = (compressed_kernel_header *) binary;␊ |
858 | ␉u_int32_t uncompressed_size = 0, size = 0, adler32 = 0;␊ |
859 | ␉void *buffer = NULL;␊ |
860 | ␉unsigned long len = 0;␊ |
861 | ␉␊ |
862 | /*#if 0␊ |
863 | ␉printf("kernel header:\n");␊ |
864 | ␉printf("signature: 0x%x\n", kernel_header->signature);␊ |
865 | ␉printf("compress_type: 0x%x\n", kernel_header->compress_type);␊ |
866 | ␉printf("adler32: 0x%x\n", kernel_header->adler32);␊ |
867 | ␉printf("uncompressed_size: 0x%x\n", kernel_header->uncompressed_size);␊ |
868 | ␉printf("compressed_size: 0x%x\n", kernel_header->compressed_size);␊ |
869 | ␉getchar();␊ |
870 | #endif*/␊ |
871 | ␊ |
872 | ␉if (kernel_header->signature == OSSwapBigToHostConstInt32('comp'))␊ |
873 | ␉{␊ |
874 | ␉␉DBG("Decompressing Kernel Cache: ");␊ |
875 | ␊ |
876 | ␉␉if ((kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss')) &&␊ |
877 | ␉␉␉(kernel_header->compress_type != OSSwapBigToHostConstInt32('lzvn')))␊ |
878 | ␉␉{␊ |
879 | ␉␉␉error("ERROR: kernel compression is bad!\n");␊ |
880 | ␉␉␉return -1;␊ |
881 | ␉␉}␊ |
882 | #if NOTDEF␊ |
883 | ␉␉if (kernel_header->platform_name[0] && strcmp(gPlatformName, kernel_header->platform_name))␊ |
884 | ␉␉{␊ |
885 | ␉␉␉return -1;␊ |
886 | ␉␉}␊ |
887 | ␊ |
888 | ␉␉if (kernel_header->root_path[0] && strcmp(gBootFile, kernel_header->root_path))␊ |
889 | ␉␉{␊ |
890 | ␉␉␉return -1;␊ |
891 | ␉␉}␊ |
892 | #endif␊ |
893 | ␉␉uncompressed_size = OSSwapBigToHostInt32(kernel_header->uncompressed_size);␊ |
894 | ␉␉binary = buffer = malloc(uncompressed_size);␊ |
895 | ␊ |
896 | ␉␉// MinusZwei␊ |
897 | ␉␉size = 0;␊ |
898 | ␉␉switch (kernel_header->compress_type)␊ |
899 | ␉␉{␊ |
900 | ␉␉␉case OSSwapBigToHostConstInt32('lzvn'):␊ |
901 | ␉␉␉␉size = decompress_lzvn( binary, uncompressed_size, &kernel_header->data[0], OSSwapBigToHostInt32(kernel_header->compressed_size));␊ |
902 | ␉␉␉␉break;␊ |
903 | ␊ |
904 | ␉␉␉case OSSwapBigToHostConstInt32('lzss'):␊ |
905 | ␉␉␉␉size = decompress_lzss( (u_int8_t *)binary, uncompressed_size, &kernel_header->data[0], OSSwapBigToHostInt32(kernel_header->compressed_size));␊ |
906 | ␉␉␉␉break;␊ |
907 | ␊ |
908 | ␉␉␉default:␊ |
909 | ␉␉␉␉break;␊ |
910 | ␉␉}␊ |
911 | ␉␉// MinusZwei␊ |
912 | ␊ |
913 | ␉␉if (uncompressed_size != size)␊ |
914 | ␉␉{␊ |
915 | ␉␉␉if ( kernel_header->compress_type == OSSwapBigToHostConstInt32('lzvn'))␊ |
916 | ␉␉␉{␊ |
917 | ␉␉␉␉error("ERROR: size mismatch from lzvn (found: %x, expected: %x).\n", size, uncompressed_size);␊ |
918 | ␉␉␉}␊ |
919 | ␊ |
920 | ␉␉␉if ( kernel_header->compress_type == OSSwapBigToHostConstInt32('lzss'))␊ |
921 | ␉␉␉{␊ |
922 | ␉␉␉␉error("ERROR: size mismatch from lzss (found: %x, expected: %x).\n", size, uncompressed_size);␊ |
923 | ␉␉␉}␊ |
924 | ␊ |
925 | ␉␉␉return -1;␊ |
926 | ␉␉}␊ |
927 | ␊ |
928 | ␉␉adler32 = Adler32(binary, uncompressed_size);␊ |
929 | ␉␉if (OSSwapBigToHostInt32(kernel_header->adler32) != adler32)␊ |
930 | ␉␉{␊ |
931 | ␉␉␉error("ERROR: adler mismatch (found: %x, expected: %x).\n", adler32, OSSwapBigToHostInt32(kernel_header->adler32));␊ |
932 | ␉␉␉return -1;␊ |
933 | ␉␉}␊ |
934 | DBG("OK.\n");␊ |
935 | ␉}␊ |
936 | ␉␊ |
937 | ␉ret = ThinFatFile(&binary, &len);␊ |
938 | ␉if (ret == 0 && len == 0 && archCpuType==CPU_TYPE_X86_64)␊ |
939 | ␉{␊ |
940 | ␉␉archCpuType=CPU_TYPE_I386;␊ |
941 | ␉␉ret = ThinFatFile(&binary, &len);␊ |
942 | ␉}␊ |
943 | ␊ |
944 | ␉// Bungo: scan binary for Darwin Kernel Version string␊ |
945 | uint32_t offset;␊ |
946 | for (offset = 0; (offset < 0xFFFFFF00) && memcmp((uint8_t *)binary + offset, (uint8_t *)gDarwinBuildVerStr, 21); offset++) {␊ |
947 | }␊ |
948 | if (offset < 0xFFFFFF00) gDarwinBuildVerStr = (char *)binary + offset;␊ |
949 | else gDarwinBuildVerStr = "";␊ |
950 | ␊ |
951 | ␉// Notify modules that the kernel has been decompressed, thinned and is about to be decoded␊ |
952 | ␉execute_hook("DecodeKernel", (void *)binary, NULL, NULL, NULL);␊ |
953 | ␊ |
954 | ␉ret = DecodeMachO(binary, rentry, raddr, rsize);␊ |
955 | ␉if (ret < 0 && archCpuType == CPU_TYPE_X86_64)␊ |
956 | ␉{␊ |
957 | ␉␉archCpuType = CPU_TYPE_I386;␊ |
958 | ␉␉ret = DecodeMachO(binary, rentry, raddr, rsize);␊ |
959 | ␉}␊ |
960 | ␊ |
961 | ␉return ret;␊ |
962 | }␊ |
963 | |