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