@@ -12,7 +12,9 @@ class NTFS
12
12
#
13
13
# Initialize the NTFS class with an already open file handler
14
14
#
15
- data_attribute = 128
15
+ DATA_ATTRIBUTE_ID = 128
16
+ INDEX_ROOT_ID = 144
17
+ INDEX_ALLOCATION_ID = 160
16
18
def initialize ( file_handler )
17
19
@file_handler = file_handler
18
20
data = @file_handler . read ( 4096 )
@@ -37,7 +39,7 @@ def initialize(file_handler)
37
39
# Gather the MFT entry corresponding to his number
38
40
#
39
41
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 )
41
43
end
42
44
43
45
#
@@ -68,10 +70,10 @@ def filename_from_filenameattribute(attribute)
68
70
def file_content_from_mft_num ( mft_num , size )
69
71
mft_record = mft_record_from_mft_num ( mft_num )
70
72
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" ]
73
75
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 ]
75
77
end
76
78
end
77
79
@@ -126,10 +128,10 @@ def parse_index_list(index_record, index_allocation_attribute)
126
128
# return the list of files in attribute directory and their MFT number and size
127
129
#
128
130
def index_list_from_attributes ( attributes )
129
- index_root_attribute = attributes [ 144 ]
131
+ index_root_attribute = attributes [ INDEX_ROOT_ID ]
130
132
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 ] )
133
135
else
134
136
return parse_index_list ( index_record , "" )
135
137
end
@@ -203,13 +205,13 @@ def mft_record_attribute(mft_record)
203
205
res [ attribute_identifier ] = mft_record [ curs + content_offset , content_size ]
204
206
else
205
207
# non resident
206
- if attribute_identifier == data_attribute
208
+ if attribute_identifier == DATA_ATTRIBUTE_ID
207
209
res [ attribute_identifier ] = mft_record [ curs , attribute_size ]
208
210
else
209
211
res [ attribute_identifier ] = cluster_from_attribute_non_resident ( mft_record [ curs , attribute_size ] )
210
212
end
211
213
end
212
- if attribute_identifier == data_attribute
214
+ if attribute_identifier == DATA_ATTRIBUTE_ID
213
215
res [ attribute_identifier ] = { "data" => res [ attribute_identifier ] , "resident" => mft_record [ curs + 8 ] == "\x00 " }
214
216
end
215
217
curs += attribute_size
0 commit comments