@@ -66,23 +66,23 @@ def gather_pf_info(name_offset, hash_offset, runcount_offset, filetime_offset, f
66
66
# from the system.
67
67
68
68
prefetch_file = read_file ( filename )
69
- if prefetch_file . empty? or prefetch_file . nil ?
69
+ if prefetch_file . blank ?
70
70
print_error ( "Couldn't read file: #{ filename } " )
71
71
return nil
72
72
else
73
73
# First we extract the saved filename
74
- pf_filename = prefetch_file [ name_offset .. name_offset + 60 ]
74
+ pf_filename = prefetch_file [ name_offset , 60 ]
75
75
idx = pf_filename . index ( "\x00 \x00 " )
76
76
name = Rex ::Text . to_ascii ( pf_filename . slice ( 0 ..idx ) )
77
77
78
78
# Then we get the runcount
79
- run_count = prefetch_file [ runcount_offset .. runcount_offset + 4 ] . unpack ( 'L* ' ) [ 0 ] . to_s
79
+ run_count = prefetch_file [ runcount_offset , 4 ] . unpack ( 'v ' ) [ 0 ]
80
80
81
81
# Then the filepath hash
82
- path_hash = prefetch_file [ hash_offset .. hash_offset + 4 ] . unpack ( 'h8 ' ) [ 0 ] . reverse . upcase . to_s
82
+ path_hash = prefetch_file [ hash_offset , 4 ] . unpack ( 'h* ' ) [ 0 ] . upcase . reverse
83
83
84
84
# Last we get the latest execution time
85
- filetime_a = prefetch_file [ filetime_offset .. ( filetime_offset + 16 ) ] . unpack ( 'q*' )
85
+ filetime_a = prefetch_file [ filetime_offset , 16 ] . unpack ( 'q*' )
86
86
filetime = filetime_a [ 0 ] + filetime_a [ 1 ]
87
87
last_exec = Time . at ( ( filetime - 116444736000000000 ) / 10000000 ) . utc . to_s
88
88
@@ -93,32 +93,32 @@ def gather_pf_info(name_offset, hash_offset, runcount_offset, filetime_offset, f
93
93
# First we'll use specific offsets for finding out the location
94
94
# and length of the filepath so that we can find it.
95
95
filepath = [ ]
96
- fpath_offset = prefetch_file [ 0x64 .. 0x68 ] . unpack ( 'h4' ) [ 0 ] . reverse . to_i ( 16 )
97
- fpath_length = prefetch_file [ 0x68 .. 0x6C ] . unpack ( 'h4' ) [ 0 ] . reverse . to_i ( 16 )
98
- filepath_data = prefetch_file [ fpath_offset .. ( fpath_offset + fpath_length ) ]
96
+ fpath_offset = prefetch_file [ 0x64 , 2 ] . unpack ( 'v' ) . first
97
+ fpath_length = prefetch_file [ 0x68 , 2 ] . unpack ( 'v' ) . first
98
+ filepath_data = prefetch_file [ fpath_offset , fpath_length ]
99
99
100
100
# This part will extract the filepath so that we can find and
101
101
# compare its contents to the filename we found previously. This
102
102
# allows us to find the filepath (if it can be found inside the
103
103
# prefetch file) used to execute the program
104
104
# referenced in the prefetch-file.
105
-
106
- if not filepath_data . nil? or not filepath_data . emtpy?
107
- fpath_data_array = filepath_data . split ( "\x00 \x00 \x00 " )
105
+ unless filepath_data . blank?
106
+ fpath_data_array = filepath_data . split ( "\\ \x00 D\x00 E\x00 V\x00 I\x00 C\x00 E" )
108
107
fpath_data_array . each do |path |
109
- fpath_entry_data = path . split ( "\\ " )
110
- fpath_entry_filename = fpath_entry_data . last
111
- if not fpath_entry_filename . nil?
112
- fpath_name = fpath_entry_filename . gsub ( /\0 / , '' )
113
- if name == fpath_name [ 0 ..29 ]
114
- fpath_path = path . gsub ( /\0 / , '' )
115
- filepath = fpath_path
108
+ unless path . blank?
109
+ fpath_name = path . split ( "\\ " ) . last . gsub ( /\0 / , '' )
110
+ if fpath_name == name
111
+ filepath << path
116
112
end
117
113
end
118
114
end
119
115
end
120
116
end
121
- return [ last_exec , path_hash , run_count , name , filepath ]
117
+ if filepath . blank?
118
+ filepath << "*** Filepath not found ***"
119
+ end
120
+
121
+ return [ last_exec , path_hash , run_count , name , filepath [ 0 ] ]
122
122
end
123
123
124
124
def run
0 commit comments