fit package
Subpackages
- fit.interfaces package
- Subpackages
- Submodules
- fit.interfaces.implementations module
- fit.interfaces.internal_injector module
InternalInjectorInternalInjector.close()InternalInjector.get_class()InternalInjector.get_mappings()InternalInjector.get_register_names()InternalInjector.interrupt()InternalInjector.is_running()InternalInjector.read_memory()InternalInjector.read_register()InternalInjector.reset()InternalInjector.run()InternalInjector.set_event()InternalInjector.write_memory()InternalInjector.write_register()
- Module contents
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:
ABCAbstract 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.
- start_bit = 0
The ending bit position.
- class fit.distribution.Fixed(cases)[source]
Bases:
DistributionFixed distribution class that generates random values based on the fixed distribution.
-
cases:
list[float]
-
cases:
- class fit.distribution.Normal(mean, variance, granularity=1)[source]
Bases:
DistributionNormal 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
-
mean:
- class fit.distribution.Uniform(start_bit, end_bit, granularity=1)[source]
Bases:
DistributionUniform distribution class that generates random values based on the uniform distribution.
fit.elf module
- class fit.elf.ELF(path)[source]
Bases:
objectClass for parsing and interacting with ELF - Executable and Linkable Format - binaries.
- 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.
- property segments: it_segments
Property that returns the segments of the ELF binary.
- Returns:
the segments of the ELF binary.
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:
- Returns:
the instance of Injector configured for GDB.
fit.injector module
- class fit.injector.Injector(bin, implementation='gdb', **kwargs)[source]
Bases:
objectClass for managing the injection process into an ELF binary.
- class Event(callback, **kwargs)[source]
Bases:
objectClass representing an event with a callback and arguments.
-
callback:
Callable[...,Any] The additional arguments for the callback function.
-
kwargs:
dict[str,Any]
-
callback:
- 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
-
golden:
dict[str,list[Any]] = {} The injected run. Dictionary with (target, value) pairs.
- 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
fit.logger module
- class fit.logger.Logger(name, level=20)[source]
Bases:
LoggerCustom 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.
fit.mapping module
- class fit.mapping.Mapping(start, end, size, offset, permission, file)[source]
Bases:
objectClass representing a memory mapping.
- class Permissions[source]
Bases:
objectClass 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:
objectClass for managing memory operations using an internal injector.
- 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:
objectClass 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:
- 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:
- Returns:
the IntList representing the random pattern.
-
word_size:
int