first commit

This commit is contained in:
2026-04-26 14:54:20 +02:00
commit 47aa9fc277
5 changed files with 216 additions and 0 deletions

8
LICENSE Normal file
View File

@@ -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.

13
Makefile Normal file
View File

@@ -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

1
README.md Normal file
View File

@@ -0,0 +1 @@
Digispark rubber-ducky-esque-thingy with OS detection

View File

@@ -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);
}
}

52
patch_library.txt Normal file
View File

@@ -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 {