How to know whether image uses sharedCacheSlide
How to know whether image uses sharedCacheSlide
- Subject: How to know whether image uses sharedCacheSlide
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sat, 07 Apr 2012 16:20:44 +0700
The following code snipped (all error processing omitted for brevity) seems to work, but I am rather troubled by using the UNDEFINED_HEADER_FLAG.
Could anybody please either confirm that this is ok or suggest a better way?
Kind regards,
Gerriet.
Code:
task_name_t target_task = mach_task_self(); // → task_for_pid(...,)
task_dyld_info_data_t infoData;
mach_msg_type_number_t task_info_outCnt = TASK_DYLD_INFO_COUNT;
kern_return_t kr = task_info( target_task,
TASK_DYLD_INFO,
(task_info_t)&infoData,
&task_info_outCnt
);
struct dyld_all_image_infos *allImageInfos = (struct dyld_all_image_infos *)infoData.all_image_info_addr;
const struct dyld_image_info *infoArray = allImageInfos->infoArray;
for( NSUInteger i = 0; i < allImageInfos->infoArrayCount; i++ )
{
const struct mach_header *head1 = infoArray[i].imageLoadAddress;
if ( head1->magic == MH_MAGIC_64 )
{
const struct mach_header_64 *head64 = (const struct mach_header_64 *)infoArray[i].imageLoadAddress;
#define UNDEFINED_HEADER_FLAG 0x80000000 // NOT in mach-o/loader.h
BOOL useSharedCacheSlide = ( head64->flags & UNDEFINED_HEADER_FLAG ) != 0;
BOOL slideDefined = NO;
const void *voidPointer = head64 + 1;
for( NSUInteger lc = 0; lc < head64->ncmds; lc++ )
{
const struct load_command *lc1 = voidPointer;
if ( lc1->cmd == LC_SEGMENT_64 )
{
const struct segment_command_64 *seg = voidPointer;
if ( strcmp( "__PAGEZERO", seg->segname ) != 0 )
{
if ( useSharedCacheSlide )
{
ourSlide = allImageInfos->sharedCacheSlide;
slideDefined = YES;
}
else if ( !slideDefined && strcmp( "__TEXT", seg->segname ) == 0 )
{
ourSlide = (uint64_t)infoArray[i].imageLoadAddress - seg->vmaddr;
slideDefined = YES;
};
if ( !slideDefined ) // error...
// print similar to vmmap
uint64_t loadedAddress = seg->vmaddr + ourSlide;
fprintf(stderr,"%-22s 6llx-6llx [%5lluK]\n",
seg->segname, loadedAddress, loadedAddress + seg->vmsize, seg->vmsize / 1024);
};
};
voidPointer += lc1->cmdsize ;
};
};
};
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden