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