Chameleon

Chameleon Svn Source Tree

Root/branches/valv/i386/boot2/drivers.c

  • Property svn:executable set to
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
42extern char gMacOSVersion;
43
44struct Module {
45 struct Module *nextModule;
46 long willLoad;
47 TagPtr dict;
48 char *plistAddr;
49 long plistLength;
50 char *executablePath;
51 char *bundlePath;
52 long bundlePathLength;
53};
54typedef struct Module Module, *ModulePtr;
55
56struct DriverInfo {
57 char *plistAddr;
58 long plistLength;
59 void *executableAddr;
60 long executableLength;
61 void *bundlePathAddr;
62 long bundlePathLength;
63};
64typedef struct DriverInfo DriverInfo, *DriverInfoPtr;
65
66#define kDriverPackageSignature1 'MKXT'
67#define kDriverPackageSignature2 'MOSX'
68
69struct DriversPackage {
70 unsigned long signature1;
71 unsigned long signature2;
72 unsigned long length;
73 unsigned long alder32;
74 unsigned long version;
75 unsigned long numDrivers;
76 unsigned long reserved1;
77 unsigned long reserved2;
78};
79typedef struct DriversPackage DriversPackage;
80
81enum {
82 kCFBundleType2,
83 kCFBundleType3
84};
85
86long (*LoadExtraDrivers_p)(FileLoadDrivers_t FileLoadDrivers_p);
87
88static unsigned long Alder32( unsigned char * buffer, long length );
89
90static long FileLoadDrivers(char *dirSpec, long plugin);
91static long NetLoadDrivers(char *dirSpec);
92static long LoadDriverMKext(char *fileSpec);
93static long LoadDriverPList(char *dirSpec, char *name, long bundleType);
94static long LoadMatchedModules(void);
95static long MatchPersonalities(void);
96static long MatchLibraries(void);
97#ifdef NOTDEF
98static ModulePtr FindModule(char *name);
99static void ThinFatFile(void **loadAddrP, unsigned long *lengthP);
100#endif
101static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities);
102static long InitDriverSupport(void);
103
104static ModulePtr gModuleHead, gModuleTail;
105static TagPtr gPersonalityHead, gPersonalityTail;
106static char * gExtensionsSpec;
107static char * gDriverSpec;
108static char * gFileSpec;
109static char * gTempSpec;
110static char * gFileName;
111
112static unsigned long
113Alder32( unsigned char * buffer, long length )
114{
115 long cnt;
116 unsigned long result, lowHalf, highHalf;
117
118 lowHalf = 1;
119 highHalf = 0;
120
121for ( cnt = 0; cnt < length; cnt++ )
122 {
123 if ((cnt % 5000) == 0)
124 {
125 lowHalf %= 65521L;
126 highHalf %= 65521L;
127 }
128
129 lowHalf += buffer[cnt];
130 highHalf += lowHalf;
131 }
132
133lowHalf %= 65521L;
134highHalf %= 65521L;
135
136result = (highHalf << 16) | lowHalf;
137
138return result;
139}
140
141
142//==========================================================================
143// InitDriverSupport
144
145static long
146InitDriverSupport( void )
147{
148 gExtensionsSpec = malloc( 4096 );
149 gDriverSpec = malloc( 4096 );
150 gFileSpec = malloc( 4096 );
151 gTempSpec = malloc( 4096 );
152 gFileName = malloc( 4096 );
153
154 if ( !gExtensionsSpec || !gDriverSpec || !gFileSpec || !gTempSpec || !gFileName )
155 stop("InitDriverSupport error");
156
157 return 0;
158}
159
160//==========================================================================
161// LoadDrivers
162
163long LoadDrivers( char * dirSpec )
164{
165 char dirSpecExtra[1024];
166
167 if ( InitDriverSupport() != 0 )
168 return 0;
169
170 // Load extra drivers if a hook has been installed.
171 if (LoadExtraDrivers_p != NULL)
172 {
173 (*LoadExtraDrivers_p)(&FileLoadDrivers);
174 }
175
176 if ( gBootFileType == kNetworkDeviceType )
177 {
178 if (NetLoadDrivers(dirSpec) != 0) {
179 error("Could not load drivers from the network\n");
180 return -1;
181 }
182 }
183 else if ( gBootFileType == kBlockDeviceType )
184 {
185 // First try to load Extra extensions from the ramdisk if isn't aliased as bt(0,0).
186
187 // First try a specfic OS version folder ie 10.5
188 sprintf(dirSpecExtra, "rd(0,0)/Extra/%s/", &gMacOSVersion);
189 if (FileLoadDrivers(dirSpecExtra, 0) != 0)
190 {
191 // Next we'll try the base
192 strcpy(dirSpecExtra, "rd(0,0)/Extra/");
193 FileLoadDrivers(dirSpecExtra, 0);
194 }
195
196 // Next try to load Extra extensions from the selected root partition.
197 strcpy(dirSpecExtra, "/Extra/");
198 if (FileLoadDrivers(dirSpecExtra, 0) != 0)
199 {
200 // If failed, then try to load Extra extensions from the boot partition
201 // in case we have a separate booter partition or a bt(0,0) aliased ramdisk.
202 if ( !(gBIOSBootVolume->biosdev == gBootVolume->biosdev && gBIOSBootVolume->part_no == gBootVolume->part_no)
203 || (gRAMDiskVolume && gRAMDiskBTAliased) )
204 {
205 // Next try a specfic OS version folder ie 10.5
206 sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", &gMacOSVersion);
207 if (FileLoadDrivers(dirSpecExtra, 0) != 0)
208 {
209 // Next we'll try the base
210 strcpy(dirSpecExtra, "bt(0,0)/Extra/");
211 FileLoadDrivers(dirSpecExtra, 0);
212 }
213 }
214 }
215
216 // Also try to load Extensions from boot helper partitions.
217 if (gBootVolume->flags & kBVFlagBooter)
218 {
219 strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");
220 if (FileLoadDrivers(dirSpecExtra, 0) != 0)
221 {
222 strcpy(dirSpecExtra, "/com.apple.boot.R/System/Library/");
223 if (FileLoadDrivers(dirSpecExtra, 0) != 0)
224 {
225 strcpy(dirSpecExtra, "/com.apple.boot.S/System/Library/");
226 FileLoadDrivers(dirSpecExtra, 0);
227 }
228 }
229 }
230
231 if (gMKextName[0] != '\0')
232 {
233 verbose("LoadDrivers: %s\n", gMKextName);
234 if ( LoadDriverMKext(gMKextName) != 0 )
235 {
236 error("Could not load %s\n", gMKextName);
237 return -1;
238 }
239 }
240 else
241 {
242 strcpy(gExtensionsSpec, dirSpec);
243 strcat(gExtensionsSpec, "System/Library/");
244 FileLoadDrivers(gExtensionsSpec, 0);
245 }
246 }
247 else
248 {
249 return 0;
250 }
251
252 MatchPersonalities();
253
254 MatchLibraries();
255
256 LoadMatchedModules();
257
258 return 0;
259}
260
261//==========================================================================
262// FileLoadMKext
263
264static long
265FileLoadMKext( const char * dirSpec, const char * extDirSpec )
266{
267 long ret, flags, time, time2;
268 char altDirSpec[512];
269
270 sprintf (altDirSpec, "%s%s", dirSpec, extDirSpec);
271 ret = GetFileInfo(altDirSpec, "Extensions.mkext", &flags, &time);
272 if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat))
273 {
274 ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2);
275 if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeDirectory) ||
276 (((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1))))
277 {
278 sprintf(gDriverSpec, "%sExtensions.mkext", altDirSpec);
279 verbose("LoadDrivers: %s\n", gDriverSpec);
280 if (LoadDriverMKext(gDriverSpec) == 0) return 0;
281 }
282 }
283 return -1;
284}
285
286//==========================================================================
287// FileLoadDrivers
288
289static long
290FileLoadDrivers( char * dirSpec, long plugin )
291{
292 long ret, length, flags, time, bundleType;
293 long long index;
294 long result = -1;
295 const char * name;
296
297 if ( !plugin )
298 {
299 // First try 10.6's path for loading Extensions.mkext.
300 if (FileLoadMKext(dirSpec, "Caches/com.apple.kext.caches/Startup/") == 0)
301 return 0;
302
303 // Next try the legacy path.
304 else if (FileLoadMKext(dirSpec, "") == 0)
305 return 0;
306
307 strcat(dirSpec, "Extensions");
308 }
309
310 index = 0;
311 while (1) {
312 ret = GetDirEntry(dirSpec, &index, &name, &flags, &time);
313 if (ret == -1) break;
314
315 // Make sure this is a directory.
316 if ((flags & kFileTypeMask) != kFileTypeDirectory) continue;
317
318 // Make sure this is a kext.
319 length = strlen(name);
320 if (strcmp(name + length - 5, ".kext")) continue;
321
322 // Save the file name.
323 strcpy(gFileName, name);
324
325 // Determine the bundle type.
326 sprintf(gTempSpec, "%s/%s", dirSpec, gFileName);
327 ret = GetFileInfo(gTempSpec, "Contents", &flags, &time);
328 if (ret == 0) bundleType = kCFBundleType2;
329 else bundleType = kCFBundleType3;
330
331 if (!plugin)
332 sprintf(gDriverSpec, "%s/%s/%sPlugIns", dirSpec, gFileName,
333 (bundleType == kCFBundleType2) ? "Contents/" : "");
334
335 ret = LoadDriverPList(dirSpec, gFileName, bundleType);
336
337 if (result != 0)
338 result = ret;
339
340 if (!plugin)
341 FileLoadDrivers(gDriverSpec, 1);
342 }
343
344 return result;
345}
346
347//==========================================================================
348//
349
350static long
351NetLoadDrivers( char * dirSpec )
352{
353 long tries;
354
355#if NODEF
356 long cnt;
357
358 // Get the name of the kernel
359 cnt = strlen(gBootFile);
360 while (cnt--) {
361 if ((gBootFile[cnt] == '\\') || (gBootFile[cnt] == ',')) {
362 cnt++;
363 break;
364 }
365 }
366#endif
367
368 // INTEL modification
369 sprintf(gDriverSpec, "%s%s.mkext", dirSpec, bootInfo->bootFile);
370
371 verbose("NetLoadDrivers: Loading from [%s]\n", gDriverSpec);
372
373 tries = 3;
374 while (tries--)
375 {
376 if (LoadDriverMKext(gDriverSpec) == 0) break;
377 }
378 if (tries == -1) return -1;
379
380 return 0;
381}
382
383//==========================================================================
384// loadDriverMKext
385
386static long
387LoadDriverMKext( char * fileSpec )
388{
389 unsigned long driversAddr, driversLength;
390 long length;
391 char segName[32];
392 DriversPackage * package;
393
394#define GetPackageElement(e) OSSwapBigToHostInt32(package->e)
395
396 // Load the MKext.
397 length = LoadThinFatFile(fileSpec, (void **)&package);
398 if (length < sizeof (DriversPackage)) return -1;
399
400 // Verify the MKext.
401 if (( GetPackageElement(signature1) != kDriverPackageSignature1) ||
402 ( GetPackageElement(signature2) != kDriverPackageSignature2) ||
403 ( GetPackageElement(length) > kLoadSize ) ||
404 ( GetPackageElement(alder32) !=
405 Alder32((unsigned char *)&package->version, GetPackageElement(length) - 0x10) ) )
406 {
407 return -1;
408 }
409
410 // Make space for the MKext.
411 driversLength = GetPackageElement(length);
412 driversAddr = AllocateKernelMemory(driversLength);
413
414 // Copy the MKext.
415 memcpy((void *)driversAddr, (void *)package, driversLength);
416
417 // Add the MKext to the memory map.
418 sprintf(segName, "DriversPackage-%lx", driversAddr);
419 AllocateMemoryRange(segName, driversAddr, driversLength,
420 kBootDriverTypeMKEXT);
421
422 return 0;
423}
424
425//==========================================================================
426// LoadDriverPList
427
428static long
429LoadDriverPList( char * dirSpec, char * name, long bundleType )
430{
431 long length, executablePathLength, bundlePathLength;
432 ModulePtr module;
433 TagPtr personalities;
434 char * buffer = 0;
435 char * tmpExecutablePath = 0;
436 char * tmpBundlePath = 0;
437 long ret = -1;
438
439 do {
440 // Save the driver path.
441
442 sprintf(gFileSpec, "%s/%s/%s", dirSpec, name,
443 (bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");
444 executablePathLength = strlen(gFileSpec) + 1;
445
446 tmpExecutablePath = malloc(executablePathLength);
447 if (tmpExecutablePath == 0) break;
448
449 strcpy(tmpExecutablePath, gFileSpec);
450
451 sprintf(gFileSpec, "%s/%s", dirSpec, name);
452 bundlePathLength = strlen(gFileSpec) + 1;
453
454 tmpBundlePath = malloc(bundlePathLength);
455 if (tmpBundlePath == 0) break;
456
457 strcpy(tmpBundlePath, gFileSpec);
458
459 // Construct the file spec to the plist, then load it.
460
461 sprintf(gFileSpec, "%s/%s/%sInfo.plist", dirSpec, name,
462 (bundleType == kCFBundleType2) ? "Contents/" : "");
463
464 length = LoadFile(gFileSpec);
465 if (length == -1) break;
466
467 length = length + 1;
468 buffer = malloc(length);
469 if (buffer == 0) break;
470
471 strlcpy(buffer, (char *)kLoadAddr, length);
472
473 // Parse the plist.
474
475 ret = ParseXML(buffer, &module, &personalities);
476 if (ret != 0) { break; }
477
478 // Allocate memory for the driver path and the plist.
479
480 module->executablePath = tmpExecutablePath;
481 module->bundlePath = tmpBundlePath;
482 module->bundlePathLength = bundlePathLength;
483 module->plistAddr = malloc(length);
484
485 if ((module->executablePath == 0) || (module->bundlePath == 0) || (module->plistAddr == 0))
486 break;
487
488 // Save the driver path in the module.
489 //strcpy(module->driverPath, tmpDriverPath);
490 tmpExecutablePath = 0;
491 tmpBundlePath = 0;
492
493 // Add the plist to the module.
494
495 strlcpy(module->plistAddr, (char *)kLoadAddr, length);
496 module->plistLength = length;
497
498 // Add the module to the end of the module list.
499
500 if (gModuleHead == 0)
501 gModuleHead = module;
502 else
503 gModuleTail->nextModule = module;
504 gModuleTail = module;
505
506 // Add the persionalities to the personality list.
507
508 if (personalities) personalities = personalities->tag;
509 while (personalities != 0)
510 {
511 if (gPersonalityHead == 0)
512 gPersonalityHead = personalities->tag;
513 else
514 gPersonalityTail->tagNext = personalities->tag;
515
516 gPersonalityTail = personalities->tag;
517 personalities = personalities->tagNext;
518 }
519
520 ret = 0;
521 }
522 while (0);
523
524 if ( buffer ) free( buffer );
525 if ( tmpExecutablePath ) free( tmpExecutablePath );
526 if ( tmpBundlePath ) free( tmpBundlePath );
527
528 return ret;
529}
530
531
532//==========================================================================
533// LoadMatchedModules
534
535static long
536LoadMatchedModules( void )
537{
538 TagPtr prop;
539 ModulePtr module;
540 char *fileName, segName[32];
541 DriverInfoPtr driver;
542 long length, driverAddr, driverLength;
543 void *executableAddr = 0;
544
545
546 module = gModuleHead;
547
548 while (module != 0)
549 {
550 if (module->willLoad)
551 {
552 prop = XMLGetProperty(module->dict, kPropCFBundleExecutable);
553
554 if (prop != 0)
555 {
556 fileName = prop->string;
557 sprintf(gFileSpec, "%s%s", module->executablePath, fileName);
558 length = LoadThinFatFile(gFileSpec, &executableAddr);
559if (length == 0)
560{
561length = LoadFile(gFileSpec);
562executableAddr = (void *)kLoadAddr;
563}
564 //printf("%s length = %d addr = 0x%x\n", gFileSpec, length, driverModuleAddr); getc();
565 }
566 else
567 length = 0;
568
569 if (length != -1)
570 {
571//driverModuleAddr = (void *)kLoadAddr;
572 //if (length != 0)
573 //{
574// ThinFatFile(&driverModuleAddr, &length);
575//}
576
577 // Make make in the image area.
578 driverLength = sizeof(DriverInfo) + module->plistLength + length + module->bundlePathLength;
579 driverAddr = AllocateKernelMemory(driverLength);
580
581 // Set up the DriverInfo.
582 driver = (DriverInfoPtr)driverAddr;
583 driver->plistAddr = (char *)(driverAddr + sizeof(DriverInfo));
584 driver->plistLength = module->plistLength;
585 if (length != 0)
586 {
587 driver->executableAddr = (void *)(driverAddr + sizeof(DriverInfo) +
588 module->plistLength);
589 driver->executableLength = length;
590 }
591 else
592 {
593 driver->executableAddr = 0;
594 driver->executableLength = 0;
595 }
596 driver->bundlePathAddr = (void *)(driverAddr + sizeof(DriverInfo) +
597 module->plistLength + driver->executableLength);
598 driver->bundlePathLength = module->bundlePathLength;
599
600 // Save the plist, module and bundle.
601 strcpy(driver->plistAddr, module->plistAddr);
602 if (length != 0)
603 {
604 memcpy(driver->executableAddr, executableAddr, length);
605 }
606 strcpy(driver->bundlePathAddr, module->bundlePath);
607
608 // Add an entry to the memory map.
609 sprintf(segName, "Driver-%lx", (unsigned long)driver);
610 AllocateMemoryRange(segName, driverAddr, driverLength,
611 kBootDriverTypeKEXT);
612 }
613 }
614 module = module->nextModule;
615 }
616
617 return 0;
618}
619
620//==========================================================================
621// MatchPersonalities
622
623static long
624MatchPersonalities( void )
625{
626 /* IONameMatch support not implemented */
627 return 0;
628}
629
630//==========================================================================
631// MatchLibraries
632
633static long
634MatchLibraries( void )
635{
636 TagPtr prop, prop2;
637 ModulePtr module, module2;
638 long done;
639
640 do {
641 done = 1;
642 module = gModuleHead;
643
644 while (module != 0)
645 {
646 if (module->willLoad == 1)
647 {
648 prop = XMLGetProperty(module->dict, kPropOSBundleLibraries);
649 if (prop != 0)
650 {
651 prop = prop->tag;
652 while (prop != 0)
653 {
654 module2 = gModuleHead;
655 while (module2 != 0)
656 {
657 prop2 = XMLGetProperty(module2->dict, kPropCFBundleIdentifier);
658 if ((prop2 != 0) && (!strcmp(prop->string, prop2->string)))
659 {
660 if (module2->willLoad == 0) module2->willLoad = 1;
661 break;
662 }
663 module2 = module2->nextModule;
664 }
665 prop = prop->tagNext;
666 }
667 }
668 module->willLoad = 2;
669 done = 0;
670 }
671 module = module->nextModule;
672 }
673 }
674 while (!done);
675
676 return 0;
677}
678
679
680//==========================================================================
681// FindModule
682
683#if NOTDEF
684static ModulePtr
685FindModule( char * name )
686{
687 ModulePtr module;
688 TagPtr prop;
689
690 module = gModuleHead;
691
692 while (module != 0)
693 {
694 prop = GetProperty(module->dict, kPropCFBundleIdentifier);
695 if ((prop != 0) && !strcmp(name, prop->string)) break;
696 module = module->nextModule;
697 }
698
699 return module;
700}
701#endif /* NOTDEF */
702
703//==========================================================================
704// ParseXML
705
706static long
707ParseXML( char * buffer, ModulePtr * module, TagPtr * personalities )
708{
709long length, pos;
710TagPtr moduleDict, required;
711ModulePtr tmpModule;
712
713 pos = 0;
714
715 while (1)
716 {
717 length = XMLParseNextTag(buffer + pos, &moduleDict);
718 if (length == -1) break;
719
720 pos += length;
721
722 if (moduleDict == 0) continue;
723 if (moduleDict->type == kTagTypeDict) break;
724
725 XMLFreeTag(moduleDict);
726 }
727
728 if (length == -1) return -1;
729
730 required = XMLGetProperty(moduleDict, kPropOSBundleRequired);
731 if ( (required == 0) ||
732 (required->type != kTagTypeString) ||
733 !strcmp(required->string, "Safe Boot"))
734 {
735 XMLFreeTag(moduleDict);
736 return -2;
737 }
738
739 tmpModule = malloc(sizeof(Module));
740 if (tmpModule == 0)
741 {
742 XMLFreeTag(moduleDict);
743 return -1;
744 }
745 tmpModule->dict = moduleDict;
746
747 // For now, load any module that has OSBundleRequired != "Safe Boot".
748
749 tmpModule->willLoad = 1;
750
751 *module = tmpModule;
752
753 // Get the personalities.
754
755 *personalities = XMLGetProperty(moduleDict, kPropIOKitPersonalities);
756
757 return 0;
758}
759
760#if NOTDEF
761static char gPlatformName[64];
762#endif
763
764long
765DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize)
766{
767 long ret;
768 compressed_kernel_header * kernel_header = (compressed_kernel_header *) binary;
769 u_int32_t uncompressed_size, size;
770 void *buffer;
771unsigned long len;
772
773#if 0
774 printf("kernel header:\n");
775 printf("signature: 0x%x\n", kernel_header->signature);
776 printf("compress_type: 0x%x\n", kernel_header->compress_type);
777 printf("adler32: 0x%x\n", kernel_header->adler32);
778 printf("uncompressed_size: 0x%x\n", kernel_header->uncompressed_size);
779 printf("compressed_size: 0x%x\n", kernel_header->compressed_size);
780 getc();
781#endif
782
783 if (kernel_header->signature == OSSwapBigToHostConstInt32('comp')) {
784 if (kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss')) {
785 error("kernel compression is bad\n");
786 return -1;
787 }
788#if NOTDEF
789 if (kernel_header->platform_name[0] && strcmp(gPlatformName, kernel_header->platform_name))
790 return -1;
791 if (kernel_header->root_path[0] && strcmp(gBootFile, kernel_header->root_path))
792 return -1;
793#endif
794
795 uncompressed_size = OSSwapBigToHostInt32(kernel_header->uncompressed_size);
796 binary = buffer = malloc(uncompressed_size);
797
798 size = decompress_lzss((u_int8_t *) binary, &kernel_header->data[0],
799 OSSwapBigToHostInt32(kernel_header->compressed_size));
800 if (uncompressed_size != size) {
801 error("size mismatch from lzss: %x\n", size);
802 return -1;
803 }
804 if (OSSwapBigToHostInt32(kernel_header->adler32) !=
805 Alder32(binary, uncompressed_size)) {
806 printf("adler mismatch\n");
807 return -1;
808 }
809 }
810
811 ret = ThinFatFile(&binary, &len);
812 if (ret == 0 && len == 0 && archCpuType==CPU_TYPE_X86_64)
813 {
814 archCpuType=CPU_TYPE_I386;
815 ret = ThinFatFile(&binary, &len);
816 }
817
818 ret = DecodeMachO(binary, rentry, raddr, rsize);
819
820 if (ret<0 && archCpuType==CPU_TYPE_X86_64)
821 {
822 archCpuType=CPU_TYPE_I386;
823 ret = DecodeMachO(binary, rentry, raddr, rsize);
824 }
825
826 return ret;
827}
828

Archive Download this file

Revision: 665