Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 145