class Ronin::Support::Binary::CTypes::StructObjectType

Represents a {Binary::Struct} type.

@api private

@since 1.0.0

Attributes

struct_class[R]

The {Struct} class.

@return [Class<Binary::Struct>]

struct_type[R]

The type used for packing literal ‘Hash` values.

@return [StructType]

Public Class Methods

new(struct_class,struct_type) click to toggle source

Initializes the memory-mapped struct type.

@param [<Binary::Struct>] struct_class

The {Struct} class.

@param [StructType] struct_type

The struct type for the struct class.
# 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

Public Instance Methods

align(new_alignment) click to toggle source

Creates a copy of the struct object type with a different {#alignment}.

@param [Integer] new_alignment

The new alignment for the new struct object type.

@return [ScalarType]

The new struct object type.
# 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
alignment() click to toggle source

The alignment, in bytes, of the memory-mapped {Struct}.

@return [Integer]

# File lib/ronin/support/binary/ctypes/struct_object_type.rb, line 75
def alignment
  @struct_type.alignment
end
dequeue_value(values) click to toggle source

Dequeues a memory object from the flat list of values.

@param [Array] values

The flat array of values.

@return [Struct]

The dequued {Struct} object.
# 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) click to toggle source

Enqueues the memory-mapped {Struct} into the list of values.

@param [Array] values

The flat array of values.

@param [Binary::Struct, Hash] struct

The {Struct} object to enqueue.
# 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
members() click to toggle source

The members of the struct type.

@return [Hash{Symbol => StructType::Member}]

# File lib/ronin/support/binary/ctypes/struct_object_type.rb, line 98
def members
  @struct_type.members
end
pack(struct) click to toggle source

Packs the memory-mapped {Struct}.

@param [Binary::Struct, Hash] struct

The memory-mapped {Struct} object.

@return [String]

The underlying binary data for the memory object.

@raise [ArgumentError]

The given value was not a {Binary::Struct} or `Hash`.
# 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
size() click to toggle source

The size of the struct type.

@return [Integer, Float::INFINITY]

# File lib/ronin/support/binary/ctypes/struct_object_type.rb, line 66
def size
  @struct_type.size
end
unpack(data) click to toggle source

Unpacks the memory-mapped {Struct}.

@param [String] data

The raw binary data to unpack.

@return [Binary::Struct]

the unpacked {Struct} object.
# File lib/ronin/support/binary/ctypes/struct_object_type.rb, line 134
def unpack(data)
  @struct_class.unpack(data)
end