fit package

Subpackages

Submodules

fit.csv module

fit.csv.export_to_csv(file_path, data)[source]

Function that exports data from a dictionary to a CSV file.

Each key in the dictionary corresponds to a column header and the value is a list of entries in that column. The function raises a ValueError if any value in the dictionary is a nested dictionary. It normalizes the data to ensure all columns have the same number of entries by repeating single values to match the longest list.

Parameters:
  • file_path (str) – The path to the CSV file to be created.

  • data (dict[str, Any]) – A dictionary containing the data to be exported, where each key is a column header.

Raises:

ValueError – If any value in the dictionary is a nested dictionary.

Return type:

None

fit.csv.import_from_csv(file_path)[source]

Function that imports data from a CSV file and stores it in a dictionary.

Each key in the dictionary corresponds to a column header and the value is a list of entries in that column.

Parameters:

file_path (str) – the path to the CSV file to be imported.

Return type:

dict[str, Any]

Returns:

the dictionary containing the CSV data, where each key is a column header and the value is a list of column entries.

fit.distribution module

class fit.distribution.Distribution(start_bit, end_bit, granularity=1)[source]

Bases: ABC

Abstract base class for defining different types of distributions.

adjust(value)[source]

Function that adjusts the value to the nearest multiple of the granularity.

Parameters:

value (int) – the value to be adjusted.

Return type:

int

Returns:

the adjusted value.

end_bit = 0

The granularity of adjustment for the values. Default is 1.

granularity = 1
length()[source]

Function that computes the length of the distribution.

Return type:

int

Returns:

the length of the distribution.

abstract random()[source]
Return type:

int

start_bit = 0

The ending bit position.

class fit.distribution.Fixed(cases)[source]

Bases: Distribution

Fixed distribution class that generates random values based on the fixed distribution.

cases: list[float]
random()[source]

Function that generates a random values based on the fixed distribution.

Return type:

int

Returns:

the random value.

class fit.distribution.Normal(mean, variance, granularity=1)[source]

Bases: Distribution

Normal distribution class that generates random values based on the normal distribution.

mean: float

The variance of the normal distribution.

random()[source]

Function that generates a random values based on the normal distribution.

Return type:

int

Returns:

the random value.

variance: float
class fit.distribution.Uniform(start_bit, end_bit, granularity=1)[source]

Bases: Distribution

Uniform distribution class that generates random values based on the uniform distribution.

random()[source]

Function that generates a random values based on the uniform distribution.

Return type:

int

Returns:

the random value.

fit.elf module

class fit.elf.ELF(path)[source]

Bases: object

Class for parsing and interacting with ELF - Executable and Linkable Format - binaries.

class Sections(bin)[source]

Bases: object

Class for parsing and interacting with ELF sections.

class Symbols(bin)[source]

Bases: object

Class for parsing and interacting with ELF symbols.

property architecture: ARCH

Property that returns the architecture of the ELF binary.

Returns:

The architecture of the ELF binary.

property bits: int

Property that returns the bitness (32 or 64 bits) of the ELF binary.

Returns:

64 if the binary is 64-bit, otherwise 32.

property header: Header

Property that returns the header of the ELF binary.

Returns:

the header of the ELF binary.

property lief: Binary

Property that returns the parsed ELF binary.

Returns:

the parsed ELF binary.

sections: Sections
property segments: it_segments

Property that returns the segments of the ELF binary.

Returns:

the segments of the ELF binary.

symbols: Symbols

The ELF sections.

fit.fitlib module

fit.fitlib.gdb_injector(bin, gdb_path='gdb_multiarch', remote=None, embedded=True, board_family=None)[source]

Function that creates an Injector instance for GDB with optional parameters.

Parameters:
  • bin (str) – the path to the binary to be injected.

  • gdb_path (str) – the path to the GDB executable. Default is “gdb_multiarch”.

  • remote (Optional[str]) – the remote target for GDB. Default is None.

  • embedded (bool) – the flag that indicates if the target is embedded. Default is True.

  • board_family (Optional[str]) – the family of the embedded board, if applicable. Default is None.

Return type:

Injector

Returns:

the instance of Injector configured for GDB.

fit.injector module

class fit.injector.Injector(bin, implementation='gdb', **kwargs)[source]

Bases: object

Class for managing the injection process into an ELF binary.

class Event(callback, **kwargs)[source]

Bases: object

Class representing an event with a callback and arguments.

callback: Callable[..., Any]

The additional arguments for the callback function.

kwargs: dict[str, Any]
add_run(result, golden=False)[source]

Function that adds a result from a run to the collection of runs.

Parameters:
  • result (dict[str, Any]) – the result of the run.

  • golden (bool) – the golden run.

Return type:

None

binary: ELF

The memory.

close()[source]

Function that closes the internal injector instance.

Return type:

None

events: dict[str, Event] = {}

The golden run. Dictionary with (target, value) pairs.

golden: dict[str, list[Any]] = {}

The injected run. Dictionary with (target, value) pairs.

memory: Memory

The registers.

regs: Registers
report()[source]

Function that reports the injection runs.

Return type:

None

reset()[source]

Function that resets the internal injector instance.

Return type:

None

run(timeout=None, injection_delay=None, inject_func=None)[source]

Function that runs the injection process with optional timeout, injection delay, and injection function.

Parameters:
  • timeout (Optional[timedelta]) – the timeout for the injection process.

  • injection_delay (Optional[timedelta]) – the delay for the injection process.

  • inject_func (Optional[Callable[..., Any]]) – the inject function for the injection process.

Return type:

str

Returns:

the result of the injection process.

runs: dict[str, list[Any]] = {}
save(path)[source]

Function that saves the runs to CSV files.

Parameters:

path (str) – the path to the CSV file.

Return type:

None

set_result_condition(event, callback=<function noop>, **kwargs)[source]

Function that sets a result condition for an event with a callback.

Parameters:
  • event (str) – the event name.

  • callback (Callable[..., Any]) – the callback function.

  • kwargs (dict[str, Any]) – the additional arguments for the callback function.

Return type:

None

class fit.injector.Registers(injector, bin)[source]

Bases: object

Class for interacting with CPU registers through an internal injector.

elf: ELF

The registers.

registers: list[str]
fit.injector.noop(_)[source]

No-operation function for default callbacks.

Parameters:

_ – Type of the Injector.

Return type:

None

fit.logger module

class fit.logger.Logger(name, level=20)[source]

Bases: Logger

Custom logger class that extends the standard logging.Logger to add colored output.

COLORS = {'CRITICAL': '\x1b[41m', 'DEBUG': '\x1b[36m', 'ERROR': '\x1b[31m', 'INFO': '\x1b[32m', 'RESET': '\x1b[0m', 'WARNING': '\x1b[33m'}
critical(msg, *args, **kwargs)[source]

Function that logs a critical message.

Parameters:
  • msg (str) – the critical message.

  • args (object) – the additional arguments passed to the logger.

  • kwargs (Any) – the additional keyword arguments passed to the logger.

Return type:

None

debug(msg, *args, **kwargs)[source]

Function that logs a debug message.

Parameters:
  • msg (str) – the debug message.

  • args (object) – the additional arguments passed to the logger.

  • kwargs (Any) – the additional keyword arguments passed to the logger.

Return type:

None

error(msg, *args, **kwargs)[source]

Function that logs an error message.

Parameters:
  • msg (str) – the error message.

  • args (object) – the additional arguments passed to the logger.

  • kwargs (Any) – the additional keyword arguments passed to the logger.

Return type:

None

format_message(level, message)[source]

Function that formats a log message with the appropriate color based on the log level.

Parameters:
  • level (str) – the log level.

  • message (str) – the log message.

Return type:

str

Returns:

the formatted log message.

info(msg, *args, **kwargs)[source]

Function that logs an info message.

Parameters:
  • msg (str) – the info message.

  • args (object) – the additional arguments passed to the logger.

  • kwargs (Any) – the additional keyword arguments passed to the logger.

Return type:

None

warning(msg, *args, **kwargs)[source]

Function that logs a warning message.

Parameters:
  • msg (str) – the warning message.

  • args (object) – the additional arguments passed to the logger.

  • kwargs (Any) – the additional keyword arguments passed to the logger.

Return type:

None

class fit.logger.TqdmLoggingHandler(level=0)[source]

Bases: Handler

A custom logging handler class that redirects log messages through tqdm’s write method.

emit(record)[source]

Function that emits a log record.

Parameters:

record (LogRecord) – the log record to be emitted.

Return type:

None

fit.logger.get()[source]

Function that gets a logger instance with the custom Logger class.

Return type:

Logger

Returns:

the logger instance.

fit.mapping module

class fit.mapping.Mapping(start, end, size, offset, permission, file)[source]

Bases: object

Class representing a memory mapping.

class Permissions[source]

Bases: object

Class representing the permissions of the file.

EXEC = 4
PRIVATE = 8
READ = 1
WRITE = 2
as_range()[source]

Function that returns the range of the memory mapping.

Return type:

range

Returns:

the memory mapping range.

end: int

The size of the memory mapping.

file: str
property is_executable: bool

Property that checks if the mapping is executable.

Returns:

True if the mapping is executable, False otherwise.

property is_private: bool

Property that checks if the mapping is private.

Returns:

True if the mapping is private, False otherwise.

property is_readable: bool

Property that checks if the mapping is readable.

Returns:

True if the mapping is readable, False otherwise.

property is_writable: bool

Property that checks if the mapping is writable.

Returns:

True if the mapping is writable, False otherwise.

offset: int

The permissions of the memory mapping.

permissions: int

The file associated with the memory mapping.

size: int

The offset of the memory mapping in the file.

start: int

The ending address of the memory mapping.

fit.memory module

class fit.memory.IntList(iterable=(), /)[source]

Bases: list[int]

Class that custom list for handling integer operations including bitwise and shift operators.

class fit.memory.Memory(injector, elf)[source]

Bases: object

Class for managing memory operations using an internal injector.

elf: ELF

The word size.

mapping_ranges()[source]

Function that returns the ranges of memory mappings.

Return type:

list[range]

Returns:

the list of ranges of memory mappings.

property mappings: list[Mapping]

Property that returns the memory mappings.

Returns:

the list of memory mappings.

word_size: int

fit.stencil module

class fit.stencil.Stencil(patterns, offset_distribution=<fit.distribution.Uniform object>, pattern_distribution=<fit.distribution.Uniform object>, word_size=4)[source]

Bases: object

Class representing a stencil used for generating random patterns with specified distributions.

layer(max_times, min_times=0)[source]

Function that generates a layered pattern by applying the stencil multiple times.

Parameters:
  • max_times (int) – the maximum number of times to apply the stencil.

  • min_times (int) – the minimum number of times to apply the stencil.

Return type:

IntList

Returns:

theIntList representing the layered pattern.

offset_distribution: Distribution

The distribution for selecting patterns.

pattern_distribution: Distribution

The patterns to use for the stencil.

pattern_size_in_words: int

The word size for the stencil.

patterns: list[int]

The pattern size.

random()[source]

Function that generates a random pattern based on the stencil’s distributions.

Return type:

IntList

Returns:

the IntList representing the random pattern.

word_size: int
fit.stencil.bits(val)[source]
Return type:

int

Module contents