Chameleon

Chameleon Commit Details

Date:2017-03-25 02:19:47 (2 years 6 months ago)
Author:ErmaC
Commit:2865
Parents: 2864
Message:Update/extend DecodeMachO and DecodeSegment functions
Changes:
M/branches/ErmaC/Enoch/i386/libsaio/saio_internal.h
M/branches/ErmaC/Enoch/i386/libsaio/load.c
M/branches/ErmaC/Enoch/i386/libsaio/xml.c
M/branches/ErmaC/Enoch/i386/boot2/drivers.c
M/branches/ErmaC/Enoch/i386/boot2/boot.c

File differences

branches/ErmaC/Enoch/i386/libsaio/xml.c
592592
593593
594594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614595
615596
616597
......
631612
632613
633614
615
616
617
618
619
620
621
622
623
624
625
626
627
634628
635629
636630
}
}
/***** false ****/
else if (!strncmp(tagName, kXMLTagFalse, sizeof(kXMLTagFalse)))
{
length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
}
/***** true ****/
else if (!strncmp(tagName, kXMLTagTrue, sizeof(kXMLTagTrue)))
{
length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
}
/***** plist ****/
/***** dict ****/
/***** data ****/
else if (!strncmp(tagName, kXMLTagData, sizeof(kXMLTagData)))
{
{
length = ParseTagDate(buffer + pos, tag);
}
/***** false ****/
else if (!strncmp(tagName, kXMLTagFalse, sizeof(kXMLTagFalse)))
{
length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
}
/***** true ****/
else if (!strncmp(tagName, kXMLTagTrue, sizeof(kXMLTagTrue)))
{
length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
}
/***** array ****/
else if (!strncmp(tagName, kXMLTagArray, sizeof(kXMLTagArray) ))
{
branches/ErmaC/Enoch/i386/libsaio/load.c
3838
3939
4040
41
41
4242
4343
4444
......
109109
110110
111111
112
112
113113
114114
115115
......
185185
186186
187187
188
188
189189
190190
191191
......
209209
210210
211211
212
213212
214213
215214
......
247246
248247
249248
250
251
249
252250
253251
254252
255
253
256254
257255
258256
259257
260
261
262
258
259
260
261
263262
264263
265
264
266265
267266
268
269
267
268
270269
271270
272271
......
275274
276275
277276
278
277
279278
280
281
279
280
281
282282
283283
284
284
285285
286286
287
288
287
288
289
289290
290291
291292
#endif
// Private functions.
static long DecodeSegment(long cmdBase, unsigned int*load_addr, unsigned int *load_size);
static long DecodeSegment(long cmdBase, unsigned int *load_addr, unsigned int *load_size, void *binary, u_int32_t uncompressed_size);
static long DecodeUnixThread(long cmdBase, unsigned int *entry);
static long DecodeSymbolTable(long cmdBase);
//==============================================================================
long DecodeMachO(void *binary, entry_t *rentry, char **raddr, int *rsize)
long DecodeMachO(void *binary, u_int32_t uncompressed_size, entry_t *rentry, char **raddr, int *rsize)
{
struct mach_header *mH;
unsigned long ncmds, cmdBase, cmd, cmdsize, cmdstart;
{
case LC_SEGMENT:
case LC_SEGMENT_64:
ret = DecodeSegment(cmdBase, &load_addr, &load_size);
ret = DecodeSegment(cmdBase, &load_addr, &load_size, binary, uncompressed_size);
if (ret == 0 && load_size != 0 && load_addr >= KERNEL_ADDR)
{
break;
}
if (ret != 0)
{
return -1;
//==============================================================================
// Private function.
static long DecodeSegment(long cmdBase, unsigned int *load_addr, unsigned int *load_size)
static long DecodeSegment(long cmdBase, unsigned int *load_addr, unsigned int *load_size, void *binary, u_int32_t uncompressed_size)
{
char *segname;
long vmsize, filesize;
unsigned long vmaddr, fileaddr;
unsigned long vmaddr, fileoff, fileaddr;
if (((long *)cmdBase)[0] == LC_SEGMENT_64)
{
struct segment_command_64 *segCmd;
segCmd = (struct segment_command_64 *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
segCmd = (struct segment_command_64 *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
fileoff = segCmd->fileoff;
fileaddr = (gBinaryAddress + segCmd->fileoff);
filesize = segCmd->filesize;
segname = segCmd->segname;
segname = (char *)segCmd->segname;
#ifdef DEBUG
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize,
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, fileaddr: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, segCmd->fileoff, (unsigned)fileaddr, (unsigned)filesize,
(unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
#endif
{
struct segment_command *segCmd;
segCmd = (struct segment_command *)cmdBase;
segCmd = (struct segment_command *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
fileoff = segCmd->fileoff;
fileaddr = (gBinaryAddress + segCmd->fileoff);
filesize = segCmd->filesize;
segname = segCmd->segname;
segname = (char *)segCmd->segname;
#ifdef DEBUG
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags);
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, fileaddr: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, segCmd->fileoff, (unsigned)fileaddr, (unsigned)filesize,
(unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
#endif
}
branches/ErmaC/Enoch/i386/libsaio/saio_internal.h
131131
132132
133133
134
134
135135
136136
137137
/* load.c */
extern bool gHaveKernelCache;
extern long ThinFatFile(void **binary, unsigned long *length);
extern long DecodeMachO(void *binary, entry_t *rentry, char **raddr, int *rsize);
extern long DecodeMachO(void *binary, u_int32_t uncompressed_size, entry_t *rentry, char **raddr, int *rsize);
/* memory.c */
long AllocateKernelMemory( long inSize );
branches/ErmaC/Enoch/i386/boot2/drivers.c
198198
199199
200200
201
201
202202
203203
204
204
205205
206206
207207
......
670670
671671
672672
673
674
675
676
677
678
673
674
675
676
677
678
679679
680680
681681
......
686686
687687
688688
689
689
690690
691691
692692
......
864864
865865
866866
867
868
869
870
871
867
868
869
870
871
872872
873873
874874
......
12271227
12281228
12291229
1230
1231
1232
1233
1234
1230
12351231
12361232
12371233
1238
1234
12391235
12401236
12411237
strcpy(dirSpecExtra, "rd(0,0)/Extra/");
FileLoadDrivers(dirSpecExtra, 0);
}
verbose("Attempting to loading drivers from \"Extra\" repository:\n");
// verbose("Attempting to loading drivers from \"Extra\" repository:\n");
// =====================================================================
// Firstly try to load drivers from Common folder
// Secondly try to load drivers from Common folder
sprintf(dirSpecExtra, "bt(0,0)/Extra/Common/");
FileLoadDrivers(dirSpecExtra, 0);
// =====================================================================
fileName = prop->string;
snprintf(gFileSpec, 4096, "%s%s", module->executablePath, fileName);
length = LoadThinFatFile(gFileSpec, &executableAddr);
if (length == 0)
{
length = LoadFile(gFileSpec);
executableAddr = (void *)kLoadAddr;
}
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
if ((length != -1) && executableAddr)
{
// Make make in the image area.
execute_hook("LoadMatchedModules", module, &length, executableAddr, NULL);
driverLength = sizeof(DriverInfo) + module->plistLength + length + module->bundlePathLength;
required = XMLGetProperty(moduleDict, kPropOSBundleRequired);
if ( (required == 0) || (required->type != kTagTypeString) || !strncmp(required->string, "Safe Boot", sizeof("Safe Boot")))
{
XMLFreeTag(moduleDict);
return -2;
}
if ( (required == 0) || (required->type != kTagTypeString) || !strncmp(required->string, "Safe Boot", sizeof("Safe Boot")))
{
XMLFreeTag(moduleDict);
return -2;
}
tmpModule = malloc(sizeof(Module));
if (tmpModule == 0)
/* ================================================================ */
// Entry point
/* ================================================================ */
ret = DecodeMachO(binary, rentry, raddr, rsize);
ret = DecodeMachO(binary, uncompressed_size, rentry, raddr, rsize);
if (ret < 0 && archCpuType == CPU_TYPE_X86_64)
{
archCpuType = CPU_TYPE_I386;
ret = DecodeMachO(binary, rentry, raddr, rsize);
ret = DecodeMachO(binary, uncompressed_size, rentry, raddr, rsize);
}
return ret;
branches/ErmaC/Enoch/i386/boot2/boot.c
10751075
10761076
10771077
1078
1079
1080
1078
1079
1080
10811081
1082
1083
1084
1085
1086
1087
10821088
1089
1090
1091
1092
1093
1094
1095
1096
10831097
10841098
10851099
......
11831197
11841198
11851199
1200
11861201
11871202
11881203
......
12481263
12491264
12501265
1251
1266
1267
12521268
12531269
12541270
//
void setupBooterArgs()
{
bool KPRebootOption= false;
bool HiDPIOption= false;
bool FlagBlackOption= false;
bool KPRebootOption= false; // I don't want this by default ( It makes me angry because I do not see the reason for the panic)+
//bool HiDPIOption= false; // (Disabled by default) 10.8+
//bool FlagBlackOption= false; // (Disabled by default) 10.10+
// OS X Lion 10.7
if ( MacOSVerCurrent >= MacOSVer2Int("10.7") ) // Lion and Up!
{
// Pike R. Alpha: Adding a 16 KB log space.
bootArgs->performanceDataSize= 0;
bootArgs->performanceDataStart= 0;
// Pike R. Alpha: AppleKeyStore.kext
bootArgs->keyStoreDataSize= 0;
bootArgs->keyStoreDataStart= 0;
bootArgs->bootMemSize= 0;
bootArgs->bootMemStart= 0;
}
// OS X Mountain Lion 10.8
if ( MacOSVerCurrent >= MacOSVer2Int("10.8") ) // Mountain Lion and Up!
{
verbose("DTrace Restrictions: %s\n", ((csrValue & 0x20) == 0) ? "enabled":"disabled"); /* (1 << 5) Allow unrestricted dtrace */
verbose("NVRAM Protections: %s\n", ((csrValue & 0x40) == 0) ? "enabled":"disabled"); /* (1 << 6) Allow unrestricted NVRAM */
//verbose("DEVICE configuration: %s\n", ((csrValue & 0x80) == 0) ? "enabled":"disabled"); /* (1 << 7) Allow device configuration */
//verbose("Disable BaseSystem Verification: %s\n", ((csrValue & 0x100) == 0) ? "enabled":"disabled"); /* (1 << 8) Disable BaseSystem Verification */
}
verbose("\n");
}
unsigned long s2 = 0; // (adler >> 16) & 0xffff;
unsigned long result;
while (len > 0) {
while (len > 0)
{
k = len < NMAX ? len : NMAX;
len -= k;
while (k >= 16)

Archive Download the corresponding diff file

Revision: 2865