GitHub

Beken tooling

The tooling for Beken (BK72xx) plugs, worked out on the Sonoff S61 - see docs/beken-s61-emulation.md. Not part of the Autoflash tool itself: these drive the BekenEmulator with this project’s patches, read and write the flash formats a conversion passes through, or analyse a firmware image statically. The experiments that proved how the stock firmware pairs, and that nothing in the conversion needs (AirKiss replay, BLE provisioning, the button and pairing drives), are in archive/s61-research/.

The emulator comes with this repository as a container image, kept as the S60’s is: emulator/ pins the upstream commit and its source archive (on the repository’s emulator-source-beken-<commit> release) and holds this project’s patches, and its bk-emu.sh pulls the published image for that version or builds it, fetches the public S61s dump from upstream’s repository (Sonoff’s firmware, which this repository never holds) and runs a tool in the container, with this checkout at /work:

tools/beken/emulator/bk-emu.sh python tools/beken/integrity_gate.py

In the container the emulator is at /opt/beken-emulator, the tools’ default BK_EMU_ROOT, and the fetched dump their default S61_DUMP; the image’s Python has capstone for the static tools too (angr, for decomp.py only, goes into a virtual environment of your own, never the system). The examples below leave out the bk-emu.sh python prefix and assume the current directory is tools/beken.

Static analysis

Work on the logical image (the dump with its CRC stripes removed, so a CPU address equals a file offset). Produce it once with unstripe.py, then point the other tools at it.

Driving the emulator

Those marked archived are in archive/s61-research/, and are run from there.

AirKiss end-to-end procedure

  1. Pick an SSID/password to provision to (a real or throwaway network).
  2. sudo ./airkiss_capture.sh <router-channel> wlp1s0 airkiss.pcap
  3. On the phone: eWeLink app → add the plug → Wi-Fi/quick (AirKiss) pairing → enter that SSID/password → start. Let it run ~30-60 s, Ctrl-C the capture.
  4. python3 airkiss_replay.py airkiss.pcap --ssid <SSID> --pass <PASS>
  5. Watch whether the firmware leaves monitor mode, probes/associates, gets DHCP.

Conversion and config migration

The conversion tool’s own S61 route is tools/autoflash/routes/beken/, built on the pieces here: fota_wrap for the push through eWeLink, rbl and stock_app for Sonoff’s firmware made again from the public dump, uf2 for an update sent to ESPHome, backup.factory_mac for the backup.

Reading the stock config and carrying the Wi-Fi credentials into OpenBeken. See the config-migration section of the emulation reference for the full findings (config partition map, OpenBeken mainConfig_t format, the signed-char Tiny_CRC8, the 0x1e1000 config offset).

Status