script to encode a payload

This commit is contained in:
2026-08-31 18:44:20 +02:00
parent 802915ee31
commit 6d08dd1678
4 changed files with 75 additions and 17 deletions
+1
View File
@@ -0,0 +1 @@
payloads/
+6
View File
@@ -9,4 +9,10 @@ cat payload.duck | python encoder.py -p -l fr > payload.bin
python3 duck2spark.py -i payload.bin -l 1 -f 1000 -o payload.ino
rm payload.bin
```
Or with the script (replace payload with the name of the payload and fr with the layout):
```bash
./encode.sh payload fr
```
Then flash your Digispark Attiny85 using arduino IDE.
Executable
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
PYTHON="python3"
ENCODER="$SCRIPT_DIR/encoder.py"
DUCK2SPARK="$SCRIPT_DIR/duck2spark.py"
INPUT_DIR="$SCRIPT_DIR/ducky-payloads"
OUTPUT_DIR="$SCRIPT_DIR/payloads"
RESOURCE_DIR="$SCRIPT_DIR/resources"
usage() {
echo "Usage: $0 <payload> <layout>"
echo
echo "Example:"
echo " $0 open-website fr"
}
if [[ $# -ne 2 ]]; then
usage
exit 1
fi
PAYLOAD="$1"
LAYOUT="$2"
INPUT="$INPUT_DIR/$PAYLOAD.duck"
OUTPUT="$OUTPUT_DIR/$PAYLOAD.ino"
TMP_BIN="$OUTPUT_DIR/$PAYLOAD.bin"
LANG_FILE="$RESOURCE_DIR/$LAYOUT.properties"
if [[ ! -f "$INPUT" ]]; then
echo "Error: payload not found: $INPUT" >&2
exit 1
fi
if [[ ! -f "$LANG_FILE" ]]; then
echo "Error: keyboard layout not found: $LANG_FILE" >&2
exit 1
fi
mkdir -p "$OUTPUT_DIR"
echo "Payload : $PAYLOAD"
echo "Layout : $LAYOUT"
echo "Input : $INPUT"
echo "Output : $OUTPUT"
# DuckyScript to binary payload.
"$PYTHON" "$ENCODER" \
-i "$INPUT" \
-o "$TMP_BIN" \
-l "$LAYOUT"
# Binary payload to Arduino sketch.
"$PYTHON" "$DUCK2SPARK" \
-i "$TMP_BIN" \
-l 1 \
-f 1000 \
-o "$OUTPUT"
# Remove intermediate file.
rm -f "$TMP_BIN"
echo "Generated $OUTPUT"
-17
View File
@@ -1,17 +0,0 @@
#include "DigiKeyboard.h"
void setup() {
// Give Linux time to enumerate the Digispark as a keyboard.
DigiKeyboard.delay(1000);
// Open a terminal.
DigiKeyboard.sendKeyStroke(KEY_T, MOD_CONTROL_LEFT | MOD_ALT_LEFT);
DigiKeyboard.delay(1000);
// Launch Firefox.
DigiKeyboard.print("firefox https://hadow.fr");
DigiKeyboard.sendKeyStroke(KEY_ENTER);
}
void loop() {
}