Esempio n. 1
0
        def fset(ptr, value):
            """Set the pointer attribute value."""
            # Handle custom type
            if not native_type:
                ptr.set_pointer(value)

                # Make sure the value will not deallocate as long as it is
                # part of this object
                ptr._pointer_values[offset] = value

            # Handle native type
            else:
                # Go down to "instance level"
                instance_ptr = ptr.get_pointer(offset)

                # Is there no space allocated?
                if not instance_ptr:
                    # Allocate space for the value
                    instance_ptr = alloc(TYPE_SIZES[type_name.upper()])

                    # Add the pointer to the set, so there will be a reference
                    # until the instance gets deleted
                    ptr._allocated_pointers.add(instance_ptr)

                    # Set the pointer
                    ptr.set_pointer(instance_ptr, offset)

                # Set the value
                getattr(instance_ptr, 'set_' + type_name)(value)
Esempio n. 2
0
        def fset(ptr, value):
            """Set the pointer attribute value."""
            # Handle custom type
            if not native_type:
                # Set the pointer
                ptr.set_pointer(value, offset)

                # Make sure the value will not deallocate as long as it is
                # part of this object
                ptr._pointer_values[offset] = value

            # Handle native type
            else:
                # Go down to "instance level"
                instance_ptr = ptr.get_pointer(offset)

                # Is there no space allocated?
                if not instance_ptr:
                    # Allocate space for the value
                    instance_ptr = alloc(TYPE_SIZES[type_name.upper()])

                    # Add the pointer to the set, so there will be a reference
                    # until the instance gets deleted
                    ptr._allocated_pointers.add(instance_ptr)

                    # Set the pointer
                    ptr.set_pointer(instance_ptr, offset)

                # Set the value
                getattr(instance_ptr, 'set_' + type_name)(value)
Esempio n. 3
0
def get_key_value_string_t(entity, key):
    result = memory.alloc(KEY_VALUE_SIZE)
    fl = server_tools.get_key_value(entity, key, result, KEY_VALUE_SIZE)
    if not fl:
        return None

    return result.get_string_pointer()
Esempio n. 4
0
    def __init__(self, address, argtypes, restype, auto_dealloc=True):
        functype = ctypes.CFUNCTYPE(restype, *argtypes)

        size = self.get_size(argtypes)
        op_codes = self.make_asm(address, size, argtypes, restype)
        op_codes_size = len(op_codes)

        self.memory = alloc(op_codes_size, auto_dealloc)
        self.memory.unprotect(op_codes_size)
        ctypes.memmove(ctypes.c_void_p(self.memory.address), op_codes,
                       op_codes_size)

        self.function = functype(self.memory.address)
Esempio n. 5
0
    def __init__(self, *args, wrap=False, auto_dealloc=True):
        """Initialize the custom type."""
        # _manager must be an instance of TypeManager. Otherwise the type
        # wasn't registered by a TypeManager.
        if not isinstance(self._manager, TypeManager):
            raise ValueError(
                'Attribute _manager must be an instance of "TypeManager".')

        # Make sure the _manager attribute wasn't set manually
        if self.__class__.__name__ not in self._manager:
            raise TypeError(
                'Custom type was not registered at a type manager.')

        # This set will contain internally allocated pointers.
        self._allocated_pointers = set()

        # This dict will hold pointers, so they don't deallocate if
        # auto_dealloc was set. {<offset>: <pointer>}
        self._pointer_values = {}

        # Do we want to wrap a pointer?
        if wrap:
            # Check if only the this pointer was passed
            if len(args) != 1:
                raise ValueError(
                    'If <wrap> is true only one argument is accepted.')

            super(CustomType, self).__init__(args[0])

        # Obviously, we want to create a new instance
        else:
            # Was a size specified?
            if self._size is None:
                raise ValueError(
                    'In order to create an instance _size is required.')

            # Allocate some space
            super(CustomType, self).__init__(alloc(self._size, False))
            self.auto_dealloc = auto_dealloc

            # Optionally, call a constructor
            if self._constructor is not None:
                self._constructor(*args)

            # No constructor, but arguments? Hmm, the user is doing something
            # wrong
            elif args:
                raise ValueError(
                    'No constructor was specified, but arguments were passed.')
Esempio n. 6
0
    def __init__(self, *args, wrap=False, auto_dealloc=True):
        """Initialize the custom type."""
        # _manager must be an instance of TypeManager. Otherwise the type
        # wasn't registered by a TypeManager.
        if not isinstance(self._manager, TypeManager):
            raise ValueError(
                'Attribute _manager must be an instance of "TypeManager".')

        # Make sure the _manager attribute wasn't set manually
        if self.__class__.__name__ not in self._manager:
            raise TypeError(
                'Custom type was not registered at a type manager.')

        # This set will contain internally allocated pointers.
        self._allocated_pointers = set()

        # This dict will hold pointers, so they don't deallocate if
        # auto_dealloc was set. {<offset>: <pointer>}
        self._pointer_values = {}

        # Do we want to wrap a pointer?
        if wrap:
            # Check if only the this pointer was passed
            if len(args) != 1:
                raise ValueError(
                    'If <wrap> is true only one argument is accepted.')

            super().__init__(args[0])

        # Obviously, we want to create a new instance
        else:
            # Was a size specified?
            if self._size is None:
                raise ValueError(
                    'In order to create an instance _size is required.')

            # Allocate some space
            super().__init__(alloc(self._size, False))
            self.auto_dealloc = auto_dealloc

            # Optionally, call a constructor
            if self._constructor is not None:
                self._constructor(*args)

            # No constructor, but arguments? Hmm, the user is doing something
            # wrong
            elif args:
                raise ValueError(
                    'No constructor was specified, but arguments were passed.')