Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic config_tree implementation #354

Merged
merged 19 commits into from
Aug 17, 2023

Conversation

Miauwkeru
Copy link
Contributor

  • Add basic unix registry parts
  • Create Config parser
  • simplify get logic
  • Detect configuration files
  • add todo
  • Add a generic space delimited config parser
  • Update hacked together "registry"

@Miauwkeru Miauwkeru force-pushed the DIS-2114_generic-config-parser-research branch from 67d0df5 to 34c62bf Compare August 11, 2023 15:35
@@ -742,6 +743,7 @@ def cmd_cat(self, args: argparse.Namespace, stdout: TextIO) -> Optional[bool]:
fh = path.open()
shutil.copyfileobj(fh, stdout)
stdout.flush()
print("")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over from debug code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was so the prompt after using cat would start at a new line.

dissect/target/plugins/os/unix/config_tree.py Outdated Show resolved Hide resolved
dissect/target/plugins/os/unix/config_tree.py Outdated Show resolved Hide resolved
dissect/target/plugins/os/unix/config_tree.py Outdated Show resolved Hide resolved
dissect/target/plugins/os/unix/config_tree.py Outdated Show resolved Hide resolved
dissect/target/plugins/os/unix/config_tree.py Outdated Show resolved Hide resolved
dissect/target/plugins/os/unix/config_tree.py Outdated Show resolved Hide resolved
dissect/target/plugins/os/unix/config_tree.py Outdated Show resolved Hide resolved
dissect/target/plugins/os/unix/config_tree.py Outdated Show resolved Hide resolved
@Miauwkeru Miauwkeru force-pushed the DIS-2114_generic-config-parser-research branch from 4b28d3c to 8e1ec61 Compare August 16, 2023 13:14
dissect/target/plugins/os/unix/config.py Outdated Show resolved Hide resolved
dissect/target/plugins/os/unix/config.py Outdated Show resolved Hide resolved


CONFIG_MAP: dict[str, LinuxConfigurationParser] = {
"ini": Ini,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you could add these extensions:

  • xml (for now uses fallbackparser, which is a constant for now pointing to txtparser)
  • txt (txtparser, just a blob of text)
  • json (fallback)
  • cnf (default)
  • conf (default)
  • sample (txtparser)
  • template (txtparser)

Then we at least have ~90% a working PoC, now xml behaves really weird.

@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Merging #354 (627552d) into main (356df08) will increase coverage by 0.06%.
The diff coverage is 70.89%.

@@            Coverage Diff             @@
##             main     #354      +/-   ##
==========================================
+ Coverage   70.70%   70.77%   +0.06%     
==========================================
  Files         235      236       +1     
  Lines       18098    18310     +212     
==========================================
+ Hits        12796    12958     +162     
- Misses       5302     5352      +50     
Flag Coverage Δ
unittests 70.77% <70.89%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
dissect/target/tools/shell.py 48.13% <27.02%> (-1.17%) ⬇️
dissect/target/plugins/os/unix/config.py 80.00% <80.00%> (ø)
dissect/target/exceptions.py 85.00% <100.00%> (+0.38%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Miauwkeru Miauwkeru marked this pull request as ready for review August 17, 2023 11:37
@Miauwkeru Miauwkeru merged commit f6b76df into main Aug 17, 2023
18 checks passed
@Miauwkeru Miauwkeru deleted the DIS-2114_generic-config-parser-research branch August 17, 2023 11:43
Copy link
Member

@Schamper Schamper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder if aligning closer with the Windows registry implementation would make more sense, instead of the filesystem implementation.


@abstractmethod
def parse_file(self, fh: TextIO) -> None:
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't @abstractmethod only work if the class inherits from ABC?

I'd probably just do the same as we do in the rest of Dissect, which is to not bother with ABC (it's pretty heavy) and just raise NotImplementedError().


# TODO: Look if I can just create a parsing function and attach it to the
# the parser below.
class LinuxConfigurationParser:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class LinuxConfigurationParser:
class ConfigurationParser:

I think the namespace makes it clear enough.


class Txt(LinuxConfigurationParser):
def parse_file(self, fh: TextIO) -> None:
self.parsed_data = {"content": fh.read(), "size": str(fh.tell())}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason you make a string out of size?


def parse_file(self, fh: TextIO) -> None:
new_info = {}
for line in fh.readlines():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for line in fh.readlines():
for line in fh:

self.parsed_data = new_info


CONFIG_MAP: dict[str, LinuxConfigurationParser] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CONFIG_MAP: dict[str, LinuxConfigurationParser] = {
CONFIG_MAP: dict[str, type[LinuxConfigurationParser]] = {

}


class ConfigurationFs(VirtualFilesystem):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class ConfigurationFs(VirtualFilesystem):
class ConfigurationFilesystem(VirtualFilesystem):



class ConfigurationFs(VirtualFilesystem):
__fstype__: str = "META:registry"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__fstype__: str = "META:registry"
__fstype__: str = "META:configuration"

@JSCU-CNI JSCU-CNI mentioned this pull request Nov 1, 2023
Poeloe pushed a commit that referenced this pull request Feb 29, 2024
Zawadidone pushed a commit to Zawadidone/dissect.target that referenced this pull request Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants