Class: Ronin::Support::Binary::CTypes::StructType::Member Private

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

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offset, type) ⇒ 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.

Initializes the member.

Parameters:

  • offset (Integer)

    The offset, in bytes, of the member from the beginning of the struct.

  • type (Type)

    The type of the member.

Since:

  • 1.0.0



64
65
66
67
# File 'lib/ronin/support/binary/ctypes/struct_type.rb', line 64

def initialize(offset,type)
  @offset = offset
  @type   = type
end

Instance Attribute Details

#offsetInteger (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 offset, in bytes, of the member from the beginning of the struct.

Returns:

Since:

  • 1.0.0



47
48
49
# File 'lib/ronin/support/binary/ctypes/struct_type.rb', line 47

def offset
  @offset
end

#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 the member.

Returns:

Since:

  • 1.0.0



52
53
54
# File 'lib/ronin/support/binary/ctypes/struct_type.rb', line 52

def type
  @type
end

Class Method Details

.pack_string_for(type, padding = 0) ⇒ 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.

Calculates the pack string for the given type and optional padding.

Parameters:

Returns:

  • (String)

    The pack string for the member.

Since:

  • 1.0.0



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

def self.pack_string_for(type,padding=0)
  if padding > 0 then "#{'x' * padding}#{type.pack_string}"
  else                type.pack_string
  end
end

.padding_for(offset, type) ⇒ Integer

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.

Calculates padding for the given type at the given offset.

Parameters:

Returns:

See Also:

Since:

  • 1.0.0



82
83
84
# File 'lib/ronin/support/binary/ctypes/struct_type.rb', line 82

def self.padding_for(offset,type)
  (type.alignment - (offset % type.alignment)) % type.alignment
end

Instance Method Details

#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 member within the struct.

Returns:

Since:

  • 1.0.0



119
120
121
# File 'lib/ronin/support/binary/ctypes/struct_type.rb', line 119

def alignment
  @type.alignment
end

#sizeInteger

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 member within the struct.

Returns:

Since:

  • 1.0.0



110
111
112
# File 'lib/ronin/support/binary/ctypes/struct_type.rb', line 110

def size
  @type.size
end