dissect.target.helpers.configutil
#
Module Contents#
Classes#
Source gotten from: |
|
Parse a configuration file specified by |
|
Parses an ini file according using the built-in python ConfigParser |
|
Read the file into |
|
This parser is used for the files that use a single level of indentation to specify a different scope. |
|
Functions#
Parses the content of an |
|
Attributes#
- class dissect.target.helpers.configutil.PeekableIterator(iterable)#
Source gotten from: https://more-itertools.readthedocs.io/en/stable/_modules/more_itertools/more.html#peekable
- __iter__()#
- __next__()#
- peek()#
- class dissect.target.helpers.configutil.ConfigurationParser(collapse: bool | set = False, collapse_inverse: bool = False, seperator: tuple[str] = ('=',), comment_prefixes: tuple[str] = (';', '#'))#
- __getitem__(item: Any) dict | str #
- __contains__(item: str) bool #
- abstract parse_file(fh: TextIO) None #
- get(item: str, default: Any | None = None) Any #
- read_file(fh: TextIO) None #
Parse a configuration file.
- Raises:
ConfigurationParsingError – If any exception occurs during during the parsing process
- keys() KeysView #
- items() ItemsView #
- class dissect.target.helpers.configutil.Default(*args, **kwargs)#
Bases:
ConfigurationParser
Parse a configuration file specified by
seperator
andcomment_prefixes
.This parser splits only on the first
seperator
it finds:key<seperator>value -> {“key”: “value”}
key<seperator>value
- continuation
-> {“key”: “value continuation”}
# Unless we collapse values, we add them to a list to not overwrite any values. key<seperator>value1 key<seperator>value2
-> {key: [value1, value2]}
<empty_space><comment> -> skip
- line_reader(fh: TextIO) Iterator[str] #
- parse_file(fh: TextIO) None #
- class dissect.target.helpers.configutil.Ini(*args, **kwargs)#
Bases:
ConfigurationParser
Parses an ini file according using the built-in python ConfigParser
- parse_file(fh: io.TextIO) None #
- class dissect.target.helpers.configutil.Txt(collapse: bool | set = False, collapse_inverse: bool = False, seperator: tuple[str] = ('=',), comment_prefixes: tuple[str] = (';', '#'))#
Bases:
ConfigurationParser
Read the file into
content
, and show the bumber of bytes read.- parse_file(fh: TextIO) None #
- class dissect.target.helpers.configutil.Indentation(*args, **kwargs)#
Bases:
Default
This parser is used for the files that use a single level of indentation to specify a different scope.
Examples of these files are for example the sshd_config file. Where “Match” statments use a single layer of indentaiton to specify a scope for the key value pairs.
The parser parses this as the following:
- key value
- key2 value2
-> {“key value”: {“key2”: “value2”}}
- parse_file(fh: TextIO) None #
- class dissect.target.helpers.configutil.ParserOptions#
- collapse: bool | set | None#
- collapse_inverse: bool | None#
- seperator: tuple[str] | None#
- comment_prefixes: tuple[str] | None#
- class dissect.target.helpers.configutil.ParserConfig#
- parser: type[ConfigurationParser]#
- collapse: bool | set | None#
- collapse_inverse: bool | None#
- seperator: tuple[str] | None#
- comment_prefixes: tuple[str] | None#
- create_parser(options: ParserOptions | None = None) ConfigurationParser #
- dissect.target.helpers.configutil.MATCH_MAP: dict[str, ParserConfig]#
- dissect.target.helpers.configutil.CONFIG_MAP: dict[tuple[str, Ellipsis], ParserConfig]#
- dissect.target.helpers.configutil.KNOWN_FILES: dict[str, type[ConfigurationParser]]#
- dissect.target.helpers.configutil.parse(path: dissect.target.filesystem.FilesystemEntry | dissect.target.helpers.fsutil.TargetPath, hint: str | None = None, *args, **kwargs) configparser.ConfigParser #
Parses the content of an
path
orentry
to a dictionary.- Parameters:
file_path – An entry or targetpath that with contents to parse
hint – A hint to what parser should be used.
collapse –
seperator – What seperator to use for key value mapping
comment_prefixes – The characters that determine a comment.
- Raises:
FileNotFoundError – If the
path
is not a file.
- dissect.target.helpers.configutil.parse_config(entry: dissect.target.filesystem.FilesystemEntry, hint: str | None = None, options: ParserOptions | None = None) configparser.ConfigParser #