dissect.fat 3.12.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 +1 -1
- dissect/fat/c_exfat.py +2 -0
- dissect/fat/c_fat.py +2 -0
- dissect/fat/exfat.py +28 -26
- dissect/fat/fat.py +68 -63
- {dissect.fat-3.12.dev1.dist-info → dissect.fat-3.12.dev2.dist-info}/METADATA +1 -1
- dissect.fat-3.12.dev2.dist-info/RECORD +12 -0
- dissect.fat-3.12.dev1.dist-info/RECORD +0 -12
- {dissect.fat-3.12.dev1.dist-info → dissect.fat-3.12.dev2.dist-info}/COPYRIGHT +0 -0
- {dissect.fat-3.12.dev1.dist-info → dissect.fat-3.12.dev2.dist-info}/LICENSE +0 -0
- {dissect.fat-3.12.dev1.dist-info → dissect.fat-3.12.dev2.dist-info}/WHEEL +0 -0
- {dissect.fat-3.12.dev1.dist-info → dissect.fat-3.12.dev2.dist-info}/top_level.txt +0 -0
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
dissect/fat/c_fat.py
CHANGED
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,7 +87,9 @@ 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
94
|
Creates a RunlistStream compatible runlist from exFAT FAT structures, in sectors.
|
|
90
95
|
|
|
@@ -120,7 +125,7 @@ class ExFAT:
|
|
|
120
125
|
|
|
121
126
|
return runlist
|
|
122
127
|
|
|
123
|
-
def get_cluster_chain(self, starting_cluster):
|
|
128
|
+
def get_cluster_chain(self, starting_cluster: int) -> list[int]:
|
|
124
129
|
"""
|
|
125
130
|
Reads the on disk FAT to construct the cluster chain
|
|
126
131
|
|
|
@@ -136,17 +141,17 @@ class ExFAT:
|
|
|
136
141
|
|
|
137
142
|
if starting_cluster < 2:
|
|
138
143
|
return chain
|
|
139
|
-
else:
|
|
140
|
-
while next_ != EOC:
|
|
141
|
-
self.fat.seek(starting_cluster * FAT_ENTRY_SIZE)
|
|
142
|
-
next_ = struct.unpack("<L", self.fat.read(FAT_ENTRY_SIZE))[0]
|
|
143
|
-
chain.append(starting_cluster)
|
|
144
|
-
starting_cluster = next_
|
|
145
144
|
|
|
146
|
-
|
|
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
|
|
147
152
|
|
|
148
153
|
@staticmethod
|
|
149
|
-
def _utc_timezone(timezone):
|
|
154
|
+
def _utc_timezone(timezone: int) -> dict[str, str | int]:
|
|
150
155
|
"""
|
|
151
156
|
Converts a Microsoft exFAT timezone byte to its UTC timezone equivalent
|
|
152
157
|
|
|
@@ -173,12 +178,12 @@ class ExFAT:
|
|
|
173
178
|
utc_name = f"UTC{hours:+03}:{minutes:02}"
|
|
174
179
|
|
|
175
180
|
return {"name": utc_name, "offset": utc_minute_offset}
|
|
176
|
-
|
|
177
|
-
|
|
181
|
+
|
|
182
|
+
return {"name": "localtime", "offset": 0}
|
|
178
183
|
|
|
179
184
|
|
|
180
185
|
class RootDirectory:
|
|
181
|
-
def __init__(self, fh, location, exfat):
|
|
186
|
+
def __init__(self, fh: BinaryIO, location: int, exfat: ExFAT):
|
|
182
187
|
self.exfat = exfat
|
|
183
188
|
self.location = location
|
|
184
189
|
self.size = 0
|
|
@@ -189,7 +194,7 @@ class RootDirectory:
|
|
|
189
194
|
self.dict = OrderedDict()
|
|
190
195
|
self._parse_root_dir(fh)
|
|
191
196
|
|
|
192
|
-
def _parse_root_dir(self, fh):
|
|
197
|
+
def _parse_root_dir(self, fh: BinaryIO) -> None:
|
|
193
198
|
"""
|
|
194
199
|
Parses the passed fh to construct the Root directory object"""
|
|
195
200
|
|
|
@@ -206,7 +211,7 @@ class RootDirectory:
|
|
|
206
211
|
self.root_dir = RunlistStream(fh, runlist, self.size, self.exfat.sector_size)
|
|
207
212
|
self.dict = self._create_root_dir(self.root_dir)
|
|
208
213
|
|
|
209
|
-
def _parse_subdir(self, entry):
|
|
214
|
+
def _parse_subdir(self, entry: c_exfat.FILE) -> OrderedDict:
|
|
210
215
|
"""
|
|
211
216
|
Parses the given sub directory file directory entry for containing files
|
|
212
217
|
|
|
@@ -225,7 +230,7 @@ class RootDirectory:
|
|
|
225
230
|
return self._parse_file_entries(fh)
|
|
226
231
|
|
|
227
232
|
@staticmethod
|
|
228
|
-
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:
|
|
229
234
|
"""
|
|
230
235
|
Assembles the filename from given file name directory entries
|
|
231
236
|
|
|
@@ -247,7 +252,7 @@ class RootDirectory:
|
|
|
247
252
|
|
|
248
253
|
return filename if not is_dir else filename + "/"
|
|
249
254
|
|
|
250
|
-
def _parse_file_entries(self, fh):
|
|
255
|
+
def _parse_file_entries(self, fh: BinaryIO) -> OrderedDict:
|
|
251
256
|
"""
|
|
252
257
|
Finds and parses file entries in a given file handle (file like object)
|
|
253
258
|
|
|
@@ -271,10 +276,7 @@ class RootDirectory:
|
|
|
271
276
|
fnentry_count = metadata.subentry_count - 1
|
|
272
277
|
|
|
273
278
|
stream = c_exfat.STREAM_DIRECTORY_ENTRY(fh.read(DIR_ENTRY_SIZE))
|
|
274
|
-
fn_entries = []
|
|
275
|
-
|
|
276
|
-
for _ in range(fnentry_count):
|
|
277
|
-
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)]
|
|
278
280
|
|
|
279
281
|
file_ = c_exfat.FILE(metadata=metadata, stream=stream, fn_entries=fn_entries)
|
|
280
282
|
if file_.metadata.attributes.directory:
|
|
@@ -294,7 +296,7 @@ class RootDirectory:
|
|
|
294
296
|
|
|
295
297
|
return entries
|
|
296
298
|
|
|
297
|
-
def _non_file_entries(self, entry):
|
|
299
|
+
def _non_file_entries(self, entry: c_exfat.FILE_DIRECTORY_ENTRY) -> None:
|
|
298
300
|
if entry.entry_type == VOLUME_LABEL_ENTRY or entry.entry_type == NO_VOLUME_LABEL_ENTRY:
|
|
299
301
|
self.volume_entry = c_exfat.VOLUME_DIRECTORY_ENTRY(entry.dumps())
|
|
300
302
|
elif entry.entry_type == BITMAP_ENTRY:
|
|
@@ -302,7 +304,7 @@ class RootDirectory:
|
|
|
302
304
|
elif entry.entry_type == UPCASE_TABLE_ENTRY:
|
|
303
305
|
self.upcase_entry = c_exfat.UPCASE_DIRECTORY_ENTRY(entry.dumps())
|
|
304
306
|
|
|
305
|
-
def _create_root_dir(self, root_dir):
|
|
307
|
+
def _create_root_dir(self, root_dir: BinaryIO) -> OrderedDict:
|
|
306
308
|
"""
|
|
307
309
|
Since exFAT does not have a dedicated root directory entry
|
|
308
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 =
|
|
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
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: dissect.fat
|
|
3
|
-
Version: 3.12.
|
|
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
|
|
@@ -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,12 +0,0 @@
|
|
|
1
|
-
dissect/fat/__init__.py,sha256=ixEDhK-BjyIQrg5DESs-SN2PKu9E3MTUC0FLLhpJENc,614
|
|
2
|
-
dissect/fat/c_exfat.py,sha256=Q1XB_xcyMU8F57TxEhKsaRBpILDYZfxSp6haXW0FDu8,7514
|
|
3
|
-
dissect/fat/c_fat.py,sha256=XW6FqGCBKpAzyydGuYi6N0xIx0ALvWBhG6x9wI8XwXg,3817
|
|
4
|
-
dissect/fat/exceptions.py,sha256=IJp8wPgPt4Cqa9cE3uJCreejGFz40E7cWFGnWAF8G20,525
|
|
5
|
-
dissect/fat/exfat.py,sha256=ZddueVanO3IFsVDFuFy44X2E57sAA5OFeum_dvBvH2w,12331
|
|
6
|
-
dissect/fat/fat.py,sha256=dyqLXMHAwG0bK8KHq8e6GdRkdjO25nmkUf7_1EJH9D8,14545
|
|
7
|
-
dissect.fat-3.12.dev1.dist-info/COPYRIGHT,sha256=Y5VsNBCyT5OYAniWS_bHHM4jQruzGRj3RBS1zmhXY58,298
|
|
8
|
-
dissect.fat-3.12.dev1.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
|
|
9
|
-
dissect.fat-3.12.dev1.dist-info/METADATA,sha256=U2roZE-Ql6C62cyOkRWj1q5KjNAamobxImtZ3FNTm9Q,3304
|
|
10
|
-
dissect.fat-3.12.dev1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
11
|
-
dissect.fat-3.12.dev1.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
|
|
12
|
-
dissect.fat-3.12.dev1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|