diff --git a/dissect/ole/c_ole.py b/dissect/ole/c_ole.py index 47775cb..f21bbf2 100644 --- a/dissect/ole/c_ole.py +++ b/dissect/ole/c_ole.py @@ -1,4 +1,4 @@ -from dissect import cstruct +from dissect.cstruct import cstruct ole_def = """ typedef short OFFSET; @@ -81,8 +81,7 @@ DFPROPTYPE _dptPropType; // [07CH,02] Reserved for future use. Must be zero. }; """ -c_ole = cstruct.cstruct() -c_ole.load(ole_def) +c_ole = cstruct().load(ole_def) SIGNATURE = b"\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1" SIGNATURE_BETA = b"\x0e\x11\xfc\x0d\xd0\xcf\x11\xe0" diff --git a/dissect/ole/ole.py b/dissect/ole/ole.py index 64883f5..5787a26 100644 --- a/dissect/ole/ole.py +++ b/dissect/ole/ole.py @@ -28,7 +28,6 @@ def __init__(self, fh): self._difatcache = {} self._chaincache = {} self._minichaincache = {} - self._dirlist = {} minifat_buf = self.chain(self.header._sectMiniFatStart).open().read() self._minifat = c_ole.uint32[len(minifat_buf) // 4](minifat_buf) @@ -38,21 +37,24 @@ def __init__(self, fh): self.root = self.directory(0) self.ministream = self.root.open() - def get(self, name): - dirlist = self.listdir() - try: - return dirlist[name] - except KeyError: - return NotFoundError(name) + def get(self, path, root=None): + root = root or self.root - def listdir(self): - if not self._dirlist: - for entry in self.root.walk(): - self._dirlist[entry.name] = entry + search_path = path.replace("\\", "/") + node = root - return self._dirlist + for part in search_path.split("/"): + if not part: + continue + + for child in node.walk(): + if child.name == part: + node = child + break + else: + raise NotFoundError(path) - dirlist = listdir + return node def directory(self, sid): try: @@ -148,29 +150,35 @@ def __init__(self, ole, sid): else: self.chain = ole.chain(self.start, self.size) + self._dirlist = {} + def __repr__(self): return "".format(self.sid, self.name, self.type, self.size) def open(self): return self.chain.open() + def listdir(self): + if not self._dirlist: + for entry in self.walk(): + self._dirlist[entry.name] = entry + + return self._dirlist + def walk(self): if self.has_left_sibling: yield self.left_sibling - for child in self.left_sibling.walk(): - yield child + yield from self.left_sibling.walk() if self.has_child: yield self.child if self.has_right_sibling: yield self.right_sibling - for child in self.right_sibling.walk(): - yield child + yield from self.right_sibling.walk() if self.has_child: - for child in self.child.walk(): - yield child + yield from self.child.walk() @property def child(self): diff --git a/pyproject.toml b/pyproject.toml index f3aa4a8..577120b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,8 +25,8 @@ classifiers = [ "Topic :: Utilities", ] dependencies = [ - "dissect.cstruct>=3.0.dev,<4.0.dev", - "dissect.util>=3.0.dev,<4.0.dev", + "dissect.cstruct>=4.dev,<5", + "dissect.util>=3,<4", ] dynamic = ["version"] @@ -35,6 +35,12 @@ homepage = "https://dissect.tools" documentation = "https://docs.dissect.tools/en/latest/projects/dissect.ole" repository = "https://github.com/fox-it/dissect.ole" +[project.optional-dependencies] +dev = [ + "dissect.cstruct>=4.0.dev,<5.0.dev", + "dissect.util>=3.0.dev,<4.0.dev", +] + [tool.black] line-length = 120 diff --git a/tox.ini b/tox.ini index 1706b81..8bed572 100644 --- a/tox.ini +++ b/tox.ini @@ -11,6 +11,7 @@ minversion = 4.4.3 requires = virtualenv>=20.16.6 [testenv] +extras = dev deps = pytest pytest-cov