Exemplo n.º 1
0
def _readProtocolRefListsAt(machO, vmaddrs):
	"""Return the an iterable of addresses to protocols from the iterable
	*vmaddrs* pointing to ``old_protocol_list``\\s."""
	
	#	struct old_protocol_list {
	#		struct old_protocol_list *next;
	#		long count;
	#		struct old_protocol *list[1];
	#	};
	
	f = machO.file
	stack = list(vmaddrs)
	
	while True:
		newStack = []
		for vmaddr in stack:
			machO.seek(machO.fromVM(vmaddr))
			(next, count) = readStruct(f, machO.makeStruct('2^'))
			if next:
				newStack.append(next)
			for addr in peekPrimitives(f, '^', count, machO.endian, machO.is64bit):
				yield addr
				
		if not newStack:
			break
		stack = newStack
Exemplo n.º 2
0
    def indirectSymbols(self, start, count, machO):
        '''Get symbol indices from the indirect symbol table, given the *start*
		index and the *count* of indices to retrieve.'''

        offset = self.indirectsymoff + start * 4 + machO.origin
        return peekPrimitives(machO.file,
                              'L',
                              count,
                              machO.endian,
                              machO.is64bit,
                              position=offset)
Exemplo n.º 3
0
def _readProtocolRefListAt(machO, vmaddr):
	"""Return the an iterable of addresses to protocols from *vmaddr*."""
	#	typedef struct protocol_list_t {
	#		// count is 64-bit by accident. 
	#		uintptr_t count;
	#		protocol_ref_t list[0]; // variable-size
	#	} protocol_list_t;
	if vmaddr:
		machO.seek(machO.fromVM(vmaddr))
		ptrStru = machO.makeStruct('^')
		count = readStruct(machO.file, ptrStru)[0]
		return peekPrimitives(machO.file, '^', count, machO.endian, machO.is64bit)
	else:
		return []
Exemplo n.º 4
0
def _readProtocolRefListAt(machO, vmaddr):
	"""Return the an iterable of addresses to protocols from *vmaddr*."""
	#	typedef struct protocol_list_t {
	#		// count is 64-bit by accident. 
	#		uintptr_t count;
	#		protocol_ref_t list[0]; // variable-size
	#	} protocol_list_t;
	if vmaddr:
		machO.seek(machO.fromVM(vmaddr))
		ptrStru = machO.makeStruct('^')
		count = readStruct(machO.file, ptrStru)[0]
		return peekPrimitives(machO.file, '^', count, machO.endian, machO.is64bit)
	else:
		return []
Exemplo n.º 5
0
	def asPrimitives(self, fmt, machO, includeAddresses=False):
		"""Read the whole section as primitives, and return an iterable of these.
		
		If *includeAddresses* is set to ``True``, return an iterable of
		(address, primitive) tuples.
		"""
		
		endian = machO.endian
		is64bit = machO.is64bit
		ssize = calcsize(decodeStructFormat(fmt, endian, is64bit))
		count = self.size // ssize
		prims = peekPrimitives(machO.file, fmt, count, endian, is64bit, position=self.offset+machO.origin)
		
		if includeAddresses:
			addrs = range(self.addr, self.addr + self.size, ssize)
			return zip(addrs, prims)
		else:
			return prims
Exemplo n.º 6
0
    def asPrimitives(self, fmt, machO, includeAddresses=False):
        """Read the whole section as primitives, and return an iterable of these.
		
		If *includeAddresses* is set to ``True``, return an iterable of
		(address, primitive) tuples.
		"""

        endian = machO.endian
        is64bit = machO.is64bit
        ssize = calcsize(decodeStructFormat(fmt, endian, is64bit))
        count = self.size // ssize
        prims = peekPrimitives(machO.file,
                               fmt,
                               count,
                               endian,
                               is64bit,
                               position=self.offset + machO.origin)

        if includeAddresses:
            addrs = list(range(self.addr, self.addr + self.size, ssize))
            return list(zip(addrs, prims))
        else:
            return prims
Exemplo n.º 7
0
	def indirectSymbols(self, start, count, machO):
		'''Get symbol indices from the indirect symbol table, given the *start*
		index and the *count* of indices to retrieve.'''
		
		offset = self.indirectsymoff + start * 4 + machO.origin
		return peekPrimitives(machO.file, 'L', count, machO.endian, machO.is64bit, position=offset)