Skip to content

Commit d9c6439

Browse files
committed
shorter the line, using more variables
1 parent 0fce908 commit d9c6439

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

lib/rex/parser/fs/ntfs.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def initialize(file_handler)
3939
# Gather the MFT entry corresponding to his number
4040
#
4141
def mft_record_from_mft_num(mft_num)
42-
cluster_from_attribute_non_resident(mft_record_attribute(@mft)[DATA_ATTRIBUTE_ID]["data"], mft_num * @cluster_per_mft_record, @bytes_per_mft_record)
42+
mft_num_offset = mft_num * @cluster_per_mft_record
43+
mft_data_attribute = mft_record_attribute(@mft)[DATA_ATTRIBUTE_ID]["data"]
44+
cluster_from_attribute_non_resident(mft_data_attribute, mft_num_offset, @bytes_per_mft_record)
4345
end
4446

4547
#
@@ -73,7 +75,8 @@ def file_content_from_mft_num(mft_num, size)
7375
if attribute_list[DATA_ATTRIBUTE_ID]["resident"]
7476
return attribute_list[DATA_ATTRIBUTE_ID]["data"]
7577
else
76-
return cluster_from_attribute_non_resident(attribute_list[DATA_ATTRIBUTE_ID]["data"])[0, size]
78+
data_attribute = attribute_list[DATA_ATTRIBUTE_ID]["data"]
79+
return cluster_from_attribute_non_resident(data_attribute)[0, size]
7780
end
7881
end
7982

@@ -88,7 +91,8 @@ def parse_index(index_entry)
8891
# mft_offset = index_entry[0.unpack("Q<",:8])[0]
8992
# work with 4 bytes
9093
mft_offset = index_entry[0, 4].unpack("V")[0]
91-
res[filename_from_filenameattribute(filename_attribute)] = { "mft_offset" => mft_offset, "file_size" => real_size_from_filenameattribute(filename_attribute) }
94+
res[filename_from_filenameattribute(filename_attribute)] = { "mft_offset" => mft_offset,
95+
"file_size" => real_size_from_filenameattribute(filename_attribute) }
9296
res
9397
end
9498

@@ -107,7 +111,9 @@ def parse_index_list(index_record, index_allocation_attribute)
107111
if index_entry[12, 4].unpack("V")[0] & 1 == 1
108112
# should be 8 bytes length
109113
vcn = index_entry[-8, 4].unpack("V")[0]
110-
res_son = parse_index_list(index_allocation_attribute[vcn * @bytes_per_cluster + 24, index_size * @bytes_per_cluster], index_allocation_attribute)
114+
vcn_in_bytes = vcn * @bytes_per_cluster
115+
index_size_in_bytes = index_size * @bytes_per_cluster
116+
res_son = parse_index_list(index_allocation_attribute[vcn_in_bytes + 24, index_size_in_bytes], index_allocation_attribute)
111117
res.update(res_son)
112118
end
113119
offset_index_entry_list += index_size
@@ -118,7 +124,9 @@ def parse_index_list(index_record, index_allocation_attribute)
118124
if index_entry[12, 4].unpack("V")[0] & 1 == 1
119125
# should be 8 bytes length
120126
vcn = index_entry[-8, 4].unpack("V")[0]
121-
res_son = parse_index_list(index_allocation_attribute[vcn * @bytes_per_cluster + 24, index_size * @bytes_per_cluster], index_allocation_attribute)
127+
vcn_in_bytes = vcn * @bytes_per_cluster
128+
index_size_in_bytes = index_size * @bytes_per_cluster
129+
res_son = parse_index_list(index_allocation_attribute[vcn_in_bytes + 24, index_size_in_bytes], index_allocation_attribute)
122130
res.update(res_son)
123131
end
124132
res
@@ -166,7 +174,8 @@ def cluster_from_attribute_non_resident(attribute, cluster_num = 0, size_max = (
166174
size_wanted = [run_length * @bytes_per_cluster, size_max - attribut.length].min
167175

168176
if cluster_num + (size_wanted / @bytes_per_cluster) >= run_list_num && (cluster_num < run_length + run_list_num)
169-
run_list_offset = (run_offset + old_offset + [cluster_num - run_list_num, 0].max) * @bytes_per_cluster
177+
run_list_offset_in_cluster = run_offset + old_offset + [cluster_num - run_list_num, 0].max
178+
run_list_offset = (run_list_offset_in_cluster) * @bytes_per_cluster
170179
run_list_offset = run_list_offset.to_i
171180
@file_handler.seek(run_list_offset)
172181

@@ -212,7 +221,8 @@ def mft_record_attribute(mft_record)
212221
end
213222
end
214223
if attribute_identifier == DATA_ATTRIBUTE_ID
215-
res[attribute_identifier] = { "data" => res[attribute_identifier], "resident" => mft_record[curs + 8] == "\x00" }
224+
res[attribute_identifier] = { "data" => res[attribute_identifier],
225+
"resident" => mft_record[curs + 8] == "\x00" }
216226
end
217227
curs += attribute_size
218228
attribute_identifier = mft_record[curs, 4].unpack("V")[0]

0 commit comments

Comments
 (0)