␊ |
/*static*/ unsigned long Adler32( unsigned char * buffer, long length );␊ |
␊ |
static long FileLoadDrivers(char *dirSpec, long plugin);␊ |
static long NetLoadDrivers(char *dirSpec);␊ |
static long LoadDriverMKext(char *fileSpec);␊ |
static long LoadDriverPList(char *dirSpec, char *name, long bundleType);␊ |
static long LoadMatchedModules(void);␊ |
long FileLoadDrivers(char *dirSpec, long plugin);␊ |
long NetLoadDrivers(char *dirSpec);␊ |
long LoadDriverMKext(char *fileSpec);␊ |
long LoadDriverPList(char *dirSpec, char *name, long bundleType);␊ |
long LoadMatchedModules(void);␊ |
␊ |
static long MatchPersonalities(void);␊ |
static long MatchLibraries(void);␊ |
#ifdef NOTDEF␊ |
|
static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities);␊ |
static long InitDriverSupport(void);␊ |
␊ |
static ModulePtr gModuleHead, gModuleTail;␊ |
ModulePtr gModuleHead, gModuleTail;␊ |
static TagPtr gPersonalityHead, gPersonalityTail;␊ |
static char * gExtensionsSpec;␊ |
static char * gDriverSpec;␊ |
|
//==========================================================================␊ |
// FileLoadDrivers␊ |
␊ |
static long␊ |
long␊ |
FileLoadDrivers( char * dirSpec, long plugin )␊ |
{␊ |
long ret, length, flags, time, bundleType;␊ |
|
return result;␊ |
}␊ |
␊ |
long␊ |
FileLoadDriver( char * dirSpec, long plugin )␊ |
{␊ |
long ret, length, flags, time, bundleType;␊ |
long long␉ index;␊ |
long result = -1;␊ |
const char * name;␊ |
␊ |
if ( !plugin )␊ |
{␊ |
// First try 10.6's path for loading Extensions.mkext.␊ |
if (FileLoadMKext(dirSpec, "Caches/com.apple.kext.caches/Startup/") == 0)␊ |
return 0;␊ |
␊ |
// Next try the legacy path.␊ |
else if (FileLoadMKext(dirSpec, "") == 0)␊ |
return 0;␊ |
␊ |
strcat(dirSpec, "Extensions");␊ |
}␊ |
␊ |
index = 0;␊ |
while (1) {␊ |
ret = GetDirEntry(dirSpec, &index, &name, &flags, &time);␊ |
if (ret == -1) break;␊ |
␊ |
// Make sure this is a directory.␊ |
if ((flags & kFileTypeMask) != kFileTypeDirectory) continue;␊ |
␊ |
// Make sure this is a kext.␊ |
length = strlen(name);␊ |
if (strcmp(name + length - 5, ".kext")) continue;␊ |
␊ |
// Save the file name.␊ |
strcpy(gFileName, name);␊ |
␊ |
// Determine the bundle type.␊ |
sprintf(gTempSpec, "%s/%s", dirSpec, gFileName);␊ |
ret = GetFileInfo(gTempSpec, "Contents", &flags, &time);␊ |
if (ret == 0) bundleType = kCFBundleType2;␊ |
else bundleType = kCFBundleType3;␊ |
␊ |
if (!plugin)␊ |
sprintf(gDriverSpec, "%s/%s/%sPlugIns", dirSpec, gFileName,␊ |
(bundleType == kCFBundleType2) ? "Contents/" : "");␊ |
␊ |
ret = LoadDriverPList(dirSpec, gFileName, bundleType);␊ |
␊ |
if (result != 0)␊ |
result = ret;␊ |
␊ |
if (!plugin) ␊ |
FileLoadDrivers(gDriverSpec, 1);␊ |
}␊ |
␊ |
return result;␊ |
}␊ |
␊ |
␊ |
//==========================================================================␊ |
// ␊ |
␊ |
static long␊ |
long␊ |
NetLoadDrivers( char * dirSpec )␊ |
{␊ |
long tries;␊ |
|
//==========================================================================␊ |
// loadDriverMKext␊ |
␊ |
static long␊ |
long␊ |
LoadDriverMKext( char * fileSpec )␊ |
{␊ |
unsigned long driversAddr, driversLength;␊ |
|
//==========================================================================␊ |
// LoadDriverPList␊ |
␊ |
static long␊ |
long␊ |
LoadDriverPList( char * dirSpec, char * name, long bundleType )␊ |
{␊ |
long length, executablePathLength, bundlePathLength;␊ |
|
do {␊ |
// Save the driver path.␊ |
␊ |
sprintf(gFileSpec, "%s/%s/%s", dirSpec, name,␊ |
if(name) sprintf(gFileSpec, "%s/%s/%s", dirSpec, name,␊ |
(bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");␊ |
else sprintf(gFileSpec, "%s/%s", dirSpec,␊ |
(bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");␊ |
executablePathLength = strlen(gFileSpec) + 1;␊ |
␊ |
tmpExecutablePath = malloc(executablePathLength);␊ |
if (tmpExecutablePath == 0) break;␊ |
␊ |
strcpy(tmpExecutablePath, gFileSpec);␊ |
␊ |
sprintf(gFileSpec, "%s/%s", dirSpec, name);␊ |
if(name) sprintf(gFileSpec, "%s/%s", dirSpec, name);␊ |
else sprintf(gFileSpec, "%s", dirSpec);␊ |
bundlePathLength = strlen(gFileSpec) + 1;␊ |
␊ |
tmpBundlePath = malloc(bundlePathLength);␊ |
|
␊ |
// Construct the file spec to the plist, then load it.␊ |
␊ |
sprintf(gFileSpec, "%s/%s/%sInfo.plist", dirSpec, name,␊ |
if(name) sprintf(gFileSpec, "%s/%s/%sInfo.plist", dirSpec, name,␊ |
(bundleType == kCFBundleType2) ? "Contents/" : "");␊ |
else sprintf(gFileSpec, "%s/%sInfo.plist", dirSpec,␊ |
(bundleType == kCFBundleType2) ? "Contents/" : "");␊ |
␊ |
length = LoadFile(gFileSpec);␊ |
if (length == -1) break;␊ |
␊ |
length = length + 1;␊ |
buffer = malloc(length);␊ |
if (buffer == 0) break;␊ |
␊ |
strlcpy(buffer, (char *)kLoadAddr, length);␊ |
␊ |
// Parse the plist.␊ |
␊ |
ret = ParseXML(buffer, &module, &personalities);␊ |
if (ret != 0) { break; }␊ |
␊ |
// Allocate memory for the driver path and the plist.␊ |
␊ |
module->executablePath = tmpExecutablePath;␊ |
|
␊ |
if ((module->executablePath == 0) || (module->bundlePath == 0) || (module->plistAddr == 0))␊ |
break;␊ |
␊ |
// Save the driver path in the module.␊ |
//strcpy(module->driverPath, tmpDriverPath);␊ |
tmpExecutablePath = 0;␊ |
|
//==========================================================================␊ |
// LoadMatchedModules␊ |
␊ |
static long␊ |
long␊ |
LoadMatchedModules( void )␊ |
{␊ |
␉TagPtr␉␉ prop;␊ |
|
//␉␉␉␉}␊ |
␊ |
␉␉␉␉// Make make in the image area.␊ |
␊ |
execute_hook("LoadMatchedModules", module, &length, executableAddr, NULL);␊ |
␊ |
␉␉␉␉driverLength = sizeof(DriverInfo) + module->plistLength + length + module->bundlePathLength;␊ |
␉␉␉␉driverAddr = AllocateKernelMemory(driverLength);␊ |
␊ |
|
ParseXML( char * buffer, ModulePtr * module, TagPtr * personalities )␊ |
{␊ |
␉long length, pos;␊ |
␉TagPtr moduleDict, required;␊ |
␉TagPtr moduleDict;␊ |
␉ModulePtr tmpModule;␊ |
␊ |
pos = 0;␊ |
|
␊ |
if (length == -1) return -1;␊ |
␊ |
required = XMLGetProperty(moduleDict, kPropOSBundleRequired);␊ |
if ( (required == 0) ||␊ |
(required->type != kTagTypeString) ||␊ |
!strcmp(required->string, "Safe Boot"))␊ |
#if 0 /** remove this check. **/ ␊ |
if (strcmp(XMLCastString(XMLGetProperty(moduleDict, kPropOSBundleRequired)), "Safe Boot") == 0)␊ |
{␊ |
// Don't load Safe Boot kexts. NOTE: -x should be check too.␊ |
XMLFreeTag(moduleDict);␊ |
return -2;␊ |
}␊ |
#endif ␊ |
␊ |
tmpModule = malloc(sizeof(Module));␊ |
if (tmpModule == 0)␊ |