dissect.fat 3.11.dev1__tar.gz → 3.12.dev2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dissect_fat-3.11.dev1/dissect.fat.egg-info → dissect_fat-3.12.dev2}/PKG-INFO +2 -2
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/dissect/fat/c_exfat.py +3 -1
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/dissect/fat/c_fat.py +2 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/dissect/fat/exfat.py +46 -38
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/dissect/fat/fat.py +68 -63
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2/dissect.fat.egg-info}/PKG-INFO +2 -2
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/dissect.fat.egg-info/SOURCES.txt +1 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/pyproject.toml +48 -5
- dissect_fat-3.12.dev2/tests/conftest.py +43 -0
- dissect_fat-3.12.dev2/tests/data/exfat4m.bin +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/test_exceptions.py +3 -1
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/test_exfat.py +38 -1
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/test_fat.py +8 -4
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tox.ini +4 -10
- dissect_fat-3.11.dev1/tests/conftest.py +0 -35
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/COPYRIGHT +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/LICENSE +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/MANIFEST.in +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/README.md +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/dissect/fat/__init__.py +1 -1
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/dissect/fat/exceptions.py +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/dissect.fat.egg-info/dependency_links.txt +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/dissect.fat.egg-info/requires.txt +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/dissect.fat.egg-info/top_level.txt +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/setup.cfg +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/__init__.py +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/data/exfat.bin +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/data/fat12.bin +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/data/fat16.bin +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/data/fat32.bin +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/docs/Makefile +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/docs/conf.py +0 -0
- {dissect_fat-3.11.dev1 → dissect_fat-3.12.dev2}/tests/docs/index.rst +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: dissect.fat
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.12.dev2
|
|
4
4
|
Summary: A Dissect module implementing parsers for the FAT and exFAT file systems, commonly used on flash memory based storage devices and UEFI partitions
|
|
5
5
|
Author-email: Dissect Team <dissect@fox-it.com>
|
|
6
6
|
License: Affero General Public License v3
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
from dissect.cstruct import cstruct
|
|
2
4
|
|
|
3
5
|
exfat_def = """
|
|
@@ -79,7 +81,7 @@ typedef struct STREAM_DIRECTORY_ENTRY {
|
|
|
79
81
|
uint64 valid_data_length; // 0x08 allocated size of data in bytes only counts for files and is used for
|
|
80
82
|
// pre-allocation zero if directory
|
|
81
83
|
uint8 reserved_2[4]; // 0x10 no clue always zero
|
|
82
|
-
uint32 location; //
|
|
84
|
+
uint32 location; // 0x14 starting cluster of data
|
|
83
85
|
uint64 data_length; // 0x18 actual size of data if directory always multiples of sector size
|
|
84
86
|
};
|
|
85
87
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import logging
|
|
2
4
|
import os
|
|
3
5
|
import struct
|
|
4
6
|
from collections import OrderedDict
|
|
5
7
|
from itertools import groupby
|
|
6
8
|
from operator import itemgetter
|
|
9
|
+
from typing import BinaryIO
|
|
7
10
|
|
|
8
11
|
from dissect.util.stream import RangeStream, RunlistStream
|
|
9
12
|
|
|
@@ -27,7 +30,7 @@ log.setLevel(os.getenv("DISSECT_LOG_EXFAT", "CRITICAL"))
|
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
class ExFAT:
|
|
30
|
-
def __init__(self, fh):
|
|
33
|
+
def __init__(self, fh: BinaryIO):
|
|
31
34
|
self.filesystem = fh
|
|
32
35
|
fh.seek(0)
|
|
33
36
|
|
|
@@ -56,7 +59,7 @@ class ExFAT:
|
|
|
56
59
|
self.upcase_table = self.root_directory.upcase_entry
|
|
57
60
|
self.volume_label = self.root_directory.volume_entry.volume_label.strip("\x00")
|
|
58
61
|
|
|
59
|
-
def cluster_to_sector(self, cluster):
|
|
62
|
+
def cluster_to_sector(self, cluster: int) -> int | None:
|
|
60
63
|
"""
|
|
61
64
|
Returns the clusters' corresponding sector address
|
|
62
65
|
|
|
@@ -70,7 +73,7 @@ class ExFAT:
|
|
|
70
73
|
sector = ((cluster - 2) * (2**self.vbr.sectors_per_cluster_exp)) + self.cluster_heap_sector
|
|
71
74
|
return sector if sector > 0 else None
|
|
72
75
|
|
|
73
|
-
def sector_to_cluster(self, sector):
|
|
76
|
+
def sector_to_cluster(self, sector: int) -> int | None:
|
|
74
77
|
"""
|
|
75
78
|
Returns the sectors' corresponding cluster address
|
|
76
79
|
|
|
@@ -84,41 +87,45 @@ class ExFAT:
|
|
|
84
87
|
cluster = ((sector - self.cluster_to_sector(2)) // self.sector_size) + 2
|
|
85
88
|
return cluster if cluster >= 2 else None
|
|
86
89
|
|
|
87
|
-
def runlist(
|
|
90
|
+
def runlist(
|
|
91
|
+
self, starting_cluster: int, not_fragmented: bool = True, size: int | None = None
|
|
92
|
+
) -> list[tuple[int, int]]:
|
|
88
93
|
"""
|
|
89
|
-
Creates a RunlistStream compatible runlist from exFAT FAT structures
|
|
94
|
+
Creates a RunlistStream compatible runlist from exFAT FAT structures, in sectors.
|
|
90
95
|
|
|
91
96
|
Args:
|
|
92
97
|
starting_cluster (int): First cluster of file, folder or location in question
|
|
93
98
|
|
|
94
99
|
Returns:
|
|
95
|
-
runlist: [(sector_offset,
|
|
100
|
+
runlist: [(sector_offset, run_length_in_sectors)]"""
|
|
96
101
|
|
|
97
102
|
# If file is not fragmented clusters will not be present in the FAT
|
|
98
103
|
cluster_chain = [starting_cluster] if not_fragmented else self.get_cluster_chain(starting_cluster)
|
|
99
104
|
runlist = []
|
|
105
|
+
sectors_per_cluster = 2**self.vbr.sectors_per_cluster_exp
|
|
100
106
|
|
|
101
107
|
# TODO Graceful way to construct a runlist of non-fragmented streams spanning multiple sectors
|
|
102
108
|
if size:
|
|
103
|
-
run = -(-size // self.cluster_size)
|
|
109
|
+
run = -(-size // self.cluster_size) * sectors_per_cluster
|
|
104
110
|
runlist.append((self.cluster_to_sector(cluster_chain[0]), run))
|
|
105
111
|
else:
|
|
106
112
|
# This is a somewhat convoluted, but short way to group successive
|
|
107
113
|
# clusters together.
|
|
108
114
|
# As the cluster numbers in the cluster_chain are strictly
|
|
109
|
-
# incrementing, a
|
|
115
|
+
# incrementing, a successive range of clusters will have the same
|
|
110
116
|
# delta with respect to their position in the cluster_chain, which
|
|
111
117
|
# is different from any other successive range, which is what is
|
|
112
118
|
# used in the groupby().
|
|
119
|
+
# Example: [(3, 1), (4, 1), (6, 1)] becomes [(3, 2), (6, 1)]
|
|
113
120
|
for _, cluster_group in groupby(enumerate(cluster_chain), lambda i: i[0] - i[1]):
|
|
114
121
|
run = list(map(itemgetter(1), cluster_group))
|
|
115
122
|
start_cluster = run[0]
|
|
116
|
-
run_len = len(run)
|
|
123
|
+
run_len = len(run) * sectors_per_cluster
|
|
117
124
|
runlist.append((self.cluster_to_sector(start_cluster), run_len))
|
|
118
125
|
|
|
119
126
|
return runlist
|
|
120
127
|
|
|
121
|
-
def get_cluster_chain(self, starting_cluster):
|
|
128
|
+
def get_cluster_chain(self, starting_cluster: int) -> list[int]:
|
|
122
129
|
"""
|
|
123
130
|
Reads the on disk FAT to construct the cluster chain
|
|
124
131
|
|
|
@@ -134,17 +141,17 @@ class ExFAT:
|
|
|
134
141
|
|
|
135
142
|
if starting_cluster < 2:
|
|
136
143
|
return chain
|
|
137
|
-
else:
|
|
138
|
-
while next_ != EOC:
|
|
139
|
-
self.fat.seek(starting_cluster * FAT_ENTRY_SIZE)
|
|
140
|
-
next_ = struct.unpack("<L", self.fat.read(FAT_ENTRY_SIZE))[0]
|
|
141
|
-
chain.append(starting_cluster)
|
|
142
|
-
starting_cluster = next_
|
|
143
144
|
|
|
144
|
-
|
|
145
|
+
while next_ != EOC:
|
|
146
|
+
self.fat.seek(starting_cluster * FAT_ENTRY_SIZE)
|
|
147
|
+
next_ = struct.unpack("<L", self.fat.read(FAT_ENTRY_SIZE))[0]
|
|
148
|
+
chain.append(starting_cluster)
|
|
149
|
+
starting_cluster = next_
|
|
150
|
+
|
|
151
|
+
return chain
|
|
145
152
|
|
|
146
153
|
@staticmethod
|
|
147
|
-
def _utc_timezone(timezone):
|
|
154
|
+
def _utc_timezone(timezone: int) -> dict[str, str | int]:
|
|
148
155
|
"""
|
|
149
156
|
Converts a Microsoft exFAT timezone byte to its UTC timezone equivalent
|
|
150
157
|
|
|
@@ -171,12 +178,12 @@ class ExFAT:
|
|
|
171
178
|
utc_name = f"UTC{hours:+03}:{minutes:02}"
|
|
172
179
|
|
|
173
180
|
return {"name": utc_name, "offset": utc_minute_offset}
|
|
174
|
-
|
|
175
|
-
|
|
181
|
+
|
|
182
|
+
return {"name": "localtime", "offset": 0}
|
|
176
183
|
|
|
177
184
|
|
|
178
185
|
class RootDirectory:
|
|
179
|
-
def __init__(self, fh, location, exfat):
|
|
186
|
+
def __init__(self, fh: BinaryIO, location: int, exfat: ExFAT):
|
|
180
187
|
self.exfat = exfat
|
|
181
188
|
self.location = location
|
|
182
189
|
self.size = 0
|
|
@@ -187,24 +194,24 @@ class RootDirectory:
|
|
|
187
194
|
self.dict = OrderedDict()
|
|
188
195
|
self._parse_root_dir(fh)
|
|
189
196
|
|
|
190
|
-
def _parse_root_dir(self, fh):
|
|
197
|
+
def _parse_root_dir(self, fh: BinaryIO) -> None:
|
|
191
198
|
"""
|
|
192
199
|
Parses the passed fh to construct the Root directory object"""
|
|
193
200
|
|
|
194
201
|
# Root dir is always present in FAT so we pass False to traverse the FAT table
|
|
195
202
|
# thus root dir is per definition fragmented
|
|
196
203
|
runlist = self.exfat.runlist(self.location, False)
|
|
197
|
-
size = 0
|
|
204
|
+
size = 0 # in bytes
|
|
198
205
|
|
|
199
206
|
# Calculate size of rootdir from runlist since rootdir has no size attribute
|
|
200
207
|
for run in runlist:
|
|
201
|
-
size += run[1] * self.exfat.
|
|
208
|
+
size += run[1] * self.exfat.sector_size
|
|
202
209
|
|
|
203
210
|
self.size = size
|
|
204
|
-
self.root_dir = RunlistStream(fh, runlist, self.size, self.exfat.
|
|
211
|
+
self.root_dir = RunlistStream(fh, runlist, self.size, self.exfat.sector_size)
|
|
205
212
|
self.dict = self._create_root_dir(self.root_dir)
|
|
206
213
|
|
|
207
|
-
def _parse_subdir(self, entry):
|
|
214
|
+
def _parse_subdir(self, entry: c_exfat.FILE) -> OrderedDict:
|
|
208
215
|
"""
|
|
209
216
|
Parses the given sub directory file directory entry for containing files
|
|
210
217
|
|
|
@@ -216,14 +223,14 @@ class RootDirectory:
|
|
|
216
223
|
"""
|
|
217
224
|
|
|
218
225
|
folder_location = entry.stream.location
|
|
219
|
-
folder_size = entry.stream.data_length
|
|
226
|
+
folder_size = entry.stream.data_length # in bytes
|
|
220
227
|
folder_runlist = self.exfat.runlist(folder_location, not_fragmented=entry.stream.flags.not_fragmented)
|
|
221
228
|
|
|
222
|
-
fh = RunlistStream(self.exfat.filesystem, folder_runlist, folder_size, self.exfat.
|
|
229
|
+
fh = RunlistStream(self.exfat.filesystem, folder_runlist, folder_size, self.exfat.sector_size)
|
|
223
230
|
return self._parse_file_entries(fh)
|
|
224
231
|
|
|
225
232
|
@staticmethod
|
|
226
|
-
def _construct_filename(fn_entries, is_dir=False):
|
|
233
|
+
def _construct_filename(fn_entries: list[c_exfat.FILENAME_DIRECTORY_ENTRY], is_dir: bool = False) -> str:
|
|
227
234
|
"""
|
|
228
235
|
Assembles the filename from given file name directory entries
|
|
229
236
|
|
|
@@ -245,7 +252,7 @@ class RootDirectory:
|
|
|
245
252
|
|
|
246
253
|
return filename if not is_dir else filename + "/"
|
|
247
254
|
|
|
248
|
-
def _parse_file_entries(self, fh):
|
|
255
|
+
def _parse_file_entries(self, fh: BinaryIO) -> OrderedDict:
|
|
249
256
|
"""
|
|
250
257
|
Finds and parses file entries in a given file handle (file like object)
|
|
251
258
|
|
|
@@ -269,26 +276,27 @@ class RootDirectory:
|
|
|
269
276
|
fnentry_count = metadata.subentry_count - 1
|
|
270
277
|
|
|
271
278
|
stream = c_exfat.STREAM_DIRECTORY_ENTRY(fh.read(DIR_ENTRY_SIZE))
|
|
272
|
-
fn_entries = []
|
|
273
|
-
|
|
274
|
-
for _ in range(fnentry_count):
|
|
275
|
-
fn_entries.append(c_exfat.FILENAME_DIRECTORY_ENTRY(fh.read(DIR_ENTRY_SIZE)))
|
|
279
|
+
fn_entries = [c_exfat.FILENAME_DIRECTORY_ENTRY(fh.read(DIR_ENTRY_SIZE)) for _ in range(fnentry_count)]
|
|
276
280
|
|
|
277
281
|
file_ = c_exfat.FILE(metadata=metadata, stream=stream, fn_entries=fn_entries)
|
|
278
282
|
if file_.metadata.attributes.directory:
|
|
279
|
-
# A directory will have its own file entry as
|
|
280
|
-
#
|
|
283
|
+
# A directory will have its own file entry as its first element and an ordered dict
|
|
284
|
+
# of file entry contained in it which can be accessed by their corresponding keys
|
|
281
285
|
filename = self._construct_filename(file_.fn_entries)
|
|
282
286
|
entries[filename] = (file_, self._parse_subdir(file_))
|
|
283
287
|
else:
|
|
284
288
|
filename = self._construct_filename(file_.fn_entries)
|
|
285
289
|
entries[filename] = (file_, None)
|
|
290
|
+
elif entry.entry_type == 0x00:
|
|
291
|
+
# We could break early on entry_type==0x00 (end-of-directory)
|
|
292
|
+
# since all following entries are expected to be 0x00 as well.
|
|
293
|
+
pass
|
|
286
294
|
else:
|
|
287
295
|
self._non_file_entries(entry)
|
|
288
296
|
|
|
289
297
|
return entries
|
|
290
298
|
|
|
291
|
-
def _non_file_entries(self, entry):
|
|
299
|
+
def _non_file_entries(self, entry: c_exfat.FILE_DIRECTORY_ENTRY) -> None:
|
|
292
300
|
if entry.entry_type == VOLUME_LABEL_ENTRY or entry.entry_type == NO_VOLUME_LABEL_ENTRY:
|
|
293
301
|
self.volume_entry = c_exfat.VOLUME_DIRECTORY_ENTRY(entry.dumps())
|
|
294
302
|
elif entry.entry_type == BITMAP_ENTRY:
|
|
@@ -296,7 +304,7 @@ class RootDirectory:
|
|
|
296
304
|
elif entry.entry_type == UPCASE_TABLE_ENTRY:
|
|
297
305
|
self.upcase_entry = c_exfat.UPCASE_DIRECTORY_ENTRY(entry.dumps())
|
|
298
306
|
|
|
299
|
-
def _create_root_dir(self, root_dir):
|
|
307
|
+
def _create_root_dir(self, root_dir: BinaryIO) -> OrderedDict:
|
|
300
308
|
"""
|
|
301
309
|
Since exFAT does not have a dedicated root directory entry
|
|
302
310
|
one has to be constructed form available parameters during filesystem parsing.
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
# - https://ogris.de/fatrepair/fat.c
|
|
3
3
|
# - https://github.com/nathanhi/pyfatfs
|
|
4
4
|
# - https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/fatgen103.doc
|
|
5
|
+
from __future__ import annotations
|
|
5
6
|
|
|
6
7
|
import datetime
|
|
7
8
|
import struct
|
|
8
9
|
from functools import lru_cache, reduce
|
|
9
10
|
from operator import itemgetter
|
|
11
|
+
from typing import TYPE_CHECKING, BinaryIO
|
|
10
12
|
|
|
11
13
|
from dissect.util.stream import RangeStream, RunlistStream
|
|
12
14
|
from dissect.util.ts import dostimestamp
|
|
@@ -34,9 +36,12 @@ from dissect.fat.exceptions import (
|
|
|
34
36
|
NotADirectoryError,
|
|
35
37
|
)
|
|
36
38
|
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
from collections.abc import Iterator
|
|
41
|
+
|
|
37
42
|
|
|
38
43
|
class FATFS:
|
|
39
|
-
def __init__(self, fh, encoding="ibm437"):
|
|
44
|
+
def __init__(self, fh: BinaryIO, encoding: str = "ibm437"):
|
|
40
45
|
self.fh = fh
|
|
41
46
|
self.encoding = encoding
|
|
42
47
|
|
|
@@ -89,8 +94,8 @@ class FATFS:
|
|
|
89
94
|
|
|
90
95
|
self.root = RootDirectory(self)
|
|
91
96
|
|
|
92
|
-
def get(self, path, dirent=None):
|
|
93
|
-
dirent =
|
|
97
|
+
def get(self, path: str, dirent: DirectoryEntry | RootDirectory | None = None) -> DirectoryEntry | RootDirectory:
|
|
98
|
+
dirent = dirent if dirent else self.root
|
|
94
99
|
|
|
95
100
|
# Programmatically we will often use the `/` separator, so replace it with the native path separator of FAT
|
|
96
101
|
# `/` is an illegal character in FAT filenames, so it's safe to replace
|
|
@@ -113,7 +118,7 @@ class FATFS:
|
|
|
113
118
|
return dirent
|
|
114
119
|
|
|
115
120
|
|
|
116
|
-
def validate_bpb(bpb):
|
|
121
|
+
def validate_bpb(bpb: c_fat.Bpb | bytes) -> None:
|
|
117
122
|
if isinstance(bpb, bytes):
|
|
118
123
|
bpb = c_fat.Bpb(bpb[: len(c_fat.Bpb)])
|
|
119
124
|
|
|
@@ -146,7 +151,7 @@ def validate_bpb(bpb):
|
|
|
146
151
|
|
|
147
152
|
|
|
148
153
|
class FAT:
|
|
149
|
-
def __init__(self, fh, fattype):
|
|
154
|
+
def __init__(self, fh: BinaryIO, fattype: Fattype):
|
|
150
155
|
self.fh = fh
|
|
151
156
|
|
|
152
157
|
if fattype == Fattype.FAT12:
|
|
@@ -162,7 +167,7 @@ class FAT:
|
|
|
162
167
|
|
|
163
168
|
self.get = lru_cache(4096)(self.get)
|
|
164
169
|
|
|
165
|
-
def get(self, cluster):
|
|
170
|
+
def get(self, cluster: int) -> int | None:
|
|
166
171
|
if cluster >= self.entry_count:
|
|
167
172
|
raise ValueError(f"Cluster exceeds FAT entry count: {cluster} >= {self.entry_count}")
|
|
168
173
|
|
|
@@ -171,20 +176,21 @@ class FAT:
|
|
|
171
176
|
self.fh.seek(offset_in_fat)
|
|
172
177
|
value = struct.unpack("<H", self.fh.read(2))[0]
|
|
173
178
|
|
|
174
|
-
if cluster & 1
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return value & 0x0FFF
|
|
178
|
-
elif self.bits_per_entry == 16:
|
|
179
|
+
return value >> 4 if cluster & 1 else value & 0x0FFF
|
|
180
|
+
|
|
181
|
+
if self.bits_per_entry == 16:
|
|
179
182
|
offset_in_fat = cluster * 2
|
|
180
183
|
self.fh.seek(offset_in_fat)
|
|
181
184
|
return struct.unpack("<H", self.fh.read(2))[0]
|
|
182
|
-
|
|
185
|
+
|
|
186
|
+
if self.bits_per_entry == 32:
|
|
183
187
|
offset_in_fat = cluster * 4
|
|
184
188
|
self.fh.seek(offset_in_fat)
|
|
185
189
|
return struct.unpack("<I", self.fh.read(4))[0] & 0x0FFFFFFF # FAT32 clusters are 28 bits
|
|
186
190
|
|
|
187
|
-
|
|
191
|
+
raise ValueError("Unsupported FAT type")
|
|
192
|
+
|
|
193
|
+
def chain(self, cluster: int) -> Iterator[int]:
|
|
188
194
|
bits = self.bits_per_entry
|
|
189
195
|
while True:
|
|
190
196
|
value = self.get(cluster)
|
|
@@ -209,7 +215,7 @@ class FAT:
|
|
|
209
215
|
|
|
210
216
|
cluster = value
|
|
211
217
|
|
|
212
|
-
def runlist(self, cluster):
|
|
218
|
+
def runlist(self, cluster: int) -> Iterator[tuple[int, int]]:
|
|
213
219
|
"""Create a runlist from a cluster chain.
|
|
214
220
|
|
|
215
221
|
First two clusters are reserved, so substract those.
|
|
@@ -232,7 +238,7 @@ class FAT:
|
|
|
232
238
|
|
|
233
239
|
|
|
234
240
|
class DirectoryEntry:
|
|
235
|
-
def __init__(self, fs, fh, parent=None):
|
|
241
|
+
def __init__(self, fs: FATFS, fh: BinaryIO, parent: DirectoryEntry | RootDirectory | None = None):
|
|
236
242
|
self.fs = fs
|
|
237
243
|
self.parent = parent
|
|
238
244
|
|
|
@@ -267,7 +273,7 @@ class DirectoryEntry:
|
|
|
267
273
|
self.dirent = c_fat.Dirent(buf)
|
|
268
274
|
|
|
269
275
|
self.ldirents.sort(key=lambda e: e.LDIR_Ord & 0x3F)
|
|
270
|
-
name_map =
|
|
276
|
+
name_map = (e.LDIR_Name1 + e.LDIR_Name2 + e.LDIR_Name3 for e in self.ldirents)
|
|
271
277
|
name_reduce = bytes(reduce(lambda a, b: a + b, name_map))
|
|
272
278
|
self.name = c_fat.wchar[None](name_reduce + b"\x00\x00")
|
|
273
279
|
else:
|
|
@@ -280,69 +286,68 @@ class DirectoryEntry:
|
|
|
280
286
|
base = dir_name[:8].decode(self.fs.encoding).rstrip("\x00").rstrip()
|
|
281
287
|
ext = dir_name[8:].decode(self.fs.encoding).rstrip("\x00").rstrip()
|
|
282
288
|
|
|
283
|
-
self.short_name = "."
|
|
289
|
+
self.short_name = f"{base}.{ext}" if ext else base
|
|
284
290
|
if not self.name:
|
|
285
291
|
self.name = self.short_name
|
|
286
292
|
|
|
287
293
|
self._runlist = None
|
|
288
294
|
self._entries = None
|
|
289
295
|
|
|
290
|
-
def __repr__(self):
|
|
296
|
+
def __repr__(self) -> str:
|
|
291
297
|
return f"<DirectoryEntry name={self.name}>"
|
|
292
298
|
|
|
293
299
|
@property
|
|
294
|
-
def path(self):
|
|
300
|
+
def path(self) -> str:
|
|
295
301
|
return "\\".join([self.parent.path if self.parent else "", self.name]).lstrip("\\")
|
|
296
302
|
|
|
297
303
|
@property
|
|
298
|
-
def size(self):
|
|
304
|
+
def size(self) -> size:
|
|
299
305
|
if self.is_directory():
|
|
300
306
|
return sum(map(itemgetter(1), self.dataruns())) * self.fs.cluster_size
|
|
301
|
-
|
|
302
|
-
return self.dirent.DIR_FileSize
|
|
307
|
+
return self.dirent.DIR_FileSize
|
|
303
308
|
|
|
304
309
|
@property
|
|
305
|
-
def cluster(self):
|
|
310
|
+
def cluster(self) -> int:
|
|
306
311
|
return (self.dirent.DIR_FstClusHI << 16) | self.dirent.DIR_FstClusLO
|
|
307
312
|
|
|
308
313
|
@property
|
|
309
|
-
def ctime(self):
|
|
314
|
+
def ctime(self) -> datetime.datetime:
|
|
310
315
|
if self.dirent.DIR_CrtDate and self.dirent.DIR_CrtTime:
|
|
311
316
|
return dostimestamp(
|
|
312
317
|
(self.dirent.DIR_CrtDate << 16) | self.dirent.DIR_CrtTime,
|
|
313
318
|
self.dirent.DIR_CrtTimeTenth,
|
|
314
319
|
)
|
|
315
|
-
return datetime.datetime(1980, 1, 1)
|
|
320
|
+
return datetime.datetime(1980, 1, 1) # noqa: DTZ001
|
|
316
321
|
|
|
317
322
|
@property
|
|
318
|
-
def atime(self):
|
|
323
|
+
def atime(self) -> datetime.datetime:
|
|
319
324
|
if self.dirent.DIR_LstAccDate:
|
|
320
325
|
return dostimestamp(self.dirent.DIR_LstAccDate << 16)
|
|
321
|
-
return datetime.datetime(1980, 1, 1)
|
|
326
|
+
return datetime.datetime(1980, 1, 1) # noqa: DTZ001
|
|
322
327
|
|
|
323
328
|
@property
|
|
324
|
-
def mtime(self):
|
|
329
|
+
def mtime(self) -> datetime.datetime:
|
|
325
330
|
return dostimestamp((self.dirent.DIR_WrtDate << 16) | self.dirent.DIR_WrtTime)
|
|
326
331
|
|
|
327
|
-
def is_readonly(self):
|
|
332
|
+
def is_readonly(self) -> bool:
|
|
328
333
|
return bool(self.dirent.DIR_Attr & c_fat.ATTR_READ_ONLY)
|
|
329
334
|
|
|
330
|
-
def is_hidden(self):
|
|
335
|
+
def is_hidden(self) -> bool:
|
|
331
336
|
return bool(self.dirent.DIR_Attr & c_fat.ATTR_HIDDEN)
|
|
332
337
|
|
|
333
|
-
def is_system(self):
|
|
338
|
+
def is_system(self) -> bool:
|
|
334
339
|
return bool(self.dirent.DIR_Attr & c_fat.ATTR_SYSTEM)
|
|
335
340
|
|
|
336
|
-
def is_volume_id(self):
|
|
341
|
+
def is_volume_id(self) -> bool:
|
|
337
342
|
return bool(self.dirent.DIR_Attr & c_fat.ATTR_VOLUME_ID)
|
|
338
343
|
|
|
339
|
-
def is_directory(self):
|
|
344
|
+
def is_directory(self) -> bool:
|
|
340
345
|
return bool(self.dirent.DIR_Attr & c_fat.ATTR_DIRECTORY)
|
|
341
346
|
|
|
342
|
-
def is_archive(self):
|
|
347
|
+
def is_archive(self) -> bool:
|
|
343
348
|
return bool(self.dirent.DIR_Attr & c_fat.ATTR_ARCHIVE)
|
|
344
349
|
|
|
345
|
-
def iterdir(self):
|
|
350
|
+
def iterdir(self) -> Iterator[DirectoryEntry]:
|
|
346
351
|
if not self.is_directory():
|
|
347
352
|
raise NotADirectoryError(self.name)
|
|
348
353
|
|
|
@@ -356,17 +361,17 @@ class DirectoryEntry:
|
|
|
356
361
|
else:
|
|
357
362
|
yield from self._entries
|
|
358
363
|
|
|
359
|
-
def dataruns(self):
|
|
364
|
+
def dataruns(self) -> list[tuple[int, int]]:
|
|
360
365
|
if self._runlist is None:
|
|
361
366
|
self._runlist = [] if self.cluster == FREE_CLUSTER else list(self.fs.fat.runlist(self.cluster))
|
|
362
367
|
return self._runlist
|
|
363
368
|
|
|
364
|
-
def open(self):
|
|
369
|
+
def open(self) -> RunlistStream:
|
|
365
370
|
return RunlistStream(self.fs.data_stream, self.dataruns(), self.size, self.fs.cluster_size)
|
|
366
371
|
|
|
367
372
|
|
|
368
373
|
class RootDirectory(DirectoryEntry):
|
|
369
|
-
def __init__(self, fs):
|
|
374
|
+
def __init__(self, fs: FATFS):
|
|
370
375
|
self.fs = fs
|
|
371
376
|
self.name = "\\"
|
|
372
377
|
self.short_name = self.name
|
|
@@ -375,53 +380,52 @@ class RootDirectory(DirectoryEntry):
|
|
|
375
380
|
self._entries = None
|
|
376
381
|
|
|
377
382
|
@property
|
|
378
|
-
def path(self):
|
|
383
|
+
def path(self) -> str:
|
|
379
384
|
return ""
|
|
380
385
|
|
|
381
386
|
@property
|
|
382
|
-
def size(self):
|
|
387
|
+
def size(self) -> int:
|
|
383
388
|
if self.fs.type in (Fattype.FAT12, Fattype.FAT16):
|
|
384
389
|
return self.fs.bpb.BPB_RootEntCnt * 32
|
|
385
|
-
|
|
386
|
-
return sum(map(itemgetter(1), self.dataruns())) * self.fs.cluster_size
|
|
390
|
+
return sum(map(itemgetter(1), self.dataruns())) * self.fs.cluster_size
|
|
387
391
|
|
|
388
392
|
@property
|
|
389
|
-
def cluster(self):
|
|
393
|
+
def cluster(self) -> int | None:
|
|
390
394
|
if self.fs.type == Fattype.FAT32:
|
|
391
395
|
return self.fs.bpb_ext.BPB_RootClus
|
|
392
396
|
return None
|
|
393
397
|
|
|
394
398
|
@property
|
|
395
|
-
def ctime(self):
|
|
396
|
-
return datetime.datetime(1980, 1, 1)
|
|
399
|
+
def ctime(self) -> datetime.datetime:
|
|
400
|
+
return datetime.datetime(1980, 1, 1) # noqa: DTZ001
|
|
397
401
|
|
|
398
402
|
@property
|
|
399
|
-
def atime(self):
|
|
400
|
-
return datetime.datetime(1980, 1, 1)
|
|
403
|
+
def atime(self) -> datetime.datetime:
|
|
404
|
+
return datetime.datetime(1980, 1, 1) # noqa: DTZ001
|
|
401
405
|
|
|
402
406
|
@property
|
|
403
|
-
def mtime(self):
|
|
404
|
-
return datetime.datetime(1980, 1, 1)
|
|
407
|
+
def mtime(self) -> datetime.datetime:
|
|
408
|
+
return datetime.datetime(1980, 1, 1) # noqa: DTZ001
|
|
405
409
|
|
|
406
|
-
def is_readonly(self):
|
|
410
|
+
def is_readonly(self) -> bool:
|
|
407
411
|
return False
|
|
408
412
|
|
|
409
|
-
def is_hidden(self):
|
|
413
|
+
def is_hidden(self) -> bool:
|
|
410
414
|
return False
|
|
411
415
|
|
|
412
|
-
def is_system(self):
|
|
416
|
+
def is_system(self) -> bool:
|
|
413
417
|
return False
|
|
414
418
|
|
|
415
|
-
def is_volume_id(self):
|
|
419
|
+
def is_volume_id(self) -> bool:
|
|
416
420
|
return False
|
|
417
421
|
|
|
418
|
-
def is_directory(self):
|
|
422
|
+
def is_directory(self) -> bool:
|
|
419
423
|
return True
|
|
420
424
|
|
|
421
|
-
def is_archive(self):
|
|
425
|
+
def is_archive(self) -> bool:
|
|
422
426
|
return False
|
|
423
427
|
|
|
424
|
-
def iterdir(self):
|
|
428
|
+
def iterdir(self) -> Iterator[DirectoryEntry]:
|
|
425
429
|
if not self._entries:
|
|
426
430
|
entries = []
|
|
427
431
|
for entry in _iter_dirent(self.fs, self.open(), self):
|
|
@@ -432,29 +436,30 @@ class RootDirectory(DirectoryEntry):
|
|
|
432
436
|
else:
|
|
433
437
|
yield from self._entries
|
|
434
438
|
|
|
435
|
-
def dataruns(self):
|
|
439
|
+
def dataruns(self) -> list[tuple[int, int]]:
|
|
436
440
|
if self._runlist is None:
|
|
437
441
|
self._runlist = [] if self.cluster == FREE_CLUSTER else list(self.fs.fat.runlist(self.cluster))
|
|
438
442
|
return self._runlist
|
|
439
443
|
|
|
440
|
-
def open(self):
|
|
444
|
+
def open(self) -> RangeStream | RunlistStream:
|
|
441
445
|
if self.fs.type in (Fattype.FAT12, Fattype.FAT16):
|
|
442
446
|
root_dir_sector = self.fs.bpb.BPB_RsvdSecCnt + (self.fs.fat_size * self.fs.bpb.BPB_NumFATs)
|
|
443
447
|
offset = root_dir_sector * self.fs.sector_size
|
|
444
448
|
return RangeStream(self.fs.fh, offset, self.size)
|
|
445
|
-
|
|
446
|
-
return RunlistStream(self.fs.data_stream, self.dataruns(), self.size, self.fs.cluster_size)
|
|
449
|
+
return RunlistStream(self.fs.data_stream, self.dataruns(), self.size, self.fs.cluster_size)
|
|
447
450
|
|
|
448
451
|
|
|
449
|
-
def mask(v, bits):
|
|
452
|
+
def mask(v: int, bits: int) -> int:
|
|
450
453
|
return v & ((1 << bits) - 1)
|
|
451
454
|
|
|
452
455
|
|
|
453
|
-
def _iter_dirent(
|
|
456
|
+
def _iter_dirent(
|
|
457
|
+
fs: FATFS, fh: BinaryIO, parent: DirectoryEntry | RootDirectory | None = None
|
|
458
|
+
) -> Iterator[DirectoryEntry]:
|
|
454
459
|
while True:
|
|
455
460
|
try:
|
|
456
461
|
yield DirectoryEntry(fs, fh, parent)
|
|
457
|
-
except EmptyDirectoryError:
|
|
462
|
+
except EmptyDirectoryError: # noqa: PERF203
|
|
458
463
|
continue
|
|
459
464
|
except LastEmptyDirectoryError:
|
|
460
465
|
break
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: dissect.fat
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.12.dev2
|
|
4
4
|
Summary: A Dissect module implementing parsers for the FAT and exFAT file systems, commonly used on flash memory based storage devices and UEFI partitions
|
|
5
5
|
Author-email: Dissect Team <dissect@fox-it.com>
|
|
6
6
|
License: Affero General Public License v3
|
|
@@ -41,13 +41,56 @@ dev = [
|
|
|
41
41
|
"dissect.util>=3.0.dev,<4.0.dev",
|
|
42
42
|
]
|
|
43
43
|
|
|
44
|
-
[tool.
|
|
44
|
+
[tool.ruff]
|
|
45
45
|
line-length = 120
|
|
46
|
+
required-version = ">=0.9.0"
|
|
46
47
|
|
|
47
|
-
[tool.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
[tool.ruff.format]
|
|
49
|
+
docstring-code-format = true
|
|
50
|
+
|
|
51
|
+
[tool.ruff.lint]
|
|
52
|
+
select = [
|
|
53
|
+
"F",
|
|
54
|
+
"E",
|
|
55
|
+
"W",
|
|
56
|
+
"I",
|
|
57
|
+
"UP",
|
|
58
|
+
"YTT",
|
|
59
|
+
"ANN",
|
|
60
|
+
"B",
|
|
61
|
+
"C4",
|
|
62
|
+
"DTZ",
|
|
63
|
+
"T10",
|
|
64
|
+
"FA",
|
|
65
|
+
"ISC",
|
|
66
|
+
"G",
|
|
67
|
+
"INP",
|
|
68
|
+
"PIE",
|
|
69
|
+
"PYI",
|
|
70
|
+
"PT",
|
|
71
|
+
"Q",
|
|
72
|
+
"RSE",
|
|
73
|
+
"RET",
|
|
74
|
+
"SLOT",
|
|
75
|
+
"SIM",
|
|
76
|
+
"TID",
|
|
77
|
+
"TCH",
|
|
78
|
+
"PTH",
|
|
79
|
+
"PLC",
|
|
80
|
+
"TRY",
|
|
81
|
+
"FLY",
|
|
82
|
+
"PERF",
|
|
83
|
+
"FURB",
|
|
84
|
+
"RUF",
|
|
85
|
+
]
|
|
86
|
+
ignore = ["E203", "B904", "UP024", "ANN002", "ANN003", "ANN204", "ANN401", "SIM105", "TRY003"]
|
|
87
|
+
|
|
88
|
+
[tool.ruff.lint.per-file-ignores]
|
|
89
|
+
"tests/docs/**" = ["INP001"]
|
|
90
|
+
|
|
91
|
+
[tool.ruff.lint.isort]
|
|
92
|
+
known-first-party = ["dissect.fat"]
|
|
93
|
+
known-third-party = ["dissect"]
|
|
51
94
|
|
|
52
95
|
[tool.setuptools]
|
|
53
96
|
license-files = ["LICENSE", "COPYRIGHT"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import TYPE_CHECKING, BinaryIO
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from collections.abc import Iterator
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def absolute_path(filename: str) -> Path:
|
|
13
|
+
return Path(__file__).parent / filename
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def open_file(name: str, mode: str = "rb") -> Iterator[BinaryIO]:
|
|
17
|
+
with absolute_path(name).open(mode) as f:
|
|
18
|
+
yield f
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.fixture
|
|
22
|
+
def exfat_simple() -> Iterator[BinaryIO]:
|
|
23
|
+
yield from open_file("data/exfat.bin")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.fixture
|
|
27
|
+
def exfat_4m() -> Iterator[BinaryIO]:
|
|
28
|
+
yield from open_file("data/exfat4m.bin")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@pytest.fixture
|
|
32
|
+
def fat12() -> Iterator[BinaryIO]:
|
|
33
|
+
yield from open_file("data/fat12.bin")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.fixture
|
|
37
|
+
def fat16() -> Iterator[BinaryIO]:
|
|
38
|
+
yield from open_file("data/fat16.bin")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.fixture
|
|
42
|
+
def fat32() -> Iterator[BinaryIO]:
|
|
43
|
+
yield from open_file("data/fat32.bin")
|
|
Binary file
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import pytest
|
|
2
4
|
|
|
3
5
|
from dissect.fat import exceptions
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
@pytest.mark.parametrize(
|
|
7
|
-
"exc, std",
|
|
9
|
+
("exc", "std"),
|
|
8
10
|
[
|
|
9
11
|
(exceptions.FileNotFoundError, FileNotFoundError),
|
|
10
12
|
(exceptions.IsADirectoryError, IsADirectoryError),
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import BinaryIO
|
|
4
|
+
|
|
1
5
|
from dissect.fat import exfat
|
|
2
6
|
|
|
3
7
|
|
|
4
|
-
def test_exfat(exfat_simple):
|
|
8
|
+
def test_exfat(exfat_simple: BinaryIO) -> None:
|
|
5
9
|
e = exfat.ExFAT(exfat_simple)
|
|
6
10
|
|
|
7
11
|
assert e.volume_label == "THESIS"
|
|
@@ -39,3 +43,36 @@ def test_exfat(exfat_simple):
|
|
|
39
43
|
assert sysvol.metadata.attributes.directory == 1
|
|
40
44
|
assert sysvol.stream.flags.not_fragmented == 1
|
|
41
45
|
assert sysvol.stream.data_length == 512
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_exfat_4m(exfat_4m: BinaryIO) -> None:
|
|
49
|
+
e = exfat.ExFAT(exfat_4m)
|
|
50
|
+
|
|
51
|
+
assert e.volume_label == ""
|
|
52
|
+
assert e.cluster_count == 512
|
|
53
|
+
assert e.sector_size == 512
|
|
54
|
+
assert e.cluster_size == 4096
|
|
55
|
+
assert e.fat_sector == 2048
|
|
56
|
+
assert e.root_dir_cluster == 5
|
|
57
|
+
assert e.root_dir_sector == 4120
|
|
58
|
+
assert e.runlist(e.root_dir_cluster) == [(e.root_dir_sector, 8)]
|
|
59
|
+
|
|
60
|
+
files = e.files
|
|
61
|
+
assert sorted(files.keys()) == ["/"]
|
|
62
|
+
|
|
63
|
+
root = files["/"][0]
|
|
64
|
+
assert root.metadata.attributes.directory == 1
|
|
65
|
+
assert root.stream.flags.not_fragmented == 0
|
|
66
|
+
assert root.stream.data_length == 4096
|
|
67
|
+
|
|
68
|
+
empty_file = files["/"][1]["file.txt"][0]
|
|
69
|
+
assert empty_file.metadata.attributes.directory == 0
|
|
70
|
+
assert empty_file.stream.flags.not_fragmented == 0
|
|
71
|
+
assert empty_file.stream.data_length == 0
|
|
72
|
+
|
|
73
|
+
subdir = files["/"][1]["subdir"][0]
|
|
74
|
+
assert subdir.metadata.attributes.directory == 1
|
|
75
|
+
assert subdir.stream.flags.not_fragmented == 1
|
|
76
|
+
assert subdir.stream.data_length == 4096
|
|
77
|
+
|
|
78
|
+
assert sorted(files["/"][1]["subdir"][1].keys()) == ["sub.txt"]
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import BinaryIO
|
|
4
|
+
|
|
1
5
|
from dissect.fat import fat
|
|
2
6
|
|
|
3
7
|
|
|
4
|
-
def test_fat12(fat12):
|
|
8
|
+
def test_fat12(fat12: BinaryIO) -> None:
|
|
5
9
|
volume_label = "VOLLAB1"
|
|
6
10
|
|
|
7
11
|
fs = fat.FATFS(fat12)
|
|
@@ -15,7 +19,7 @@ def test_fat12(fat12):
|
|
|
15
19
|
verify_fs_content(fs, volume_label)
|
|
16
20
|
|
|
17
21
|
|
|
18
|
-
def test_fat16(fat16):
|
|
22
|
+
def test_fat16(fat16: BinaryIO) -> None:
|
|
19
23
|
volume_label = "LABFAT16"
|
|
20
24
|
|
|
21
25
|
fs = fat.FATFS(fat16)
|
|
@@ -29,7 +33,7 @@ def test_fat16(fat16):
|
|
|
29
33
|
verify_fs_content(fs, volume_label)
|
|
30
34
|
|
|
31
35
|
|
|
32
|
-
def test_fat32(fat32):
|
|
36
|
+
def test_fat32(fat32: BinaryIO) -> None:
|
|
33
37
|
volume_label = "LABFAT32"
|
|
34
38
|
|
|
35
39
|
fs = fat.FATFS(fat32)
|
|
@@ -43,7 +47,7 @@ def test_fat32(fat32):
|
|
|
43
47
|
verify_fs_content(fs, volume_label)
|
|
44
48
|
|
|
45
49
|
|
|
46
|
-
def verify_fs_content(fs, volume_label):
|
|
50
|
+
def verify_fs_content(fs: fat.FATFS, volume_label: str) -> None:
|
|
47
51
|
entries_map = {e.name: e for e in fs.root.iterdir()}
|
|
48
52
|
|
|
49
53
|
assert set(entries_map.keys()) == {volume_label, "file1.txt", "file2.txt", "subdir1"}
|
|
@@ -32,23 +32,17 @@ commands =
|
|
|
32
32
|
[testenv:fix]
|
|
33
33
|
package = skip
|
|
34
34
|
deps =
|
|
35
|
-
|
|
36
|
-
isort==5.11.4
|
|
35
|
+
ruff==0.9.2
|
|
37
36
|
commands =
|
|
38
|
-
|
|
39
|
-
isort dissect tests
|
|
37
|
+
ruff format dissect tests
|
|
40
38
|
|
|
41
39
|
[testenv:lint]
|
|
42
40
|
package = skip
|
|
43
41
|
deps =
|
|
44
|
-
|
|
45
|
-
flake8
|
|
46
|
-
flake8-black
|
|
47
|
-
flake8-isort
|
|
48
|
-
isort==5.11.4
|
|
42
|
+
ruff==0.9.2
|
|
49
43
|
vermin
|
|
50
44
|
commands =
|
|
51
|
-
|
|
45
|
+
ruff check dissect tests
|
|
52
46
|
vermin -t=3.9- --no-tips --lint dissect tests
|
|
53
47
|
|
|
54
48
|
[flake8]
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
import pytest
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def absolute_path(filename):
|
|
7
|
-
return os.path.join(os.path.dirname(__file__), filename)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@pytest.fixture
|
|
11
|
-
def exfat_simple():
|
|
12
|
-
name = "data/exfat.bin"
|
|
13
|
-
with open(absolute_path(name), "rb") as f:
|
|
14
|
-
yield f
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@pytest.fixture
|
|
18
|
-
def fat12():
|
|
19
|
-
name = "data/fat12.bin"
|
|
20
|
-
with open(absolute_path(name), "rb") as f:
|
|
21
|
-
yield f
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@pytest.fixture
|
|
25
|
-
def fat16():
|
|
26
|
-
name = "data/fat16.bin"
|
|
27
|
-
with open(absolute_path(name), "rb") as f:
|
|
28
|
-
yield f
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@pytest.fixture
|
|
32
|
-
def fat32():
|
|
33
|
-
name = "data/fat32.bin"
|
|
34
|
-
with open(absolute_path(name), "rb") as f:
|
|
35
|
-
yield f
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -14,11 +14,11 @@ from dissect.fat.exfat import ExFAT
|
|
|
14
14
|
from dissect.fat.fat import FATFS
|
|
15
15
|
|
|
16
16
|
__all__ = [
|
|
17
|
-
"ExFAT",
|
|
18
17
|
"FATFS",
|
|
19
18
|
"BadClusterError",
|
|
20
19
|
"EmptyDirectoryError",
|
|
21
20
|
"Error",
|
|
21
|
+
"ExFAT",
|
|
22
22
|
"FileNotFoundError",
|
|
23
23
|
"FreeClusterError",
|
|
24
24
|
"InvalidBPB",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|