Skip to content

Commit

Permalink
address peer review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
twiggler committed Dec 12, 2024
1 parent 755f6cf commit 3a817e2
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions dissect/target/plugins/apps/productivity/msoffice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import itertools
from pathlib import Path
from typing import Iterable, Iterator, Set
from typing import Iterable, Iterator
from xml.etree.ElementTree import Element

from defusedxml import ElementTree
Expand Down Expand Up @@ -53,17 +53,17 @@ class ClickOnceDeploymentManifestParser:
def __init__(self, target: Target, user_sid: str) -> None:
self._target = target
self._user_sid = user_sid
self._visited_manifests: Set[Path] = set()
self._codebases: Set[Path] = set()
self._visited_manifests: set[Path] = set()
self._codebases: set[Path] = set()

def find_codebases(self, manifest_path: str) -> Iterable[str]:
def find_codebases(self, manifest_path: str) -> set[str]:
"""Dig for executables given a manifest"""

self._visited_manifests.clear()
self._codebases.clear()
return self._parse_manifest(manifest_path)

def _parse_manifest(self, manifest_path_str: str) -> Set[Path]:
def _parse_manifest(self, manifest_path_str: str) -> set[Path]:
# See https://learn.microsoft.com/en-us/visualstudio/deployment/clickonce-deployment-manifest?view=vs-2022

manifest_path: Path = self._target.resolve(manifest_path_str, self._user_sid)
Expand Down Expand Up @@ -142,14 +142,6 @@ def check_compatible(self) -> None:
if not self.target.has_function("registry") or not list(self.target.registry.keys(f"HKLM\\{self.OFFICE_KEY}")):
raise UnsupportedPluginError("Registry key not found: %s", self.OFFICE_KEY)

Check warning on line 143 in dissect/target/plugins/apps/productivity/msoffice.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/apps/productivity/msoffice.py#L142-L143

Added lines #L142 - L143 were not covered by tests

@export(record=[OfficeWebAddinRecord, OfficeNativeAddinRecord, OfficeStartupItem])
def all(self) -> Iterator[OfficeWebAddinRecord | OfficeNativeAddinRecord | OfficeStartupItem]:
"""Aggregate to list all add-in types and startup items"""

yield from self.startup()
yield from self.web()
yield from self.native()

@export(record=OfficeWebAddinRecord)
def web(self) -> Iterator[OfficeWebAddinRecord]:
"""List all web add-ins by parsing the manifests in the web extension framework cache"""
Expand Down Expand Up @@ -246,24 +238,21 @@ def _lookup_com_executable(self, prog_id: str) -> str | None:
except RegistryError:
pass

Check warning on line 239 in dissect/target/plugins/apps/productivity/msoffice.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/apps/productivity/msoffice.py#L238-L239

Added lines #L238 - L239 were not covered by tests

def _parse_vsto_manifest(self, manifest_path: str, user_sid: str) -> Iterable[str]:
def _parse_vsto_manifest(self, manifest_path: str, user_sid: str) -> set[str]:
"""Parse a vsto manifest.
Non-local manifests, i.e. not ending with suffix "vstolocal" are listed but skipped.
"""

if not manifest_path.endswith("vstolocal"):
self.target.log.warning("Parsing of remote vsto manifest %s is not supported")
return [manifest_path]
return set(manifest_path)

Check warning on line 249 in dissect/target/plugins/apps/productivity/msoffice.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/apps/productivity/msoffice.py#L248-L249

Added lines #L248 - L249 were not covered by tests

manifest_parser = ClickOnceDeploymentManifestParser(self.target, user_sid)
return manifest_parser.find_codebases(manifest_path.removesuffix("|vstolocal"))

def _parse_web_addin_manifest(self, manifest_path: Path) -> OfficeWebAddinRecord:
"""Parses a web addin manifest.
See https://learn.microsoft.com/en-us/office/dev/add-ins/develop/xml-manifest-overview?tabs=tabid-1
"""
"""Parses a web addin manifest."""

ns = {"": "http://schemas.microsoft.com/office/appforoffice/1.1"}

Expand Down

0 comments on commit 3a817e2

Please sign in to comment.