dissect.fat 3.11__tar.gz → 3.12.dev1__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.
Files changed (32) hide show
  1. {dissect_fat-3.11/dissect.fat.egg-info → dissect_fat-3.12.dev1}/PKG-INFO +2 -2
  2. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/dissect/fat/c_exfat.py +1 -1
  3. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/dissect/fat/exfat.py +18 -12
  4. {dissect_fat-3.11 → dissect_fat-3.12.dev1/dissect.fat.egg-info}/PKG-INFO +2 -2
  5. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/dissect.fat.egg-info/SOURCES.txt +1 -0
  6. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/pyproject.toml +1 -0
  7. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/conftest.py +7 -0
  8. dissect_fat-3.12.dev1/tests/data/exfat4m.bin +0 -0
  9. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/test_exfat.py +33 -0
  10. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/COPYRIGHT +0 -0
  11. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/LICENSE +0 -0
  12. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/MANIFEST.in +0 -0
  13. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/README.md +0 -0
  14. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/dissect/fat/__init__.py +0 -0
  15. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/dissect/fat/c_fat.py +0 -0
  16. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/dissect/fat/exceptions.py +0 -0
  17. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/dissect/fat/fat.py +0 -0
  18. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/dissect.fat.egg-info/dependency_links.txt +0 -0
  19. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/dissect.fat.egg-info/requires.txt +0 -0
  20. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/dissect.fat.egg-info/top_level.txt +0 -0
  21. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/setup.cfg +0 -0
  22. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/__init__.py +0 -0
  23. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/data/exfat.bin +0 -0
  24. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/data/fat12.bin +0 -0
  25. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/data/fat16.bin +0 -0
  26. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/data/fat32.bin +0 -0
  27. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/docs/Makefile +0 -0
  28. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/docs/conf.py +0 -0
  29. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/docs/index.rst +0 -0
  30. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/test_exceptions.py +0 -0
  31. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tests/test_fat.py +0 -0
  32. {dissect_fat-3.11 → dissect_fat-3.12.dev1}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dissect.fat
3
- Version: 3.11
3
+ Version: 3.12.dev1
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
@@ -79,7 +79,7 @@ typedef struct STREAM_DIRECTORY_ENTRY {
79
79
  uint64 valid_data_length; // 0x08 allocated size of data in bytes only counts for files and is used for
80
80
  // pre-allocation zero if directory
81
81
  uint8 reserved_2[4]; // 0x10 no clue always zero
82
- uint32 location; // 0x15 starting cluster of data
82
+ uint32 location; // 0x14 starting cluster of data
83
83
  uint64 data_length; // 0x18 actual size of data if directory always multiples of sector size
84
84
  };
85
85
 
@@ -86,34 +86,36 @@ class ExFAT:
86
86
 
87
87
  def runlist(self, starting_cluster, not_fragmented=True, size=None):
88
88
  """
89
- Creates a RunlistStream compatible runlist from exFAT FAT structures
89
+ Creates a RunlistStream compatible runlist from exFAT FAT structures, in sectors.
90
90
 
91
91
  Args:
92
92
  starting_cluster (int): First cluster of file, folder or location in question
93
93
 
94
94
  Returns:
95
- runlist: [(sector_offset, run_length)]"""
95
+ runlist: [(sector_offset, run_length_in_sectors)]"""
96
96
 
97
97
  # If file is not fragmented clusters will not be present in the FAT
98
98
  cluster_chain = [starting_cluster] if not_fragmented else self.get_cluster_chain(starting_cluster)
99
99
  runlist = []
100
+ sectors_per_cluster = 2**self.vbr.sectors_per_cluster_exp
100
101
 
101
102
  # TODO Graceful way to construct a runlist of non-fragmented streams spanning multiple sectors
102
103
  if size:
103
- run = -(-size // self.cluster_size)
104
+ run = -(-size // self.cluster_size) * sectors_per_cluster
104
105
  runlist.append((self.cluster_to_sector(cluster_chain[0]), run))
105
106
  else:
106
107
  # This is a somewhat convoluted, but short way to group successive
107
108
  # clusters together.
108
109
  # As the cluster numbers in the cluster_chain are strictly
109
- # incrementing, a succesive range of clusters will have the same
110
+ # incrementing, a successive range of clusters will have the same
110
111
  # delta with respect to their position in the cluster_chain, which
111
112
  # is different from any other successive range, which is what is
112
113
  # used in the groupby().
114
+ # Example: [(3, 1), (4, 1), (6, 1)] becomes [(3, 2), (6, 1)]
113
115
  for _, cluster_group in groupby(enumerate(cluster_chain), lambda i: i[0] - i[1]):
114
116
  run = list(map(itemgetter(1), cluster_group))
115
117
  start_cluster = run[0]
116
- run_len = len(run)
118
+ run_len = len(run) * sectors_per_cluster
117
119
  runlist.append((self.cluster_to_sector(start_cluster), run_len))
118
120
 
119
121
  return runlist
@@ -194,14 +196,14 @@ class RootDirectory:
194
196
  # Root dir is always present in FAT so we pass False to traverse the FAT table
195
197
  # thus root dir is per definition fragmented
196
198
  runlist = self.exfat.runlist(self.location, False)
197
- size = 0
199
+ size = 0 # in bytes
198
200
 
199
201
  # Calculate size of rootdir from runlist since rootdir has no size attribute
200
202
  for run in runlist:
201
- size += run[1] * self.exfat.cluster_size
203
+ size += run[1] * self.exfat.sector_size
202
204
 
203
205
  self.size = size
204
- self.root_dir = RunlistStream(fh, runlist, self.size, self.exfat.cluster_size)
206
+ self.root_dir = RunlistStream(fh, runlist, self.size, self.exfat.sector_size)
205
207
  self.dict = self._create_root_dir(self.root_dir)
206
208
 
207
209
  def _parse_subdir(self, entry):
@@ -216,10 +218,10 @@ class RootDirectory:
216
218
  """
217
219
 
218
220
  folder_location = entry.stream.location
219
- folder_size = entry.stream.data_length
221
+ folder_size = entry.stream.data_length # in bytes
220
222
  folder_runlist = self.exfat.runlist(folder_location, not_fragmented=entry.stream.flags.not_fragmented)
221
223
 
222
- fh = RunlistStream(self.exfat.filesystem, folder_runlist, folder_size, self.exfat.cluster_size)
224
+ fh = RunlistStream(self.exfat.filesystem, folder_runlist, folder_size, self.exfat.sector_size)
223
225
  return self._parse_file_entries(fh)
224
226
 
225
227
  @staticmethod
@@ -276,13 +278,17 @@ class RootDirectory:
276
278
 
277
279
  file_ = c_exfat.FILE(metadata=metadata, stream=stream, fn_entries=fn_entries)
278
280
  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
281
+ # A directory will have its own file entry as its first element and an ordered dict
282
+ # of file entry contained in it which can be accessed by their corresponding keys
281
283
  filename = self._construct_filename(file_.fn_entries)
282
284
  entries[filename] = (file_, self._parse_subdir(file_))
283
285
  else:
284
286
  filename = self._construct_filename(file_.fn_entries)
285
287
  entries[filename] = (file_, None)
288
+ elif entry.entry_type == 0x00:
289
+ # We could break early on entry_type==0x00 (end-of-directory)
290
+ # since all following entries are expected to be 0x00 as well.
291
+ pass
286
292
  else:
287
293
  self._non_file_entries(entry)
288
294
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dissect.fat
3
- Version: 3.11
3
+ Version: 3.12.dev1
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
@@ -21,6 +21,7 @@ tests/test_exceptions.py
21
21
  tests/test_exfat.py
22
22
  tests/test_fat.py
23
23
  tests/data/exfat.bin
24
+ tests/data/exfat4m.bin
24
25
  tests/data/fat12.bin
25
26
  tests/data/fat16.bin
26
27
  tests/data/fat32.bin
@@ -56,3 +56,4 @@ license-files = ["LICENSE", "COPYRIGHT"]
56
56
  include = ["dissect.*"]
57
57
 
58
58
  [tool.setuptools_scm]
59
+ local_scheme = "no-local-version"
@@ -14,6 +14,13 @@ def exfat_simple():
14
14
  yield f
15
15
 
16
16
 
17
+ @pytest.fixture
18
+ def exfat_4m():
19
+ name = "data/exfat4m.bin"
20
+ with open(absolute_path(name), "rb") as f:
21
+ yield f
22
+
23
+
17
24
  @pytest.fixture
18
25
  def fat12():
19
26
  name = "data/fat12.bin"
@@ -39,3 +39,36 @@ def test_exfat(exfat_simple):
39
39
  assert sysvol.metadata.attributes.directory == 1
40
40
  assert sysvol.stream.flags.not_fragmented == 1
41
41
  assert sysvol.stream.data_length == 512
42
+
43
+
44
+ def test_exfat_4m(exfat_4m):
45
+ e = exfat.ExFAT(exfat_4m)
46
+
47
+ assert e.volume_label == ""
48
+ assert e.cluster_count == 512
49
+ assert e.sector_size == 512
50
+ assert e.cluster_size == 4096
51
+ assert e.fat_sector == 2048
52
+ assert e.root_dir_cluster == 5
53
+ assert e.root_dir_sector == 4120
54
+ assert e.runlist(e.root_dir_cluster) == [(e.root_dir_sector, 8)]
55
+
56
+ files = e.files
57
+ assert sorted(files.keys()) == ["/"]
58
+
59
+ root = files["/"][0]
60
+ assert root.metadata.attributes.directory == 1
61
+ assert root.stream.flags.not_fragmented == 0
62
+ assert root.stream.data_length == 4096
63
+
64
+ empty_file = files["/"][1]["file.txt"][0]
65
+ assert empty_file.metadata.attributes.directory == 0
66
+ assert empty_file.stream.flags.not_fragmented == 0
67
+ assert empty_file.stream.data_length == 0
68
+
69
+ subdir = files["/"][1]["subdir"][0]
70
+ assert subdir.metadata.attributes.directory == 1
71
+ assert subdir.stream.flags.not_fragmented == 1
72
+ assert subdir.stream.data_length == 4096
73
+
74
+ assert sorted(files["/"][1]["subdir"][1].keys()) == ["sub.txt"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes