Class: PacketGen::Plugin::SMB::Filetime

Inherits:
Object
  • Object
show all
Includes:
Types::Fieldable
Defined in:
lib/packetgen/plugin/smb/filetime.rb

Overview

SMB FILETIME.

Author:

  • Sylvain Daubert

Constant Summary collapse

NO_TIME =

Base time for SMB FILETIME. This value also indicate no time.

Time.utc(1601).freeze
ONE_SEC =

Numbers of 100ns in one second

10_000_000
FORMAT_TIME_STR =

String to format time

'%Y-%m-%d %H:%M:%S.%9N %Z'
PARSE_TIME_STR =

String to parse time

'%Y-%m-%d %H:%M:%S.%N %Z'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Filetime

Returns a new instance of Filetime.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :filetime (Integer)
  • :time (Time)

Raises:

  • (ArgumentError)

    if :time and :filetime are both given.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/packetgen/plugin/smb/filetime.rb', line 37

def initialize(options={})
  if (options.keys & %i[time filetime]).size == 2
    raise ArgumentError, ':time and :filetime options are both given'
  end

  @int = PacketGen::Types::SInt64le.new(options[:filetime])
  if options[:time]
    @time = options[:time].getgm
    @int.value = time2filetime
  else
    @time = filetime2time
  end
end

Class Method Details

.nowFiletime

Return a new Filetime object initialized to current time.

Returns:



29
30
31
# File 'lib/packetgen/plugin/smb/filetime.rb', line 29

def self.now
  new(time: Time.now.utc)
end

Instance Method Details

#from_human(str) ⇒ self

Returns:

  • (self)


70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/packetgen/plugin/smb/filetime.rb', line 70

def from_human(str)
  return self if str.nil?

  @time = if str == 'no time'
            Time.at(NO_TIME)
          else
            DateTime.strptime(str, PARSE_TIME_STR).to_time
          end
  @int.value = time2filetime

  self
end

#no_time?Boolean

Check if there is no time specified

Returns:

  • (Boolean)


91
92
93
# File 'lib/packetgen/plugin/smb/filetime.rb', line 91

def no_time?
  to_i.zero?
end

#read(str) ⇒ String

Returns self.

Parameters:

  • str (::String)

Returns:



53
54
55
56
57
# File 'lib/packetgen/plugin/smb/filetime.rb', line 53

def read(str)
  @int.read(str[0, 8])
  @time = filetime2time
  self
end

#szInteger

Returns:

  • (Integer)


96
97
98
# File 'lib/packetgen/plugin/smb/filetime.rb', line 96

def sz
  @int.sz
end

#to_humanString

Human readable filetime

Returns:



61
62
63
64
65
66
67
# File 'lib/packetgen/plugin/smb/filetime.rb', line 61

def to_human
  if no_time?
    'no time'
  else
    @time.strftime(FORMAT_TIME_STR)
  end
end

#to_iInteger

Get filetime integer value

Returns:

  • (Integer)


85
86
87
# File 'lib/packetgen/plugin/smb/filetime.rb', line 85

def to_i
  @int.to_i
end

#to_sString

Returns:



101
102
103
# File 'lib/packetgen/plugin/smb/filetime.rb', line 101

def to_s
  @int.to_s
end

#to_timeTime

Returns:

  • (Time)


106
107
108
# File 'lib/packetgen/plugin/smb/filetime.rb', line 106

def to_time
  @time
end