dissect.extfs 3.13.dev1__tar.gz → 3.14__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 (33) hide show
  1. dissect_extfs-3.14/.git-blame-ignore-revs +6 -0
  2. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/PKG-INFO +3 -2
  3. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect/extfs/extfs.py +41 -89
  4. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect.extfs.egg-info/PKG-INFO +3 -2
  5. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect.extfs.egg-info/SOURCES.txt +2 -3
  6. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/pyproject.toml +0 -1
  7. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/tests/conftest.py +4 -0
  8. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/tests/test_ext4.py +4 -21
  9. dissect_extfs-3.13.dev1/tests/data/ext4_symlink_test2.bin.gz +0 -0
  10. dissect_extfs-3.13.dev1/tests/data/ext4_symlink_test3.bin.gz +0 -0
  11. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/.gitattributes +0 -0
  12. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/COPYRIGHT +0 -0
  13. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/LICENSE +0 -0
  14. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/MANIFEST.in +0 -0
  15. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/README.md +0 -0
  16. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect/extfs/__init__.py +0 -0
  17. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect/extfs/c_ext.py +0 -0
  18. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect/extfs/c_jdb2.py +0 -0
  19. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect/extfs/exceptions.py +0 -0
  20. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect/extfs/journal.py +0 -0
  21. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect.extfs.egg-info/dependency_links.txt +0 -0
  22. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect.extfs.egg-info/requires.txt +0 -0
  23. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/dissect.extfs.egg-info/top_level.txt +0 -0
  24. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/setup.cfg +0 -0
  25. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/tests/__init__.py +0 -0
  26. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/tests/data/ext4.bin.gz +0 -0
  27. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/tests/data/ext4_sparse.bin.gz +0 -0
  28. /dissect_extfs-3.13.dev1/tests/data/ext4_symlink_test1.bin.gz → /dissect_extfs-3.14/tests/data/ext4_symlink_test.bin.gz +0 -0
  29. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/tests/docs/Makefile +0 -0
  30. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/tests/docs/conf.py +0 -0
  31. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/tests/docs/index.rst +0 -0
  32. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/tests/test_exceptions.py +0 -0
  33. {dissect_extfs-3.13.dev1 → dissect_extfs-3.14}/tox.ini +0 -0
@@ -0,0 +1,6 @@
1
+ # Formatting commits. You can ignore them during git-blame with `--ignore-rev` or `--ignore-revs-file`.
2
+ #
3
+ # $ git config --add 'blame.ignoreRevsFile' '.git-blame-ignore-revs'
4
+ #
5
+ # Change linter to Ruff (#35)
6
+ b1ed30e2b6c178614aec845204419993f3f88dda
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: dissect.extfs
3
- Version: 3.13.dev1
3
+ Version: 3.14
4
4
  Summary: A Dissect module implementing a parser for the ExtFS file system, the native filesystem for Linux operating systems
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -27,6 +27,7 @@ Requires-Dist: dissect.util<4,>=3
27
27
  Provides-Extra: dev
28
28
  Requires-Dist: dissect.cstruct<5.0.dev,>=4.0.dev; extra == "dev"
29
29
  Requires-Dist: dissect.util<4.0.dev,>=3.0.dev; extra == "dev"
30
+ Dynamic: license-file
30
31
 
31
32
  # dissect.extfs
32
33
 
@@ -4,7 +4,7 @@ import io
4
4
  import logging
5
5
  import os
6
6
  import stat
7
- from functools import lru_cache
7
+ from functools import cached_property, lru_cache
8
8
  from typing import TYPE_CHECKING, BinaryIO
9
9
  from uuid import UUID
10
10
 
@@ -39,8 +39,6 @@ log.setLevel(os.getenv("DISSECT_LOG_EXTFS", "CRITICAL"))
39
39
  class ExtFS:
40
40
  def __init__(self, fh: BinaryIO):
41
41
  self.fh = fh
42
- # self._path_cache = {}
43
- self._journal = None
44
42
 
45
43
  fh.seek(c_ext.EXT2_SBOFF)
46
44
  sb = c_ext.ext4_super_block(fh)
@@ -100,42 +98,34 @@ class ExtFS:
100
98
  self.get_inode = lru_cache(1024)(self.get_inode)
101
99
  self._read_group_desc = lru_cache(356)(self._read_group_desc)
102
100
 
103
- @property
101
+ @cached_property
104
102
  def journal(self) -> JDB2:
105
- if not self._journal:
106
- if not self.sb.s_feature_compat & c_ext.EXT3_FEATURE_COMPAT_HAS_JOURNAL:
107
- raise Error("Journal not supported")
108
-
109
- inum = self.sb.s_journal_inum
110
- if inum == 0:
111
- raise Error(
112
- f"Journal inum is 0, could be on external device (s_journal_uuid = {self.sb.s_journal_uuid})"
113
- )
103
+ if not self.sb.s_feature_compat & c_ext.EXT3_FEATURE_COMPAT_HAS_JOURNAL:
104
+ raise Error("Journal not supported")
114
105
 
115
- inode = self.get_inode(inum)
116
- self._journal = JDB2(inode.open())
106
+ inum = self.sb.s_journal_inum
107
+ if inum == 0:
108
+ raise Error(f"Journal inum is 0, could be on external device (s_journal_uuid = {self.sb.s_journal_uuid})")
117
109
 
118
- return self._journal
110
+ inode = self.get_inode(inum)
111
+ return JDB2(inode.open())
119
112
 
120
- def get(self, path: str | int, node: INode | None = None) -> INode:
121
- if isinstance(path, int):
122
- return self.get_inode(path)
113
+ def get(self, path_or_inum: str | int, node: INode | None = None) -> INode:
114
+ if isinstance(path_or_inum, int):
115
+ return self.get_inode(path_or_inum)
123
116
 
124
117
  node = node if node else self.root
125
- parts = path.split("/")
126
- for part_num, part in enumerate(parts):
118
+ parts = path_or_inum.split("/")
119
+ for part in parts:
127
120
  if not part:
128
121
  continue
129
122
 
130
- while node.filetype == stat.S_IFLNK and part_num < len(parts):
131
- node = node.link_inode
132
-
133
123
  for entry in node.iterdir():
134
124
  if entry.filename == part:
135
125
  node = entry
136
126
  break
137
127
  else:
138
- raise FileNotFoundError(f"File not found: {path}")
128
+ raise FileNotFoundError(f"File not found: {path_or_inum}")
139
129
 
140
130
  return node
141
131
 
@@ -144,17 +134,11 @@ class ExtFS:
144
134
  inum: int,
145
135
  filename: str | None = None,
146
136
  filetype: int | None = None,
147
- parent: INode | None = None,
148
- lazy: bool = False,
149
137
  ) -> INode:
150
138
  if inum < c_ext.EXT2_BAD_INO or inum > self.sb.s_inodes_count:
151
139
  raise Error(f"inum out of range {c_ext.EXT2_BAD_INO}-{self.sb.s_inodes_count}: {inum}")
152
140
 
153
- inode = INode(self, inum, filename, filetype, parent=parent)
154
- if not lazy:
155
- inode._inode = inode._read_inode()
156
-
157
- return inode
141
+ return INode(self, inum, filename, filetype)
158
142
 
159
143
  def _read_group_desc(self, group_num: int) -> c_ext.ext2_group_desc | c_ext.ext4_group_desc:
160
144
  if group_num >= self.groups_count:
@@ -186,27 +170,18 @@ class INode:
186
170
  inum: int,
187
171
  filename: str | None = None,
188
172
  filetype: int | None = None,
189
- parent: INode | None = None,
190
173
  ):
191
174
  self.extfs = extfs
192
175
  self.inum = inum
193
- self.parent = parent
194
- self._inode = None
195
-
196
176
  self.filename = filename
197
177
  self._filetype = filetype
198
- self._size = None
199
- self._link = None
200
- self._link_inode = None
201
- self._xattr = None
202
-
203
- self._dirlist = None
204
178
  self._runlist = None
205
179
 
206
180
  def __repr__(self) -> str:
207
181
  return f"<inode {self.inum}>"
208
182
 
209
- def _read_inode(self) -> c_ext.ext4_inode:
183
+ @cached_property
184
+ def inode(self) -> c_ext.ext4_inode:
210
185
  block_group_num, index = divmod(self.inum - 1, self.extfs.sb.s_inodes_per_group)
211
186
  block_group = self.extfs._read_group_desc(block_group_num)
212
187
 
@@ -219,17 +194,9 @@ class INode:
219
194
  self.extfs.fh.seek(offset)
220
195
  return c_ext.ext4_inode(self.extfs.fh)
221
196
 
222
- @property
223
- def inode(self) -> c_ext.ext4_inode:
224
- if not self._inode:
225
- self._inode = self._read_inode()
226
- return self._inode
227
-
228
- @property
197
+ @cached_property
229
198
  def size(self) -> int:
230
- if not self._size:
231
- self._size = (self.inode.i_size_high << 32) + self.inode.i_size_lo
232
- return self._size
199
+ return (self.inode.i_size_high << 32) + self.inode.i_size_lo
233
200
 
234
201
  @property
235
202
  def filetype(self) -> int:
@@ -237,50 +204,37 @@ class INode:
237
204
  self._filetype = stat.S_IFMT(self.inode.i_mode)
238
205
  return self._filetype
239
206
 
240
- @property
207
+ @cached_property
241
208
  def link(self) -> str:
242
209
  if self.filetype != stat.S_IFLNK:
243
210
  raise NotASymlinkError(f"{self!r} is not a symlink")
244
211
 
245
- if not self._link:
246
- self._link = self.open().read().decode(errors="surrogateescape")
247
- return self._link
212
+ return self.open().read().decode(errors="surrogateescape")
248
213
 
249
- @property
250
- def link_inode(self) -> INode:
251
- if not self._link_inode:
252
- # Relative lookups work because . and .. are actual directory entries
253
- link = self.link
254
- relnode = None if link.startswith("/") else self.parent
255
- self._link_inode = self.extfs.get(self.link, relnode)
256
- return self._link_inode
257
-
258
- @property
214
+ @cached_property
259
215
  def xattr(self) -> list[XAttr]:
260
- if not self._xattr:
261
- xattr = []
216
+ xattr = []
262
217
 
263
- if self.inode.i_extra.strip(b"\x00"):
264
- buf = io.BytesIO(self.inode.i_extra)
265
- hdr = c_ext.ext4_xattr_ibody_header(buf)
266
- if hdr.h_magic != c_ext.EXT4_XATTR_MAGIC:
267
- raise Error("Invalid xattr magic value")
218
+ if self.inode.i_extra.strip(b"\x00"):
219
+ buf = io.BytesIO(self.inode.i_extra)
220
+ hdr = c_ext.ext4_xattr_ibody_header(buf)
221
+ if hdr.h_magic != c_ext.EXT4_XATTR_MAGIC:
222
+ raise Error("Invalid xattr magic value")
268
223
 
269
- xattr.extend(_iter_xattr(self, buf, len(self.inode.i_extra), 4))
224
+ xattr.extend(_iter_xattr(self, buf, len(self.inode.i_extra), 4))
270
225
 
271
- if self.inode.i_file_acl_lo:
272
- block = (self.inode.i_file_acl_high << 32) | self.inode.i_file_acl_lo
273
- block_offset = block * self.extfs.block_size
226
+ if self.inode.i_file_acl_lo:
227
+ block = (self.inode.i_file_acl_high << 32) | self.inode.i_file_acl_lo
228
+ block_offset = block * self.extfs.block_size
274
229
 
275
- buf = RangeStream(self.extfs.fh, block_offset, self.extfs.block_size)
276
- hdr = c_ext.ext4_xattr_header(buf)
277
- if hdr.h_magic != c_ext.EXT4_XATTR_MAGIC:
278
- raise Error("Invalid xattr magic value")
230
+ buf = RangeStream(self.extfs.fh, block_offset, self.extfs.block_size)
231
+ hdr = c_ext.ext4_xattr_header(buf)
232
+ if hdr.h_magic != c_ext.EXT4_XATTR_MAGIC:
233
+ raise Error("Invalid xattr magic value")
279
234
 
280
- xattr.extend(_iter_xattr(self, buf, buf.size))
235
+ xattr.extend(_iter_xattr(self, buf, buf.size))
281
236
 
282
- self._xattr = xattr
283
- return self._xattr
237
+ return xattr
284
238
 
285
239
  @property
286
240
  def atime(self) -> datetime:
@@ -337,9 +291,7 @@ class INode:
337
291
  return _parse_ns_ts(time, time_extra)
338
292
 
339
293
  def listdir(self) -> dict[str, INode]:
340
- if not self._dirlist:
341
- self._dirlist = {node.filename: node for node in self.iterdir()}
342
- return self._dirlist
294
+ return {node.filename: node for node in self.iterdir()}
343
295
 
344
296
  dirlist = listdir
345
297
 
@@ -365,7 +317,7 @@ class INode:
365
317
  if ftype:
366
318
  ftype = FILETYPES[ftype]
367
319
 
368
- yield self.extfs.get_inode(direntry.inode, fname, ftype, parent=self, lazy=True)
320
+ yield self.extfs.get_inode(direntry.inode, fname, ftype)
369
321
 
370
322
  offset += direntry.rec_len
371
323
  buf.seek(offset)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: dissect.extfs
3
- Version: 3.13.dev1
3
+ Version: 3.14
4
4
  Summary: A Dissect module implementing a parser for the ExtFS file system, the native filesystem for Linux operating systems
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -27,6 +27,7 @@ Requires-Dist: dissect.util<4,>=3
27
27
  Provides-Extra: dev
28
28
  Requires-Dist: dissect.cstruct<5.0.dev,>=4.0.dev; extra == "dev"
29
29
  Requires-Dist: dissect.util<4.0.dev,>=3.0.dev; extra == "dev"
30
+ Dynamic: license-file
30
31
 
31
32
  # dissect.extfs
32
33
 
@@ -1,3 +1,4 @@
1
+ .git-blame-ignore-revs
1
2
  .gitattributes
2
3
  COPYRIGHT
3
4
  LICENSE
@@ -22,9 +23,7 @@ tests/test_exceptions.py
22
23
  tests/test_ext4.py
23
24
  tests/data/ext4.bin.gz
24
25
  tests/data/ext4_sparse.bin.gz
25
- tests/data/ext4_symlink_test1.bin.gz
26
- tests/data/ext4_symlink_test2.bin.gz
27
- tests/data/ext4_symlink_test3.bin.gz
26
+ tests/data/ext4_symlink_test.bin.gz
28
27
  tests/docs/Makefile
29
28
  tests/docs/conf.py
30
29
  tests/docs/index.rst
@@ -99,4 +99,3 @@ license-files = ["LICENSE", "COPYRIGHT"]
99
99
  include = ["dissect.*"]
100
100
 
101
101
  [tool.setuptools_scm]
102
- local_scheme = "no-local-version"
@@ -27,3 +27,7 @@ def ext4_bin() -> Iterator[BinaryIO]:
27
27
  @pytest.fixture
28
28
  def ext4_sparse_bin() -> Iterator[BinaryIO]:
29
29
  yield from gzip_file("data/ext4_sparse.bin.gz")
30
+
31
+ @pytest.fixture
32
+ def ext4_symlink_bin() -> Iterator[BinaryIO]:
33
+ yield from gzip_file("data/ext4_symlink_test.bin.gz")
@@ -1,14 +1,11 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import datetime
4
- import gzip
5
4
  import stat
6
5
  from io import BytesIO
7
6
  from typing import TYPE_CHECKING, BinaryIO
8
7
  from unittest.mock import call, patch
9
8
 
10
- import pytest
11
-
12
9
  from dissect.extfs.c_ext import c_ext
13
10
  from dissect.extfs.extfs import EXT4, ExtFS, INode
14
11
 
@@ -80,25 +77,11 @@ def test_sparse(ext4_sparse_bin: BinaryIO) -> None:
80
77
  assert sparse_all.dataruns() == [(None, 5120)]
81
78
 
82
79
 
83
- @pytest.mark.parametrize(
84
- "image_file",
85
- [
86
- ("tests/data/ext4_symlink_test1.bin.gz"),
87
- ("tests/data/ext4_symlink_test2.bin.gz"),
88
- ("tests/data/ext4_symlink_test3.bin.gz"),
89
- ],
90
- )
91
- def test_symlinks(image_file: str) -> None:
80
+ def test_symlinks(ext4_symlink_bin: BinaryIO) -> None:
92
81
  path = "/path/to/dir/with/file.ext"
93
- expect = b"resolved!\n"
94
-
95
- def resolve(node: INode) -> INode:
96
- while node.filetype == stat.S_IFLNK:
97
- node = node.link_inode
98
- return node
99
82
 
100
- with gzip.open(image_file, "rb") as disk:
101
- assert resolve(ExtFS(disk).get(path)).open().read() == expect
83
+ extfs = ExtFS(ext4_symlink_bin)
84
+ assert extfs.get(path).link == "../../../../other/path/source/to/my/file.ext"
102
85
 
103
86
 
104
87
  @patch("dissect.extfs.extfs.INode.open", return_value=BytesIO(b"\x00" * 16))
@@ -108,7 +91,7 @@ def test_infinite_loop_protection(ExtFS: ExtFS, log: Logger, *args) -> None:
108
91
  ExtFS.sb.s_inodes_count = 69
109
92
  ExtFS._dirtype = c_ext.ext2_dir_entry_2
110
93
  inode = INode(ExtFS, 1, filetype=stat.S_IFDIR)
111
- inode._size = 16
94
+ inode.size = 16
112
95
  for _ in inode.iterdir():
113
96
  pass
114
97
  assert call.critical("Zero-length directory entry in %s (offset 0x%x)", inode, 0) in log.mock_calls
File without changes
File without changes