Context and logging¶
context
¶
Global, thread-local-free configuration object, modelled after pwntools' context.
Example
from hwntools import context
context.log_level = "debug"
context.timeout = 5
with context.local(endian="big"):
...
SerialDefaults
dataclass
¶
SerialDefaults(baudrate: int = 115200, bytesize: int = 8, parity: str = 'N', stopbits: float = 1, xonxoff: bool = False, rtscts: bool = False)
Default line settings used by hwntools.serial when not given explicitly.
Context
dataclass
¶
Context(timeout: float = 10.0, tool_timeout: float = 600.0, newline: bytes = b'\n', arch: str = 'arm', bits: int = 32, endian: Endian = 'little', serial: SerialDefaults = SerialDefaults(), _log_level: int = INFO)
Process-wide settings. Use the module level context instance.
log_level
property
writable
¶
Current log level as an int (logging.INFO etc.).
Assign either an int or one of debug, info, warn, error, silent.
update
¶
Set several attributes at once. arch also updates bits/endian.
log
¶
pwntools-style console logging: [*] info, [+] success, [!] warn, progress lines.
Messages go to stderr so that tool output on stdout stays clean. Output is filtered by
context.log_level.
Logger
¶
Small logger with pwntools' look and feel.
hexdump
¶
Log a hexdump of data at level (debug by default).
Progress
¶
Progress(logger: Logger, msg: str, status: str = '', min_interval: float = 2.0)
A single status line that can be updated in place.
On a TTY the line is rewritten; otherwise updates are rate limited to one every few seconds so logs stay readable.
status
¶
Update the progress line (rate-limited without a terminal unless force).