utils

pydecipher.utils.check_for_our_xdis()None

Check that the pydecipher fork of xdis is installed.

Exits if its not.

pydecipher.utils.check_read_access(path: pathlib.Path)None

Verify that we can read successfully from the given file path.

Parameters

path (os.PathLike) – The path to check.

pydecipher.utils.check_write_access(path: pathlib.Path)None

Verify that we can write successfully to the given file path.

Parameters

path (pathlib.Path) – The path to check.

pydecipher.utils.parse_for_strings(data: bytes)Set[str]

Given a blob of data, will return a set of all the readable/printable strings.

Parameters

data (bytes) – The data to search for printable strings.

Returns

A set of the printable strings in this data.

Return type

Set[str]

pydecipher.utils.parse_for_version_strings(data: bytes, formats=['[0-9](?:\\.[0-9]+)+', '(?<=(python))[0-9]{2}'])List[str]

Search for Python version numbers within a blob of data.

Parameters

data (bytes) – The data to search for version strings.

Returns

The Python versions found, along with the the strings that contain those version numbers. Format is (version_number, string_that_contained_version_number).

Return type

List[Tuple[str, str]]

pydecipher.utils.rglob_limit_depth(path_obj: pathlib.Path, pattern: str, n: int = 1)Generator[os.PathLike, None, None]

Path object rglob, but allows for limit to depth of recursive search.

Parameters
  • path_obj (pathlib.Path) – The path to recursively search for the pattern.

  • pattern (str) – The pattern to search for.

  • n (int) – The maximum recursive depth.

Yields

pathlib.Path – A path matching the given pattern.

pydecipher.utils.slugify(value: str, allow_unicode: bool = False)str

Take a string and remove any potentially ‘problematic’ characters.

Note

This function is taken from Django’s codebase.

Converts a string to a URL slug by:

  1. Converting to ASCII if allow_unicode is False (the default).

  2. Removing characters that aren’t alphanumerics, underscores, hyphens, or whitespace.

  3. Removing leading and trailing whitespace.

  4. Converting to lowercase.

  5. Replacing any whitespace or repeated dashes with single dashes.

Parameters
  • value (str) – The string to be converted

  • allow_unicode (bool) – Whether or not to allow unicode characters.

Returns

The cleaned string.

Return type

str