Skip to content

Commit 0fce908

Browse files
committed
add constant class
1 parent f4ec6bd commit 0fce908

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/rex/parser/fs/ntfs.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class NTFS
1212
#
1313
# Initialize the NTFS class with an already open file handler
1414
#
15-
data_attribute = 128
15+
DATA_ATTRIBUTE_ID = 128
16+
INDEX_ROOT_ID = 144
17+
INDEX_ALLOCATION_ID = 160
1618
def initialize(file_handler)
1719
@file_handler = file_handler
1820
data = @file_handler.read(4096)
@@ -37,7 +39,7 @@ def initialize(file_handler)
3739
# Gather the MFT entry corresponding to his number
3840
#
3941
def mft_record_from_mft_num(mft_num)
40-
cluster_from_attribute_non_resident(mft_record_attribute(@mft)[data_attribute]["data"], mft_num * @cluster_per_mft_record, @bytes_per_mft_record)
42+
cluster_from_attribute_non_resident(mft_record_attribute(@mft)[DATA_ATTRIBUTE_ID]["data"], mft_num * @cluster_per_mft_record, @bytes_per_mft_record)
4143
end
4244

4345
#
@@ -68,10 +70,10 @@ def filename_from_filenameattribute(attribute)
6870
def file_content_from_mft_num(mft_num, size)
6971
mft_record = mft_record_from_mft_num(mft_num)
7072
attribute_list = mft_record_attribute(mft_record)
71-
if attribute_list[data_attribute]["resident"]
72-
return attribute_list[data_attribute]["data"]
73+
if attribute_list[DATA_ATTRIBUTE_ID]["resident"]
74+
return attribute_list[DATA_ATTRIBUTE_ID]["data"]
7375
else
74-
return cluster_from_attribute_non_resident(attribute_list[data_attribute]["data"])[0, size]
76+
return cluster_from_attribute_non_resident(attribute_list[DATA_ATTRIBUTE_ID]["data"])[0, size]
7577
end
7678
end
7779

@@ -126,10 +128,10 @@ def parse_index_list(index_record, index_allocation_attribute)
126128
# return the list of files in attribute directory and their MFT number and size
127129
#
128130
def index_list_from_attributes(attributes)
129-
index_root_attribute = attributes[144]
131+
index_root_attribute = attributes[INDEX_ROOT_ID]
130132
index_record = index_root_attribute[16, index_root_attribute.length - 16]
131-
if attributes.key?(160)
132-
return parse_index_list(index_record, attributes[160])
133+
if attributes.key?(INDEX_ALLOCATION_ID)
134+
return parse_index_list(index_record, attributes[INDEX_ALLOCATION_ID])
133135
else
134136
return parse_index_list(index_record, "")
135137
end
@@ -203,13 +205,13 @@ def mft_record_attribute(mft_record)
203205
res[attribute_identifier] = mft_record[curs + content_offset, content_size]
204206
else
205207
# non resident
206-
if attribute_identifier == data_attribute
208+
if attribute_identifier == DATA_ATTRIBUTE_ID
207209
res[attribute_identifier] = mft_record[curs, attribute_size]
208210
else
209211
res[attribute_identifier] = cluster_from_attribute_non_resident(mft_record[curs, attribute_size])
210212
end
211213
end
212-
if attribute_identifier == data_attribute
214+
if attribute_identifier == DATA_ATTRIBUTE_ID
213215
res[attribute_identifier] = { "data" => res[attribute_identifier], "resident" => mft_record[curs + 8] == "\x00" }
214216
end
215217
curs += attribute_size

0 commit comments

Comments
 (0)