Class: PacketGen::Plugin::SMB2::GUID

Inherits:
BinStruct::Struct
  • Object
show all
Includes:
BinStruct::Structable
Defined in:
lib/packetgen/plugin/smb2/guid.rb

Overview

GUID, also known as UUID, is a 16-byte structure, intended to serve as a unique identifier for an object. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data1 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data2 | Data3 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data4 |

  •                                                           +
    
    | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Author:

  • Sylvain Daubert

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#data1 ⇒ Integer

32-bit little-endian data1

Returns:

  • (Integer)


30
# File 'lib/packetgen/plugin/smb2/guid.rb', line 30

define_attr :data1, BinStruct::Int32le

#data2 ⇒ Integer

16-bit little-endian data2

Returns:

  • (Integer)


34
# File 'lib/packetgen/plugin/smb2/guid.rb', line 34

define_attr :data2, BinStruct::Int16le

#data3 ⇒ Integer

16-bit little-endian data3

Returns:

  • (Integer)


38
# File 'lib/packetgen/plugin/smb2/guid.rb', line 38

define_attr :data3, BinStruct::Int16le

#data4 ⇒ Integer

64-bit big-endian data4

Returns:

  • (Integer)


42
# File 'lib/packetgen/plugin/smb2/guid.rb', line 42

define_attr :data4, BinStruct::Int64

Instance Method Details

#from_human(guid) ⇒ self

Set GUID from a human-readable string

Parameters:

  • guid (String)

Returns:

  • (self)


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/packetgen/plugin/smb2/guid.rb', line 56

def from_human(guid)
  return self if guid.nil? || guid.empty?

  values = guid.split('-').map { |v| v.to_i(16) }
  return self if values.size != 5

  self.data1 = values[0]
  self.data2 = values[1]
  self.data3 = values[2]
  self.data4 = (values[3] << 48) | values[4]
  self
end

#to_human ⇒ String

Get a human-readable GUID, as specified in RFC 4122 guid.to_human # => "7aedb437-01b9-41d4-a5f7-9e6c06e16c8a"

Returns:

  • (String)


47
48
49
50
51
# File 'lib/packetgen/plugin/smb2/guid.rb', line 47

def to_human
  data4p1 = data4 >> 48
  data4p2 = data4 & 0xffff_ffff_ffff
  '%08x-%04x-%04x-%04x-%012x' % [data1, data2, data3, data4p1, data4p2] # rubocop:disable Style/FormatStringToken
end