Index: branches/azimutz/Chazi/i386/libsaio/xml.c =================================================================== --- branches/azimutz/Chazi/i386/libsaio/xml.c (revision 1059) +++ branches/azimutz/Chazi/i386/libsaio/xml.c (revision 1060) @@ -22,16 +22,52 @@ * @APPLE_LICENSE_HEADER_END@ */ -//#include "libsaio.h" #include "bootstruct.h" +#include "libsaio.h" #include "sl.h" #include "xml.h" -//Azi: UPDATE THIS FILE - ADLER STUFF***** -// start - this code is unchanged since boot132, were it was exactly the same -// as the one in drivers.c. Atm, the one in drivers.c has some more stuff; it could be -// added on xml.h which is included on drivers.c and here?? -struct Module { +string_ref *ref_strings = NULL; + +/// TODO: remove below +static char* buffer_start = NULL; +// TODO: redo the next two functions +void SaveRefString(char* string, int id) +{ + //printf("Adding Ref String %d (%s)\n", id, string); + string_ref* tmp = ref_strings; + while(tmp) + { + if(tmp->id == id) + { + tmp->string = malloc(strlen(string)+1); + sprintf(tmp->string, "%s", string); + return; + } + tmp = tmp->next; + } + + string_ref* new_ref = malloc(sizeof(string_ref)); + new_ref->string = malloc(strlen(string)+1); + sprintf(new_ref->string, "%s", string); + new_ref->id = id; + new_ref->next = ref_strings; + ref_strings = new_ref; +} + +char* GetRefString(int id) +{ + string_ref* tmp = ref_strings; + while(tmp) + { + if(tmp->id == id) return tmp->string; + tmp = tmp->next; + } + //verbose("Unable to locate Ref String %d\n", id); + return ""; +} + +struct Module { struct Module *nextModule; long willLoad; TagPtr dict; @@ -56,7 +92,7 @@ unsigned long signature1; unsigned long signature2; unsigned long length; - unsigned long alder32; + unsigned long adler32; unsigned long version; unsigned long numDrivers; unsigned long reserved1; @@ -68,8 +104,8 @@ kCFBundleType2, kCFBundleType3 }; -//Azi: end ---//--- + #define DOFREE 1 static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty); @@ -113,6 +149,49 @@ return 0; } +// XMLGetTag(int index) + +// XMLTagCount( TagPtr dict ) +int XMLTagCount( TagPtr dict ) +{ + int count = 0; + TagPtr tagList, tag; + + if (dict->type != kTagTypeDict && dict->type != kTagTypeArray) return 0; + tag = 0; + tagList = dict->tag; + while (tagList) + { + tag = tagList; + tagList = tag->tagNext; + + if (((tag->type != kTagTypeKey) && ((tag->string == 0) || (tag->string[0] == 0))) + && (dict->type != kTagTypeArray) // If we are an array, any element is valid + ) continue; + + if(tag->type == kTagTypeKey) printf("Located key %s\n", tag->string); + + count++; + } + + return count; +} + +TagPtr XMLGetElement( TagPtr dict, int id ) +{ + if(dict->type != kTagTypeArray) return 0; + + int element = 0; + TagPtr tmp = dict->tag; + + while(element < id) + { + element++; + tmp = tmp->tagNext; + } + + return tmp; +} /* Function for basic XML character entities parsing */ char* @@ -171,12 +250,13 @@ return out; } -#if UNUSED +//#if UNUSED //========================================================================== // XMLParseFile -// Expects to see one dictionary in the XML file. +// Expects to see one dictionary in the XML file, the final pos will be returned +// If the pos is not equal to the strlen, then there are multiple dicts // Puts the first dictionary it finds in the -// tag pointer and returns 0, or returns -1 if not found. +// tag pointer and returns the end of the dic, or returns -1 if not found. // long XMLParseFile( char * buffer, TagPtr * dict ) @@ -184,10 +264,18 @@ long length, pos; TagPtr tag; pos = 0; - + char *configBuffer; + + + + configBuffer = malloc(strlen(buffer)+1); + strcpy(configBuffer, buffer); + + buffer_start = configBuffer; + while (1) { - length = XMLParseNextTag(buffer + pos, &tag); + length = XMLParseNextTag(configBuffer + pos, &tag); if (length == -1) break; pos += length; @@ -197,84 +285,248 @@ XMLFreeTag(tag); } - if (length < 0) { + free(configBuffer); + if (length < 0) { return -1; } *dict = tag; - return 0; + return pos; } -#endif /* UNUSED */ +//#endif /* UNUSED */ //========================================================================== // ParseNextTag - +// TODO: cleanup long XMLParseNextTag( char * buffer, TagPtr * tag ) { long length, pos; char * tagName; + + length = GetNextTag(buffer, &tagName, 0); + if (length == -1) return -1; + + pos = length; + if (!strncmp(tagName, kXMLTagPList, 6)) + { + length = 0; + } + /***** dict ****/ + else if (!strcmp(tagName, kXMLTagDict)) + { + length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); + } + else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/') + { + length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1); + } + else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " "))) + { + length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); + } + /***** key ****/ + else if (!strcmp(tagName, kXMLTagKey)) + { + length = ParseTagKey(buffer + pos, tag); + } + + /***** string ****/ + else if (!strcmp(tagName, kXMLTagString)) + { + length = ParseTagString(buffer + pos, tag); + } + else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " "))) + { + // TODO: save tag if if found + if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID))) + { + // ID= + int id = 0; + int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1; + while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; + tagName[cnt] = 0; + char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\""); + while(*val) + { + if ((*val >= '0' && *val <= '9')) // 0 - 9 + { + id = (id * 10) + (*val++ - '0'); + } + else + { + printf("ParseStringID error (0x%x)\n", *val); + getchar(); + return -1; + } + } + length = ParseTagString(buffer + pos, tag); + + SaveRefString(buffer + pos, id); + } + else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) + { + // IDREF= + int id = 0; + int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1; + while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; + tagName[cnt] = 0; + char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\""); + while(*val) + { + if ((*val >= '0' && *val <= '9')) // 0 - 9 + { + id = (id * 10) + (*val++ - '0'); + } + else + { + printf("ParseStringIDREF error (0x%x)\n", *val); + getchar(); + return -1; + } + } + char* str = GetRefString(id); - length = GetNextTag(buffer, &tagName, 0); - if (length == -1) return -1; - - pos = length; - if (!strncmp(tagName, kXMLTagPList, 6)) - { - length = 0; - } - else if (!strcmp(tagName, kXMLTagDict)) - { - length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); - } - else if (!strcmp(tagName, kXMLTagDict "/")) - { - length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1); - } - else if (!strcmp(tagName, kXMLTagKey)) - { - length = ParseTagKey(buffer + pos, tag); - } - else if (!strcmp(tagName, kXMLTagString)) - { - length = ParseTagString(buffer + pos, tag); - } - else if (!strcmp(tagName, kXMLTagInteger)) - { - length = ParseTagInteger(buffer + pos, tag); - } - else if (!strcmp(tagName, kXMLTagData)) - { - length = ParseTagData(buffer + pos, tag); - } - else if (!strcmp(tagName, kXMLTagDate)) - { - length = ParseTagDate(buffer + pos, tag); - } - else if (!strcmp(tagName, kXMLTagFalse)) - { - length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse); - } - else if (!strcmp(tagName, kXMLTagTrue)) - { - length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue); - } - else if (!strcmp(tagName, kXMLTagArray)) - { - length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); - } - else if (!strcmp(tagName, kXMLTagArray "/")) - { - length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1); - } - else - { - *tag = 0; - length = 0; - } - - if (length == -1) return -1; - - return pos + length; + TagPtr tmpTag = NewTag(); + tmpTag->type = kTagTypeString; + tmpTag->string = str; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0; + *tag = tmpTag; + + length = 0; + //printf("Located IDREF, id = %d, string = %s\n", id, str); + } + } + + /***** integer ****/ + else if (!strcmp(tagName, kXMLTagInteger)) + { + length = ParseTagInteger(buffer + pos, tag); + } + else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " "))) + { + if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID))) + { + // ID= + int id = 0; + int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1; + while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; + tagName[cnt] = 0; + char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\""); + while(*val) + { + if ((*val >= '0' && *val <= '9')) // 0 - 9 + { + id = (id * 10) + (*val++ - '0'); + } + else + { + printf("ParseIntegerID error (0x%x)\n", *val); + getchar(); + return -1; + } + } + length = ParseTagInteger(buffer + pos, tag); + + SaveRefString((*tag)->string, id); + } + else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) + { + // IDREF= + int id = 0; + int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1; + while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; + tagName[cnt] = 0; + char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\""); + while(*val) + { + if ((*val >= '0' && *val <= '9')) // 0 - 9 + { + id = (id * 10) + (*val++ - '0'); + } + else + { + printf("ParseStringIDREF error (0x%x)\n", *val); + getchar(); + return -1; + } + } + int integer = (int)GetRefString(id); + + TagPtr tmpTag = NewTag(); + tmpTag->type = kTagTypeInteger; + tmpTag->string = (char*) integer; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0; + + *tag = tmpTag; + + length = 0; + //printf("Located IDREF, id = %d, string = %s\n", id, str); + } + else + { + length = ParseTagInteger(buffer + pos, tag); + } + } + + /***** data ****/ + else if (!strcmp(tagName, kXMLTagData)) + { + length = ParseTagData(buffer + pos, tag); + } + else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " "))) + { + length = ParseTagData(buffer + pos, tag); + } + else if (!strcmp(tagName, kXMLTagDate)) + { + length = ParseTagDate(buffer + pos, tag); + } + + /***** date ****/ + else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " "))) + { + length = ParseTagDate(buffer + pos, tag); + } + + /***** false ****/ + else if (!strcmp(tagName, kXMLTagFalse)) + { + length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse); + } + /***** true ****/ + else if (!strcmp(tagName, kXMLTagTrue)) + { + length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue); + } + + /***** array ****/ + else if (!strcmp(tagName, kXMLTagArray)) + { + length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); + } + else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " "))) + { + length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); + } + else if (!strcmp(tagName, kXMLTagArray "/")) + { + length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1); + } + + /***** unknown ****/ + else + { + *tag = 0; + length = 0; + } + + if (length == -1) return -1; + + return pos + length; } //========================================================================== @@ -319,6 +571,7 @@ tmpTag->type = type; tmpTag->string = 0; + tmpTag->offset = buffer_start ? buffer - buffer_start : 0; tmpTag->tag = tagList; tmpTag->tagNext = 0; @@ -361,6 +614,7 @@ tmpTag->type = kTagTypeKey; tmpTag->string = string; tmpTag->tag = subTag; + tmpTag->offset = buffer_start ? buffer - buffer_start: 0; tmpTag->tagNext = 0; *tag = tmpTag; @@ -376,12 +630,11 @@ { long length; char * string; - TagPtr tmpTag; length = FixDataMatchingTag(buffer, kXMLTagString); if (length == -1) return -1; - tmpTag = NewTag(); + TagPtr tmpTag = NewTag(); if (tmpTag == 0) return -1; string = NewSymbol(buffer); @@ -394,6 +647,7 @@ tmpTag->type = kTagTypeString; tmpTag->string = string; tmpTag->tag = 0; + tmpTag->offset = buffer_start ? buffer - buffer_start: 0; tmpTag->tagNext = 0; *tag = tmpTag; @@ -407,19 +661,92 @@ ParseTagInteger( char * buffer, TagPtr * tag ) { long length, integer; + bool negative = false; TagPtr tmpTag; - - length = FixDataMatchingTag(buffer, kXMLTagInteger); + char* val = buffer; + int size; + + if(buffer[0] == '<') + { + printf("Warning integer is non existant\n"); + getchar(); + tmpTag = NewTag(); + tmpTag->type = kTagTypeInteger; + tmpTag->string = 0; + tmpTag->tag = 0; + tmpTag->offset = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return 0; + } + + size = length = FixDataMatchingTag(buffer, kXMLTagInteger); if (length == -1) return -1; tmpTag = NewTag(); if (tmpTag == 0) return -1; integer = 0; - + + if(size > 1 && (val[1] == 'x' || val[1] == 'X')) // Hex value + { + val += 2; + while(*val) + { + if ((*val >= '0' && *val <= '9')) // 0 - 9 + { + integer = (integer * 16) + (*val++ - '0'); + } + else if ((*val >= 'a' && *val <= 'f')) // a - f + { + integer = (integer * 16) + (*val++ - 'a' + 10); + } + else if ((*val >= 'A' && *val <= 'F')) // A - F + { + integer = (integer * 16) + (*val++ - 'a' + 10); + } + else + { + printf("ParseTagInteger hex error (0x%x) in buffer %s\n", *val, buffer); + getchar(); + return -1; + } + } + } + else if ( size ) // Decimal value + { + if (*val == '-') + { + negative = true; + val++; + size--; + } + + for (integer = 0; size > 0; size--) + { + if(*val) // UGLY HACK, fix me. + { + if (*val < '0' || *val > '9') + { + printf("ParseTagInteger decimal error (0x%x) in buffer %s\n", *val, buffer); + getchar(); + return -1; + } + + integer = (integer * 10) + (*val++ - '0'); + } + } + + if (negative) + integer = -integer; + } + tmpTag->type = kTagTypeInteger; - tmpTag->string = (char *)integer; - tmpTag->tag = 0; + tmpTag->string = (char *)integer; + tmpTag->tag = 0; + tmpTag->offset = buffer_start ? buffer - buffer_start: 0; tmpTag->tagNext = 0; *tag = tmpTag; @@ -435,16 +762,24 @@ { long length; TagPtr tmpTag; - + length = FixDataMatchingTag(buffer, kXMLTagData); if (length == -1) return -1; tmpTag = NewTag(); if (tmpTag == 0) return -1; + //printf("ParseTagData unimplimented\n"); + //printf("Data: %s\n", buffer); + // getchar(); + + // TODO: base64 decode + + char* string = NewSymbol(buffer); tmpTag->type = kTagTypeData; - tmpTag->string = 0; + tmpTag->string = string; tmpTag->tag = 0; + tmpTag->offset = buffer_start ? buffer - buffer_start: 0; tmpTag->tagNext = 0; *tag = tmpTag; @@ -467,9 +802,13 @@ tmpTag = NewTag(); if (tmpTag == 0) return -1; + printf("ParseTagDate unimplimented\n"); + getchar(); + tmpTag->type = kTagTypeDate; tmpTag->string = 0; tmpTag->tag = 0; + tmpTag->offset = buffer_start ? buffer - buffer_start: 0; tmpTag->tagNext = 0; *tag = tmpTag; @@ -491,6 +830,7 @@ tmpTag->type = type; tmpTag->string = 0; tmpTag->tag = 0; + tmpTag->offset = buffer_start ? buffer - buffer_start: 0; tmpTag->tagNext = 0; *tag = tmpTag; @@ -608,6 +948,7 @@ tag->type = kTagTypeNone; tag->string = 0; tag->tag = 0; + tag->offset = 0; tag->tagNext = gTagsFree; gTagsFree = tag; #else @@ -671,7 +1012,7 @@ #if DOFREE static void FreeSymbol( char * string ) -{ +{ SymbolPtr symbol, prev; prev = 0; @@ -715,3 +1056,66 @@ return symbol; } + +bool XMLIsType(TagPtr dict, enum xmltype type) +{ + if(!dict) return (type == kTagTypeNone); + return (dict->type == type); +} + +/*** Cast functions ***/ +TagPtr XMLCastArray(TagPtr dict) +{ + if(!dict) return NULL; + if(dict->type == kTagTypeArray) return dict; + else return NULL; +} + +TagPtr XMLCastDict(TagPtr dict) +{ + if(!dict) return NULL; + if(dict->type == kTagTypeDict) return dict; + else return NULL; +} + +char* XMLCastString(TagPtr dict) +{ + if(!dict) return NULL; + + if((dict->type == kTagTypeString) || + (dict->type == kTagTypeKey)) return dict->string; + + return NULL; +} + +long XMLCastStringOffset(TagPtr dict) +{ + if(dict && + ((dict->type == kTagTypeString) || + (dict->type == kTagTypeKey))) + { + return dict->offset; + } + else + { + return -1; + } +} + +bool XMLCastBoolean(TagPtr dict) +{ + if(!dict) return false; + if(dict->type == kTagTypeTrue) return true; + return false; +} + +int XMLCastInteger(TagPtr dict) +{ + if(!dict) + { + printf("XMLCastInteger: null dict\n"); + return 0; + } + if(dict->type == kTagTypeInteger) return (int)(dict->string); + return 0; +} Index: branches/azimutz/Chazi/i386/libsaio/xml.h =================================================================== --- branches/azimutz/Chazi/i386/libsaio/xml.h (revision 1059) +++ branches/azimutz/Chazi/i386/libsaio/xml.h (revision 1060) @@ -25,7 +25,7 @@ #ifndef __LIBSAIO_XML_H #define __LIBSAIO_XML_H -enum { +enum xmltype { kTagTypeNone = 0, kTagTypeDict, kTagTypeKey, @@ -38,6 +38,16 @@ kTagTypeArray }; +struct string_ref +{ + char* string; + int id; + struct string_ref* next; +}; +typedef struct string_ref string_ref; + +extern string_ref* ref_strings; + #define kXMLTagPList "plist " #define kXMLTagDict "dict" #define kXMLTagKey "key" @@ -49,6 +59,8 @@ #define kXMLTagTrue "true/" #define kXMLTagArray "array" +#define kXMLStringID "ID=" +#define kXMLStringIDRef "IDREF=" #define kPropCFBundleIdentifier ("CFBundleIdentifier") #define kPropCFBundleExecutable ("CFBundleExecutable") @@ -71,6 +83,18 @@ extern long gImageLastKernelAddr; TagPtr XMLGetProperty( TagPtr dict, const char * key ); +TagPtr XMLGetElement( TagPtr dict, int id ); +int XMLTagCount( TagPtr dict ); + +bool XMLIsType(TagPtr dict, enum xmltype type); + +bool XMLCastBoolean( TagPtr dict ); +char* XMLCastString( TagPtr dict ); +long XMLCastStringOffset(TagPtr dict); +int XMLCastInteger ( TagPtr dict ); +TagPtr XMLCastDict ( TagPtr dict ); +TagPtr XMLCastArray( TagPtr dict ); + long XMLParseNextTag(char *buffer, TagPtr *tag); void XMLFreeTag(TagPtr tag); char* XMLDecode(const char *in); Index: branches/azimutz/Chazi/i386/boot2/drivers.c =================================================================== --- branches/azimutz/Chazi/i386/boot2/drivers.c (revision 1059) +++ branches/azimutz/Chazi/i386/boot2/drivers.c (revision 1060) @@ -69,7 +69,7 @@ unsigned long signature1; unsigned long signature2; unsigned long length; - unsigned long alder32; + unsigned long adler32; unsigned long version; unsigned long numDrivers; unsigned long reserved1; @@ -84,7 +84,7 @@ long (*LoadExtraDrivers_p)(FileLoadDrivers_t FileLoadDrivers_p); -static unsigned long Alder32( unsigned char * buffer, long length ); +/*static*/ unsigned long Adler32( unsigned char * buffer, long length ); static long FileLoadDrivers(char *dirSpec, long plugin); static long NetLoadDrivers(char *dirSpec); @@ -108,8 +108,8 @@ static char * gTempSpec; static char * gFileName; -static unsigned long -Alder32( unsigned char * buffer, long length ) +/*static*/ unsigned long +Adler32( unsigned char * buffer, long length ) { long cnt; unsigned long result, lowHalf, highHalf; @@ -278,7 +278,7 @@ if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat)) { ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2); - //Azi: hum... finaly got it :P + verbose("(%s) Extensions time +1 = %d\n", __FUNCTION__, time2 + 1); if ((ret != 0) @@ -286,7 +286,7 @@ || (((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1)))) { sprintf(gDriverSpec, "%sExtensions.mkext", altDirSpec); - //Azi: hum... finaly got it :P + msglog("LoadDrivers: Loading from [%s]\n", gDriverSpec); if (LoadDriverMKext(gDriverSpec) == 0) @@ -322,7 +322,6 @@ index = 0; while (1) { - ret = GetDirEntry(dirSpec, &index, &name, &flags, &time); if (ret == -1) break; @@ -419,8 +418,8 @@ if (( GetPackageElement(signature1) != kDriverPackageSignature1) || ( GetPackageElement(signature2) != kDriverPackageSignature2) || ( GetPackageElement(length) > kLoadSize ) || - ( GetPackageElement(alder32) != - Alder32((unsigned char *)&package->version, GetPackageElement(length) - 0x10) ) ) + ( GetPackageElement(adler32) != + Adler32((unsigned char *)&package->version, GetPackageElement(length) - 0x10) ) ) { return -1; } @@ -553,86 +552,86 @@ static long LoadMatchedModules( void ) { - TagPtr prop; - ModulePtr module; - char *fileName, segName[32]; - DriverInfoPtr driver; - long length, driverAddr, driverLength; - void *executableAddr = 0; + TagPtr prop; + ModulePtr module; + char *fileName, segName[32]; + DriverInfoPtr driver; + long length, driverAddr, driverLength; + void *executableAddr = 0; - module = gModuleHead; + module = gModuleHead; - while (module != 0) - { - if (module->willLoad) - { - prop = XMLGetProperty(module->dict, kPropCFBundleExecutable); + while (module != 0) + { + if (module->willLoad) + { + prop = XMLGetProperty(module->dict, kPropCFBundleExecutable); - if (prop != 0) - { - fileName = prop->string; - sprintf(gFileSpec, "%s%s", module->executablePath, fileName); - length = LoadThinFatFile(gFileSpec, &executableAddr); + if (prop != 0) + { + fileName = prop->string; + sprintf(gFileSpec, "%s%s", module->executablePath, fileName); + length = LoadThinFatFile(gFileSpec, &executableAddr); if (length == 0) { length = LoadFile(gFileSpec); executableAddr = (void *)kLoadAddr; } - //printf("%s length = %d addr = 0x%x\n", gFileSpec, length, driverModuleAddr); getchar(); - } - else - length = 0; +// printf("%s length = %d addr = 0x%x\n", gFileSpec, length, driverModuleAddr); getchar(); + } + else + length = 0; - if (length != -1) - { - //driverModuleAddr = (void *)kLoadAddr; - //if (length != 0) - //{ - // ThinFatFile(&driverModuleAddr, &length); - //} + if (length != -1) + { +// driverModuleAddr = (void *)kLoadAddr; +// if (length != 0) +// { +// ThinFatFile(&driverModuleAddr, &length); +// } - // Make make in the image area. - driverLength = sizeof(DriverInfo) + module->plistLength + length + module->bundlePathLength; - driverAddr = AllocateKernelMemory(driverLength); + // Make make in the image area. + driverLength = sizeof(DriverInfo) + module->plistLength + length + module->bundlePathLength; + driverAddr = AllocateKernelMemory(driverLength); - // Set up the DriverInfo. - driver = (DriverInfoPtr)driverAddr; - driver->plistAddr = (char *)(driverAddr + sizeof(DriverInfo)); - driver->plistLength = module->plistLength; - if (length != 0) - { - driver->executableAddr = (void *)(driverAddr + sizeof(DriverInfo) + - module->plistLength); - driver->executableLength = length; - } - else - { - driver->executableAddr = 0; - driver->executableLength = 0; - } - driver->bundlePathAddr = (void *)(driverAddr + sizeof(DriverInfo) + - module->plistLength + driver->executableLength); - driver->bundlePathLength = module->bundlePathLength; + // Set up the DriverInfo. + driver = (DriverInfoPtr)driverAddr; + driver->plistAddr = (char *)(driverAddr + sizeof(DriverInfo)); + driver->plistLength = module->plistLength; + if (length != 0) + { + driver->executableAddr = (void *)(driverAddr + sizeof(DriverInfo) + + module->plistLength); + driver->executableLength = length; + } + else + { + driver->executableAddr = 0; + driver->executableLength = 0; + } + driver->bundlePathAddr = (void *)(driverAddr + sizeof(DriverInfo) + + module->plistLength + driver->executableLength); + driver->bundlePathLength = module->bundlePathLength; - // Save the plist, module and bundle. - strcpy(driver->plistAddr, module->plistAddr); - if (length != 0) - { - memcpy(driver->executableAddr, executableAddr, length); - } - strcpy(driver->bundlePathAddr, module->bundlePath); + // Save the plist, module and bundle. + strcpy(driver->plistAddr, module->plistAddr); + if (length != 0) + { + memcpy(driver->executableAddr, executableAddr, length); + } + strcpy(driver->bundlePathAddr, module->bundlePath); - // Add an entry to the memory map. - sprintf(segName, "Driver-%lx", (unsigned long)driver); - AllocateMemoryRange(segName, driverAddr, driverLength, - kBootDriverTypeKEXT); - } - } - module = module->nextModule; - } + // Add an entry to the memory map. + sprintf(segName, "Driver-%lx", (unsigned long)driver); + AllocateMemoryRange(segName, driverAddr, driverLength, + kBootDriverTypeKEXT); + } + } + module = module->nextModule; + } - return 0; + return 0; } //========================================================================== @@ -782,64 +781,70 @@ long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize) { - long ret; - compressed_kernel_header * kernel_header = (compressed_kernel_header *) binary; - u_int32_t uncompressed_size, size; - void *buffer; + long ret; + compressed_kernel_header * kernel_header = (compressed_kernel_header *) binary; + u_int32_t uncompressed_size, size; + void *buffer; unsigned long len; - + #if 0 - printf("kernel header:\n"); - printf("signature: 0x%x\n", kernel_header->signature); - printf("compress_type: 0x%x\n", kernel_header->compress_type); - printf("adler32: 0x%x\n", kernel_header->adler32); - printf("uncompressed_size: 0x%x\n", kernel_header->uncompressed_size); - printf("compressed_size: 0x%x\n", kernel_header->compressed_size); - getchar(); + printf("kernel header:\n"); + printf("signature: 0x%x\n", kernel_header->signature); + printf("compress_type: 0x%x\n", kernel_header->compress_type); + printf("adler32: 0x%x\n", kernel_header->adler32); + printf("uncompressed_size: 0x%x\n", kernel_header->uncompressed_size); + printf("compressed_size: 0x%x\n", kernel_header->compressed_size); + getchar(); #endif - - if (kernel_header->signature == OSSwapBigToHostConstInt32('comp')) { - if (kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss')) { - error("kernel compression is bad\n"); - return -1; - } + + if (kernel_header->signature == OSSwapBigToHostConstInt32('comp')) + { + if (kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss')) + { + error("kernel compression is bad\n"); + return -1; + } #if NOTDEF - if (kernel_header->platform_name[0] && strcmp(gPlatformName, kernel_header->platform_name)) - return -1; - if (kernel_header->root_path[0] && strcmp(gBootFile, kernel_header->root_path)) - return -1; + if (kernel_header->platform_name[0] && strcmp(gPlatformName, kernel_header->platform_name)) + return -1; + if (kernel_header->root_path[0] && strcmp(gBootFile, kernel_header->root_path)) + return -1; #endif - - uncompressed_size = OSSwapBigToHostInt32(kernel_header->uncompressed_size); - binary = buffer = malloc(uncompressed_size); - - size = decompress_lzss((u_int8_t *) binary, &kernel_header->data[0], - OSSwapBigToHostInt32(kernel_header->compressed_size)); - if (uncompressed_size != size) { - error("size mismatch from lzss: %x\n", size); - return -1; - } - if (OSSwapBigToHostInt32(kernel_header->adler32) != - Alder32(binary, uncompressed_size)) { - printf("adler mismatch\n"); - return -1; - } - } - - ret = ThinFatFile(&binary, &len); - if (ret == 0 && len == 0 && archCpuType==CPU_TYPE_X86_64) - { - archCpuType=CPU_TYPE_I386; - ret = ThinFatFile(&binary, &len); - } - - ret = DecodeMachO(binary, rentry, raddr, rsize); + uncompressed_size = OSSwapBigToHostInt32(kernel_header->uncompressed_size); + binary = buffer = malloc(uncompressed_size); + + size = decompress_lzss((u_int8_t *) binary, &kernel_header->data[0], + OSSwapBigToHostInt32(kernel_header->compressed_size)); + if (uncompressed_size != size) { + error("size mismatch from lzss: %x\n", size); + return -1; + } + + if (OSSwapBigToHostInt32(kernel_header->adler32) != + Adler32(binary, uncompressed_size)) + { + printf("adler mismatch\n"); + return -1; + } + } - if (ret<0 && archCpuType==CPU_TYPE_X86_64) - { - archCpuType=CPU_TYPE_I386; + // Notify modules that the kernel has been decompressed, is about to be decoded + execute_hook("DecodeKernel", (void*)binary, NULL, NULL, NULL); + + ret = ThinFatFile(&binary, &len); + if (ret == 0 && len == 0 && archCpuType==CPU_TYPE_X86_64) + { + archCpuType=CPU_TYPE_I386; + ret = ThinFatFile(&binary, &len); + } + ret = DecodeMachO(binary, rentry, raddr, rsize); - } - - return ret; + + if (ret<0 && archCpuType==CPU_TYPE_X86_64) + { + archCpuType=CPU_TYPE_I386; + ret = DecodeMachO(binary, rentry, raddr, rsize); + } + + return ret; } Index: branches/azimutz/Chazi/i386/boot2/bmdecompress.c =================================================================== --- branches/azimutz/Chazi/i386/boot2/bmdecompress.c (revision 1059) +++ branches/azimutz/Chazi/i386/boot2/bmdecompress.c (revision 1060) @@ -20,9 +20,8 @@ * @APPLE_LICENSE_HEADER_END@ */ -#include "libsa.h" // replaced boot.h +#include "libsa.h" - static void PreviewDecompress16(uint32_t * compressBuffer, uint32_t width, uint32_t height, uint32_t row,