Class: PacketGen::Plugin::SMB::Filetime
- Inherits:
-
Object
- Object
- PacketGen::Plugin::SMB::Filetime
- Includes:
- Types::Fieldable
- 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 37 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.
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
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
91 92 93 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 91 def no_time? to_i.zero? end |
#read(str) ⇒ String
Returns self.
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 |
#sz ⇒ Integer
96 97 98 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 96 def sz @int.sz end |
#to_human ⇒ String
Human readable filetime
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_i ⇒ Integer
Get filetime integer value
85 86 87 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 85 def to_i @int.to_i end |
#to_s ⇒ String
101 102 103 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 101 def to_s @int.to_s end |
#to_time ⇒ Time
106 107 108 |
# File 'lib/packetgen/plugin/smb/filetime.rb', line 106 def to_time @time end |