Class: Ronin::Support::Binary::CTypes::UnboundedArrayType Private

Inherits:
AggregateType show all
Defined in:
lib/ronin/support/binary/ctypes/unbounded_array_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 an unbounded array type.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Attributes inherited from Type

#pack_string

Instance Method Summary collapse

Methods inherited from Type

#[], #uninitialized_value

Constructor Details

#initialize(type, alignment: nil) ⇒ UnboundedArrayType

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 unbounded array type.

Parameters:

  • type (Type)

    The type of each element in the unbounded array type.

Raises:

Since:

  • 1.0.0



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 49

def initialize(type, alignment: nil)
  if type.kind_of?(UnboundedArrayType)
    raise(ArgumentError,"cannot initialize a nested #{UnboundedArrayType}")
  end

  @type      = type
  @alignment = alignment

  super(
    # "T*" syntax only works on individual pack-string codes,
    # so we only set #pack_string for scalar types that also have
    # a #pack_string.
    pack_string: if @type.kind_of?(ScalarType) && @type.pack_string
                   "#{@type.pack_string}*"
                 end
  )
end

Instance Attribute Details

#typeType (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 of each element in the unbounded array type.

Returns:

Since:

  • 1.0.0



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

def type
  @type
end

Instance Method Details

#align(new_alignment) ⇒ ScalarType

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 unbounded array type with a different #alignment.

Parameters:

  • new_alignment (Integer)

    The new alignment for the new unbounded array type.

Returns:

Since:

  • 1.0.0



95
96
97
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 95

def align(new_alignment)
  self.class.new(@type, alignment: 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, for the unbounded array.

Returns:

Since:

  • 1.0.0



81
82
83
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 81

def alignment
  @alignment || @type.alignment
end

#dequeue_value(values) ⇒ 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 an array from the flat list of values.

Parameters:

  • values (Array)

    The flat array of values.

Returns:

  • (Array)

    The dequeued array.

Since:

  • 1.0.0



218
219
220
221
222
223
224
225
226
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 218

def dequeue_value(values)
  array = []

  until values.empty?
    array << @type.dequeue_value(values)
  end

  return array
end

#endian:little, ...

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 endianness of each element in the unbounded array.

Returns:

  • (:little, :big, nil)

    Indicates whether each element is little-endian, big-endian, or nil if each element has no endianness.

Since:

  • 1.0.0



115
116
117
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 115

def endian
  @type.endian
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 an array of values onto the flat list of values.

Parameters:

  • values (Array)

    The flat array of values.

  • array (Array)

    The array to enqueue.

Since:

  • 1.0.0



201
202
203
204
205
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 201

def enqueue_value(values,array)
  array.each do |element|
    @type.enqueue_value(values,element)
  end
end

#lengthFloat::INFINITY

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 "length" of the unbounded array type.

Returns:

  • (Float::INFINITY)

Since:

  • 1.0.0



104
105
106
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 104

def length
  Float::INFINITY
end

#pack(array) ⇒ String

Packs an array of values into the type's binary format.

Parameters:

Returns:

  • (String)

    The packed binary data.

Since:

  • 1.0.0



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 148

def pack(array)
  if @pack_string
    super(array)
  else
    buffer = String.new

    array.each do |element|
      buffer << @type.pack(element)
    end

    return buffer
  end
end

#signed?Boolean

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.

Indicates whether each element is signed.

Returns:

  • (Boolean)

Since:

  • 1.0.0



124
125
126
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 124

def signed?
  @type.signed?
end

#sizeFloat::INFINITY

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 "size" in bytes of the unbounded array type.

Returns:

  • (Float::INFINITY)

Since:

  • 1.0.0



72
73
74
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 72

def size
  Float::INFINITY
end

#unpack(data) ⇒ Array<Integer, Float, String, nil>

Unpacks an array of binary data.

Parameters:

  • data (String)

    The binary data to unpack.

Returns:

Since:

  • 1.0.0



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 173

def unpack(data)
  if @pack_string
    super(data)
  else
    case @type
    when StringType
      unpack_strings(data)
    else
      type_size = @type.size

      (0...data.bytesize).step(type_size).map do |offset|
        @type.unpack(data.byteslice(offset,type_size))
      end
    end
  end
end

#unsigned?Boolean

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.

Indicates whether each element is unsigned.

Returns:

  • (Boolean)

Since:

  • 1.0.0



133
134
135
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 133

def unsigned?
  @type.unsigned?
end