dissect.target 3.16.dev41__py3-none-any.whl → 3.16.dev43__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,10 +3,16 @@
3
3
  from __future__ import print_function
4
4
 
5
5
  import argparse
6
+ import itertools
6
7
  import logging
7
8
 
8
9
  from dissect.target import Target
9
- from dissect.target.exceptions import RegistryError, TargetError
10
+ from dissect.target.exceptions import (
11
+ RegistryError,
12
+ RegistryKeyNotFoundError,
13
+ TargetError,
14
+ )
15
+ from dissect.target.helpers.regutil import RegistryKey
10
16
  from dissect.target.tools.utils import (
11
17
  catch_sigpipe,
12
18
  configure_generic_arguments,
@@ -29,7 +35,8 @@ def main():
29
35
  parser.add_argument("targets", metavar="TARGETS", nargs="+", help="Targets to load")
30
36
  parser.add_argument("-k", "--key", required=True, help="key to query")
31
37
  parser.add_argument("-kv", "--value", help="value to query")
32
- parser.add_argument("-d", "--depth", type=int, const=0, nargs="?", default=1)
38
+ parser.add_argument("-d", "--depth", type=int, const=0, nargs="?", default=1, help="max depth of subkeys to print")
39
+ parser.add_argument("-l", "--length", type=int, default=100, help="max length of key value to print")
33
40
 
34
41
  configure_generic_arguments(parser)
35
42
  args = parser.parse_args()
@@ -38,34 +45,50 @@ def main():
38
45
 
39
46
  try:
40
47
  for target in Target.open_all(args.targets):
48
+ if not target.has_function("registry"):
49
+ target.log.error("Target has no Windows Registry")
50
+ continue
51
+
41
52
  try:
42
- if args.value:
43
- for key in target.registry.keys(args.key):
44
- try:
45
- print(key.value(args.value))
46
- except RegistryError:
47
- continue
48
- else:
53
+ keys = target.registry.keys(args.key)
54
+ first_key = next(keys)
55
+
56
+ print(target)
57
+
58
+ for key in itertools.chain([first_key], keys):
49
59
  try:
50
- print(target)
51
- for key in target.registry.keys(args.key):
52
- recursor(key, args.depth, 0)
60
+ if args.value:
61
+ print(key.value(args.value))
62
+ else:
63
+ recursor(key, args.depth, 0, args.length)
53
64
  except RegistryError:
54
65
  log.exception("Failed to find registry value")
55
- except Exception:
56
- log.exception("Failed to iterate key")
66
+
67
+ except (RegistryKeyNotFoundError, StopIteration):
68
+ target.log.error("Key %r does not exist", args.key)
69
+
70
+ except Exception as e:
71
+ target.log.error("Failed to iterate key: %s", e)
72
+ target.log.debug("", exc_info=e)
57
73
  except TargetError as e:
58
74
  log.error(e)
59
75
  log.debug("", exc_info=e)
60
76
  parser.exit(1)
61
77
 
62
78
 
63
- def recursor(key, depth, indent):
64
- print(" " * indent + f"+ {key.name!r} ({key.ts})")
79
+ def recursor(key: RegistryKey, depth: int, indent: int, max_length: int = 100) -> None:
80
+ class_name = ""
81
+ if key.class_name:
82
+ class_name = f" ({key.class_name})"
83
+
84
+ print(" " * indent + f"+ {key.name!r} ({key.ts})" + class_name)
65
85
 
66
86
  for r in key.values():
67
87
  try:
68
- print(" " * indent + f" - {r.name!r} {repr(r.value)[:100]}")
88
+ value = repr(r.value)
89
+ if len(value) > max_length:
90
+ value = value[:max_length] + "..."
91
+ print(" " * indent + f" - {r.name!r} {value}")
69
92
  except NotImplementedError:
70
93
  continue
71
94
 
@@ -73,7 +96,7 @@ def recursor(key, depth, indent):
73
96
  return
74
97
 
75
98
  for subkey in key.subkeys():
76
- recursor(subkey, depth - 1, indent + 2)
99
+ recursor(subkey, depth - 1, indent + 2, max_length)
77
100
 
78
101
 
79
102
  if __name__ == "__main__":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dissect.target
3
- Version: 3.16.dev41
3
+ Version: 3.16.dev43
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
@@ -35,7 +35,7 @@ Requires-Dist: flow.record ~=3.14.0
35
35
  Requires-Dist: structlog
36
36
  Provides-Extra: cb
37
37
  Requires-Dist: dissect.target[full] ; extra == 'cb'
38
- Requires-Dist: carbon-black-cloud-sdk-python ~=1.4.3 ; extra == 'cb'
38
+ Requires-Dist: carbon-black-cloud-sdk ~=1.4.3 ; extra == 'cb'
39
39
  Provides-Extra: full
40
40
  Requires-Dist: asn1crypto ; extra == 'full'
41
41
  Requires-Dist: dissect.btrfs <2.0.dev,>=1.0.dev ; extra == 'full'
@@ -317,7 +317,7 @@ dissect/target/tools/info.py,sha256=3smHr8I71yj3kCjsQ5nXkOHI9T_N8UwvkVa1CNOxB-s,
317
317
  dissect/target/tools/logging.py,sha256=5ZnumtMWLyslxfrUGZ4ntRyf3obOOhmn8SBjKfdLcEg,4174
318
318
  dissect/target/tools/mount.py,sha256=L_0tSmiBdW4aSaF0vXjB0bAkTC0kmT2N1hrbW6s5Jow,3254
319
319
  dissect/target/tools/query.py,sha256=1LbvUKSmXOCMb4xqP3t86JkOgFzKlc7mLCqcczfLht8,16018
320
- dissect/target/tools/reg.py,sha256=tII0MLqJ-3lOt7jE-zHUDqYrk0P4euPjiSS_99FT6LE,2378
320
+ dissect/target/tools/reg.py,sha256=FDsiBBDxjWVUBTRj8xn82vZe-J_d9piM-TKS3PHZCcM,3193
321
321
  dissect/target/tools/shell.py,sha256=EBRNKiIV3ljaXKAXraA6DmrIw8Cy5h9irAuwlblP3zo,43251
322
322
  dissect/target/tools/utils.py,sha256=bhVZ3-8YynpHkBl4m1T4IpSpCArAXnEjjYwAFGW5JPg,10595
323
323
  dissect/target/tools/dump/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -332,10 +332,10 @@ dissect/target/volumes/luks.py,sha256=OmCMsw6rCUXG1_plnLVLTpsvE1n_6WtoRUGQbpmu1z
332
332
  dissect/target/volumes/lvm.py,sha256=wwQVR9I3G9YzmY6UxFsH2Y4MXGBcKL9aayWGCDTiWMU,2269
333
333
  dissect/target/volumes/md.py,sha256=j1K1iKmspl0C_OJFc7-Q1BMWN2OCC5EVANIgVlJ_fIE,1673
334
334
  dissect/target/volumes/vmfs.py,sha256=-LoUbn9WNwTtLi_4K34uV_-wDw2W5hgaqxZNj4UmqAQ,1730
335
- dissect.target-3.16.dev41.dist-info/COPYRIGHT,sha256=m-9ih2RVhMiXHI2bf_oNSSgHgkeIvaYRVfKTwFbnJPA,301
336
- dissect.target-3.16.dev41.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
337
- dissect.target-3.16.dev41.dist-info/METADATA,sha256=FsrZyLCUUmg0r0ffyWK_i0vhYmYxnk2Z_piZijkEGbo,11107
338
- dissect.target-3.16.dev41.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
339
- dissect.target-3.16.dev41.dist-info/entry_points.txt,sha256=tvFPa-Ap-gakjaPwRc6Fl6mxHzxEZ_arAVU-IUYeo_s,447
340
- dissect.target-3.16.dev41.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
341
- dissect.target-3.16.dev41.dist-info/RECORD,,
335
+ dissect.target-3.16.dev43.dist-info/COPYRIGHT,sha256=m-9ih2RVhMiXHI2bf_oNSSgHgkeIvaYRVfKTwFbnJPA,301
336
+ dissect.target-3.16.dev43.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
337
+ dissect.target-3.16.dev43.dist-info/METADATA,sha256=k_mmSMwlIKc86B11l-UAys9JHWtSfbicJtUob1FmEfE,11100
338
+ dissect.target-3.16.dev43.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
339
+ dissect.target-3.16.dev43.dist-info/entry_points.txt,sha256=tvFPa-Ap-gakjaPwRc6Fl6mxHzxEZ_arAVU-IUYeo_s,447
340
+ dissect.target-3.16.dev43.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
341
+ dissect.target-3.16.dev43.dist-info/RECORD,,