Class: Ronin::Support::Binary::CTypes::ArrayObjectType Private

Inherits:
ObjectType
  • Object
show all
Defined in:
lib/ronin/support/binary/ctypes/array_object_type.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a Array in memory.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Attributes inherited from ObjectType

#size

Attributes inherited from Type

#pack_string

Instance Method Summary collapse

Methods inherited from Type

#[], #size, #uninitialized_value

Constructor Details

#initialize(array_type) ⇒ ArrayObjectType

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the memory-mapped array type.

Parameters:

Since:

  • 1.0.0



46
47
48
49
50
# File 'lib/ronin/support/binary/ctypes/array_object_type.rb', line 46

def initialize(array_type)
  @array_type = array_type

  super(@array_type.size)
end

Instance Attribute Details

#array_typeArrayType (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The type used for packing literal Array values.

Returns:

Since:

  • 1.0.0



38
39
40
# File 'lib/ronin/support/binary/ctypes/array_object_type.rb', line 38

def array_type
  @array_type
end

Instance Method Details

#align(new_alignment) ⇒ ArrayObjectType

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a copy of the array object type with a different #alignment.

Parameters:

  • new_alignment (Integer)

    The new alignment for the new array object type.

Returns:

Since:

  • 1.0.0



89
90
91
# File 'lib/ronin/support/binary/ctypes/array_object_type.rb', line 89

def align(new_alignment)
  self.class.new(@array_type.align(new_alignment))
end

#alignmentInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The alignment, in bytes, of the memory-mapped array type.

Returns:

Since:

  • 1.0.0



75
76
77
# File 'lib/ronin/support/binary/ctypes/array_object_type.rb', line 75

def alignment
  @array_type.alignment
end

#dequeue_value(values) ⇒ Binary::Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Dequeues a memory object from the flat list of values.

Parameters:

  • values (::Array)

    The flat array of values.

Returns:

Since:

  • 1.0.0



156
157
158
# File 'lib/ronin/support/binary/ctypes/array_object_type.rb', line 156

def dequeue_value(values)
  Binary::Array.new(@array_type.type,values.shift)
end

#enqueue_value(values, array) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enqueues the memory-mapped array into the list of values.

Parameters:

Since:

  • 1.0.0



138
139
140
141
142
143
144
145
# File 'lib/ronin/support/binary/ctypes/array_object_type.rb', line 138

def enqueue_value(values,array)
  case array
  when Binary::Array
    values.push(array.to_s)
  when ::Array
    values.push(@array_type.pack(array))
  end
end

#lengthInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The number of elements in the memory-mapped array type.

Returns:

Since:

  • 1.0.0



66
67
68
# File 'lib/ronin/support/binary/ctypes/array_object_type.rb', line 66

def length
  @array_type.length
end

#pack(array) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Packs the memory-mapped array.

Parameters:

Returns:

  • (String)

    The underlying binary data for the memory object.

Raises:

  • (ArgumentError)

    The given value was not a Array or Array.

Since:

  • 1.0.0



105
106
107
108
109
110
111
112
113
114
# File 'lib/ronin/support/binary/ctypes/array_object_type.rb', line 105

def pack(array)
  case array
  when Binary::Array
    array.to_s
  when ::Array
    @array_type.pack(array)
  else
    raise(ArgumentError,"value must be either a #{Binary::Array} or an #{::Array}: #{array.inspect}")
  end
end

#typeType

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The type of the element in the memory-mapped array type.

Returns:

Since:

  • 1.0.0



57
58
59
# File 'lib/ronin/support/binary/ctypes/array_object_type.rb', line 57

def type
  @array_type.type
end

#unpack(data) ⇒ Binary::Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Unpacks the memory-mapped array.

Parameters:

  • data (String)

    The raw binary data to unpack.

Returns:

Since:

  • 1.0.0



125
126
127
# File 'lib/ronin/support/binary/ctypes/array_object_type.rb', line 125

def unpack(data)
  Binary::Array.new(@array_type.type,data)
end