Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 543