dissect.target 3.8.dev33__py3-none-any.whl → 3.8.dev35__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,10 @@ Also contains some other filesystem related utilities.
5
5
 
6
6
  from __future__ import annotations
7
7
 
8
+ import bz2
8
9
  import errno
9
10
  import fnmatch
11
+ import gzip
10
12
  import hashlib
11
13
  import io
12
14
  import logging
@@ -973,7 +975,12 @@ def resolve_link(
973
975
  def open_decompress(path: TargetPath, mode: str = "rb") -> Union[BinaryIO, TextIO]:
974
976
  """Open and decompress a file. Handles gz and bz2 files. Uncompressed files are opened as-is.
975
977
 
976
- Assumes that the ``path`` exists.
978
+ Args:
979
+ path: The path to the file to open and decompress. It is assumed this path exists.
980
+ mode: The mode in which to open the file.
981
+
982
+ Returns:
983
+ An binary or text IO stream, depending on the mode with which the file was opened.
977
984
 
978
985
  Example:
979
986
  bytes_buf = open_decompress(Path("/dir/file.gz")).read()
@@ -981,16 +988,17 @@ def open_decompress(path: TargetPath, mode: str = "rb") -> Union[BinaryIO, TextI
981
988
  for line in open_decompress(Path("/dir/file.gz"), "rt"):
982
989
  print(line)
983
990
  """
984
-
985
- if path.suffix == ".gz":
986
- import gzip
987
-
988
- return gzip.open(path.open(), mode)
989
- elif path.suffix == ".bz2":
990
- import bz2
991
-
992
- return bz2.open(path.open(), mode)
991
+ file = path.open()
992
+ magic = file.read(4)
993
+ file.seek(0)
994
+
995
+ if magic[:2] == b"\x1f\x8b":
996
+ return gzip.open(file, mode)
997
+ # In a valid bz2 header the 4th byte is in the range b'1' ... b'9'.
998
+ elif magic[:3] == b"BZh" and 0x31 <= magic[3] <= 0x39:
999
+ return bz2.open(file, mode)
993
1000
  else:
1001
+ file.close()
994
1002
  return path.open(mode)
995
1003
 
996
1004
 
@@ -143,6 +143,15 @@ class TargetCmd(cmd.Cmd):
143
143
 
144
144
  return cmd.Cmd.default(self, line)
145
145
 
146
+ def emptyline(self):
147
+ """This function forces Python's cmd.Cmd module to behave like a regular shell.
148
+
149
+ When entering an empty command, the cmd module will by default repeat the previous command.
150
+ By defining an empty ``emptyline`` function we make sure no command is executed instead.
151
+ See https://stackoverflow.com/a/16479030
152
+ """
153
+ pass
154
+
146
155
  def _exec(self, func, command_args_str):
147
156
  """
148
157
  Command execution helper that chains initial command and piped
@@ -720,6 +729,20 @@ class TargetCli(TargetCmd):
720
729
  shutil.copyfileobj(fh, stdout)
721
730
  stdout.flush()
722
731
 
732
+ @arg("path")
733
+ def cmd_zcat(self, args, stdout):
734
+ """print file content from compressed files"""
735
+ paths = self.resolveglobpath(args.path)
736
+ stdout = stdout.buffer
737
+ for path in paths:
738
+ path = self.checkfile(path)
739
+ if not path:
740
+ continue
741
+
742
+ fh = fsutil.open_decompress(path)
743
+ shutil.copyfileobj(fh, stdout)
744
+ stdout.flush()
745
+
723
746
  @arg("path")
724
747
  def cmd_hexdump(self, args, stdout):
725
748
  """print a hexdump of the first X bytes"""
@@ -748,6 +771,15 @@ class TargetCli(TargetCmd):
748
771
 
749
772
  pydoc.pager(path.open("rt", errors="ignore").read(10 * 1024 * 1024))
750
773
 
774
+ @arg("path")
775
+ def cmd_zless(self, args, stdout):
776
+ """open the first 10 MB of a compressed file with zless"""
777
+ path = self.checkfile(args.path)
778
+ if not path:
779
+ return
780
+
781
+ pydoc.pager(fsutil.open_decompress(path, "rt").read(10 * 1024 * 1024))
782
+
751
783
  @arg("path", nargs="+")
752
784
  def cmd_readlink(self, args, stdout):
753
785
  """print resolved symbolic links or canonical file names"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dissect.target
3
- Version: 3.8.dev33
3
+ Version: 3.8.dev35
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
@@ -37,7 +37,7 @@ dissect/target/helpers/cache.py,sha256=3_akK2L4-aWhRJh_TxP8Eks3jY-PwpWBi-0R6MjAZ
37
37
  dissect/target/helpers/config.py,sha256=7YCHHQfwlWuIAQHTqLVjdFSVYAB_xABiZYRPxXU6_Qw,1188
38
38
  dissect/target/helpers/descriptor_extensions.py,sha256=uT8GwznfDAiIgMM7JKKOY0PXKMv2c0GCqJTCkWFgops,2605
39
39
  dissect/target/helpers/docs.py,sha256=wxrhQKaV6F--Q4L69QwaXl-2EOZMp6POVnZ3_-9GeQE,4834
40
- dissect/target/helpers/fsutil.py,sha256=2LsEP6p6QvV2wJTj_PQYS9Jg3kazuUaB1t8gLGTH9PQ,31320
40
+ dissect/target/helpers/fsutil.py,sha256=LFSUF6X1JGw7LFT0h7lTEbEny6cjmiI8zE509Z_Dd-w,31695
41
41
  dissect/target/helpers/hashutil.py,sha256=SSLl5BCAxiyanjEfDex0wSVu7D3uEbRKK3sRzRPePYY,2059
42
42
  dissect/target/helpers/keychain.py,sha256=O4zYovoBhCZzaHxJy31Qf4qaosM82khdtHm0khybNfs,3099
43
43
  dissect/target/helpers/lazy.py,sha256=4VnF-fUKor1K77Z09F4YnLpxM9PMHULzS9SJwVOnUS0,1799
@@ -240,7 +240,7 @@ dissect/target/tools/logging.py,sha256=5ZnumtMWLyslxfrUGZ4ntRyf3obOOhmn8SBjKfdLc
240
240
  dissect/target/tools/mount.py,sha256=oPjE954wRPnuhiXavoTSoZkMGKa5GpH9cMWZ3-piQd8,2320
241
241
  dissect/target/tools/query.py,sha256=Btt_PMVAWIYHhPLg0b8u5e_TDdG8CG5xapxLu82dbSE,11466
242
242
  dissect/target/tools/reg.py,sha256=37g_Xdb5ZbYAkMgQFmZNdKM_wWP9Bcw2Kk6quo1gwZ4,2147
243
- dissect/target/tools/shell.py,sha256=-zr5QaekJi7vXEnS_u8ua4KBSJm5TSJTIy6KlzFTvso,34908
243
+ dissect/target/tools/shell.py,sha256=HICeIN5kCZYyGmAm_riWO9xrGnQmOzSp-Oici4QeO6Y,36003
244
244
  dissect/target/tools/utils.py,sha256=i9gHb-_IK73NEiA9sKVCPkeY80lRj_RYpGXnsy_4Ak8,6727
245
245
  dissect/target/tools/dump/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
246
246
  dissect/target/tools/dump/run.py,sha256=yHn9xl_VjasgiuLpjtZdnLW32QCbkwHfnnTPY6Ck_aw,9689
@@ -251,10 +251,10 @@ dissect/target/volumes/bde.py,sha256=gYGg5yF9MNARwNzEkrEfZmKkxyZW4rhLkpdnPJCbhGk
251
251
  dissect/target/volumes/disk.py,sha256=95grSsPt1BLVpKwTclwQYzPFGKTkFFqapIk0RoGWf38,968
252
252
  dissect/target/volumes/lvm.py,sha256=zXAfszxNR6tOGrKAtAa_E-JhjI-sXQyR4VYLXD-kqCw,1616
253
253
  dissect/target/volumes/vmfs.py,sha256=mlAJ8278tYaoRjk1u6tFFlCaDQUrVu5ZZE4ikiFvxi8,1707
254
- dissect.target-3.8.dev33.dist-info/COPYRIGHT,sha256=m-9ih2RVhMiXHI2bf_oNSSgHgkeIvaYRVfKTwFbnJPA,301
255
- dissect.target-3.8.dev33.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
256
- dissect.target-3.8.dev33.dist-info/METADATA,sha256=d99d4LbLekrjkDplEZphsBXKlPDPomwWBKK_s31TeQA,9752
257
- dissect.target-3.8.dev33.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
258
- dissect.target-3.8.dev33.dist-info/entry_points.txt,sha256=tvFPa-Ap-gakjaPwRc6Fl6mxHzxEZ_arAVU-IUYeo_s,447
259
- dissect.target-3.8.dev33.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
260
- dissect.target-3.8.dev33.dist-info/RECORD,,
254
+ dissect.target-3.8.dev35.dist-info/COPYRIGHT,sha256=m-9ih2RVhMiXHI2bf_oNSSgHgkeIvaYRVfKTwFbnJPA,301
255
+ dissect.target-3.8.dev35.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
256
+ dissect.target-3.8.dev35.dist-info/METADATA,sha256=S4ko-GsgaonoytojPJM2DGAbtTSRxXCzZMxGVkxDk1Y,9752
257
+ dissect.target-3.8.dev35.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
258
+ dissect.target-3.8.dev35.dist-info/entry_points.txt,sha256=tvFPa-Ap-gakjaPwRc6Fl6mxHzxEZ_arAVU-IUYeo_s,447
259
+ dissect.target-3.8.dev35.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
260
+ dissect.target-3.8.dev35.dist-info/RECORD,,