def get_value(self, var):
        """
		Get the value of the variable.
		:param var: The variable name (can be a stack address, register name or a number).
		:type var: str
		:return: The variable name.
		:rtype: str
		"""
        if is_int(var):
            # The variable is a number
            return var

        elif self._registers_manager.is_register(var):
            # The variable is a register
            if var in self._reg_state_dict:
                return self._reg_state_dict[var]
            elif self._registers_manager.get_register_family(
                    var) in self._reg_state_dict:
                return self._reg_state_dict[
                    self._registers_manager.get_register_family(var)]
            else:
                return var

        else:
            # The variable is a stack address
            return self._stack_frame_state[
                var].value if var in self._stack_frame_state else var
    def get_value(self, var, instruction):
        """
		Get the value of the variable.
		:param var: The variable name (can be a stack address, register name or a number).
		:type var: str
		:return: The variable name.
		:rtype: str
		"""
        if is_int(var):
            # The variable is a number
            return var

        elif self._registers_manager.is_register(var):
            # The variable is a register
            if var in self._reg_state_dict:
                return self._reg_state_dict[var]
            elif self._registers_manager.get_register_family(
                    var) in self._reg_state_dict:
                return self._reg_state_dict[
                    self._registers_manager.get_register_family(var)]
            else:
                return var

        elif self.is_global_var(var):
            target_addr = instruction._comment_address
            target_prefix = self.get_english_size(var).lower()
            target = target_prefix + '_' + hex(target_addr)[2:]
            return target

        else:
            # The variable is a stack address
            return self._stack_frame_state[
                var].value if var in self._stack_frame_state else var
Example #3
0
 def NUM(self, t):
     if is_int(t.value):
         t.value = Expression(Constants.INT_TYPE, int(t.value),
                              str(t.value))
     else:
         t.value = Expression(Constants.FLOAT_TYPE, float(t.value),
                              str(t.value))
     return t
    def set_type(self, stack_element, element_type):
        if is_int(stack_element) or self._registers_manager.is_register(
                stack_element):
            raise Exception('Error: Invalid stack element\n')

        if stack_element in self._stack_frame_state:
            self._stack_frame_state[stack_element] = self._stack_frame_state[
                stack_element]._replace(type=element_type)
        else:
            self._stack_frame_state[stack_element] = StackEntry(
                value=stack_element, type=element_type)
    def get_size(self, value):
        """
		For the given value, return the size of the value (amount of bits).

		Example:
			get_size('DWORD ptr [ebp-0x10]') ---> 32

		:param value: The value we wish to know the size of.
		:type: str
		:return: The size in bits.
		:rtype: int
		"""
        if self._registers_manager.is_register(value):
            register = self._registers_manager.get_register(value)
            if register.size == 128:
                return 128
            elif register.size == 64:
                return 64
            elif register.size == 32:
                return 32
            elif register.size == 16:
                return 16
            else:
                return 8

        elif is_int(value, 16):
            return self.get_const_size(value)

        else:
            size = value.split(' ')[0]

            if size == 'BYTE':
                return 8
            elif size == 'WORD':
                return 16
            elif size == 'DWORD':
                return 32
            elif size == 'QWORD':
                return 64
            else:
                raise Exception(
                    'Invalid size in dst/src of an instruction, value: %s ' %
                    value)
 def get_type(self, stack_element):
     if is_int(stack_element) or self._registers_manager.is_register(
             stack_element):
         raise Exception('Error: Invalid stack element\n')
     return stack_element.split(' ')[0]