From 47aa9fc2774f9b3b7230f3ca8b727f1e6e68d96d Mon Sep 17 00:00:00 2001 From: "N0\\A" Date: Sun, 26 Apr 2026 14:54:20 +0200 Subject: [PATCH] first commit --- LICENSE | 8 ++ Makefile | 13 +++ README.md | 1 + multi-os-thingy/multi-os-thingy.ino | 142 ++++++++++++++++++++++++++++ patch_library.txt | 52 ++++++++++ 5 files changed, 216 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 multi-os-thingy/multi-os-thingy.ino create mode 100644 patch_library.txt diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b9c199c --- /dev/null +++ b/LICENSE @@ -0,0 +1,8 @@ +ISC License: + +Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC") +Copyright (c) 1995-2003 by Internet Software Consortium + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e3592c6 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +BOARD=digistump:avr:digispark-tiny +SKETCH=multi-os-thingy/multi-os-thingy.ino + +all: compile upload + +compile: + arduino-cli compile --fqbn $(BOARD) $(SKETCH) + +upload: + arduino-cli upload -p usb --fqbn $(BOARD) $(SKETCH) + +clean: + rm -rf build diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ee8f9a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Digispark rubber-ducky-esque-thingy with OS detection \ No newline at end of file diff --git a/multi-os-thingy/multi-os-thingy.ino b/multi-os-thingy/multi-os-thingy.ino new file mode 100644 index 0000000..5c71d4b --- /dev/null +++ b/multi-os-thingy/multi-os-thingy.ino @@ -0,0 +1,142 @@ +#include "DigiKeyboard.h" + +#ifndef KEY_CAPS_LOCK +#define KEY_CAPS_LOCK 0x39 +#endif + +#define OS_UNKNOWN 0 +#define OS_WINDOWS 1 +#define OS_LINUX 2 +#define OS_MAC 3 + +volatile uint8_t g_ledWriteCount = 0; + +extern "C" uchar usbFunctionWrite(uchar *data, uchar len) { + g_ledWriteCount++; + (void)data; + (void)len; + return 1; +} + +extern "C" void usbFunctionWriteOut(uchar *data, uchar len) { + (void)data; + (void)len; +} + +uint8_t detectOS(uint16_t waitMs) { + g_ledWriteCount = 0; + + DigiKeyboard.sendKeyStroke(KEY_CAPS_LOCK); + uint16_t elapsed = 0; + while (elapsed < waitMs) { + DigiKeyboard.update(); + DigiKeyboard.delay(10); + elapsed += 10; + } + + DigiKeyboard.sendKeyStroke(KEY_CAPS_LOCK); + elapsed = 0; + while (elapsed < waitMs) { + DigiKeyboard.update(); + DigiKeyboard.delay(10); + elapsed += 10; + } + + if (g_ledWriteCount == 0) + return OS_MAC; + + g_ledWriteCount = 0; + + DigiKeyboard.sendKeyStroke(0x47); + elapsed = 0; + while (elapsed < waitMs) { + DigiKeyboard.update(); + DigiKeyboard.delay(10); + elapsed += 10; + } + + DigiKeyboard.sendKeyStroke(0x47); + elapsed = 0; + while (elapsed < waitMs) { + DigiKeyboard.update(); + DigiKeyboard.delay(10); + elapsed += 10; + } + + if (g_ledWriteCount == 0) + return OS_LINUX; + return OS_WINDOWS; +} + +void runWindows() { + DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); + DigiKeyboard.delay(400); + DigiKeyboard.print("notepad"); + DigiKeyboard.sendKeyStroke(KEY_ENTER); + DigiKeyboard.delay(800); + + DigiKeyboard.print("All your DOS are belong to us"); +} + +void runLinux() { + DigiKeyboard.sendKeyStroke(KEY_T, MOD_CONTROL_LEFT | MOD_ALT_LEFT); + DigiKeyboard.delay(1000); + + DigiKeyboard.print("echo 'All your Linux are belong to us' > /tmp/msg.txt && " + "xdg-open /tmp/msg.txt && exit"); + DigiKeyboard.sendKeyStroke(KEY_ENTER); +} + +void runMac() { + DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT); + DigiKeyboard.delay(600); + DigiKeyboard.print("terminal"); + DigiKeyboard.sendKeyStroke(KEY_ENTER); + DigiKeyboard.delay(1000); + + DigiKeyboard.print("echo 'All your Mac are belong to us' > /tmp/msg.txt && " + "open /tmp/msg.txt"); + DigiKeyboard.sendKeyStroke(KEY_ENTER); +} + +void setup() { pinMode(1, OUTPUT); } + +void loop() { + DigiKeyboard.delay(1500); + DigiKeyboard.sendKeyStroke(0); + + uint8_t os = detectOS(1000); + + uint8_t blinks = (os == OS_WINDOWS) ? 1 + : (os == OS_LINUX) ? 2 + : (os == OS_MAC) ? 3 + : 8; + for (uint8_t i = 0; i < blinks; i++) { + digitalWrite(1, HIGH); + DigiKeyboard.delay(200); + digitalWrite(1, LOW); + DigiKeyboard.delay(200); + } + DigiKeyboard.delay(400); + + switch (os) { + case OS_WINDOWS: + runWindows(); + break; + case OS_LINUX: + runLinux(); + break; + case OS_MAC: + runMac(); + break; + default: + break; + } + + for (;;) { + digitalWrite(1, HIGH); + DigiKeyboard.delay(500); + digitalWrite(1, LOW); + DigiKeyboard.delay(500); + } +} diff --git a/patch_library.txt b/patch_library.txt new file mode 100644 index 0000000..a7ccac9 --- /dev/null +++ b/patch_library.txt @@ -0,0 +1,52 @@ +Libraries must be patched before compiling +/libraries/DigisparkKeyboard/ + +------------------------------------------------------------ +File: usbconfig.h +------------------------------------------------------------ + +Find and change these #define values to: + +#define USB_CFG_IMPLEMENT_FN_WRITE 1 +#define USB_CFG_IMPLEMENT_FN_WRITEOUT 1 +#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 53 + +------------------------------------------------------------ +File: DigiKeyboard.h +------------------------------------------------------------ + +Find: + + 0x81, 0x00, // INPUT (Data,Ary,Abs) + 0xc0 // END_COLLECTION + +Replace with: + + 0x81, 0x00, // INPUT (Data,Ary,Abs) + 0x05, 0x08, // USAGE_PAGE (LEDs) + 0x19, 0x01, // USAGE_MINIMUM (Num Lock) + 0x29, 0x05, // USAGE_MAXIMUM (Kana) + 0x95, 0x05, // REPORT_COUNT (5) + 0x75, 0x01, // REPORT_SIZE (1) + 0x91, 0x02, // OUTPUT (Data,Var,Abs) - 5 LED bits + 0x95, 0x01, // REPORT_COUNT (1) + 0x75, 0x03, // REPORT_SIZE (3) + 0x91, 0x03, // OUTPUT (Const,Var,Abs) - padding + 0xc0 // END_COLLECTION + + +Find inside usbFunctionSetup(): + + } else if (rq->bRequest == USBRQ_HID_SET_IDLE) { + idleRate = rq->wValue.bytes[1]; + } + } else { + +Replace with: + + } else if (rq->bRequest == USBRQ_HID_SET_IDLE) { + idleRate = rq->wValue.bytes[1]; + } else if (rq->bRequest == USBRQ_HID_SET_REPORT) { + return USB_NO_MSG; + } + } else { \ No newline at end of file