Class: Ronin::Support::Binary::CTypes::UnionObjectType Private

Inherits:
ObjectType
  • Object
show all
Defined in:
lib/ronin/support/binary/ctypes/union_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 Union 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(union_class, union_type) ⇒ UnionObjectType

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

Parameters:

  • union_class (Union.class)

    The Union class.

  • union_type (UnionType)

    The union type for the union class.

Since:

  • 1.0.0



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

def initialize(union_class,union_type)
  @union_class = union_class
  @union_type  = union_type

  super(@union_type.size)
end

Instance Attribute Details

#union_classUnion.class (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 Union class.

Returns:

Since:

  • 1.0.0



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

def union_class
  @union_class
end

#union_typeUnionType (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/union_object_type.rb', line 43

def union_type
  @union_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 union object type with a different #alignment.

Parameters:

  • new_alignment (Integer)

    The new alignment for the new union object type.

Returns:

Since:

  • 1.0.0



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

def align(new_alignment)
  self.class.new(@union_class,@union_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 Union.

Returns:

Since:

  • 1.0.0



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

def alignment
  @union_type.alignment
end

#dequeue_value(values) ⇒ Union

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/union_object_type.rb', line 165

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

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

Parameters:

Since:

  • 1.0.0



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

def enqueue_value(values,union)
  case union
  when Binary::Union
    values.push(union.to_s)
  when Hash
    values.push(@union_type.pack(union))
  end
end

#membersHash{Symbol => UnionType::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 union type.

Returns:

Since:

  • 1.0.0



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

def members
  @union_type.members
end

#pack(union) ⇒ 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 Union.

Parameters:

Returns:

  • (String)

    The underlying binary data for the memory object.

Raises:

  • (ArgumentError)

    The given value was not a Union or Hash.

Since:

  • 1.0.0



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

def pack(union)
  case union
  when Binary::Union
    union.to_s
  when Hash
    @union_type.pack(union)
  else
    raise(ArgumentError,"value must be either a #{Binary::Union} or an #{Hash}: #{union.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 union type.

Returns:

Since:

  • 1.0.0



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

def size
  @union_type.size
end

#unpack(data) ⇒ Binary::Union

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

Parameters:

  • data (String)

    The raw binary data to unpack.

Returns:

Since:

  • 1.0.0



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

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