|
whiskers 0.4.5
RP2350 BadUSB Tool
|
This project uses Lua 5.5.0 to act as a scripting language for the device. Lua scripts are easily swappable and shareable, not the mention the language being very flexible and easy to use. Lua is used to control file access, USB functions, configuration, and ever other user accessible function of the device.
This is a bit more technical on how it's actually implemented under the hood. The lua script will only be ran once and once it has completed (either finished cleanly or errored out) the device will not attempt to re-run it. The USB code & logic lives on a separate core that lasts the entire lifetime of the device, so do not be afraid to setup MSC storage over USB and then close the Lua script as it will remain active until the device is physically turned off.
The default file operation and OS functions do not work and instead you should use the wlua_ functions. These functions were designed to work with the HAL and are custom made, but work similarly to standard POSIX functions.
The device will first check if a script is on the SD card named "payload.lua", if not found it will try to run any saved scripts from the internal flash memory. If neither is found, simply nothing happens.
When errors occur, debug information is printed via stdout (typically UART serial). Only critical errors (ones that are directly unrecoverable) will crash the lua script, most other small errors will just print to stdout and the interpreter will keep on chugging running the script.
Due to the nature of Lua and it's interpreter under the hood, large chunks of the code must be passed at once or the interpreter can lose context of conditional statements (like while loops, if/else, etc.) and will break. So internally up to 32k characters are passed in at a time to the interpreter. If your program is for some reason longer than this, make sure at the 32k (1024 * 32 to be exact) mark it splits not in between any conditional logic (ie. a loop). This limit can also be tuned to be higher if need be.
Using lua is as simple as writing a lua script, naming it "payload.lua", and inserting it into the root directory on the SD card for the device. The device will always automatically attempt to run this script at boot, and will NOT re-run it upon completion or failure.
The version of lua being used is 5.5.0. All basic lua library functions (besides those that deal with os functions, like time, randomness, and file operation) are usable like normal. For the functions that are not available, ie. file operations, custom functions have been exposed to the user and can be viewed here.
Other functions, including the ones that involve all the USB functionality (main functionality of the device) can also be found on the lua function documentation page.