Skip to content

Commit

Permalink
Cleanup shell.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Miauwkeru committed Aug 16, 2023
1 parent 290040c commit 4b28d3c
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions dissect/target/tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
RegistryKeyNotFoundError,
RegistryValueNotFoundError,
)
from dissect.target.filesystem import RootFilesystemEntry
from dissect.target.filesystem import RootFilesystemEntry, FilesystemEntry
from dissect.target.helpers import fsutil, regutil
from dissect.target.plugin import arg
from dissect.target.plugins.os.unix.config_tree import ConfigurationFs
Expand Down Expand Up @@ -810,7 +810,7 @@ def cmd_readlink(self, args: argparse.Namespace, stdout: TextIO) -> Optional[boo
def cmd_registry(self, args: argparse.Namespace, stdout: TextIO) -> Optional[bool]:
"""drop into a registry shell"""
if self.target.os == "linux":
run_cli(UnixRegistryCli(self.target))
run_cli(UnixConfigTreeCli(self.target))
return

hive = None
Expand Down Expand Up @@ -866,44 +866,44 @@ def cmd_enter(self, args: argparse.Namespace, stdout: TextIO) -> None:
print()


class UnixRegistryCli(TargetCli):
def __init__(self, target):
class UnixConfigTreeCli(TargetCli):
def __init__(self, target: Target):
TargetCmd.__init__(self, target)
self.registry = ConfigurationFs(target)
self.config_tree = ConfigurationFs(target)
self.prompt_base = target.name

self.cwd = None
self.chdir("/")

@property
def prompt(self):
return f"{self.prompt_base}/registry {self.cwd}> "
def prompt(self) -> str:
return f"{self.prompt_base}/config_tree {self.cwd}> "

def check_compatible(target):
def check_compatible(target) -> bool:
return target.fs.get("/etc") is not None

def resolve_path(self, path):
def resolve_path(self, path: Optional[Union[str, fsutil.TargetPath]]) -> fsutil.TargetPath:
if not path:
return self.cwd

if isinstance(path, fsutil.TargetPath):
return path

path = fsutil.abspath(path, cwd=str(self.cwd), alt_separator=self.registry.alt_separator)
return self.registry.path(path)
path = fsutil.abspath(path, cwd=str(self.cwd), alt_separator=self.config_tree.alt_separator)
return self.config_tree.path(path)

def resolve_key(self, path):
return self.registry.path(path).get()
def resolve_key(self, path) -> FilesystemEntry:
return self.config_tree.path(path).get()

def resolve_glob_path(self, path):
def resolve_glob_path(self, path: fsutil.TargetPath) -> Iterator[fsutil.TargetPath]:
path = self.resolve_path(path)
if path.exists():
yield path
else:
# Strip the leading '/' as non-relative patterns are unsupported as glob patterns.
glob_path = str(path).lstrip("/")
try:
for path in self.registry.path("/").glob(glob_path):
for path in self.config_tree.path("/").glob(glob_path):
yield path
except ValueError as err:
# The generator returned by glob() will raise a
Expand Down

0 comments on commit 4b28d3c

Please sign in to comment.