dissect.target 3.17.dev9__py3-none-any.whl → 3.17.dev11__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.
@@ -29,11 +29,11 @@ from dissect.target.filesystem import FilesystemEntry
29
29
  from dissect.target.helpers.fsutil import TargetPath
30
30
 
31
31
  try:
32
- import yaml
32
+ from ruamel.yaml import YAML
33
33
 
34
- PY_YAML = True
34
+ HAS_YAML = True
35
35
  except ImportError:
36
- PY_YAML = False
36
+ HAS_YAML = False
37
37
 
38
38
  try:
39
39
  if sys.version_info < (3, 11):
@@ -413,11 +413,11 @@ class Yaml(ConfigurationParser):
413
413
  """Parses a Yaml file."""
414
414
 
415
415
  def parse_file(self, fh: TextIO) -> None:
416
- if PY_YAML:
417
- parsed_data = yaml.load(fh, yaml.BaseLoader)
416
+ if HAS_YAML:
417
+ parsed_data = YAML(typ="safe").load(fh)
418
418
  self.parsed_data = ListUnwrapper.unwrap(parsed_data)
419
419
  else:
420
- raise ConfigurationParsingError("Failed to parse file, please install PyYAML.")
420
+ raise ConfigurationParsingError("Failed to parse file, please install ruamel.yaml.")
421
421
 
422
422
 
423
423
  class Toml(ConfigurationParser):
@@ -12,11 +12,11 @@ from dissect.target.helpers.fsutil import TargetPath
12
12
  from dissect.target.target import Target
13
13
 
14
14
  try:
15
- import yaml
15
+ from ruamel.yaml import YAML
16
16
 
17
- PY_YAML = True
17
+ HAS_YAML = True
18
18
  except ImportError:
19
- PY_YAML = False
19
+ HAS_YAML = False
20
20
 
21
21
  IGNORED_IPS = [
22
22
  "0.0.0.0",
@@ -49,7 +49,7 @@ class Template:
49
49
  """Sets the name of the the used parsing template to the name of the discovered network manager."""
50
50
  self.name = name
51
51
 
52
- def create_config(self, path: TargetPath) -> Union[dict, None]:
52
+ def create_config(self, path: TargetPath) -> Optional[dict]:
53
53
  """Create a network config dictionary based on the configured template and supplied path.
54
54
 
55
55
  Args:
@@ -73,26 +73,26 @@ class Template:
73
73
  config = self._parse_configparser_config(path)
74
74
  return config
75
75
 
76
- def _parse_netplan_config(self, fh: TargetPath) -> Union[dict, None]:
76
+ def _parse_netplan_config(self, path: TargetPath) -> Optional[dict]:
77
77
  """Internal function to parse a netplan YAML based configuration file into a dict.
78
78
 
79
79
  Args:
80
- fh: A file-like object to the configuration file to be parsed.
80
+ fh: A path to the configuration file to be parsed.
81
81
 
82
82
  Returns:
83
83
  Dictionary containing the parsed YAML based configuration file.
84
84
  """
85
- if PY_YAML:
86
- return self.parser(stream=fh.open(), Loader=yaml.FullLoader)
85
+ if HAS_YAML:
86
+ return self.parser(path.open("rb"))
87
87
  else:
88
- self.target.log.error("Failed to parse %s. Cannot import PyYAML", self.name)
88
+ self.target.log.error("Failed to parse %s. Cannot import ruamel.yaml", self.name)
89
89
  return None
90
90
 
91
- def _parse_wicked_config(self, fh: TargetPath) -> dict:
91
+ def _parse_wicked_config(self, path: TargetPath) -> dict:
92
92
  """Internal function to parse a wicked XML based configuration file into a dict.
93
93
 
94
94
  Args:
95
- fh: A file-like object to the configuration file to be parsed.
95
+ fh: A path to the configuration file to be parsed.
96
96
 
97
97
  Returns:
98
98
  Dictionary containing the parsed xml based Linux network manager based configuration file.
@@ -101,44 +101,43 @@ class Template:
101
101
  # we have to replace the ":" for this with "___" (three underscores) to make the xml config non-namespaced.
102
102
  pattern = compile(r"(?<=\n)\s+(<.+?>)")
103
103
  replace_match: Callable[[Match]] = lambda match: match.group(1).replace(":", "___")
104
- text = sub(pattern, replace_match, fh.open("rt").read())
104
+ text = sub(pattern, replace_match, path.open("rt").read())
105
105
 
106
106
  xml = self.parser.parse(StringIO(text))
107
107
  return self._parse_xml_config(xml, self.sections, self.options)
108
108
 
109
- def _parse_configparser_config(self, fh: TargetPath) -> dict:
109
+ def _parse_configparser_config(self, path: TargetPath) -> dict:
110
110
  """Internal function to parse ConfigParser compatible configuration files into a dict.
111
111
 
112
112
  Args:
113
- fh: A file-like object to the configuration file to be parsed.
113
+ path: A path to the configuration file to be parsed.
114
114
 
115
115
  Returns:
116
116
  Dictionary containing the parsed ConfigParser compatible configuration file.
117
117
  """
118
118
  try:
119
- self.parser.read_string(fh.open("rt").read(), fh.name)
119
+ self.parser.read_string(path.open("rt").read(), path.name)
120
120
  return self.parser._sections
121
121
  except MissingSectionHeaderError:
122
122
  # configparser does like config files without headers, so we inject a header to make it work.
123
- self.parser.read_string(f"[{self.name}]\n" + fh.open("rt").read(), fh.name)
123
+ self.parser.read_string(f"[{self.name}]\n" + path.open("rt").read(), path.name)
124
124
  return self.parser._sections
125
125
 
126
- def _parse_text_config(self, comments: str, delim: str, fh: TargetPath) -> dict:
126
+ def _parse_text_config(self, comments: str, delim: str, path: TargetPath) -> dict:
127
127
  """Internal function to parse a basic plain text based configuration file into a dict.
128
128
 
129
129
  Args:
130
130
  comments: A string value defining the comment style of the configuration file.
131
131
  delim: A string value defining the delimiters used in the configuration file.
132
- fh: A file-like object to the configuration file to be parsed.
132
+ path: A path to the configuration file to be parsed.
133
133
 
134
134
  Returns:
135
135
  Dictionary with a parsed plain text based Linux network manager configuration file.
136
136
  """
137
137
  config = defaultdict(dict)
138
138
  option_dict = {}
139
- fh = fh.open("rt")
140
139
 
141
- for line in fh.readlines():
140
+ for line in path.open("rt"):
142
141
  line = line.strip()
143
142
 
144
143
  if not line or line.startswith(comments):
@@ -631,7 +630,9 @@ TEMPLATES = {
631
630
  ["netctl"],
632
631
  ["address", "gateway", "dns", "ip"],
633
632
  ),
634
- "netplan": Template("netplan", yaml.load if PY_YAML else None, ["network"], ["addresses", "dhcp4", "gateway4"]),
633
+ "netplan": Template(
634
+ "netplan", YAML(typ="safe").load if HAS_YAML else None, ["network"], ["addresses", "dhcp4", "gateway4"]
635
+ ),
635
636
  "NetworkManager": Template(
636
637
  "NetworkManager",
637
638
  ConfigParser(delimiters=("="), comment_prefixes="#", dict_type=dict),
@@ -1,27 +1,30 @@
1
+ from pathlib import Path
2
+ from typing import TYPE_CHECKING
3
+
1
4
  try:
2
- import yaml
5
+ from ruamel.yaml import YAML
3
6
  except ImportError:
4
- raise ImportError("Missing PyYAML dependency")
7
+ raise ImportError("Missing ruamel.yaml dependency")
5
8
 
6
9
  from dissect.target import container
7
10
  from dissect.target.loader import Loader
8
11
 
12
+ if TYPE_CHECKING:
13
+ from dissect.target.target import Target
14
+
9
15
 
10
16
  class TargetLoader(Loader):
11
17
  """Load target files."""
12
18
 
13
- def __init__(self, path, **kwargs):
19
+ def __init__(self, path: Path, **kwargs):
14
20
  super().__init__(path)
15
21
  self.base_dir = path.parent
16
- self.definition = yaml.safe_load(path.open("rb"))
22
+ self.definition = YAML(typ="safe").load(path.open("rb"))
17
23
 
18
24
  @staticmethod
19
- def detect(path):
25
+ def detect(path: Path) -> bool:
20
26
  return path.suffix.lower() == ".target"
21
27
 
22
- def map(self, target):
28
+ def map(self, target: Target) -> None:
23
29
  for disk in self.definition["disks"]:
24
30
  target.disks.add(container.open(disk))
25
-
26
- def open(self, path):
27
- return self.base_dir.joinpath(path).open("rb")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dissect.target
3
- Version: 3.17.dev9
3
+ Version: 3.17.dev11
4
4
  Summary: This module ties all other Dissect modules together, it provides a programming API and command line tools which allow easy access to various data sources inside disk images or file collections (a.k.a. targets)
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -56,7 +56,7 @@ Requires-Dist: dissect.xfs <4.0.dev,>=3.0.dev ; extra == 'full'
56
56
  Requires-Dist: ipython ; extra == 'full'
57
57
  Requires-Dist: fusepy ; extra == 'full'
58
58
  Requires-Dist: pycryptodome ; extra == 'full'
59
- Requires-Dist: pyyaml ; extra == 'full'
59
+ Requires-Dist: ruamel.yaml ; extra == 'full'
60
60
  Requires-Dist: zstandard ; extra == 'full'
61
61
  Requires-Dist: tomli ; (python_version < "3.11") and extra == 'full'
62
62
  Provides-Extra: mqtt
@@ -44,7 +44,7 @@ dissect/target/filesystems/zip.py,sha256=WT1bQhzX_1MXXVZTKrJniae4xqRqMZ8FsfbvhgG
44
44
  dissect/target/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
45
  dissect/target/helpers/cache.py,sha256=_0w_iPD1OM066Ueyadb70erQW05jNnpJe-bDDN1UyXc,8444
46
46
  dissect/target/helpers/config.py,sha256=6917CZ6eDHaK_tOoiVEIndyhRXO6r6eCBIleq6f47PQ,2346
47
- dissect/target/helpers/configutil.py,sha256=czuzKdcV7O6OZopDv3Olr00uGbBAXxEnm0QLX_xIj8g,25617
47
+ dissect/target/helpers/configutil.py,sha256=Q4qVD_XSawG0MYrTzAjezWL-pCZMAW14Zmg54KGUddU,25637
48
48
  dissect/target/helpers/cyber.py,sha256=Ki5oSU0GgQxjgC_yWoeieGP7GOY5blQCzNX7vy7Pgas,16782
49
49
  dissect/target/helpers/descriptor_extensions.py,sha256=uT8GwznfDAiIgMM7JKKOY0PXKMv2c0GCqJTCkWFgops,2605
50
50
  dissect/target/helpers/docs.py,sha256=J5U65Y3yOTqxDEZRCdrEmO63XQCeDzOJea1PwPM6Cyc,5146
@@ -56,7 +56,7 @@ dissect/target/helpers/loaderutil.py,sha256=kiyMWra_gVxfNSGwLlgxLcuuqAYuCMDc5NiC
56
56
  dissect/target/helpers/localeutil.py,sha256=Y4Fh4jDSGfm5356xSLMriUCN8SZP_FAHg_iodkAxNq4,1504
57
57
  dissect/target/helpers/mount.py,sha256=JxhUYyEbDnHfzPpfuWy4nV9OwCJPoDSGdHHNiyvd_l0,3949
58
58
  dissect/target/helpers/mui.py,sha256=i-7XoHbu4WO2fYapK9yGAMW04rFlgRispknc1KQIS5Q,22258
59
- dissect/target/helpers/network_managers.py,sha256=tjqkVWn7i3PpBPkYnKUU0XxhqTTJlIjOc7Y2jpzdzA4,24525
59
+ dissect/target/helpers/network_managers.py,sha256=FSFYVuHsOzxLc68_LTzfFUd3IIBQQpI7rJRwTg7xznQ,24494
60
60
  dissect/target/helpers/polypath.py,sha256=h8p7m_OCNiQljGwoZh5Aflr9H2ot6CZr6WKq1OSw58o,2175
61
61
  dissect/target/helpers/protobuf.py,sha256=NwKrZD4q9v7J8GnZX9gbzMUMV5pR78eAV17jgWOz_EY,1730
62
62
  dissect/target/helpers/record.py,sha256=lWl7k2Mp9Axllm0tXzPGJx2zj2zONsyY_p5g424T0Lc,4826
@@ -98,7 +98,7 @@ dissect/target/loaders/res.py,sha256=8b178x05t9K31wOeP8yGD1IdR3RpiMGz7wcvtHmmHjk
98
98
  dissect/target/loaders/smb.py,sha256=qP8m4Jq7hvAvUCF9jB4yr2Zut7p_R02_vxziNN3R1to,13070
99
99
  dissect/target/loaders/tanium.py,sha256=P9euiQzvVaQQtMQlEmNe0V25w1BkQFRZBuS-0-ksHpY,1585
100
100
  dissect/target/loaders/tar.py,sha256=ah5t9tzplJp-fJrvwTTtfqdjXTpZLQIikWglnaTKQHs,4087
101
- dissect/target/loaders/target.py,sha256=Bp3kcfW-ntkgDZ9IpYPMoR-4FDBPqcLD_W88Z9IU--o,692
101
+ dissect/target/loaders/target.py,sha256=MU_HUtg58YdhdZu6ga1sYG7fK61Dn7N0TBkWXDCWwyc,798
102
102
  dissect/target/loaders/targetd.py,sha256=sfbn2_j3il2G-rPywAoNT5YPtD5KmKkmBv1zrPDRs6I,8250
103
103
  dissect/target/loaders/utm.py,sha256=e5x5ZI3HeL0STh4S-CaQb68Rnug4SVZR9zlmHaGFj0M,978
104
104
  dissect/target/loaders/vb.py,sha256=CnQcn7bAkMzIB1y-lWLtPPXdIVsyeDaT6hTZEurjkV4,2072
@@ -336,10 +336,10 @@ dissect/target/volumes/luks.py,sha256=OmCMsw6rCUXG1_plnLVLTpsvE1n_6WtoRUGQbpmu1z
336
336
  dissect/target/volumes/lvm.py,sha256=wwQVR9I3G9YzmY6UxFsH2Y4MXGBcKL9aayWGCDTiWMU,2269
337
337
  dissect/target/volumes/md.py,sha256=j1K1iKmspl0C_OJFc7-Q1BMWN2OCC5EVANIgVlJ_fIE,1673
338
338
  dissect/target/volumes/vmfs.py,sha256=-LoUbn9WNwTtLi_4K34uV_-wDw2W5hgaqxZNj4UmqAQ,1730
339
- dissect.target-3.17.dev9.dist-info/COPYRIGHT,sha256=m-9ih2RVhMiXHI2bf_oNSSgHgkeIvaYRVfKTwFbnJPA,301
340
- dissect.target-3.17.dev9.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
341
- dissect.target-3.17.dev9.dist-info/METADATA,sha256=rrG21HM56wECrGN8APM0LyujcBAO773I7jqfWjLIyMc,11294
342
- dissect.target-3.17.dev9.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
343
- dissect.target-3.17.dev9.dist-info/entry_points.txt,sha256=tvFPa-Ap-gakjaPwRc6Fl6mxHzxEZ_arAVU-IUYeo_s,447
344
- dissect.target-3.17.dev9.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
345
- dissect.target-3.17.dev9.dist-info/RECORD,,
339
+ dissect.target-3.17.dev11.dist-info/COPYRIGHT,sha256=m-9ih2RVhMiXHI2bf_oNSSgHgkeIvaYRVfKTwFbnJPA,301
340
+ dissect.target-3.17.dev11.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
341
+ dissect.target-3.17.dev11.dist-info/METADATA,sha256=IWvuvSd5YuV8CNcAMgSB_Wyovg2fnHzh7cZzU41v1TY,11300
342
+ dissect.target-3.17.dev11.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
343
+ dissect.target-3.17.dev11.dist-info/entry_points.txt,sha256=tvFPa-Ap-gakjaPwRc6Fl6mxHzxEZ_arAVU-IUYeo_s,447
344
+ dissect.target-3.17.dev11.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
345
+ dissect.target-3.17.dev11.dist-info/RECORD,,