Simulator¶
See the simulator quickstart for an introduction.
sim
¶
Simulated devices for dry runs and tests: a fake U-Boot console and a fake Linux shell.
A SimDevice can be driven in-process through SimTube, or exposed on a real
pseudo-terminal with PtyBridge (POSIX only) so that hwntools.serial talks to
it exactly like a USB-UART adapter:
from hwntools import serial
from hwntools.sim import FakeUBoot, PtyBridge
with PtyBridge(FakeUBoot()) as bridge:
io = serial(bridge.port)
...
These fakes model the behaviour that matters for scripting (echo, prompts, autoboot timing,
md.b formatting, login prompts) and are not emulators.
SimDevice
¶
FakeUBoot
¶
FakeUBoot(memory: bytes = b'', mem_base: int = 2147483648, env: Mapping[str, str] | None = None, prompt: str = '=> ', autoboot_delay: float = 1.0, stop_string: str | None = None, corrupt_md_every: int = 0, max_md_count: int = 65536)
Bases: _LineDevice
A U-Boot console with autoboot countdown, env and a memory region for md.b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memory
|
bytes
|
bytes visible at |
b''
|
env
|
Mapping[str, str] | None
|
initial environment. |
None
|
autoboot_delay
|
float
|
seconds the countdown waits for a key ( |
1.0
|
stop_string
|
str | None
|
if set, only this string (e.g. |
None
|
corrupt_md_every
|
int
|
corrupt one byte of every N-th |
0
|
FakeLinuxShell
¶
FakeLinuxShell(credentials: Mapping[str, str] | None = None, root: bool = True, cwd: str | None = None, path: str | None = None, hostname: str = 'device', boot_log: str = '', command_hook: Callable[[str], str | None] | None = None)
Bases: _LineDevice
A serial console with an optional login prompt in front of a real /bin/sh.
Every command line is executed with sh -c (POSIX only) in cwd, so file reads,
base64, od and friends behave like on a device. path restricts the tools that are
available, which lets tests exercise fallbacks.