Class: Ronin::Support::Binary::CTypes::StructObjectType Private

Inherits:
ObjectType
  • Object
show all
Defined in:
lib/ronin/support/binary/ctypes/struct_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 Struct 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(struct_class, struct_type) ⇒ StructObjectType

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

Parameters:

Since:

  • 1.0.0



54
55
56
57
58
59
# File 'lib/ronin/support/binary/ctypes/struct_object_type.rb', line 54

def initialize(struct_class,struct_type)
  @struct_class = struct_class
  @struct_type  = struct_type

  super(@struct_type.size)
end

Instance Attribute Details

#struct_classClass<Binary::Struct> (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 Struct class.

Returns:

Since:

  • 1.0.0



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

def struct_class
  @struct_class
end

#struct_typeStructType (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 Hash values.

Returns:

Since:

  • 1.0.0



43
44
45
# File 'lib/ronin/support/binary/ctypes/struct_object_type.rb', line 43

def struct_type
  @struct_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 struct object type with a different #alignment.

Parameters:

  • new_alignment (Integer)

    The new alignment for the new struct object type.

Returns:

Since:

  • 1.0.0



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

def align(new_alignment)
  self.class.new(@struct_class,@struct_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 Struct.

Returns:

Since:

  • 1.0.0



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

def alignment
  @struct_type.alignment
end

#dequeue_value(values) ⇒ Struct

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



165
166
167
# File 'lib/ronin/support/binary/ctypes/struct_object_type.rb', line 165

def dequeue_value(values)
  @struct_class.new(values.shift)
end

#enqueue_value(values, struct) ⇒ 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 Struct into the list of values.

Parameters:

Since:

  • 1.0.0



147
148
149
150
151
152
153
154
# File 'lib/ronin/support/binary/ctypes/struct_object_type.rb', line 147

def enqueue_value(values,struct)
  case struct
  when Binary::Struct
    values.push(struct.to_s)
  when Hash
    values.push(@struct_type.pack(struct))
  end
end

#membersHash{Symbol => StructType::Member}

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 members of the struct type.

Returns:

Since:

  • 1.0.0



98
99
100
# File 'lib/ronin/support/binary/ctypes/struct_object_type.rb', line 98

def members
  @struct_type.members
end

#pack(struct) ⇒ 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 Struct.

Parameters:

Returns:

  • (String)

    The underlying binary data for the memory object.

Raises:

  • (ArgumentError)

    The given value was not a Struct or Hash.

Since:

  • 1.0.0



114
115
116
117
118
119
120
121
122
123
# File 'lib/ronin/support/binary/ctypes/struct_object_type.rb', line 114

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

#sizeInteger, Float::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 of the struct type.

Returns:

Since:

  • 1.0.0



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

def size
  @struct_type.size
end

#unpack(data) ⇒ Binary::Struct

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

Parameters:

  • data (String)

    The raw binary data to unpack.

Returns:

Since:

  • 1.0.0



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

def unpack(data)
  @struct_class.unpack(data)
end