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

Inherits:
Types::Fields
  • Object
show all
Includes:
Types::Fieldable
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

#data1Integer

32-bit little-endian data1

Returns:

  • (Integer)


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

define_field :data1, PacketGen::Types::Int32le

#data2Integer

16-bit little-endian data2

Returns:

  • (Integer)


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

define_field :data2, PacketGen::Types::Int16le

#data3Integer

16-bit little-endian data3

Returns:

  • (Integer)


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

define_field :data3, PacketGen::Types::Int16le

#data4Integer

64-bit big-endian data4

Returns:

  • (Integer)


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

define_field :data4, PacketGen::Types::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('-')
  return self if values.size != 5

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

#to_humanString

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]
end