Class: PacketGen::Plugin::SMB::Filetime
- Inherits:
-
Object
- Object
- PacketGen::Plugin::SMB::Filetime
- Defined in:
- lib/packetgen/plugin/smb/filetime.rb
Overview
SMB FILETIME.
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
-
.now ⇒ Filetime
Return a new Filetime object initialized to current time.
Instance Method Summary collapse
- #from_human(str) ⇒ self
-
#initialize(options = {}) ⇒ Filetime
constructor
A new instance of Filetime.
-
#no_time? ⇒ Boolean
Check if there is no time specified.
-
#read(str) ⇒ String
Self.
- #sz ⇒ Integer
-
#to_human ⇒ String
Human readable filetime.
-
#to_i ⇒ Integer
Get filetime integer value.
- #to_s ⇒ String
- #to_time ⇒ Time
Constructor Details
#initialize(options = {}) ⇒ Filetime
Returns a new instance of Filetime.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 35 def initialize(={}) if (.keys & %i[time filetime]).size == 2 raise ArgumentError, ':time and :filetime options are both given' end @int = PacketGen::Types::SInt64le.new([:filetime]) if [:time] @time = [:time].getgm @int.value = time2filetime else @time = filetime2time end end |
Class Method Details
.now ⇒ Filetime
Return a new Filetime object initialized to current time.
27 28 29 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 27 def self.now new(time: Time.now.utc) end |
Instance Method Details
#from_human(str) ⇒ self
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 68 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
89 90 91 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 89 def no_time? to_i.zero? end |
#read(str) ⇒ String
Returns self.
51 52 53 54 55 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 51 def read(str) @int.read(str[0, 8]) @time = filetime2time self end |
#sz ⇒ Integer
94 95 96 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 94 def sz @int.sz end |
#to_human ⇒ String
Human readable filetime
59 60 61 62 63 64 65 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 59 def to_human if no_time? 'no time' else @time.strftime(FORMAT_TIME_STR) end end |
#to_i ⇒ Integer
Get filetime integer value
83 84 85 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 83 def to_i @int.to_i end |
#to_s ⇒ String
99 100 101 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 99 def to_s @int.to_s end |
#to_time ⇒ Time
104 105 106 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 104 def to_time @time end |