Workspace

class tritondse.workspace.Workspace(root_dir: tritondse.types.PathLike)[source]

Class to abstract the file tree of the current exploration workspace. A user willing to save additional files in the workspace is invited to do it from the workspace API as it somehow abstract the exact location of it.

Parameters:

root_dir (tritondse.types.PathLike) – Root directory of the workspace. Created if not existing

BIN_DIR = 'bin'
CORPUS_DIR = 'corpus'
CRASH_DIR = 'crashes'
DEFAULT_WORKSPACE = '/tmp/triton_workspace'
FAIL_DIR = 'fails'
HANG_DIR = 'hangs'
LOG_FILE = 'tritondse.log'
METADATA_DIR = 'metadata'
WORKLIST_DIR = 'worklist'
get_binary_directory() Path[source]

Get the directory containing the executable (and its dependencies). :return: Path of the directory

get_metadata_file(name: str) str | None[source]

Read a metadata file from the workspace on disk. Data is read as a string. If the given file does not exist, None is returned

Parameters:

name (str) – file name (can also be a path)

Returns:

File content as string if existing

Return type:

Optional[str]

get_metadata_file_path(name: str) Path[source]

Get a file path in the workspace directory that the user can write into. Might be called for the user to write on its own the file content. If name is a file tree, all parent directories are created.

Parameters:

name (str) – filename wanted

Returns:

absolute filepath (regardless of whether it exists or not)

initialize(flush: bool = False) None[source]

Initialize the workspace by creating all required sub-folders if not already existing.

Parameters:

flush (bool) – if True deletes all files contained in the workspace

iter_corpus() Generator[Seed, None, None][source]

Iterate over the corpus files as Seed object.

Returns:

generator of Seed object

Return type:

Generator[Seed, None, None]

iter_crashes() Generator[Seed, None, None][source]

Iterate over the crashes files as Seed object.

Returns:

generator of Seed object

Return type:

Generator[Seed, None, None]

iter_fails() Generator[Seed, None, None][source]

Iterate over the fail files as Seed object.

Returns:

generator of Seed object

Return type:

Generator[Seed, None, None]

iter_hangs() Generator[Seed, None, None][source]

Iterate over the hang files as Seed object.

Returns:

generator of Seed object

Return type:

Generator[Seed, None, None]

iter_worklist() Generator[Seed, None, None][source]

Iterate over the worklist files as Seed object. Worklist are all the pending seeds

Returns:

generator of Seed object

Return type:

Generator[Seed, None, None]

property logfile_path
root_dir: Path

root directory of the Workspace

save_file(rel_path: tritondse.types.PathLike, content: str | bytes, override: bool = False)[source]

Save an arbitrary file in the workspace by providing the relative path of the file. If override is True, erase the previous file if any.

Parameters:
  • rel_path (tritondse.types.PathLike) – relative path of the file

  • content (Union[str, bytes]) – content to write

  • override (bool) – whether to override or not an existing file

save_metadata_file(name: str, content: str | bytes) None[source]

Save content in a file name in the metadata directory. The name should be a file name not a path.

Parameters:
  • name (str) – file name

  • content (Union[str, bytes]) – content of the file to write

save_seed(seed: Seed) None[source]

Save the current seed in the workspace directory matching its status.

Parameters:

seed (Seed) – Seed to save

update_seed_location(seed: Seed) None[source]

Move a worklist seed to its final location according to its (new) status. Typically used to move a seed from pending ones to corpus or crash once it is fully consumed.

Parameters:

seed (Seed) – seed to move