--- title: Ourosboros Flash Reader author: Patrick Schönberger date: 16.07.2025 transition: none revealjs-url: https://cdn.jsdelivr.net/npm/reveal.js@5.2.1 slideNumber: true --- ## Structure - Start with the problem - Work our way to the solution step by step ## The Problem - How to access data on Shelly devices? - Most Shelly devices are based on ESPs - They don't contain usable data like logs - They do contain user-identifiable data ## - Extract the flash memory and read the data - Do it read-only and document the process - Existing solutions (esptool, mos) can modify memory - They are very complex, and thus hard to modify - What about a custom tool? ## Talking to the ESP - What is the bare minimum needed to talk to an ESP? - Two modes: boot and run - Serial pins are exposed on some Shelly devices and accessible on others - In boot mode they can be used to communicate using a custom protocol ## - What can we do with the protocol? - Synchronize - Write RAM, flash and registers - Configure memory etc. - On the ESP32 it can read flash, but not on the ESP8266, ESP32C3 or ESP32C6 - How do other tools read flash? ## Reading Flash Memory - We cannot directly read flash, but we can write RAM - Write a program for the ESP, load it into RAM and run - This is called the flash loader or stub loader - Esptool uses two versions: - Legacy C version - New Rust version ## - The C version is getting replaced but it is much simpler and it supports ESP8266 - We customize this version by removing write and erase commands - This way we technically have write access until the flash loader is activated - The extraction tool is small and contains no write or erase commands ## Serial Protocol - SLIP frames... ## Demo ## cloc ## ```sh $ cloc esp-flasher-stub/ ----------------------------------------------------------- Language files blank comment code ----------------------------------------------------------- Rust 12 327 78 1863 Logos 14 32 0 249 YAML 3 34 12 214 Markdown 1 34 0 89 TOML 4 8 2 61 ----------------------------------------------------------- SUM: 34 435 92 2476 ----------------------------------------------------------- ``` ## ```sh $ cloc esp-hal ----------------------------------------------------------- Language files blank comment code ----------------------------------------------------------- Rust 492 18739 26120 115809 Linker Script 51 499 1404 11315 Markdown 66 2014 12 5262 TOML 43 505 412 4481 Logos 44 229 15 1105 YAML 13 151 67 1054 Jinja Template 3 52 0 255 JSON 2 0 0 48 CSV 3 0 0 21 SVG 1 0 0 4 ----------------------------------------------------------- SUM: 718 22189 28030 139354 ----------------------------------------------------------- ``` ## ```sh $ cloc esptool-legacy-flasher-stub/ ----------------------------------------------------------- Language files blank comment code ----------------------------------------------------------- Linker Script 32 787 1188 18751 C 6 1284 636 7689 C/C++ Header 8 463 557 1687 make 1 36 33 130 YAML 4 19 0 114 Python 2 25 21 80 Markdown 3 58 0 76 Bourne Shell 2 9 8 23 TOML 1 1 0 20 Jinja Template 1 4 2 14 ----------------------------------------------------------- SUM: 60 2686 2445 28584 ----------------------------------------------------------- ```