Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazileon/i386/boot2/drivers.c

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

Archive Download this file

Revision: 401