Class: Ronin::Support::Binary::CTypes::StringType Private

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

Since:

  • 1.0.0

Instance Attribute Summary

Attributes inherited from Type

#pack_string

Instance Method Summary collapse

Methods inherited from Type

#[], #align, #uninitialized_value

Constructor Details

#initializeStringType

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

Since:

  • 1.0.0



37
38
39
# File 'lib/ronin/support/binary/ctypes/string_type.rb', line 37

def initialize
  super(pack_string: 'Z*')
end

Instance Method Details

#alignment1

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 for the string type

Returns:

  • (1)

Since:

  • 1.0.0



57
58
59
# File 'lib/ronin/support/binary/ctypes/string_type.rb', line 57

def alignment
  1
end

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

Dequeues a string from the flat list of values.

Parameters:

  • values (Array)

    The flat array of values.

Returns:

  • (String)

    The dequeued string.

Since:

  • 1.0.0



135
136
137
# File 'lib/ronin/support/binary/ctypes/string_type.rb', line 135

def dequeue_value(values)
  values.shift
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.

Enqueues a string onto the flat list of values.

Parameters:

  • values (Array)

    The flat array of values.

  • value (String, nil)

    The string to enqueue.

Since:

  • 1.0.0



120
121
122
# File 'lib/ronin/support/binary/ctypes/string_type.rb', line 120

def enqueue_value(values,value)
  values.push(value)
end

#pack(value) ⇒ String

Packs the String into a null-terminated C String.

Parameters:

  • value (String)

    The String to pack.

Returns:

  • (String)

    The packed binary data.

Since:

  • 1.0.0



90
91
92
# File 'lib/ronin/support/binary/ctypes/string_type.rb', line 90

def pack(value)
  [value].pack(@pack_string)
end

#signed?true

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.

Indicates that the String contains signed characters.

Returns:

  • (true)

Since:

  • 1.0.0



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

def signed?
  true
end

#sizeFloat::INFINITY Also known as: length

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.

Indicates that Strings can have arbitrary size.

Returns:

  • (Float::INFINITY)

Since:

  • 1.0.0



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

def size
  Float::INFINITY
end

#unpack(data) ⇒ String?

Unpacks a null-terminated C String.

Parameters:

  • data (String)

    The binary data to unpack.

Returns:

  • (String, nil)

    The unpacked String.

Since:

  • 1.0.0



105
106
107
# File 'lib/ronin/support/binary/ctypes/string_type.rb', line 105

def unpack(data)
  data.unpack1(@pack_string)
end

#unsigned?false

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.

Indicates that the String does not contains unsigned characters.

Returns:

  • (false)

Since:

  • 1.0.0



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

def unsigned?
  false
end