diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8418ee2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +payloads/ diff --git a/README.md b/README.md index 66cb743..579e1e5 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/encode.sh b/encode.sh new file mode 100755 index 0000000..3c9c483 --- /dev/null +++ b/encode.sh @@ -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 " + 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" diff --git a/payloads/open-website-qwerty.ino b/payloads/open-website-qwerty.ino deleted file mode 100644 index 6560ce8..0000000 --- a/payloads/open-website-qwerty.ino +++ /dev/null @@ -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() { -}