Class: RubySMB::Field::FileTime

Inherits:
BinData::Primitive
  • Object
show all
Defined in:
lib/ruby_smb/field/file_time.rb

Overview

Represents a Windows FILETIME structure as defined in FILETIME structure

Constant Summary collapse

EPOCH_DIFF_100NS =

Difference between the Windows and Unix epochs, in 100ns intervals

116_444_736_000_000_000
NS_MULTIPLIER =
10_000_000

Instance Method Summary collapse

Instance Method Details

#getBinData::Bit64

Gets the value of the field



15
16
17
# File 'lib/ruby_smb/field/file_time.rb', line 15

def get
  val
end

#set(value) ⇒ Object

Sets the value of the field from a DateTime,Time,Fixnum, or object that can be converted to an integer. Datetime and Time objects get converted to account for the Windows/Unix Epoch difference. Any other parameter passed in will be assumed to already be correct.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ruby_smb/field/file_time.rb', line 26

def set(value)
  case value
  when DateTime
    set(value.to_time)
  when Time
    time_int = value.to_i
    time_int *= NS_MULTIPLIER
    adjusted_epoch = time_int + EPOCH_DIFF_100NS
    set(adjusted_epoch)
  when Fixnum
    self.val = value
  else
    self.val = value.to_i
  end
  val
end

#to_datetimeDateTime

Returns the value of the field as a DateTime



46
47
48
49
# File 'lib/ruby_smb/field/file_time.rb', line 46

def to_datetime
  time = to_time
  time.to_datetime
end

#to_timeTime

Returns the value of the field as a Time



54
55
56
57
58
59
# File 'lib/ruby_smb/field/file_time.rb', line 54

def to_time
  windows_int = val
  adjusted_epoch = windows_int - EPOCH_DIFF_100NS
  unix_int = adjusted_epoch / NS_MULTIPLIER
  Time.at unix_int
end