Chameleon

Chameleon Commit Details

Date:2011-05-31 06:41:26 (12 years 10 months ago)
Author:Evan Lojewski
Commit:929
Parents: 928
Message:Modified macho-o parse, clients can now get the load addr + virtual addr of segments
Changes:
M/trunk/i386/boot2/modules.c
M/trunk/i386/boot2/modules.h

File differences

trunk/i386/boot2/modules.c
5353
5454
5555
56
56
5757
5858
5959
......
6969
7070
7171
72
72
7373
7474
7575
......
166166
167167
168168
169
169
170170
171171
172172
......
308308
309309
310310
311
311
312
313
314
315
312316
313317
314318
......
377381
378382
379383
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
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
407411
408412
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
436438
437439
438440
if(symbols_module_start != (void*)0xFFFFFFFF)
{
// Module system was compiled in (Symbols.dylib addr known)
module_start = parse_mach(module_data, &load_module, &add_symbol);
module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);
if(module_start && module_start != (void*)0xFFFFFFFF)
{
else
{
module_data -= 0x10; // XCODE 4 HACK
module_start = parse_mach(module_data, &load_module, &add_symbol);
module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);
if(module_start && module_start != (void*)0xFFFFFFFF)
{
if (moduleSize && read(fh, module_base, moduleSize) == moduleSize)
{
// Module loaded into memory, parse it
module_start = parse_mach(module_base, &load_module, &add_symbol);
module_start = parse_mach(module_base, &load_module, &add_symbol, NULL);
if(module_start && module_start != (void*)0xFFFFFFFF)
{
* NOTE: If the module is unable to load ot completeion, the modules
* symbols will still be available.
*/
void* parse_mach(void* binary, int(*dylib_loader)(char*), long long(*symbol_handler)(char*, long long, char))
void* parse_mach(void* binary,
int(*dylib_loader)(char*),
long long(*symbol_handler)(char*, long long, char),
void (*section_handler)(char* section, char* segment, long long offset, long long address)
)
{
char is64 = false;
void (*module_start)(void) = NULL;
break;
case LC_SEGMENT: // 32bit macho
segCommand = binary + binaryIndex;
if(strcmp("__TEXT", segCommand->segname) == 0)
{
UInt32 sectionIndex;
sectionIndex = sizeof(struct segment_command);
struct section *sect;
while(sectionIndex < segCommand->cmdsize)
{
sect = binary + binaryIndex + sectionIndex;
sectionIndex += sizeof(struct section);
if(strcmp("__text", sect->sectname) == 0)
{
// __TEXT,__text found, save the offset and address for when looking for the calls.
textSection = sect->offset;
textAddress = sect->addr;
break;
}
}
}
{
segCommand = binary + binaryIndex;
UInt32 sectionIndex;
sectionIndex = sizeof(struct segment_command);
struct section *sect;
while(sectionIndex < segCommand->cmdsize)
{
sect = binary + binaryIndex + sectionIndex;
sectionIndex += sizeof(struct section);
if(section_handler) section_handler(sect->sectname, segCommand->segname, sect->offset, sect->addr);
if((strcmp("__TEXT", segCommand->segname) == 0) && (strcmp("__text", sect->sectname) == 0))
{
// __TEXT,__text found, save the offset and address for when looking for the calls.
textSection = sect->offset;
textAddress = sect->addr;
}
}
}
break;
case LC_SEGMENT_64:// 64bit macho's
segCommand64 = binary + binaryIndex;
if(strcmp("__TEXT", segCommand64->segname) == 0)
{
UInt32 sectionIndex;
sectionIndex = sizeof(struct segment_command_64);
struct section_64 *sect;
while(sectionIndex < segCommand64->cmdsize)
{
sect = binary + binaryIndex + sectionIndex;
sectionIndex += sizeof(struct section_64);
if(strcmp("__text", sect->sectname) == 0)
{
// __TEXT,__text found, save the offset and address for when looking for the calls.
textSection = sect->offset;
textAddress = sect->addr;
break;
}
}
}
{
segCommand64 = binary + binaryIndex;
UInt32 sectionIndex;
sectionIndex = sizeof(struct segment_command_64);
struct section_64 *sect;
while(sectionIndex < segCommand64->cmdsize)
{
sect = binary + binaryIndex + sectionIndex;
sectionIndex += sizeof(struct section_64);
if(section_handler) section_handler(sect->sectname, segCommand->segname, sect->offset, sect->addr);
if((strcmp("__TEXT", segCommand->segname) == 0) && (strcmp("__text", sect->sectname) == 0))
{
// __TEXT,__text found, save the offset and address for when looking for the calls.
textSection = sect->offset;
textAddress = sect->addr;
}
}
}
break;
trunk/i386/boot2/modules.h
7777
7878
7979
80
80
81
82
8183
8284
8385
/********************************************************************************/
void*parse_mach(void* binary,
int(*dylib_loader)(char*),
long long(*symbol_handler)(char*, long long, char));
long long(*symbol_handler)(char*, long long, char),
void (*section_handler)(char* section, char* segment, long long offset, long long address)
);
unsigned inthandle_symtable(UInt32 base,
struct symtab_command* symtabCommand,
long long(*symbol_handler)(char*, long long, char),

Archive Download the corresponding diff file

Revision: 929