dissect.extfs 3.14.dev1__py3-none-any.whl → 3.14.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/extfs/extfs.py +34 -62
- {dissect_extfs-3.14.dev1.dist-info → dissect_extfs-3.14.dev2.dist-info}/METADATA +1 -1
- {dissect_extfs-3.14.dev1.dist-info → dissect_extfs-3.14.dev2.dist-info}/RECORD +7 -7
- {dissect_extfs-3.14.dev1.dist-info → dissect_extfs-3.14.dev2.dist-info}/WHEEL +0 -0
- {dissect_extfs-3.14.dev1.dist-info → dissect_extfs-3.14.dev2.dist-info}/licenses/COPYRIGHT +0 -0
- {dissect_extfs-3.14.dev1.dist-info → dissect_extfs-3.14.dev2.dist-info}/licenses/LICENSE +0 -0
- {dissect_extfs-3.14.dev1.dist-info → dissect_extfs-3.14.dev2.dist-info}/top_level.txt +0 -0
dissect/extfs/extfs.py
CHANGED
|
@@ -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,7 +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._journal = None
|
|
43
42
|
|
|
44
43
|
fh.seek(c_ext.EXT2_SBOFF)
|
|
45
44
|
sb = c_ext.ext4_super_block(fh)
|
|
@@ -99,22 +98,17 @@ class ExtFS:
|
|
|
99
98
|
self.get_inode = lru_cache(1024)(self.get_inode)
|
|
100
99
|
self._read_group_desc = lru_cache(356)(self._read_group_desc)
|
|
101
100
|
|
|
102
|
-
@
|
|
101
|
+
@cached_property
|
|
103
102
|
def journal(self) -> JDB2:
|
|
104
|
-
if not self.
|
|
105
|
-
|
|
106
|
-
raise Error("Journal not supported")
|
|
107
|
-
|
|
108
|
-
inum = self.sb.s_journal_inum
|
|
109
|
-
if inum == 0:
|
|
110
|
-
raise Error(
|
|
111
|
-
f"Journal inum is 0, could be on external device (s_journal_uuid = {self.sb.s_journal_uuid})"
|
|
112
|
-
)
|
|
103
|
+
if not self.sb.s_feature_compat & c_ext.EXT3_FEATURE_COMPAT_HAS_JOURNAL:
|
|
104
|
+
raise Error("Journal not supported")
|
|
113
105
|
|
|
114
|
-
|
|
115
|
-
|
|
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})")
|
|
116
109
|
|
|
117
|
-
|
|
110
|
+
inode = self.get_inode(inum)
|
|
111
|
+
return JDB2(inode.open())
|
|
118
112
|
|
|
119
113
|
def get(self, path_or_inum: str | int, node: INode | None = None) -> INode:
|
|
120
114
|
if isinstance(path_or_inum, int):
|
|
@@ -140,16 +134,11 @@ class ExtFS:
|
|
|
140
134
|
inum: int,
|
|
141
135
|
filename: str | None = None,
|
|
142
136
|
filetype: int | None = None,
|
|
143
|
-
lazy: bool = False,
|
|
144
137
|
) -> INode:
|
|
145
138
|
if inum < c_ext.EXT2_BAD_INO or inum > self.sb.s_inodes_count:
|
|
146
139
|
raise Error(f"inum out of range {c_ext.EXT2_BAD_INO}-{self.sb.s_inodes_count}: {inum}")
|
|
147
140
|
|
|
148
|
-
|
|
149
|
-
if not lazy:
|
|
150
|
-
inode._inode = inode._read_inode()
|
|
151
|
-
|
|
152
|
-
return inode
|
|
141
|
+
return INode(self, inum, filename, filetype)
|
|
153
142
|
|
|
154
143
|
def _read_group_desc(self, group_num: int) -> c_ext.ext2_group_desc | c_ext.ext4_group_desc:
|
|
155
144
|
if group_num >= self.groups_count:
|
|
@@ -184,20 +173,15 @@ class INode:
|
|
|
184
173
|
):
|
|
185
174
|
self.extfs = extfs
|
|
186
175
|
self.inum = inum
|
|
187
|
-
self._inode = None
|
|
188
|
-
|
|
189
176
|
self.filename = filename
|
|
190
177
|
self._filetype = filetype
|
|
191
|
-
self._size = None
|
|
192
|
-
self._link = None
|
|
193
|
-
self._xattr = None
|
|
194
|
-
|
|
195
178
|
self._runlist = None
|
|
196
179
|
|
|
197
180
|
def __repr__(self) -> str:
|
|
198
181
|
return f"<inode {self.inum}>"
|
|
199
182
|
|
|
200
|
-
|
|
183
|
+
@cached_property
|
|
184
|
+
def inode(self) -> c_ext.ext4_inode:
|
|
201
185
|
block_group_num, index = divmod(self.inum - 1, self.extfs.sb.s_inodes_per_group)
|
|
202
186
|
block_group = self.extfs._read_group_desc(block_group_num)
|
|
203
187
|
|
|
@@ -210,17 +194,9 @@ class INode:
|
|
|
210
194
|
self.extfs.fh.seek(offset)
|
|
211
195
|
return c_ext.ext4_inode(self.extfs.fh)
|
|
212
196
|
|
|
213
|
-
@
|
|
214
|
-
def inode(self) -> c_ext.ext4_inode:
|
|
215
|
-
if not self._inode:
|
|
216
|
-
self._inode = self._read_inode()
|
|
217
|
-
return self._inode
|
|
218
|
-
|
|
219
|
-
@property
|
|
197
|
+
@cached_property
|
|
220
198
|
def size(self) -> int:
|
|
221
|
-
|
|
222
|
-
self._size = (self.inode.i_size_high << 32) + self.inode.i_size_lo
|
|
223
|
-
return self._size
|
|
199
|
+
return (self.inode.i_size_high << 32) + self.inode.i_size_lo
|
|
224
200
|
|
|
225
201
|
@property
|
|
226
202
|
def filetype(self) -> int:
|
|
@@ -228,41 +204,37 @@ class INode:
|
|
|
228
204
|
self._filetype = stat.S_IFMT(self.inode.i_mode)
|
|
229
205
|
return self._filetype
|
|
230
206
|
|
|
231
|
-
@
|
|
207
|
+
@cached_property
|
|
232
208
|
def link(self) -> str:
|
|
233
209
|
if self.filetype != stat.S_IFLNK:
|
|
234
210
|
raise NotASymlinkError(f"{self!r} is not a symlink")
|
|
235
211
|
|
|
236
|
-
|
|
237
|
-
self._link = self.open().read().decode(errors="surrogateescape")
|
|
238
|
-
return self._link
|
|
212
|
+
return self.open().read().decode(errors="surrogateescape")
|
|
239
213
|
|
|
240
|
-
@
|
|
214
|
+
@cached_property
|
|
241
215
|
def xattr(self) -> list[XAttr]:
|
|
242
|
-
|
|
243
|
-
xattr = []
|
|
216
|
+
xattr = []
|
|
244
217
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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")
|
|
250
223
|
|
|
251
|
-
|
|
224
|
+
xattr.extend(_iter_xattr(self, buf, len(self.inode.i_extra), 4))
|
|
252
225
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
|
256
229
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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")
|
|
261
234
|
|
|
262
|
-
|
|
235
|
+
xattr.extend(_iter_xattr(self, buf, buf.size))
|
|
263
236
|
|
|
264
|
-
|
|
265
|
-
return self._xattr
|
|
237
|
+
return xattr
|
|
266
238
|
|
|
267
239
|
@property
|
|
268
240
|
def atime(self) -> datetime:
|
|
@@ -345,7 +317,7 @@ class INode:
|
|
|
345
317
|
if ftype:
|
|
346
318
|
ftype = FILETYPES[ftype]
|
|
347
319
|
|
|
348
|
-
yield self.extfs.get_inode(direntry.inode, fname, ftype
|
|
320
|
+
yield self.extfs.get_inode(direntry.inode, fname, ftype)
|
|
349
321
|
|
|
350
322
|
offset += direntry.rec_len
|
|
351
323
|
buf.seek(offset)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dissect.extfs
|
|
3
|
-
Version: 3.14.
|
|
3
|
+
Version: 3.14.dev2
|
|
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
|
|
@@ -2,11 +2,11 @@ dissect/extfs/__init__.py,sha256=1_K5exKlh5eEUQF-vFkj0JzdDoxIZxPp4EC6B_8rQtI,346
|
|
|
2
2
|
dissect/extfs/c_ext.py,sha256=4429SV3LXJIeD1YIot-vzS-pVdNguwlcvi37cFfh1pY,23423
|
|
3
3
|
dissect/extfs/c_jdb2.py,sha256=4KZ_eq6MQ_gCh1VGtw11G_mN4PEV6PvJBDNUGhfLbMM,3664
|
|
4
4
|
dissect/extfs/exceptions.py,sha256=rVL-M01CBpk74d8VeeeqQuwD5P1WHluvNbAnj5D8BBw,263
|
|
5
|
-
dissect/extfs/extfs.py,sha256=
|
|
5
|
+
dissect/extfs/extfs.py,sha256=44JAPhjOuA-C0FM3VregnqlEE5EMuDJ4mXODX40RwhU,17700
|
|
6
6
|
dissect/extfs/journal.py,sha256=3od5IdtKAeF6zFi2iCcQ-YynrQx4e8_SAJ7zpv6Qv3k,5043
|
|
7
|
-
dissect_extfs-3.14.
|
|
8
|
-
dissect_extfs-3.14.
|
|
9
|
-
dissect_extfs-3.14.
|
|
10
|
-
dissect_extfs-3.14.
|
|
11
|
-
dissect_extfs-3.14.
|
|
12
|
-
dissect_extfs-3.14.
|
|
7
|
+
dissect_extfs-3.14.dev2.dist-info/licenses/COPYRIGHT,sha256=vz2IXoFr4ZWY2Q8QmDgdqzZmyqHhRZiAQC490UHWWdQ,300
|
|
8
|
+
dissect_extfs-3.14.dev2.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
|
|
9
|
+
dissect_extfs-3.14.dev2.dist-info/METADATA,sha256=dVHfjZDOC_q8IdVQbcwVde8Sziny5D2EUyWCit8h2Dw,3282
|
|
10
|
+
dissect_extfs-3.14.dev2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
+
dissect_extfs-3.14.dev2.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
|
|
12
|
+
dissect_extfs-3.14.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|