def tokens(self):
     """MLIL tokens (read-only)"""
     count = ctypes.c_ulonglong()
     tokens = ctypes.POINTER(core.BNInstructionTextToken)()
     if ((self.instr_index is not None)
             and (self.function.source_function is not None) and
         (self.expr_index == core.BNGetMediumLevelILIndexForInstruction(
             self.function.handle, self.instr_index))):
         if not core.BNGetMediumLevelILInstructionText(
                 self.function.handle, self.function.source_function.handle,
                 self.function.arch.handle, self.instr_index, tokens,
                 count):
             return None
     else:
         if not core.BNGetMediumLevelILExprText(
                 self.function.handle, self.function.arch.handle,
                 self.expr_index, tokens, count):
             return None
     result = []
     for i in xrange(0, count.value):
         token_type = InstructionTextTokenType(tokens[i].type)
         text = tokens[i].text
         value = tokens[i].value
         size = tokens[i].size
         operand = tokens[i].operand
         context = tokens[i].context
         confidence = tokens[i].confidence
         address = tokens[i].address
         result.append(
             function.InstructionTextToken(token_type, text, value, size,
                                           operand, context, address,
                                           confidence))
     core.BNFreeInstructionText(tokens, count.value)
     return result
Beispiel #2
0
	def get_disassembly_text(self, settings=None):
		"""
		``get_disassembly_text`` returns a list of function.DisassemblyTextLine objects for the current basic block.
		:Example:

			>>>current_basic_block.get_disassembly_text()
			[<0x100000f30: _main:>, <0x100000f30: push    rbp>, ... ]
		"""
		settings_obj = None
		if settings:
			settings_obj = settings.handle

		count = ctypes.c_ulonglong()
		lines = core.BNGetBasicBlockDisassemblyText(self.handle, settings_obj, count)
		result = []
		for i in xrange(0, count.value):
			addr = lines[i].addr
			tokens = []
			for j in xrange(0, lines[i].count):
				token_type = InstructionTextTokenType(lines[i].tokens[j].type)
				text = lines[i].tokens[j].text
				value = lines[i].tokens[j].value
				size = lines[i].tokens[j].size
				operand = lines[i].tokens[j].operand
				tokens.append(function.InstructionTextToken(token_type, text, value, size, operand))
			result.append(function.DisassemblyTextLine(addr, tokens))
		core.BNFreeDisassemblyTextLines(lines, count.value)
		return result
Beispiel #3
0
	def get_tokens_after_name(self):
		count = ctypes.c_ulonglong()
		tokens = core.BNGetTypeTokensAfterName(self.handle, count)
		result = []
		for i in xrange(0, count.value):
			token_type = InstructionTextTokenType(tokens[i].type)
			text = tokens[i].text
			value = tokens[i].value
			size = tokens[i].size
			operand = tokens[i].operand
			context = tokens[i].context
			address = tokens[i].address
			result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address))
		core.BNFreeTokenList(tokens, count.value)
		return result
Beispiel #4
0
	def tokens(self):
		"""Type string as a list of tokens (read-only)"""
		count = ctypes.c_ulonglong()
		tokens = core.BNGetTypeTokens(self.handle, count)
		result = []
		for i in xrange(0, count.value):
			token_type = InstructionTextTokenType(tokens[i].type)
			text = tokens[i].text
			value = tokens[i].value
			size = tokens[i].size
			operand = tokens[i].operand
			context = tokens[i].context
			address = tokens[i].address
			result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address))
		core.BNFreeTokenList(tokens, count.value)
		return result
Beispiel #5
0
	def get_tokens_after_name(self, base_confidence = max_confidence):
		count = ctypes.c_ulonglong()
		platform = None
		if self.platform is not None:
			platform = self.platform.handle
		tokens = core.BNGetTypeTokensAfterName(self.handle, platform, base_confidence, count)
		result = []
		for i in xrange(0, count.value):
			token_type = InstructionTextTokenType(tokens[i].type)
			text = tokens[i].text
			value = tokens[i].value
			size = tokens[i].size
			operand = tokens[i].operand
			context = tokens[i].context
			confidence = tokens[i].confidence
			address = tokens[i].address
			result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
		core.BNFreeTokenList(tokens, count.value)
		return result
Beispiel #6
0
    def get_disassembly_text(self, settings=None):
        """
		``get_disassembly_text`` returns a list of function.DisassemblyTextLine objects for the current basic block.

		:param DisassemblySettings settings: (optional) DisassemblySettings object
		:Example:

			>>> current_basic_block.get_disassembly_text()
			[<0x100000f30: _main:>, <0x100000f30: push    rbp>, ... ]
		"""
        settings_obj = None
        if settings:
            settings_obj = settings.handle

        count = ctypes.c_ulonglong()
        lines = core.BNGetBasicBlockDisassemblyText(self.handle, settings_obj,
                                                    count)
        result = []
        for i in xrange(0, count.value):
            addr = lines[i].addr
            if (lines[i].instrIndex != 0xffffffffffffffff) and hasattr(
                    self, 'il_function'):
                il_instr = self.il_function[lines[i].instrIndex]
            else:
                il_instr = None
            tokens = []
            for j in xrange(0, lines[i].count):
                token_type = InstructionTextTokenType(lines[i].tokens[j].type)
                text = lines[i].tokens[j].text
                value = lines[i].tokens[j].value
                size = lines[i].tokens[j].size
                operand = lines[i].tokens[j].operand
                context = lines[i].tokens[j].context
                confidence = lines[i].tokens[j].confidence
                address = lines[i].tokens[j].address
                tokens.append(
                    function.InstructionTextToken(token_type, text, value,
                                                  size, operand, context,
                                                  address, confidence))
            result.append(function.DisassemblyTextLine(addr, tokens, il_instr))
        core.BNFreeDisassemblyTextLines(lines, count.value)
        return result