Class: Ronin::Support::Binary::CTypes::Type Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/support/binary/ctypes/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.

Base class for all types.

Since:

  • 1.0.0

Direct Known Subclasses

AggregateType, EnumType, ObjectType, ScalarType, StringType

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pack_string:) ⇒ Type

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

Parameters:

  • pack_string (String, nil)

    The String for Array#pack or String#unpack.

Since:

  • 1.0.0



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

def initialize(pack_string: )
  @pack_string = pack_string
end

Instance Attribute Details

#pack_stringString? (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.

Note:

May return nil if the type does not map to a Ruby pack-string.

The String for Array#pack or String#unpack.

Returns:

Since:

  • 1.0.0



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

def pack_string
  @pack_string
end

Instance Method Details

#[](length = nil) ⇒ ArrayType, 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.

Creates an Array type around the scalar type.

Parameters:

  • length (Integer, nil) (defaults to: nil)

    The length of the Array.

Returns:

Since:

  • 1.0.0



60
61
62
63
64
# File 'lib/ronin/support/binary/ctypes/type.rb', line 60

def [](length=nil)
  if length then ArrayType.new(self,length)
  else           UnboundedArrayType.new(self)
  end
end

#align(new_alignment) ⇒ Type

This method is abstract.

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

Parameters:

  • new_alignment (Integer)

    The new alignment for the new type.

Returns:

  • (Type)

    The new type.

Raises:

  • (NotImplementedError)

Since:

  • 1.0.0



117
118
119
# File 'lib/ronin/support/binary/ctypes/type.rb', line 117

def align(new_alignment)
  raise(NotImplementedError,"#{self.class}##{__method__} was not implemented")
end

#alignmentInteger

This method is abstract.

The alignment, in bytes, for the type.

Returns:

Raises:

  • (NotImplementedError)

Since:

  • 1.0.0



100
101
102
# File 'lib/ronin/support/binary/ctypes/type.rb', line 100

def alignment
  raise(NotImplementedError,"#{self.class}##{__method__} was not implemented")
end

#dequeue_value(values) ⇒ 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.

This method is abstract.

Dequeues a value from the flat list of values.

Parameters:

  • values (Array)

    The flat array of values.

Returns:

  • (Object)

    The dequeued value.

Raises:

  • (NotImplementedError)

Since:

  • 1.0.0



185
186
187
# File 'lib/ronin/support/binary/ctypes/type.rb', line 185

def dequeue_value(values)
  raise(NotImplementedError,"#{self.class}##{__method__} was not implemented")
end

#enqueue_value(values, value) ⇒ 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.

This method is abstract.

Enqueues a value onto the flat list of values.

Parameters:

  • values (Array)

    The flat array of values.

  • value (Object)

    The value to enqueue.

Raises:

  • (NotImplementedError)

Since:

  • 1.0.0



168
169
170
# File 'lib/ronin/support/binary/ctypes/type.rb', line 168

def enqueue_value(values,value)
  raise(NotImplementedError,"#{self.class}##{__method__} was not implemented")
end

#pack(value) ⇒ String

This method is abstract.

Packs the value into the type's binary format.

Parameters:

  • value (Object)

    The value to pack.

Returns:

  • (String)

    The packed binary data.

Raises:

  • (NotImplementedError)

Since:

  • 1.0.0



134
135
136
# File 'lib/ronin/support/binary/ctypes/type.rb', line 134

def pack(value)
  raise(NotImplementedError,"#{self.class}##{__method__} was not implemented")
end

#sizeInteger

This method is abstract.

The size of the type.

Returns:

  • (Integer)

    The size of the type in bytes.

Raises:

  • (NotImplementedError)

Since:

  • 1.0.0



87
88
89
# File 'lib/ronin/support/binary/ctypes/type.rb', line 87

def size
  raise(NotImplementedError,"#{self.class}##{__method__} was not implemented")
end

#uninitialized_valuenil

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.

This method is abstract.

The default uniniitalized value for the type.

Returns:

  • (nil)

Since:

  • 1.0.0



73
74
75
# File 'lib/ronin/support/binary/ctypes/type.rb', line 73

def uninitialized_value
  nil
end

#unpack(data) ⇒ Object

This method is abstract.

Unpacks the binary data.

Parameters:

  • data (String)

    The binary data to unpack.

Returns:

  • (Object)

    The unpacked value.

Raises:

  • (NotImplementedError)

Since:

  • 1.0.0



151
152
153
# File 'lib/ronin/support/binary/ctypes/type.rb', line 151

def unpack(data)
  raise(NotImplementedError,"#{self.class}##{__method__} was not implemented")
end