Chameleon

Chameleon Commit Details

Date:2011-05-11 17:56:47 (8 years 2 months ago)
Author:Evan Lojewski
Commit:796
Parents: 795
Message:Typo fix. Modified Adler32 so that it has global scope
Changes:
M/trunk/i386/boot2/drivers.c
M/trunk/i386/libsaio/saio_types.h
M/trunk/i386/libsaio/xml.h
M/trunk/i386/libsaio/xml.c

File differences

trunk/i386/libsaio/xml.c
2727
2828
2929
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
3071
3172
3273
......
5293
5394
5495
55
96
5697
5798
5899
......
110151
111152
112153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
113198
114199
115200
......
168253
169254
170255
171
256
172257
173258
174
259
260
175261
176
262
177263
178264
179265
......
181267
182268
183269
184
270
271
272
273
274
275
276
277
278
185279
186280
187
281
188282
189283
190284
......
194288
195289
196290
197
291
292
198293
199294
200295
201
296
202297
203
298
204299
205300
206301
207
302
208303
209304
210305
......
213308
214309
215310
216
311
217312
218313
219314
220315
221316
317
222318
223319
224320
225321
226
322
227323
228324
229325
326
327
328
329
330
230331
231332
232333
233334
335
336
234337
235338
236339
237340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
238411
239412
240413
241414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
242488
243489
244490
245491
492
493
494
495
246496
247497
248498
249499
500
501
502
503
504
505
506
507
250508
251509
252510
253511
512
254513
255514
256515
257516
517
518
258519
259520
260521
261522
523
524
525
526
262527
263528
264529
265530
531
532
266533
267534
268535
269536
270537
271538
539
272540
273541
274542
......
316584
317585
318586
587
319588
320589
321590
......
358627
359628
360629
630
361631
362632
363633
......
373643
374644
375645
376
377646
378647
379648
380649
381
650
382651
383652
384653
......
391660
392661
393662
663
394664
395665
396666
......
404674
405675
406676
677
407678
408
409
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
410700
411701
412702
413703
414704
415705
416
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
417762
418
419
763
764
765
420766
421767
422768
423
769
424770
425771
426772
......
432778
433779
434780
435
781
436782
437783
438784
439785
440786
441787
788
789
790
791
792
793
794
442795
443
796
444797
798
445799
446800
447801
......
464818
465819
466820
821
822
823
467824
468825
469826
827
470828
471829
472830
......
488846
489847
490848
849
491850
492851
493852
......
609968
610969
611970
971
612972
613973
614974
......
7201080
7211081
7221082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
#include "sl.h"
#include "xml.h"
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;
unsigned long signature1;
unsigned long signature2;
unsigned long length;
unsigned long alder32;
unsigned long adler32;
unsigned long version;
unsigned long numDrivers;
unsigned long reserved1;
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*
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 )
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;
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 )
{
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 (!strcmp(tagName, kXMLTagDict "/"))
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);
getc();
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);
getc();
return -1;
}
}
char* str = GetRefString(id);
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);
getc();
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);
getc();
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;
tmpTag->type = type;
tmpTag->string = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start : 0;
tmpTag->tag = tagList;
tmpTag->tagNext = 0;
tmpTag->type = kTagTypeKey;
tmpTag->string = string;
tmpTag->tag = subTag;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
{
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);
tmpTag->type = kTagTypeString;
tmpTag->string = string;
tmpTag->tag = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
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");
getc();
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);
getc();
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);
getc();
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;
return length;
}
{
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);
//getc();
// 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;
tmpTag = NewTag();
if (tmpTag == 0) return -1;
printf("ParseTagDate unimplimented\n");
getc();
tmpTag->type = kTagTypeDate;
tmpTag->string = 0;
tmpTag->tag = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
tmpTag->type = type;
tmpTag->string = 0;
tmpTag->tag = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
tag->type = kTagTypeNone;
tag->string = 0;
tag->tag = 0;
tag->offset = 0;
tag->tagNext = gTagsFree;
gTagsFree = tag;
#else
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;
}
trunk/i386/libsaio/xml.h
2525
2626
2727
28
28
2929
3030
3131
......
3838
3939
4040
41
42
43
44
45
46
47
48
49
50
51
4152
4253
4354
......
4960
5061
5162
63
64
5265
66
5367
5468
5569
......
7185
7286
7387
88
89
90
91
92
93
94
95
96
97
98
99
74100
75101
76102
#ifndef __LIBSAIO_XML_H
#define __LIBSAIO_XML_H
enum {
enum xmltype {
kTagTypeNone = 0,
kTagTypeDict,
kTagTypeKey,
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"
#define kXMLTagTrue "true/"
#define kXMLTagArray "array"
#define kXMLStringID"ID="
#define kXMLStringIDRef "IDREF="
#define kPropCFBundleIdentifier ("CFBundleIdentifier")
#define kPropCFBundleExecutable ("CFBundleExecutable")
#define kPropOSBundleRequired ("OSBundleRequired")
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);
trunk/i386/libsaio/saio_types.h
5656
5757
5858
59
5960
6061
6162
struct Tag {
long type;
char *string;
long offset;
struct Tag *tag;
struct Tag *tagNext;
};
trunk/i386/boot2/drivers.c
7070
7171
7272
73
73
7474
7575
7676
......
8585
8686
8787
88
88
8989
9090
9191
......
109109
110110
111111
112
113
112
113
114114
115115
116116
......
397397
398398
399399
400
401
400
401
402402
403403
404404
......
798798
799799
800800
801
801
802802
803803
804804
unsigned long signature1;
unsigned long signature2;
unsigned long length;
unsigned long alder32;
unsigned long adler32;
unsigned long version;
unsigned long numDrivers;
unsigned long reserved1;
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);
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;
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;
}
return -1;
}
if (OSSwapBigToHostInt32(kernel_header->adler32) !=
Alder32(binary, uncompressed_size)) {
Adler32(binary, uncompressed_size)) {
printf("adler mismatch\n");
return -1;
}

Archive Download the corresponding diff file

Revision: 796