Chameleon

Chameleon Commit Details

Date:2015-05-22 22:15:48 (8 years 10 months ago)
Author:ErmaC
Commit:2689
Parents: 2688
Message:Merge Rock/Paper/Scissors algo (Credits to cparm)
Changes:
M/branches/ErmaC/Enoch/CHANGES
M/branches/ErmaC/Enoch/i386/libsaio/stringTable.c

File differences

branches/ErmaC/Enoch/i386/libsaio/stringTable.c
102102
103103
104104
105
105
106106
107107
108108
......
156156
157157
158158
159
160
161
162
159163
160164
161165
......
175179
176180
177181
178
179
182
183
184
185
186
180187
181188
182189
......
224231
225232
226233
227
234
235
228236
237
238
239
240
229241
230242
231243
......
263275
264276
265277
278
279
280
281
266282
267283
268284
......
302318
303319
304320
305
321
322
306323
307324
308325
......
315332
316333
317334
318
335
336
319337
320338
321339
322340
323
341
324342
325343
326344
......
374392
375393
376394
377
378
379
395
396
397
398
399
400
380401
381402
382403
383404
384405
385
386
406
407
408
409
387410
388411
389412
390413
391414
392415
393
416
417
394418
395419
396420
......
399423
400424
401425
402
403426
404427
405428
......
414437
415438
416439
417
418
419
440
441
442
443
444
445
420446
421447
422448
423449
424450
425
451
452
426453
427454
428455
429456
430457
431
432
458
459
460
461
433462
434463
435464
436465
437466
438467
439
468
469
440470
441471
442472
443473
444
474
475
445476
446477
447478
448
479
480
481
449482
450483
451484
......
486519
487520
488521
489
522
523
490524
491525
492526
......
496530
497531
498532
499
500
533
534
535
536
501537
502538
503539
504540
505
541
542
506543
507544
508545
509
546
547
510548
511549
512550
513
551
552
514553
515554
516555
......
527566
528567
529568
530
531
569
570
571
572
532573
533574
534575
535576
536577
537578
538
579
580
539581
540582
541583
......
555597
556598
557599
558
600
559601
560602
603
604
561605
562606
563
607
608
609
610
611
564612
565
613
614
566615
567
616
617
568618
569619
570620
571621
572622
573
623
624
574625
575626
576
627
628
577629
578630
579631
......
738790
739791
740792
793
794
741795
742796
743797
744798
745799
746800
747
801
802
748803
749
804
805
750806
751
807
808
809
752810
753
754
755
756
811
812
813
814
815
816
817
757818
758819
759
820
760821
761
822
762823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
763838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
764897
765898
766899
tab = (char *)table;
buf = (char *)malloc(len + 3);
sprintf(buf, "\"%s\"", key);
snprintf(buf, len + 3,"\"%s\"", key);
len = strlen(buf);
while(*tab) {
}
bufsize = end - begin + 1;
newstr = malloc(bufsize);
if (!newstr)
{
return 0;
}
strlcpy(newstr, begin, bufsize);
*list = end;
*size = newsize;
if (*table == '\\') {
table += 2;
ret += 1 + (compress ? 0 : 1);
} else {
if (*table == '\"') {
}
else
{
if (*table == '\"')
{
return ret;
}
ret++;
char *newstr, *p;
int size;
if (getValueForConfigTableKey(config, key, &val, &size)) {
if (getValueForConfigTableKey(config, key, &val, &size))
{
newstr = (char *)malloc(size+1);
if (!newstr)
{
return 0;
}
for (p = newstr; size; size--, p++, val++) {
if ((*p = *val) == '\\') {
switch (*++val) {
if (getValueForKey(key, &val, &size, config) && size) {
newstr = (char *)malloc(size + 1);
if (!newstr)
{
return 0;
}
strlcpy(newstr, val, size + 1);
return newstr;
} else {
while (*line) {
/* look for keyword or argument */
while (isspace(*line)) {
while (isspace(*line))
{
line++;
}
value = line;
value_len = 0;
}
if ((strlen(match) == key_len) && strncmp(match, key, key_len) == 0) {
if ((strlen(match) == key_len) && strncmp(match, key, key_len) == 0)
{
// create a new string
char* newstr = malloc(value_len + 1);
strncpy(newstr, value, value_len);
newstr[value_len] = 0;
*matchval = newstr;
*len = value_len;
retval = true;
int size, sum;
bool negative = false;
if (getValueForKey(key, &val, &size, config)) {
if (size) {
if (*val == '-') {
if (getValueForKey(key, &val, &size, config))
{
if (size)
{
if (*val == '-')
{
negative = true;
val++;
size--;
}
for (sum = 0; size > 0; size--) {
if (*val < '0' || *val > '9') {
for (sum = 0; size > 0; size--)
{
if (*val < '0' || *val > '9')
{
return false;
}
sum = (sum * 10) + (*val++ - '0');
}
if (negative) {
if (negative)
{
sum = -sum;
}
*value = sum;
}
return false;
}
/*
*
*/
bool negative = false;
bool percentage = false;
if (getValueForKey(key, &val, &size, config)) {
if ( size ) {
if (*val == '-') {
if (getValueForKey(key, &val, &size, config))
{
if ( size )
{
if (*val == '-')
{
negative = true;
val++;
size--;
}
if (val[size-1] == '%') {
if (val[size-1] == '%')
{
percentage = true;
size--;
}
// convert string to integer
for (sum = 0; size > 0; size--) {
if (*val < '0' || *val > '9') {
for (sum = 0; size > 0; size--)
{
if (*val < '0' || *val > '9')
{
return false;
}
sum = (sum * 10) + (*val++ - '0');
}
if (percentage) {
if (percentage)
{
sum = ( dimension_max * sum ) / 100;
}
// calculate offset from opposite origin
if (negative) {
if (negative)
{
sum = ( ( dimension_max - object_size ) - sum );
}
} else {
}
else
{
// null value calculate center
sum = ( dimension_max - object_size ) / 2;
int overrideSize;
bool override, ret;
if (getValueForBootKey(bootArgs->CommandLine, key, val, size)) {
if (getValueForBootKey(bootArgs->CommandLine, key, val, size))
{
return true;
}
// and prefer its values with the exceptions for
// "Kernel"="mach_kernel" and "Kernel Flags"="".
if (config->canOverride) {
if (getValueForConfigTableKey(&bootInfo->chameleonConfig, key, &overrideVal, &overrideSize)) {
if (config->canOverride)
{
if (getValueForConfigTableKey(&bootInfo->chameleonConfig, key, &overrideVal, &overrideSize))
{
override = true;
// NOTE: Values are defined by apple as being in com.apple.Boot.plist
// kHelperRootUUIDKey, kKernelArchKey, kMKextCacheKey, kKernelCacheKey, kKernelNameKey, kKernelFlagsKey
if (ret && (strcmp(key, kKernelNameKey) == 0) && (overrideSize == 0)) {
if (ret && (strcmp(key, kKernelNameKey) == 0) && (overrideSize == 0))
{
override = false;
}
if (ret && (strcmp(key, kKernelFlagsKey) == 0) && (overrideSize == 0)) {
if (ret && (strcmp(key, kKernelFlagsKey) == 0) && (overrideSize == 0))
{
override = false;
}
if (override) {
if (override)
{
*val = overrideVal;
*size = overrideSize;
ret = true;
{
char *p2 = p1, tmp;
while (*p1 != '\0') {
while (*p2 != '\0' && *p2 != '\n') {
while (*p1 != '\0')
{
while (*p2 != '\0' && *p2 != '\n')
{
p2++;
}
tmp = *p2;
*p2 = '\0';
printf("%s\n", p1);
*p2 = tmp;
if (tmp == '\0') {
if (tmp == '\0')
{
break;
}
p1 = ++p2;
int ParseXMLFile( char *buffer, TagPtr *dict )
{
long length, pos;
TagPtr tag;
TagPtr tag = 0;
pos = 0;
char *configBuffer;
length = strlen(buffer) + 1;
configBuffer = malloc(strlen(buffer)+1);
strcpy(configBuffer, buffer);
if (!configBuffer)
{
return -1;
}
strlcpy(configBuffer, buffer, length );
while (1) {
while (1)
{
length = XMLParseNextTag(configBuffer + pos, &tag);
if (length == -1) {
if (length == -1)
{
break;
}
pos += length;
if (tag == 0) {
if (tag == 0)
{
continue;
}
if (tag->type == kTagTypeDict) {
if (tag->type == kTagTypeDict)
{
break;
}
*/
int loadHelperConfig(config_file_t *config)
{
int rfd, pfd, sfd, count, ret=-1, fixedsize;
char *dirspec[] = {
"/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
};
int i, fd, count, ret=-1;
// This is a simple rock - paper scissors algo. R beats S, P beats R, S beats P
// If all three, S is used for now. This should be changed to something else (say, timestamp?)
for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++)
pfd = open(dirspec[0], 0);
if(pfd >= 0)// com.apple.boot.P exists
{
if ((fd = open(dirspec[i], 0)) >= 0)
sfd = open(dirspec[2], 0); // com.apple.boot.S takes precidence if it also exists
if(sfd >= 0)
{
// read file
count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);
close(fd);
// Use sfd
fixedsize = MIN(file_size(sfd),IO_CONFIG_DATA_SIZE);
count = read(sfd, config->plist, fixedsize);
close(sfd);
close(pfd);
if (count != fixedsize) return -1;
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid = true;
sysConfigValid = true;
ret=0;
break;
}
else
{
// used pfd
fixedsize = MIN(file_size(pfd),IO_CONFIG_DATA_SIZE);
count = read(pfd, config->plist, fixedsize);
close(pfd);
if (count != fixedsize) return -1;
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid = true;
ret = 0;
}
}
else
{
rfd = open(dirspec[1], 0); // com.apple.boot.R exists
if(rfd >= 0)
{
pfd = open(dirspec[2], 0); // com.apple.boot.P takes recidence if it exists
if(pfd >= 0)
{
// use sfd
fixedsize = MIN(file_size(pfd),IO_CONFIG_DATA_SIZE);
count = read(pfd, config->plist, fixedsize);
close(pfd);
close(rfd);
if (count != fixedsize) return -1;
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid = true;
ret = 0;
}
else
{
// use rfd
fixedsize = MIN(file_size(rfd),IO_CONFIG_DATA_SIZE);
count = read(rfd, config->plist, fixedsize);
close(rfd);
if (count != fixedsize) return -1;
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid = true;
ret = 0;
}
}
else
{
sfd = open(dirspec[2], 0); // com.apple.boot.S exists, but nothing else does
if(sfd >= 0)
{
// use sfd
fixedsize = MIN(file_size(sfd),IO_CONFIG_DATA_SIZE);
count = read(sfd, config->plist, fixedsize);
close(sfd);
if (count != fixedsize) return -1;
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid = true;
ret = 0;
}
}
}
return ret;
}
branches/ErmaC/Enoch/CHANGES
1
12
23
34
- cparm : Rock - Paper - Scissors algo
- Bronya : Improve support for AMD CPU.
- Bungo : Added "machine-signature"
- Zenith432 : Protect timing code in scan_cpu() from interrupts, use bios for sleep()

Archive Download the corresponding diff file

Revision: 2689