dissect.fat 3.11.dev1__py3-none-any.whl → 3.12.dev2__py3-none-any.whl

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/__init__.py CHANGED
@@ -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",
dissect/fat/c_exfat.py CHANGED
@@ -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; // 0x15 starting cluster of data
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
 
dissect/fat/c_fat.py CHANGED
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from dissect.cstruct import cstruct
2
4
 
3
5
  # https://ogris.de/fatrepair/fat.c
dissect/fat/exfat.py CHANGED
@@ -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(self, starting_cluster, not_fragmented=True, size=None):
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, run_length)]"""
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 succesive range of clusters will have the same
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
- return chain
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
- else:
175
- return {"name": "localtime", "offset": 0}
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.cluster_size
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.cluster_size)
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.cluster_size)
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 it's first element
280
- # and a ordered dict of file entry contained in it which can be accessed by their corresponding keys
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.
dissect/fat/fat.py CHANGED
@@ -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 = self.root if not dirent else 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
- return value >> 4
176
- else:
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
- elif self.bits_per_entry == 32:
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
- def chain(self, cluster):
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 = map(lambda e: e.LDIR_Name1 + e.LDIR_Name2 + e.LDIR_Name3, self.ldirents)
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 = ".".join([base, ext]) if ext else base
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
- else:
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
- else:
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
- else:
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(fs, fh, parent=None):
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
1
+ Metadata-Version: 2.2
2
2
  Name: dissect.fat
3
- Version: 3.11.dev1
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
@@ -22,11 +22,11 @@ Requires-Python: ~=3.9
22
22
  Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  License-File: COPYRIGHT
25
- Requires-Dist: dissect.cstruct <5,>=4
26
- Requires-Dist: dissect.util <4,>=3
25
+ Requires-Dist: dissect.cstruct<5,>=4
26
+ Requires-Dist: dissect.util<4,>=3
27
27
  Provides-Extra: dev
28
- Requires-Dist: dissect.cstruct <5.0.dev,>=4.0.dev ; extra == 'dev'
29
- Requires-Dist: dissect.util <4.0.dev,>=3.0.dev ; extra == 'dev'
28
+ Requires-Dist: dissect.cstruct<5.0.dev,>=4.0.dev; extra == "dev"
29
+ Requires-Dist: dissect.util<4.0.dev,>=3.0.dev; extra == "dev"
30
30
 
31
31
  # dissect.fat
32
32
 
@@ -0,0 +1,12 @@
1
+ dissect/fat/__init__.py,sha256=BRoDzxtS23A8m8GSDxbr5NJVCgjvr1e9MNUyeg5QP9w,614
2
+ dissect/fat/c_exfat.py,sha256=40aY46lBTW8Z2pxC-kWz7DoxNmGP74OClKW8gXhQe3Q,7550
3
+ dissect/fat/c_fat.py,sha256=0t-BIdI3V-6jicrqRpdRINRfVbRy-jH-EWdw99RZW-w,3853
4
+ dissect/fat/exceptions.py,sha256=IJp8wPgPt4Cqa9cE3uJCreejGFz40E7cWFGnWAF8G20,525
5
+ dissect/fat/exfat.py,sha256=2vWXGqkfDrjr5WZUNTLvOdw0HQ_QZZQI59Aj-eYHU6w,12656
6
+ dissect/fat/fat.py,sha256=YIBtNQ5Us4FsNnTzOwVq8NeX-yTT1RvZduG34Ght9mA,15531
7
+ dissect.fat-3.12.dev2.dist-info/COPYRIGHT,sha256=Y5VsNBCyT5OYAniWS_bHHM4jQruzGRj3RBS1zmhXY58,298
8
+ dissect.fat-3.12.dev2.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
9
+ dissect.fat-3.12.dev2.dist-info/METADATA,sha256=5ZCQCWAcoLbQopSyOZoCG6gwS-GqHHKWfQTcHkk9FeA,3304
10
+ dissect.fat-3.12.dev2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
11
+ dissect.fat-3.12.dev2.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
12
+ dissect.fat-3.12.dev2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,12 +0,0 @@
1
- dissect/fat/__init__.py,sha256=ixEDhK-BjyIQrg5DESs-SN2PKu9E3MTUC0FLLhpJENc,614
2
- dissect/fat/c_exfat.py,sha256=mI3GWrR7RtClDIblAN0IXX2q-ItZaTvT1zxwWYM0Ymc,7514
3
- dissect/fat/c_fat.py,sha256=XW6FqGCBKpAzyydGuYi6N0xIx0ALvWBhG6x9wI8XwXg,3817
4
- dissect/fat/exceptions.py,sha256=IJp8wPgPt4Cqa9cE3uJCreejGFz40E7cWFGnWAF8G20,525
5
- dissect/fat/exfat.py,sha256=pvpT5yIfHyxKim5FThLePrYnfrOUUEdjD2KX-sELvF4,11881
6
- dissect/fat/fat.py,sha256=dyqLXMHAwG0bK8KHq8e6GdRkdjO25nmkUf7_1EJH9D8,14545
7
- dissect.fat-3.11.dev1.dist-info/COPYRIGHT,sha256=Y5VsNBCyT5OYAniWS_bHHM4jQruzGRj3RBS1zmhXY58,298
8
- dissect.fat-3.11.dev1.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
9
- dissect.fat-3.11.dev1.dist-info/METADATA,sha256=LZLfaPvRCKmo_XcJJmZrI1xoMaIyG4UXW2AKN9JItio,3310
10
- dissect.fat-3.11.dev1.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
11
- dissect.fat-3.11.dev1.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
12
- dissect.fat-3.11.dev1.dist-info/RECORD,,