boinc/lib/mac/QMachOImage.c
// Callback for FindLoadCommand.
//
// IMPORTANT:
// The contents of the load command pointed to be cmd may be byte swapped.
//
// On entry, qmoImage will not be NULL
// On entry, cmd will not be NULL
// Return true if this load command is the one you're looking for


On entry, qmoImage will not be NULL
On entry, cmd will not be NULL
Return true if this load command is the one you're looking for
On entry qmoImage will not be NULL On entry cmd will not be NULL Return true if this load command is the one you ' re looking for
static const struct load_command * FindLoadCommand(
	QMOImageRef				qmoImage, 
	LoadCommandCompareProc	compareProc, 
	void *					compareRefCon
)
{
	uint32_t	cmdIndex;
	uint32_t	cmdCount;
	const struct load_command *	firstCommand;
	const struct load_command *	thisCommand;
	const char *				commandLimit;
	const struct load_command *	result;
	assert(qmoImage    != NULL);
	assert(qmoImage->machHeader != NULL);
	assert(compareProc != NULL);
	cmdCount = QMOImageToLocalUInt32(qmoImage, qmoImage->machHeader->ncmds);
	if (qmoImage->is64Bit) {
		firstCommand = (const struct load_command *) (((const char *) qmoImage->machHeader) + sizeof(struct mach_header_64));
	} else {
		firstCommand = (const struct load_command *) (((const char *) qmoImage->machHeader) + sizeof(struct mach_header));
	}
	result = NULL;
	cmdIndex = 0;
	commandLimit = ((const char *) qmoImage->machHeader) + qmoImage->machHeaderSize;
	thisCommand = firstCommand;
	while ( (result == NULL) && (cmdIndex < cmdCount) ) {
		uint32_t	thisCommandSize;
		thisCommandSize = QMOImageToLocalUInt32(qmoImage, thisCommand->cmdsize);
		assert( ((const char *) thisCommand) >= ((const char *) firstCommand) );
		assert( ((const char *) thisCommand) <  commandLimit );
		assert( (((const char *) thisCommand) + thisCommandSize) <= commandLimit );
		if ( compareProc(qmoImage, thisCommand, compareRefCon) ) {
			result = thisCommand;
		} else {
			thisCommand = (const struct load_command *) (((const char *) thisCommand) + QMOImageToLocalUInt32(qmoImage, thisCommand->cmdsize));
			cmdIndex += 1;
		}
	}
	return result;
}
static const struct load_command * FindLoadCommand ( QMOImageRef qmoImage , LoadCommandCompareProc compareProc , void * compareRefCon ) { uint32_t cmdIndex ; uint32_t cmdCount ; const struct load_command * firstCommand ; const struct load_command * thisCommand ; const char * commandLimit ; const struct load_command * result ; assert ( qmoImage != NULL ) ; assert ( qmoImage -> machHeader != NULL ) ; assert ( compareProc != NULL ) ; cmdCount = QMOImageToLocalUInt32 ( qmoImage , qmoImage -> machHeader -> ncmds ) ; if ( qmoImage -> is64Bit ) { firstCommand = ( const struct load_command * ) ( ( ( const char * ) qmoImage -> machHeader ) + sizeof ( struct mach_header_64 ) ) ; } else { firstCommand = ( const struct load_command * ) ( ( ( const char * ) qmoImage -> machHeader ) + sizeof ( struct mach_header ) ) ; } result = NULL ; cmdIndex = 0 ; commandLimit = ( ( const char * ) qmoImage -> machHeader ) + qmoImage -> machHeaderSize ; thisCommand = firstCommand ; while ( ( result == NULL ) && ( cmdIndex < cmdCount ) ) { uint32_t thisCommandSize ; thisCommandSize = QMOImageToLocalUInt32 ( qmoImage , thisCommand -> cmdsize ) ; assert ( ( ( const char * ) thisCommand ) >= ( ( const char * ) firstCommand ) ) ; assert ( ( ( const char * ) thisCommand ) < commandLimit ) ; assert ( ( ( ( const char * ) thisCommand ) + thisCommandSize ) <= commandLimit ) ; if ( compareProc ( qmoImage , thisCommand , compareRefCon ) ) { result = thisCommand ; } else { thisCommand = ( const struct load_command * ) ( ( ( const char * ) thisCommand ) + QMOImageToLocalUInt32 ( qmoImage , thisCommand -> cmdsize ) ) ; cmdIndex += 1 ; } } return result ; }
Callback for FindLoadCommand.
Callback for FindLoadCommand .
// Finds a load command within a Mach-O image.  Iterates through the load commands,  // from first to last, calling compareProc on each one.  If compareProc returns  // true, that load command becomes the function result.  If compareProc never returns  // true, the function result is NULL. // Get the command count. // Get the start of the first command. // Iterate through the commands until compareProc returns true.