@@ -13,7 +13,6 @@ module Ui
13
13
#
14
14
###
15
15
class Console ::CommandDispatcher ::Priv ::Timestomp
16
-
17
16
Klass = Console ::CommandDispatcher ::Priv ::Timestomp
18
17
19
18
include Console ::CommandDispatcher
@@ -28,7 +27,8 @@ class Console::CommandDispatcher::Priv::Timestomp
28
27
"-b" => [ false , "Set the MACE timestamps so that EnCase shows blanks" ] ,
29
28
"-r" => [ false , "Set the MACE timestamps recursively on a directory" ] ,
30
29
"-v" => [ false , "Display the UTC MACE values of the file" ] ,
31
- "-h" => [ false , "Help banner" ] )
30
+ "-h" => [ false , "Help banner" ]
31
+ )
32
32
33
33
#
34
34
# List of supported commands.
@@ -51,91 +51,110 @@ def name
51
51
# line timestomp interface provides with a similar argument set.
52
52
#
53
53
def cmd_timestomp ( *args )
54
- if ( args . length < 2 )
55
- print_line ( "\n Usage: timestomp OPTIONS file_path \n " +
54
+ if args . length < 2
55
+ print_line ( "\n Usage: timestomp <file(s)> OPTIONS \n " +
56
56
@@timestomp_opts . usage )
57
57
return
58
58
end
59
59
60
- file_path = nil
61
- args . each { |a | file_path = a unless a [ 0 ] == "-" }
62
-
63
- if file_path . nil?
64
- print_line ( "\n No file_path specified." )
65
- return
66
- end
67
-
68
- args . delete ( file_path )
60
+ paths = [ ]
69
61
70
62
modified = nil
71
63
accessed = nil
72
64
creation = nil
73
65
emodified = nil
74
66
75
- @@timestomp_opts . parse ( args ) { |opt , idx , val |
67
+ blank_file_mace = false
68
+ blank_directory_mace = false
69
+ get_file_mace = false
70
+
71
+ @@timestomp_opts . parse ( args ) do |opt , _idx , val |
76
72
case opt
77
- when "-m"
78
- modified = str_to_time ( val )
79
- when "-a"
80
- accessed = str_to_time ( val )
81
- when "-c"
82
- creation = str_to_time ( val )
83
- when "-e"
84
- emodified = str_to_time ( val )
85
- when "-z"
86
- print_line ( "#{ val } " )
87
- modified = str_to_time ( val )
88
- accessed = str_to_time ( val )
89
- creation = str_to_time ( val )
90
- emodified = str_to_time ( val )
91
- when "-f"
92
- print_status ( "Setting MACE attributes on #{ file_path } from #{ val } " )
93
- client . priv . fs . set_file_mace_from_file ( file_path , val )
94
- when "-b"
95
- print_status ( "Blanking file MACE attributes on #{ file_path } " )
96
- client . priv . fs . blank_file_mace ( file_path )
97
- when "-r"
98
- print_status ( "Blanking directory MACE attributes on #{ file_path } " )
99
- client . priv . fs . blank_directory_mace ( file_path )
100
- when "-v"
101
- hash = client . priv . fs . get_file_mace ( file_path )
102
-
103
- print_line ( "Modified : #{ hash [ 'Modified' ] } " )
104
- print_line ( "Accessed : #{ hash [ 'Accessed' ] } " )
105
- print_line ( "Created : #{ hash [ 'Created' ] } " )
106
- print_line ( "Entry Modified: #{ hash [ 'Entry Modified' ] } " )
107
- when "-h"
108
- print_line ( "\n Usage: timestomp file_path OPTIONS\n " +
109
- @@timestomp_opts . usage )
110
- return
73
+ when "-m"
74
+ modified = str_to_time ( val )
75
+ when "-a"
76
+ accessed = str_to_time ( val )
77
+ when "-c"
78
+ creation = str_to_time ( val )
79
+ when "-e"
80
+ emodified = str_to_time ( val )
81
+ when "-z"
82
+ modified = str_to_time ( val )
83
+ accessed = str_to_time ( val )
84
+ creation = str_to_time ( val )
85
+ emodified = str_to_time ( val )
86
+ when "-f"
87
+ print_status ( "Setting MACE attributes on #{ path } from #{ val } " )
88
+ hash = client . priv . fs . get_file_mace ( path )
89
+ if hash
90
+ modified = str_to_time ( hash [ 'Modified' ] )
91
+ accessed = str_to_time ( hash [ 'Accessed' ] )
92
+ creation = str_to_time ( hash [ 'Created' ] )
93
+ emodified = str_to_time ( hash [ 'Entry Modified' ] )
94
+ end
95
+ when "-b"
96
+ blank_file_mace = true
97
+ when "-r"
98
+ blank_directory_mace = true
99
+ when "-v"
100
+ get_file_mace = true
101
+ when "-h"
102
+ print_line ( "\n Usage: timestomp <file(s)> OPTIONS\n " +
103
+ @@timestomp_opts . usage )
104
+ return nil
105
+ when nil
106
+ paths << val
107
+ end
108
+ end
109
+
110
+ if paths . empty?
111
+ print_line ( "\n No paths specified." )
112
+ return
113
+ end
114
+
115
+ paths . uniq . each do |path |
116
+ # If any one of the four times were specified, change them.
117
+ if modified || accessed || creation || emodified
118
+ print_status ( "Setting specific MACE attributes on #{ path } " )
119
+ client . priv . fs . set_file_mace ( path , modified , accessed , creation , emodified )
120
+ end
121
+
122
+ if blank_file_mace
123
+ print_status ( "Blanking file MACE attributes on #{ path } " )
124
+ client . priv . fs . blank_file_mace ( path )
111
125
end
112
- }
113
126
114
- # If any one of the four times were specified, change them.
115
- if ( modified or accessed or creation or emodified )
116
- print_status ( "Setting specific MACE attributes on #{ file_path } " )
117
- client . priv . fs . set_file_mace ( file_path , modified , accessed ,
118
- creation , emodified )
127
+ if blank_directory_mace
128
+ print_status ( "Blanking directory MACE attributes on #{ path } " )
129
+ client . priv . fs . blank_directory_mace ( path )
130
+ end
131
+
132
+ if get_file_mace
133
+ hash = client . priv . fs . get_file_mace ( path )
134
+ print_status ( "Showing MACE attributes for #{ path } " )
135
+ print_line ( "Modified : #{ hash [ 'Modified' ] } " )
136
+ print_line ( "Accessed : #{ hash [ 'Accessed' ] } " )
137
+ print_line ( "Created : #{ hash [ 'Created' ] } " )
138
+ print_line ( "Entry Modified: #{ hash [ 'Entry Modified' ] } " )
139
+ end
119
140
end
120
141
end
121
142
122
- protected
143
+ protected
123
144
124
145
#
125
146
# Converts a date/time in the form of MM/DD/YYYY HH24:MI:SS
126
147
#
127
148
def str_to_time ( str ) # :nodoc:
128
- r , mon , day , year , hour , min , sec = str . match ( "^(\\ d+?)/(\\ d+?)/(\\ d+?) (\\ d+?):(\\ d+?):(\\ d+?)$" ) . to_a
149
+ _r , mon , day , year , hour , min , sec = str . match ( "^(\\ d+?)/(\\ d+?)/(\\ d+?) (\\ d+?):(\\ d+?):(\\ d+?)$" ) . to_a
129
150
130
- if ( mon == nil )
151
+ if mon . nil?
131
152
raise ArgumentError , "Invalid date format, expected MM/DD/YYYY HH24:MI:SS (got #{ str } )"
132
153
end
133
154
134
155
Time . mktime ( year , mon , day , hour , min , sec , 0 )
135
156
end
136
-
137
157
end
138
-
139
158
end
140
159
end
141
160
end
0 commit comments