Skip to content

libdebug.data.signal_catcher

SignalCatcher dataclass

Catch a signal raised by the target process.

Attributes:

Name Type Description
signal_number int

The signal number to catch.

callback Callable[[ThreadContext, CaughtSignal], None]

The callback defined by the user to execute when the signal is caught.

recursive bool

Whether, when the signal is hijacked with another one, the signal catcher associated with the new signal should be considered as well. Defaults to False.

enabled bool

Whether the signal will be caught or not.

hit_count int

The number of times the signal has been caught.

Source code in libdebug/data/signal_catcher.py
@dataclass
class SignalCatcher:
    """Catch a signal raised by the target process.

    Attributes:
        signal_number (int): The signal number to catch.
        callback (Callable[[ThreadContext, CaughtSignal], None]): The callback defined by the user to execute when the signal is caught.
        recursive (bool): Whether, when the signal is hijacked with another one, the signal catcher associated with the new signal should be considered as well. Defaults to False.
        enabled (bool): Whether the signal will be caught or not.
        hit_count (int): The number of times the signal has been caught.
    """

    signal_number: int
    callback: Callable[[ThreadContext, SignalCatcher], None]
    recursive: bool = True
    enabled: bool = True
    hit_count: int = 0

    def enable(self: SignalCatcher) -> None:
        """Enable the signal catcher."""
        provide_internal_debugger(self)._ensure_process_stopped()
        self.enabled = True

    def disable(self: SignalCatcher) -> None:
        """Disable the signal catcher."""
        provide_internal_debugger(self)._ensure_process_stopped()
        self.enabled = False

    def hit_on(self: SignalCatcher, thread_context: ThreadContext) -> bool:
        """Returns whether the signal catcher has been hit on the given thread context."""
        return self.enabled and thread_context.signal_number == self.signal_number

    def __hash__(self: SignalCatcher) -> int:
        """Return the hash of the signal catcher, based just on the signal number."""
        return hash(self.signal_number)

__hash__()

Return the hash of the signal catcher, based just on the signal number.

Source code in libdebug/data/signal_catcher.py
def __hash__(self: SignalCatcher) -> int:
    """Return the hash of the signal catcher, based just on the signal number."""
    return hash(self.signal_number)

disable()

Disable the signal catcher.

Source code in libdebug/data/signal_catcher.py
def disable(self: SignalCatcher) -> None:
    """Disable the signal catcher."""
    provide_internal_debugger(self)._ensure_process_stopped()
    self.enabled = False

enable()

Enable the signal catcher.

Source code in libdebug/data/signal_catcher.py
def enable(self: SignalCatcher) -> None:
    """Enable the signal catcher."""
    provide_internal_debugger(self)._ensure_process_stopped()
    self.enabled = True

hit_on(thread_context)

Returns whether the signal catcher has been hit on the given thread context.

Source code in libdebug/data/signal_catcher.py
def hit_on(self: SignalCatcher, thread_context: ThreadContext) -> bool:
    """Returns whether the signal catcher has been hit on the given thread context."""
    return self.enabled and thread_context.signal_number == self.signal_number