From 55d06d7b6280a637d7d698eccf1779e55686e02f Mon Sep 17 00:00:00 2001 From: dj1ch Date: Mon, 18 Mar 2024 23:39:38 -0700 Subject: [PATCH 01/23] duckyscript --- pico-key/duckyscript.h | 120 +++++++++++++++++++++++++++++++++++++++++ pico-key/pico-key.c | 3 ++ 2 files changed, 123 insertions(+) create mode 100644 pico-key/duckyscript.h diff --git a/pico-key/duckyscript.h b/pico-key/duckyscript.h new file mode 100644 index 0000000..c8939b9 --- /dev/null +++ b/pico-key/duckyscript.h @@ -0,0 +1,120 @@ +/** + * duckyscript.h + * define duckyscript in C...? +*/ + +#ifndef DUCKYSCRIPT_H +#define DUCKYSCRIPT_H + +// keys are yet to be defined + +// control keys +#define WINDOWS +#define GUI +#define APP +#define MENU +#define SHIFT +#define ALT +#define CONTROL +#define CTRL + +// arrows +#define DOWNARROW +#define DOWN +#define LEFTARROW +#define LEFT +#define RIGHTARROW +#define RIGHT +#define UPARROW +#define UP + +// other keys? +#define BREAK +#define PAUSE +#define CAPSLOCK +#define DELETE +#define END +#define ESC +#define ESCAPE +#define HOME +#define INSERT +#define NUMLOCK +#define PAGEUP +#define PAGEDOWN +#define PRINTSCREEN +#define ENTER +#define SCROLLLOCK +#define SPACE +#define TAB +#define BACKSPACE + +// abc's +#define A +#define B +#define C +#define D +#define E +#define F +#define G +#define H +#define I +#define J +#define K +#define L +#define M +#define N +#define O +#define P +#define Q +#define R +#define S +#define T +#define U +#define V +#define W +#define X +#define Y +#define Z + +// f keys +#define F1 +#define F2 +#define F3 +#define F4 +#define F5 +#define F6 +#define F7 +#define F8 +#define F9 +#define F10 +#define F11 +#define F12 + +// mouse actions +typedef enum { + MOUSE_MOVE, + MOUSE_CLICK, + MOUSE_RIGHT_CLICK, + MOUSE_MIDDLE_CLICK +} mse; + +// keyboard actions +typedef enum { + PRESS_KEY, + RELEASE_KEY +} key; + +// mouse commands +typedef struct { + mse action; + int x; + int y; +} mseCommand; + +// keyboard commands +typedef struct { + key action; + char key; +} keyCommand; + +#endif // DUCKYSCRIPT_H \ No newline at end of file diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index 15ad07c..9d306a5 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -11,6 +11,9 @@ // config #include "config.h" +// duckyscript +#include "duckyscript.h" + // libraries #include #include From 8be19ca778ead7466cb1c159b38221d36612ef4e Mon Sep 17 00:00:00 2001 From: dj1ch Date: Tue, 19 Mar 2024 08:33:37 -0700 Subject: [PATCH 02/23] payload reading and testing --- pico-key/config.c | 7 +++++ pico-key/duckyscript.c | 11 ++++++++ pico-key/duckyscript.h | 6 ++-- pico-key/pico-key.c | 63 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 pico-key/config.c create mode 100644 pico-key/duckyscript.c diff --git a/pico-key/config.c b/pico-key/config.c new file mode 100644 index 0000000..441daea --- /dev/null +++ b/pico-key/config.c @@ -0,0 +1,7 @@ +/** + * config.c + * configuration related things in a source file +*/ + +#include "config.h" + diff --git a/pico-key/duckyscript.c b/pico-key/duckyscript.c new file mode 100644 index 0000000..2ef7d44 --- /dev/null +++ b/pico-key/duckyscript.c @@ -0,0 +1,11 @@ +/** + * duckyscript.c + * this handles the commmands and the hid +*/ + +#include "duckyscript.h" + +int run(const char* command) { + + return 0; +} \ No newline at end of file diff --git a/pico-key/duckyscript.h b/pico-key/duckyscript.h index c8939b9..ea265bd 100644 --- a/pico-key/duckyscript.h +++ b/pico-key/duckyscript.h @@ -93,9 +93,9 @@ // mouse actions typedef enum { MOUSE_MOVE, - MOUSE_CLICK, - MOUSE_RIGHT_CLICK, - MOUSE_MIDDLE_CLICK + CLICK, + RIGHT_CLICK, + MIDDLE_CLICK } mse; // keyboard actions diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index 9d306a5..16b51d7 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -131,13 +131,70 @@ void buildScript() { } void testScript() { + printf("\nRemember that testing the script will run this on your machine!\n"); + char userWarning[10]; -} + while (1) { + printf("Are you okay with this? (Y/N) > "); + + // get only the characters + fgets(userWarning, sizeof(userWarning), stdin); + userWarning[strcspn(userWarning, "\n")] = '\0'; + + // convert to uppercase + for (int i = 0; userWarning[i]; i++) { + userWarning[i] = toupper(userWarning[i]); + } + + if (strcmp(userWarning, "Y") == 0) { + continue; + } else if (strcmp(userWarning, "N") == 0) { + break; + } else { + printf("%s: Not a valid response\n", userWarning); + continue; + } + } + + char scriptPath[256]; + while (1) { + printf("Script to test? > "); + fgets(scriptPath, sizeof(scriptPath), stdin); + scriptPath[strcspn(scriptPath, "\n")] = '\0'; + + if (strcmp(scriptPath, "EXIT") == 0 || strcmp(scriptPath, "exit") == 0) { + break; + } else { + read(scriptPath); + } + } +} // crap i gotta build a new compiler for this :/ -void read() { +void read(const char* filePath) { + FILE *file = fopen(filePath, "r"); -} + if (file == NULL) { + perror("Can't open '%s' :/", filePath); + return; + } + + char line[256]; + while (fgets(line, sizeof(line), file)) { + char *command = strtok(line, " \t\n"); + + char *param = strtok(NULL, "\n"); + while (param && strtok(NULL, "\n")) { + strcat(command, " "); + strcat(command, param); + param = strtok(NULL, "\n"); + } + + run(command); + } + + fclose(filePath); +} void fakeUSB() { bool led = false; From 37bc423b8deb7261f4803a33e216fde84e421a44 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Wed, 20 Mar 2024 08:05:29 -0700 Subject: [PATCH 03/23] added c files to headers --- pico-key/config.c | 6 ++++++ pico-key/duckyscript.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pico-key/config.c b/pico-key/config.c index 441daea..78dcf78 100644 --- a/pico-key/config.c +++ b/pico-key/config.c @@ -5,3 +5,9 @@ #include "config.h" +void checkConfig() { + printf("\nCurrent Config: \n"); + printf("LED definition: \n"); + printf("Payload location: \n"); + printf("Current version: \n"); +} \ No newline at end of file diff --git a/pico-key/duckyscript.c b/pico-key/duckyscript.c index 2ef7d44..2a3bf5f 100644 --- a/pico-key/duckyscript.c +++ b/pico-key/duckyscript.c @@ -5,7 +5,8 @@ #include "duckyscript.h" +// run a duckyscript command based on what is in duckyscript.h int run(const char* command) { - + return 0; } \ No newline at end of file From 80f79b6350fb1789df88958bf6fdbbe924fbda9b Mon Sep 17 00:00:00 2001 From: dj1ch Date: Fri, 22 Mar 2024 22:42:03 -0700 Subject: [PATCH 04/23] grammar --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 065611c..a7083f1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A physical pentesting toolkit on a regular Raspberry Pi Pico. ### Intro -The Raspberry Pi Pico is a flexible microcontroller board designed for multiple purposes. With this project I intend to use make a powerful Keystroke Injection tool for such an intricate board with a special purpose. It is designed to be easy to configure, modify, and use for fun. This will be designed to be a little more than a *Bad USB*. Instead of being a basic, high level program on a Pico, we build firmware designed for this purpose. +The Raspberry Pi Pico is a flexible microcontroller board designed for multiple purposes. With this project, I intend to use make a powerful Keystroke Injection tool for such an intricate board with a special purpose. It is designed to be easy to configure, modify, and use for fun. This will be designed to be a little more than a *Bad USB*. Instead of being a basic, high-level program on a Pico, we build firmware designed for keystroke injection. ### Development progress This [project](https://github.com/users/dj1ch/projects/3) showcases my progress thus far. @@ -20,11 +20,11 @@ Unlike your usual *Bad USB*, the setup is a lot more complex. 3. Your config must be edited to allow the script to be run on startup after editing it, using the shell or your computer. -**Before asking to install, this is merely a blueprint for what I will be working on for the next couple weeks!** +**Before asking to install, this is merely a blueprint for what I will be working on for the next couple of weeks!** ### The shell -The shell allows you to do a fair share of things with the board, allowing you to make it look like a USB drive by blinking the LED, checking board stats, and the testing of payloads. I plan on making this a very small "OS" for the Pico to do basic things. +The shell allows you to do a fair share of things with the board, allowing you to make it look like a USB drive by blinking the LED, checking board stats, and testing of payloads. I plan on making this a very small "OS" for the Pico to do basic things. ### FAQ @@ -34,10 +34,10 @@ Most of the changes haven't been tested and it is yet to work as intended. This **Can it do things other than Keystroke injection?** -It's pretty bare bones right now, it has a work in progress text editor, to build the scripts on the board without having to worry about editing the files on your own computer, along with being able to test scripts on the device it is plugged into. Unless we can implement some way to control GPIO over the shell, it does only keystroke injection. The OS itself is minimal and can only do so much. +It's pretty bare bones right now, it has a work-in-progress text editor, to build the scripts on the board without having to worry about editing the files on your computer, along with being able to test scripts on the device it is plugged into. Unless we can implement some way to control GPIO over the shell, it does only keystroke injection. The OS itself is minimal and can only do so much. ### Contributing -TBA, will add contributing guidelines soon +TBA will add contributing guidelines soon **Made with :heart: by [@dj1ch](https://github.com/dj1ch)** From a2f07f323e11edc946931b45c4a42dcd6c245261 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Sat, 23 Mar 2024 11:13:13 -0700 Subject: [PATCH 05/23] printing full config --- pico-key/config.c | 9 ++++++--- pico-key/config.h | 2 +- pico-key/pico-key.c | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pico-key/config.c b/pico-key/config.c index 78dcf78..8e4ac0b 100644 --- a/pico-key/config.c +++ b/pico-key/config.c @@ -7,7 +7,10 @@ void checkConfig() { printf("\nCurrent Config: \n"); - printf("LED definition: \n"); - printf("Payload location: \n"); - printf("Current version: \n"); + printf("LED Pin definition: "); + printf(LED_PIN); + printf("Payload location: "); + printf(PAYLOAD_LOCATION); + printf("Current version: "); + printf(VERSION); } \ No newline at end of file diff --git a/pico-key/config.h b/pico-key/config.h index da17339..1385354 100644 --- a/pico-key/config.h +++ b/pico-key/config.h @@ -8,7 +8,7 @@ // configuration parameters #define LED_PIN PICO_DEFAULT_LED_PIN -#define PAYLOAD_LOCATION "/payload.dd" +#define PAYLOAD_LOCATION "/payload.dd\n" #define RUN_ON_STARTUP true // version diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index 16b51d7..0841b36 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -282,5 +282,5 @@ void boardInfo() { // we can only really print memory here printf("\nBoard info:\n"); printf(malloc_stats() + " bytes"); - printf(VERSION); + printf(checkConfig()); } \ No newline at end of file From b45cf805166a7c038bc6637be8c90755e6c92d14 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Thu, 28 Mar 2024 00:12:25 -0700 Subject: [PATCH 06/23] keys --- pico-key/duckyscript.h | 148 ++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 75 deletions(-) diff --git a/pico-key/duckyscript.h b/pico-key/duckyscript.h index ea265bd..6f9715a 100644 --- a/pico-key/duckyscript.h +++ b/pico-key/duckyscript.h @@ -6,89 +6,87 @@ #ifndef DUCKYSCRIPT_H #define DUCKYSCRIPT_H -// keys are yet to be defined - // control keys -#define WINDOWS -#define GUI -#define APP -#define MENU -#define SHIFT -#define ALT -#define CONTROL -#define CTRL +#define WINDOWS 0x08 +#define GUI 0x10 +#define APP 0x20 +#define MENU 0x40 +#define SHIFT 0x80 +#define ALT 0x40 +#define CONTROL 0x20 +#define CTRL 0x20 // arrows -#define DOWNARROW -#define DOWN -#define LEFTARROW -#define LEFT -#define RIGHTARROW -#define RIGHT -#define UPARROW -#define UP +#define DOWNARROW 0x51 +#define DOWN 0x51 +#define LEFTARROW 0x50 +#define LEFT 0x50 +#define RIGHTARROW 0x4F +#define RIGHT 0x4F +#define UPARROW 0x52 +#define UP 0x52 -// other keys? -#define BREAK -#define PAUSE -#define CAPSLOCK -#define DELETE -#define END -#define ESC -#define ESCAPE -#define HOME -#define INSERT -#define NUMLOCK -#define PAGEUP -#define PAGEDOWN -#define PRINTSCREEN -#define ENTER -#define SCROLLLOCK -#define SPACE -#define TAB -#define BACKSPACE +// other keys +#define BREAK 0x48 +#define PAUSE 0x48 +#define CAPSLOCK 0x39 +#define DELETE 0x4C +#define END 0x4D +#define ESC 0x29 +#define ESCAPE 0x29 +#define HOME 0x4A +#define INSERT 0x49 +#define NUMLOCK 0x53 +#define PAGEUP 0x4B +#define PAGEDOWN 0x4E +#define PRINTSCREEN 0x46 +#define ENTER 0x28 +#define SCROLLLOCK 0x47 +#define SPACE 0x2C +#define TAB 0x2B +#define BACKSPACE 0x2A // abc's -#define A -#define B -#define C -#define D -#define E -#define F -#define G -#define H -#define I -#define J -#define K -#define L -#define M -#define N -#define O -#define P -#define Q -#define R -#define S -#define T -#define U -#define V -#define W -#define X -#define Y -#define Z +#define A 0x04 +#define B 0x05 +#define C 0x06 +#define D 0x07 +#define E 0x08 +#define F 0x09 +#define G 0x0A +#define H 0x0B +#define I 0x0C +#define J 0x0D +#define K 0x0E +#define L 0x0F +#define M 0x10 +#define N 0x11 +#define O 0x12 +#define P 0x13 +#define Q 0x14 +#define R 0x15 +#define S 0x16 +#define T 0x17 +#define U 0x18 +#define V 0x19 +#define W 0x1A +#define X 0x1B +#define Y 0x1C +#define Z 0x1D // f keys -#define F1 -#define F2 -#define F3 -#define F4 -#define F5 -#define F6 -#define F7 -#define F8 -#define F9 -#define F10 -#define F11 -#define F12 +#define F1 0x3A +#define F2 0x3B +#define F3 0x3C +#define F4 0x3D +#define F5 0x3E +#define F6 0x3F +#define F7 0x40 +#define F8 0x41 +#define F9 0x42 +#define F10 0x43 +#define F11 0x44 +#define F12 0x45 // mouse actions typedef enum { From 1515449f8454cc5e7ec404d9a019a7040e53826b Mon Sep 17 00:00:00 2001 From: dj1ch Date: Thu, 28 Mar 2024 23:44:25 -0700 Subject: [PATCH 07/23] making a simple memory writing system --- pico-key/CMakeLists.txt | 4 +- pico-key/config.c | 16 --- pico-key/config.h | 17 --- pico-key/duckyscript.c | 12 -- pico-key/duckyscript.h | 118 ------------------ pico-key/pico-key.c | 256 +++------------------------------------- 6 files changed, 17 insertions(+), 406 deletions(-) delete mode 100644 pico-key/config.c delete mode 100644 pico-key/config.h delete mode 100644 pico-key/duckyscript.c delete mode 100644 pico-key/duckyscript.h diff --git a/pico-key/CMakeLists.txt b/pico-key/CMakeLists.txt index d808a7d..c5404ae 100644 --- a/pico-key/CMakeLists.txt +++ b/pico-key/CMakeLists.txt @@ -14,9 +14,6 @@ project(pico-key) # start sdk pico_sdk_init() -# include config -include_directories(config) - # source add_executable(pico-key pico-key.c) @@ -25,6 +22,7 @@ target_link_libraries(pico-key pico_stdio pico_stdlib pico_malloc + hardware_flash hardware_uart hardware_gpio ) diff --git a/pico-key/config.c b/pico-key/config.c deleted file mode 100644 index 8e4ac0b..0000000 --- a/pico-key/config.c +++ /dev/null @@ -1,16 +0,0 @@ -/** - * config.c - * configuration related things in a source file -*/ - -#include "config.h" - -void checkConfig() { - printf("\nCurrent Config: \n"); - printf("LED Pin definition: "); - printf(LED_PIN); - printf("Payload location: "); - printf(PAYLOAD_LOCATION); - printf("Current version: "); - printf(VERSION); -} \ No newline at end of file diff --git a/pico-key/config.h b/pico-key/config.h deleted file mode 100644 index 1385354..0000000 --- a/pico-key/config.h +++ /dev/null @@ -1,17 +0,0 @@ -/** - * config.h - * configurations are defined here -*/ - -#ifndef CONFIG_H -#define CONFIG_H - -// configuration parameters -#define LED_PIN PICO_DEFAULT_LED_PIN -#define PAYLOAD_LOCATION "/payload.dd\n" -#define RUN_ON_STARTUP true - -// version -#define VERSION "0.1.0-alpha\n" - -#endif // CONFIG_H \ No newline at end of file diff --git a/pico-key/duckyscript.c b/pico-key/duckyscript.c deleted file mode 100644 index 2a3bf5f..0000000 --- a/pico-key/duckyscript.c +++ /dev/null @@ -1,12 +0,0 @@ -/** - * duckyscript.c - * this handles the commmands and the hid -*/ - -#include "duckyscript.h" - -// run a duckyscript command based on what is in duckyscript.h -int run(const char* command) { - - return 0; -} \ No newline at end of file diff --git a/pico-key/duckyscript.h b/pico-key/duckyscript.h deleted file mode 100644 index 6f9715a..0000000 --- a/pico-key/duckyscript.h +++ /dev/null @@ -1,118 +0,0 @@ -/** - * duckyscript.h - * define duckyscript in C...? -*/ - -#ifndef DUCKYSCRIPT_H -#define DUCKYSCRIPT_H - -// control keys -#define WINDOWS 0x08 -#define GUI 0x10 -#define APP 0x20 -#define MENU 0x40 -#define SHIFT 0x80 -#define ALT 0x40 -#define CONTROL 0x20 -#define CTRL 0x20 - -// arrows -#define DOWNARROW 0x51 -#define DOWN 0x51 -#define LEFTARROW 0x50 -#define LEFT 0x50 -#define RIGHTARROW 0x4F -#define RIGHT 0x4F -#define UPARROW 0x52 -#define UP 0x52 - -// other keys -#define BREAK 0x48 -#define PAUSE 0x48 -#define CAPSLOCK 0x39 -#define DELETE 0x4C -#define END 0x4D -#define ESC 0x29 -#define ESCAPE 0x29 -#define HOME 0x4A -#define INSERT 0x49 -#define NUMLOCK 0x53 -#define PAGEUP 0x4B -#define PAGEDOWN 0x4E -#define PRINTSCREEN 0x46 -#define ENTER 0x28 -#define SCROLLLOCK 0x47 -#define SPACE 0x2C -#define TAB 0x2B -#define BACKSPACE 0x2A - -// abc's -#define A 0x04 -#define B 0x05 -#define C 0x06 -#define D 0x07 -#define E 0x08 -#define F 0x09 -#define G 0x0A -#define H 0x0B -#define I 0x0C -#define J 0x0D -#define K 0x0E -#define L 0x0F -#define M 0x10 -#define N 0x11 -#define O 0x12 -#define P 0x13 -#define Q 0x14 -#define R 0x15 -#define S 0x16 -#define T 0x17 -#define U 0x18 -#define V 0x19 -#define W 0x1A -#define X 0x1B -#define Y 0x1C -#define Z 0x1D - -// f keys -#define F1 0x3A -#define F2 0x3B -#define F3 0x3C -#define F4 0x3D -#define F5 0x3E -#define F6 0x3F -#define F7 0x40 -#define F8 0x41 -#define F9 0x42 -#define F10 0x43 -#define F11 0x44 -#define F12 0x45 - -// mouse actions -typedef enum { - MOUSE_MOVE, - CLICK, - RIGHT_CLICK, - MIDDLE_CLICK -} mse; - -// keyboard actions -typedef enum { - PRESS_KEY, - RELEASE_KEY -} key; - -// mouse commands -typedef struct { - mse action; - int x; - int y; -} mseCommand; - -// keyboard commands -typedef struct { - key action; - char key; -} keyCommand; - -#endif // DUCKYSCRIPT_H \ No newline at end of file diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index 0841b36..a5bccae 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -4,16 +4,6 @@ * built by @dj1ch */ -/** developer note: - * old pr w/ python is here: https://github.com/dj1ch/pico-key/pull/1/commits/5d4c65106c6aa490b7eb047827c1ed3a00a21377 -*/ - -// config -#include "config.h" - -// duckyscript -#include "duckyscript.h" - // libraries #include #include @@ -24,9 +14,18 @@ #include "pico/stdio.h" #include "pico/stdlib.h" #include "pico/malloc.h" +#include "hardware/flash" #include "hardware/uart.h" #include "hardware/gpio.h" +// define area to write payload +#define FILE_CONTENTS_SIZE 256 +#define FLASH_TARGET_OFFSET (256 * 1024) + +const uint8_t file_contents[FILE_CONTENTS_SIZE] = { + 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\n', '\0' +}; + void boot() { // boot logo char coolArt[] = "pico-key..."; @@ -39,248 +38,25 @@ void boot() { // board info boardInfo(); - - if (RUN_ON_STARTUP) { - read(); - return 0; - } else { - // do nothing - } } int main() { + stdio_init_all(); boot(); - while (true) { - printf("\n1. Build Bad USB script\n"); - printf("2. Test Bad USB script\n"); - printf("3. Fake USB drive\n"); - printf("4. Misc\n"); - printf("5. Options\n"); - sleep(1); - - int choice; - printf("\n> "); - scanf("%d", &choice); - switch (choice) { - case 1: - buildScript(); - break; + printf("Erasing memory in target region!\n"); + flash_range_erase(FLASH_TARGET_OFFSET, FLASH_PAGE_SIZE); + printf("Done.\n"); - case 2: - testScript(); - break; + printf("Writing to flash...\n") + flash_range_program(FLASH_TARGET_OFFSET, file_contents, FILE_CONTENTS_SIZE); + printf("Done.\n") - case 3: - fakeUSB(); - break; - - case 4: - misc(); - break; - - case 5: - options(); - break; - - default: - printf("\n%d: Invalid choice :/\n", choice); - break; - } - } return 0; } -void buildScript() { - printf("\nPayloads are built here, but can also be modified using a file manager."); - printf("Every time you press enter it will be written to the file.\n"); - printf("Type 'exit' to stop.\n"); - - // assume it's named payload.dd - FILE *file = fopen(PAYLOAD_LOCATION, "w"); - - if (file == NULL) { - printf("Failed to open payload.dd! :(\n"); - return; - } - - // 25 chars max!! most of the time commands are shorter. - const int MAX_LINE_LENGTH = 25; - char script[MAX_LINE_LENGTH]; - - while (true) { - printf("\n> "); - // get line and write it - fgets(script, sizeof(script), stdin); - script[strcspn(script, "\n")] = '\0'; - - for (int i = 0; script[i]; i++) { - script[i] = toupper(script[i]); - } - - // exit if command is "exit" - if (strcmp(script, "EXIT") == 0) { - break; - } - - fprintf(file, "%s\n", script); - - } - fclose(file); - printf("Script saved to payload.dd!\n"); -} - -void testScript() { - printf("\nRemember that testing the script will run this on your machine!\n"); - char userWarning[10]; - - while (1) { - printf("Are you okay with this? (Y/N) > "); - - // get only the characters - fgets(userWarning, sizeof(userWarning), stdin); - userWarning[strcspn(userWarning, "\n")] = '\0'; - - // convert to uppercase - for (int i = 0; userWarning[i]; i++) { - userWarning[i] = toupper(userWarning[i]); - } - - if (strcmp(userWarning, "Y") == 0) { - continue; - } else if (strcmp(userWarning, "N") == 0) { - break; - } else { - printf("%s: Not a valid response\n", userWarning); - continue; - } - } - - char scriptPath[256]; - while (1) { - printf("Script to test? > "); - fgets(scriptPath, sizeof(scriptPath), stdin); - scriptPath[strcspn(scriptPath, "\n")] = '\0'; - - if (strcmp(scriptPath, "EXIT") == 0 || strcmp(scriptPath, "exit") == 0) { - break; - } else { - read(scriptPath); - } - } -} - -// crap i gotta build a new compiler for this :/ -void read(const char* filePath) { - FILE *file = fopen(filePath, "r"); - - if (file == NULL) { - perror("Can't open '%s' :/", filePath); - return; - } - - char line[256]; - while (fgets(line, sizeof(line), file)) { - char *command = strtok(line, " \t\n"); - - char *param = strtok(NULL, "\n"); - while (param && strtok(NULL, "\n")) { - strcat(command, " "); - strcat(command, param); - param = strtok(NULL, "\n"); - } - - run(command); - } - - fclose(filePath); -} - -void fakeUSB() { - bool led = false; - - printf("\n1. Start LED blinking\n"); - printf("2. Stop LED blinking\n"); - printf("\n> "); - - int choiceA; - scanf("%d", &choiceA); - switch (choiceA) { - case 1: - if (led) { - printf("Already running! :/\n"); - } else { - led = true; - while (led) { - gpio_put(LED_PIN, 1); // led on - sleep_ms(500); - gpio_put(LED_PIN, 0); // led off - sleep_ms(500); - - if (scanf("%d", &choiceA) == 1 && choiceA == 2) { - led = false; - } - } - } - break; - - case 2: - led = false; - break; - - default: - printf("%d: Invalid choice\n", choiceA); - } -} - -void misc() { - printf("\nNothing here, for now... :/\n"); - printf("\n> "); - - char choiceB[10]; - - // remove whitespace - fgets(choiceB, sizeof(choiceB), stdin); - choiceB[strcspn(choiceB, "\n")] = '\0'; - - // uppercase and compare it - for (int i = 0; choiceB[i]; i++) { - choiceB[i] = toupper(choiceB[i]); - } - - if (strcmp(choiceB, "EXIT") == 0) { - return; - } -} - -void options() { - printf("\nHere we would put settings to set for the board, see the current board information, etc.\n"); - printf("\n1. Print board info\n") - printf("\n> ") - - char choiceC[10]; - - // remove whitespace - fgets(choiceC, sizeof(choiceC), stdin); - choiceC[strcspn(choiceC, "\n")] = '\0'; - - // uppercase and compare it - for (int i = 0; choiceC[i]; i++) { - choiceC[i] = toupper(choiceC[i]); - } - - if (strcmp(choiceC, "EXIT") == 0) { - return; - } - - if (strcmp(choiceC, "1") == 0) { - boardInfo(); - } -} - void boardInfo() { // we can only really print memory here printf("\nBoard info:\n"); printf(malloc_stats() + " bytes"); - printf(checkConfig()); } \ No newline at end of file From 90e25a57166ed8a9c48781d6d32e13b15e5f3826 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Fri, 29 Mar 2024 07:02:28 -0700 Subject: [PATCH 08/23] i forgot --- pico-key/pico-key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index a5bccae..200c608 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -58,5 +58,5 @@ int main() { void boardInfo() { // we can only really print memory here printf("\nBoard info:\n"); - printf(malloc_stats() + " bytes"); + printf(malloc_stats() + " bytes\n"); } \ No newline at end of file From 322f1ca68799605e482ecbc23e2622634fb1a4af Mon Sep 17 00:00:00 2001 From: dj1ch Date: Sat, 30 Mar 2024 10:15:20 -0700 Subject: [PATCH 09/23] might build w/ arduino --- pico-key/CMakeLists.txt | 31 --------------- pico-key/pico_sdk_import.cmake | 73 ---------------------------------- 2 files changed, 104 deletions(-) delete mode 100644 pico-key/CMakeLists.txt delete mode 100644 pico-key/pico_sdk_import.cmake diff --git a/pico-key/CMakeLists.txt b/pico-key/CMakeLists.txt deleted file mode 100644 index c5404ae..0000000 --- a/pico-key/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# cmake version! -cmake_minimum_required(VERSION 3.13) - -# set path -# this is assuming you pulled this from github -set(PICO_SDK_PATH "~/pico-sdk") - -# include the sdk -include(pico_sdk_import.cmake) - -# project name -project(pico-key) - -# start sdk -pico_sdk_init() - -# source -add_executable(pico-key pico-key.c) - -# pico sdk libraries -target_link_libraries(pico-key - pico_stdio - pico_stdlib - pico_malloc - hardware_flash - hardware_uart - hardware_gpio -) - -# generate extra files -pico_add_extra_outputs(pico-key) \ No newline at end of file diff --git a/pico-key/pico_sdk_import.cmake b/pico-key/pico_sdk_import.cmake deleted file mode 100644 index 65f8a6f..0000000 --- a/pico-key/pico_sdk_import.cmake +++ /dev/null @@ -1,73 +0,0 @@ -# This is a copy of /external/pico_sdk_import.cmake - -# This can be dropped into an external project to help locate this SDK -# It should be include()ed prior to project() - -if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) - set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) - message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") -endif () - -if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) - set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) - message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") -endif () - -if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) - set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) - message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") -endif () - -set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") -set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") -set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") - -if (NOT PICO_SDK_PATH) - if (PICO_SDK_FETCH_FROM_GIT) - include(FetchContent) - set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) - if (PICO_SDK_FETCH_FROM_GIT_PATH) - get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") - endif () - # GIT_SUBMODULES_RECURSE was added in 3.17 - if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") - FetchContent_Declare( - pico_sdk - GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk - GIT_TAG master - GIT_SUBMODULES_RECURSE FALSE - ) - else () - FetchContent_Declare( - pico_sdk - GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk - GIT_TAG master - ) - endif () - - if (NOT pico_sdk) - message("Downloading Raspberry Pi Pico SDK") - FetchContent_Populate(pico_sdk) - set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) - endif () - set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) - else () - message(FATAL_ERROR - "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." - ) - endif () -endif () - -get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") -if (NOT EXISTS ${PICO_SDK_PATH}) - message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") -endif () - -set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) -if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) - message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") -endif () - -set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) - -include(${PICO_SDK_INIT_CMAKE_FILE}) From 082446acae4971f3a863f1eeee6ae8df998a025b Mon Sep 17 00:00:00 2001 From: dj1ch Date: Sun, 31 Mar 2024 00:33:43 -0700 Subject: [PATCH 10/23] re added back files --- pico-key/CMakeLists.txt | 33 +++++++++ pico-key/config.c | 16 +++++ pico-key/config.h | 17 +++++ pico-key/duckyscript.c | 12 ++++ pico-key/duckyscript.h | 118 +++++++++++++++++++++++++++++++++ pico-key/pico_sdk_import.cmake | 73 ++++++++++++++++++++ 6 files changed, 269 insertions(+) create mode 100644 pico-key/CMakeLists.txt create mode 100644 pico-key/config.c create mode 100644 pico-key/config.h create mode 100644 pico-key/duckyscript.c create mode 100644 pico-key/duckyscript.h create mode 100644 pico-key/pico_sdk_import.cmake diff --git a/pico-key/CMakeLists.txt b/pico-key/CMakeLists.txt new file mode 100644 index 0000000..d808a7d --- /dev/null +++ b/pico-key/CMakeLists.txt @@ -0,0 +1,33 @@ +# cmake version! +cmake_minimum_required(VERSION 3.13) + +# set path +# this is assuming you pulled this from github +set(PICO_SDK_PATH "~/pico-sdk") + +# include the sdk +include(pico_sdk_import.cmake) + +# project name +project(pico-key) + +# start sdk +pico_sdk_init() + +# include config +include_directories(config) + +# source +add_executable(pico-key pico-key.c) + +# pico sdk libraries +target_link_libraries(pico-key + pico_stdio + pico_stdlib + pico_malloc + hardware_uart + hardware_gpio +) + +# generate extra files +pico_add_extra_outputs(pico-key) \ No newline at end of file diff --git a/pico-key/config.c b/pico-key/config.c new file mode 100644 index 0000000..8e4ac0b --- /dev/null +++ b/pico-key/config.c @@ -0,0 +1,16 @@ +/** + * config.c + * configuration related things in a source file +*/ + +#include "config.h" + +void checkConfig() { + printf("\nCurrent Config: \n"); + printf("LED Pin definition: "); + printf(LED_PIN); + printf("Payload location: "); + printf(PAYLOAD_LOCATION); + printf("Current version: "); + printf(VERSION); +} \ No newline at end of file diff --git a/pico-key/config.h b/pico-key/config.h new file mode 100644 index 0000000..1385354 --- /dev/null +++ b/pico-key/config.h @@ -0,0 +1,17 @@ +/** + * config.h + * configurations are defined here +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +// configuration parameters +#define LED_PIN PICO_DEFAULT_LED_PIN +#define PAYLOAD_LOCATION "/payload.dd\n" +#define RUN_ON_STARTUP true + +// version +#define VERSION "0.1.0-alpha\n" + +#endif // CONFIG_H \ No newline at end of file diff --git a/pico-key/duckyscript.c b/pico-key/duckyscript.c new file mode 100644 index 0000000..2a3bf5f --- /dev/null +++ b/pico-key/duckyscript.c @@ -0,0 +1,12 @@ +/** + * duckyscript.c + * this handles the commmands and the hid +*/ + +#include "duckyscript.h" + +// run a duckyscript command based on what is in duckyscript.h +int run(const char* command) { + + return 0; +} \ No newline at end of file diff --git a/pico-key/duckyscript.h b/pico-key/duckyscript.h new file mode 100644 index 0000000..6f9715a --- /dev/null +++ b/pico-key/duckyscript.h @@ -0,0 +1,118 @@ +/** + * duckyscript.h + * define duckyscript in C...? +*/ + +#ifndef DUCKYSCRIPT_H +#define DUCKYSCRIPT_H + +// control keys +#define WINDOWS 0x08 +#define GUI 0x10 +#define APP 0x20 +#define MENU 0x40 +#define SHIFT 0x80 +#define ALT 0x40 +#define CONTROL 0x20 +#define CTRL 0x20 + +// arrows +#define DOWNARROW 0x51 +#define DOWN 0x51 +#define LEFTARROW 0x50 +#define LEFT 0x50 +#define RIGHTARROW 0x4F +#define RIGHT 0x4F +#define UPARROW 0x52 +#define UP 0x52 + +// other keys +#define BREAK 0x48 +#define PAUSE 0x48 +#define CAPSLOCK 0x39 +#define DELETE 0x4C +#define END 0x4D +#define ESC 0x29 +#define ESCAPE 0x29 +#define HOME 0x4A +#define INSERT 0x49 +#define NUMLOCK 0x53 +#define PAGEUP 0x4B +#define PAGEDOWN 0x4E +#define PRINTSCREEN 0x46 +#define ENTER 0x28 +#define SCROLLLOCK 0x47 +#define SPACE 0x2C +#define TAB 0x2B +#define BACKSPACE 0x2A + +// abc's +#define A 0x04 +#define B 0x05 +#define C 0x06 +#define D 0x07 +#define E 0x08 +#define F 0x09 +#define G 0x0A +#define H 0x0B +#define I 0x0C +#define J 0x0D +#define K 0x0E +#define L 0x0F +#define M 0x10 +#define N 0x11 +#define O 0x12 +#define P 0x13 +#define Q 0x14 +#define R 0x15 +#define S 0x16 +#define T 0x17 +#define U 0x18 +#define V 0x19 +#define W 0x1A +#define X 0x1B +#define Y 0x1C +#define Z 0x1D + +// f keys +#define F1 0x3A +#define F2 0x3B +#define F3 0x3C +#define F4 0x3D +#define F5 0x3E +#define F6 0x3F +#define F7 0x40 +#define F8 0x41 +#define F9 0x42 +#define F10 0x43 +#define F11 0x44 +#define F12 0x45 + +// mouse actions +typedef enum { + MOUSE_MOVE, + CLICK, + RIGHT_CLICK, + MIDDLE_CLICK +} mse; + +// keyboard actions +typedef enum { + PRESS_KEY, + RELEASE_KEY +} key; + +// mouse commands +typedef struct { + mse action; + int x; + int y; +} mseCommand; + +// keyboard commands +typedef struct { + key action; + char key; +} keyCommand; + +#endif // DUCKYSCRIPT_H \ No newline at end of file diff --git a/pico-key/pico_sdk_import.cmake b/pico-key/pico_sdk_import.cmake new file mode 100644 index 0000000..65f8a6f --- /dev/null +++ b/pico-key/pico_sdk_import.cmake @@ -0,0 +1,73 @@ +# This is a copy of /external/pico_sdk_import.cmake + +# This can be dropped into an external project to help locate this SDK +# It should be include()ed prior to project() + +if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) + set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) + message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) + set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) + message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) + set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) + message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") +endif () + +set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") +set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") +set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") + +if (NOT PICO_SDK_PATH) + if (PICO_SDK_FETCH_FROM_GIT) + include(FetchContent) + set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) + if (PICO_SDK_FETCH_FROM_GIT_PATH) + get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") + endif () + # GIT_SUBMODULES_RECURSE was added in 3.17 + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + GIT_SUBMODULES_RECURSE FALSE + ) + else () + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + ) + endif () + + if (NOT pico_sdk) + message("Downloading Raspberry Pi Pico SDK") + FetchContent_Populate(pico_sdk) + set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) + endif () + set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) + else () + message(FATAL_ERROR + "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." + ) + endif () +endif () + +get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") +if (NOT EXISTS ${PICO_SDK_PATH}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") +endif () + +set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) +if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") +endif () + +set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) + +include(${PICO_SDK_INIT_CMAKE_FILE}) From beb4d69b05bbf8115d1c84412c9399c427a93cf2 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Sun, 31 Mar 2024 00:42:09 -0700 Subject: [PATCH 11/23] define as a char --- pico-key/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pico-key/config.h b/pico-key/config.h index 1385354..2e9c8aa 100644 --- a/pico-key/config.h +++ b/pico-key/config.h @@ -8,7 +8,7 @@ // configuration parameters #define LED_PIN PICO_DEFAULT_LED_PIN -#define PAYLOAD_LOCATION "/payload.dd\n" +const char* PAYLOAD_LOCATION = "/payload.dd\n"; #define RUN_ON_STARTUP true // version From 6b2d23521e8ca5c377539dec88d1fa0c01c5fd5d Mon Sep 17 00:00:00 2001 From: dj1ch Date: Sun, 31 Mar 2024 00:43:17 -0700 Subject: [PATCH 12/23] restored pico-key.c --- pico-key/pico-key.c | 258 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 241 insertions(+), 17 deletions(-) diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index 200c608..0841b36 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -4,6 +4,16 @@ * built by @dj1ch */ +/** developer note: + * old pr w/ python is here: https://github.com/dj1ch/pico-key/pull/1/commits/5d4c65106c6aa490b7eb047827c1ed3a00a21377 +*/ + +// config +#include "config.h" + +// duckyscript +#include "duckyscript.h" + // libraries #include #include @@ -14,18 +24,9 @@ #include "pico/stdio.h" #include "pico/stdlib.h" #include "pico/malloc.h" -#include "hardware/flash" #include "hardware/uart.h" #include "hardware/gpio.h" -// define area to write payload -#define FILE_CONTENTS_SIZE 256 -#define FLASH_TARGET_OFFSET (256 * 1024) - -const uint8_t file_contents[FILE_CONTENTS_SIZE] = { - 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\n', '\0' -}; - void boot() { // boot logo char coolArt[] = "pico-key..."; @@ -38,25 +39,248 @@ void boot() { // board info boardInfo(); + + if (RUN_ON_STARTUP) { + read(); + return 0; + } else { + // do nothing + } } int main() { - stdio_init_all(); boot(); + while (true) { + printf("\n1. Build Bad USB script\n"); + printf("2. Test Bad USB script\n"); + printf("3. Fake USB drive\n"); + printf("4. Misc\n"); + printf("5. Options\n"); + sleep(1); + + int choice; + printf("\n> "); + scanf("%d", &choice); - printf("Erasing memory in target region!\n"); - flash_range_erase(FLASH_TARGET_OFFSET, FLASH_PAGE_SIZE); - printf("Done.\n"); + switch (choice) { + case 1: + buildScript(); + break; - printf("Writing to flash...\n") - flash_range_program(FLASH_TARGET_OFFSET, file_contents, FILE_CONTENTS_SIZE); - printf("Done.\n") + case 2: + testScript(); + break; + case 3: + fakeUSB(); + break; + + case 4: + misc(); + break; + + case 5: + options(); + break; + + default: + printf("\n%d: Invalid choice :/\n", choice); + break; + } + } return 0; } +void buildScript() { + printf("\nPayloads are built here, but can also be modified using a file manager."); + printf("Every time you press enter it will be written to the file.\n"); + printf("Type 'exit' to stop.\n"); + + // assume it's named payload.dd + FILE *file = fopen(PAYLOAD_LOCATION, "w"); + + if (file == NULL) { + printf("Failed to open payload.dd! :(\n"); + return; + } + + // 25 chars max!! most of the time commands are shorter. + const int MAX_LINE_LENGTH = 25; + char script[MAX_LINE_LENGTH]; + + while (true) { + printf("\n> "); + // get line and write it + fgets(script, sizeof(script), stdin); + script[strcspn(script, "\n")] = '\0'; + + for (int i = 0; script[i]; i++) { + script[i] = toupper(script[i]); + } + + // exit if command is "exit" + if (strcmp(script, "EXIT") == 0) { + break; + } + + fprintf(file, "%s\n", script); + + } + fclose(file); + printf("Script saved to payload.dd!\n"); +} + +void testScript() { + printf("\nRemember that testing the script will run this on your machine!\n"); + char userWarning[10]; + + while (1) { + printf("Are you okay with this? (Y/N) > "); + + // get only the characters + fgets(userWarning, sizeof(userWarning), stdin); + userWarning[strcspn(userWarning, "\n")] = '\0'; + + // convert to uppercase + for (int i = 0; userWarning[i]; i++) { + userWarning[i] = toupper(userWarning[i]); + } + + if (strcmp(userWarning, "Y") == 0) { + continue; + } else if (strcmp(userWarning, "N") == 0) { + break; + } else { + printf("%s: Not a valid response\n", userWarning); + continue; + } + } + + char scriptPath[256]; + while (1) { + printf("Script to test? > "); + fgets(scriptPath, sizeof(scriptPath), stdin); + scriptPath[strcspn(scriptPath, "\n")] = '\0'; + + if (strcmp(scriptPath, "EXIT") == 0 || strcmp(scriptPath, "exit") == 0) { + break; + } else { + read(scriptPath); + } + } +} + +// crap i gotta build a new compiler for this :/ +void read(const char* filePath) { + FILE *file = fopen(filePath, "r"); + + if (file == NULL) { + perror("Can't open '%s' :/", filePath); + return; + } + + char line[256]; + while (fgets(line, sizeof(line), file)) { + char *command = strtok(line, " \t\n"); + + char *param = strtok(NULL, "\n"); + while (param && strtok(NULL, "\n")) { + strcat(command, " "); + strcat(command, param); + param = strtok(NULL, "\n"); + } + + run(command); + } + + fclose(filePath); +} + +void fakeUSB() { + bool led = false; + + printf("\n1. Start LED blinking\n"); + printf("2. Stop LED blinking\n"); + printf("\n> "); + + int choiceA; + scanf("%d", &choiceA); + switch (choiceA) { + case 1: + if (led) { + printf("Already running! :/\n"); + } else { + led = true; + while (led) { + gpio_put(LED_PIN, 1); // led on + sleep_ms(500); + gpio_put(LED_PIN, 0); // led off + sleep_ms(500); + + if (scanf("%d", &choiceA) == 1 && choiceA == 2) { + led = false; + } + } + } + break; + + case 2: + led = false; + break; + + default: + printf("%d: Invalid choice\n", choiceA); + } +} + +void misc() { + printf("\nNothing here, for now... :/\n"); + printf("\n> "); + + char choiceB[10]; + + // remove whitespace + fgets(choiceB, sizeof(choiceB), stdin); + choiceB[strcspn(choiceB, "\n")] = '\0'; + + // uppercase and compare it + for (int i = 0; choiceB[i]; i++) { + choiceB[i] = toupper(choiceB[i]); + } + + if (strcmp(choiceB, "EXIT") == 0) { + return; + } +} + +void options() { + printf("\nHere we would put settings to set for the board, see the current board information, etc.\n"); + printf("\n1. Print board info\n") + printf("\n> ") + + char choiceC[10]; + + // remove whitespace + fgets(choiceC, sizeof(choiceC), stdin); + choiceC[strcspn(choiceC, "\n")] = '\0'; + + // uppercase and compare it + for (int i = 0; choiceC[i]; i++) { + choiceC[i] = toupper(choiceC[i]); + } + + if (strcmp(choiceC, "EXIT") == 0) { + return; + } + + if (strcmp(choiceC, "1") == 0) { + boardInfo(); + } +} + void boardInfo() { // we can only really print memory here printf("\nBoard info:\n"); - printf(malloc_stats() + " bytes\n"); + printf(malloc_stats() + " bytes"); + printf(checkConfig()); } \ No newline at end of file From 7b7f218d055d71d478590406c770afe61914692d Mon Sep 17 00:00:00 2001 From: dj1ch Date: Sun, 31 Mar 2024 13:58:26 -0700 Subject: [PATCH 13/23] payload reading --- pico-key/config.c | 12 +++++------- pico-key/config.h | 22 ++++++++++++++++------ pico-key/duckyscript.c | 25 +++++++++++++++++++++++++ pico-key/duckyscript.h | 3 +++ pico-key/pico-key.c | 4 ++++ 5 files changed, 53 insertions(+), 13 deletions(-) diff --git a/pico-key/config.c b/pico-key/config.c index 8e4ac0b..54daaea 100644 --- a/pico-key/config.c +++ b/pico-key/config.c @@ -5,12 +5,10 @@ #include "config.h" -void checkConfig() { +void checkConfig(const Configuration& config) { printf("\nCurrent Config: \n"); - printf("LED Pin definition: "); - printf(LED_PIN); - printf("Payload location: "); - printf(PAYLOAD_LOCATION); - printf("Current version: "); - printf(VERSION); + printf("LED Pin definition: %d\n", config.led_pin); + printf("Payload location: %s\n", config.payload_location.c_str()); + printf("Run on startup: %s\n", config.run_on_startup ? "true" : "false"); + printf("Current version: %s\n", config.version.c_str()); } \ No newline at end of file diff --git a/pico-key/config.h b/pico-key/config.h index 2e9c8aa..3dd69c0 100644 --- a/pico-key/config.h +++ b/pico-key/config.h @@ -6,12 +6,22 @@ #ifndef CONFIG_H #define CONFIG_H -// configuration parameters +#include +#include + +// default config params #define LED_PIN PICO_DEFAULT_LED_PIN -const char* PAYLOAD_LOCATION = "/payload.dd\n"; -#define RUN_ON_STARTUP true +#define DEFAULT_PAYLOAD_LOCATION "/payload.dd" +#define DEFAULT_RUN_ON_STARTUP true + +// configuration structure +struct Configuration { + int led_pin; + std::string payload_location; + bool run_on_startup; + std::string version; +}; -// version -#define VERSION "0.1.0-alpha\n" +Configuration load(const char* filename); -#endif // CONFIG_H \ No newline at end of file +#endif // CONFIG_H diff --git a/pico-key/duckyscript.c b/pico-key/duckyscript.c index 2a3bf5f..cb3bbff 100644 --- a/pico-key/duckyscript.c +++ b/pico-key/duckyscript.c @@ -6,6 +6,31 @@ #include "duckyscript.h" // run a duckyscript command based on what is in duckyscript.h +void read(const char* payloadFile) { + FILE *file = fopen(payloadFile, "r"); + + char line[256]; + while (fgets(line, sizeof(line), file)) { + char *token = strtok(line, " \t\n"); + while (token != NULL) { + // matching + if (strcmp(token, "CTRL") == 0) { + run(CTRL); + } else if (strcmp(token, "ALT") == 0) { + run(ALT); + } + else { + printf("Command or key not found: %s\n :/", token); + } + + // Get the next token + token = strtok(NULL, " \t\n"); + } + } + + fclose(payloadFile); +} + int run(const char* command) { return 0; diff --git a/pico-key/duckyscript.h b/pico-key/duckyscript.h index 6f9715a..bc8ced7 100644 --- a/pico-key/duckyscript.h +++ b/pico-key/duckyscript.h @@ -6,6 +6,9 @@ #ifndef DUCKYSCRIPT_H #define DUCKYSCRIPT_H +#include +#include + // control keys #define WINDOWS 0x08 #define GUI 0x10 diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index 0841b36..c7f960a 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -83,6 +83,10 @@ int main() { options(); break; + case 69: + printf("\nWhat did you expect to be here???\n"); + break; + default: printf("\n%d: Invalid choice :/\n", choice); break; From e6facabdc6cec20212e97f19b03ce76328779856 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Sun, 31 Mar 2024 13:58:28 -0700 Subject: [PATCH 14/23] descriptions! --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a7083f1..21ff8a3 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ A physical pentesting toolkit on a regular Raspberry Pi Pico. ### Intro +You've probably seen other similar tools for other MCU's and SBC's, such as the ESP32 Marauder, ESP8266 Deauther, P4wnP1 A.L.O.A, PocketPhishr, Pwnagotchi, etc. Although these are all very good projects, there hasn't been much talk regarding the Raspberry Pi Pico becoming a good tool in the right hands. + The Raspberry Pi Pico is a flexible microcontroller board designed for multiple purposes. With this project, I intend to use make a powerful Keystroke Injection tool for such an intricate board with a special purpose. It is designed to be easy to configure, modify, and use for fun. This will be designed to be a little more than a *Bad USB*. Instead of being a basic, high-level program on a Pico, we build firmware designed for keystroke injection. ### Development progress @@ -30,7 +32,7 @@ The shell allows you to do a fair share of things with the board, allowing you t **How long will it be until a release?** -Most of the changes haven't been tested and it is yet to work as intended. This might take a while depending on how long it will take to implement the wanted feature(s). Most likely this will all be finalized sometime around March/April 2024 +Most of the changes haven't been tested and it is yet to work as intended. This might take a while depending on how long it will take to implement the wanted feature(s). Most likely this will all be finalized sometime around late April 2024 **Can it do things other than Keystroke injection?** From 135a4eaa2baf2b76ab5d055b3c48face8a49ebcf Mon Sep 17 00:00:00 2001 From: dj1ch Date: Sun, 31 Mar 2024 16:41:29 -0700 Subject: [PATCH 15/23] that was already added --- pico-key/duckyscript.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/pico-key/duckyscript.c b/pico-key/duckyscript.c index cb3bbff..2a3bf5f 100644 --- a/pico-key/duckyscript.c +++ b/pico-key/duckyscript.c @@ -6,31 +6,6 @@ #include "duckyscript.h" // run a duckyscript command based on what is in duckyscript.h -void read(const char* payloadFile) { - FILE *file = fopen(payloadFile, "r"); - - char line[256]; - while (fgets(line, sizeof(line), file)) { - char *token = strtok(line, " \t\n"); - while (token != NULL) { - // matching - if (strcmp(token, "CTRL") == 0) { - run(CTRL); - } else if (strcmp(token, "ALT") == 0) { - run(ALT); - } - else { - printf("Command or key not found: %s\n :/", token); - } - - // Get the next token - token = strtok(NULL, " \t\n"); - } - } - - fclose(payloadFile); -} - int run(const char* command) { return 0; From f92a0e9b8ea175f75f423e509d4a21f043a5b139 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Tue, 2 Apr 2024 00:31:00 -0700 Subject: [PATCH 16/23] very important stuff --- pico-key/egg.c | 36 ++++++++++++++++++++++++++++++++++++ pico-key/egg.h | 6 ++++++ pico-key/pico-key.c | 5 ++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 pico-key/egg.c create mode 100644 pico-key/egg.h diff --git a/pico-key/egg.c b/pico-key/egg.c new file mode 100644 index 0000000..9ade330 --- /dev/null +++ b/pico-key/egg.c @@ -0,0 +1,36 @@ +/** + * egg.c + * maybe this is an easter egg ;) +*/ + +#include "egg.h" + +void specialMessage() { + printf("\nWhat did you expect to be here???\n"); + printf("\nAnyway, wanna play a game? (Y/N) > "); + + char* specialChoice[10]; + + fgets(specialChoice, sizeof(specialChoice), stdin); + specialChoice[strcspn(specialChoice, "\n")] = '\0'; + + for (int i = 0; specialChoicep[i]; i++) { + specialChoice[i] = toupper(specialChoice[i]); + } + + if (strcmp(specialChoice, "Y") == 0) { + continue; + } else if (strcmp(specialChoice, "N") == 0) { + break; + } else { + printf("%s: Not a valid response\n", specialChoice); + continue; + } + + // cool game + game(); +} + +void game() { + +} \ No newline at end of file diff --git a/pico-key/egg.h b/pico-key/egg.h new file mode 100644 index 0000000..0c1392f --- /dev/null +++ b/pico-key/egg.h @@ -0,0 +1,6 @@ +/** + * egg.h + * special header? +*/ + +#include \ No newline at end of file diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index c7f960a..b30ad05 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -14,6 +14,9 @@ // duckyscript #include "duckyscript.h" +// :) +#include "egg.h" + // libraries #include #include @@ -84,7 +87,7 @@ int main() { break; case 69: - printf("\nWhat did you expect to be here???\n"); + specialMessage(); break; default: From 384eb447e2d70a84972494d09bada0c6b525a45e Mon Sep 17 00:00:00 2001 From: dj1ch Date: Tue, 2 Apr 2024 00:38:43 -0700 Subject: [PATCH 17/23] fixed guards --- pico-key/config.h | 2 +- pico-key/{egg.c => easter-egg.c} | 2 +- pico-key/easter-egg.h | 16 ++++++++++++++++ pico-key/egg.h | 6 ------ pico-key/pico-key.h | 31 +++++++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 8 deletions(-) rename pico-key/{egg.c => easter-egg.c} (96%) create mode 100644 pico-key/easter-egg.h delete mode 100644 pico-key/egg.h create mode 100644 pico-key/pico-key.h diff --git a/pico-key/config.h b/pico-key/config.h index 3dd69c0..0324ca8 100644 --- a/pico-key/config.h +++ b/pico-key/config.h @@ -22,6 +22,6 @@ struct Configuration { std::string version; }; -Configuration load(const char* filename); +void checkConfig(); #endif // CONFIG_H diff --git a/pico-key/egg.c b/pico-key/easter-egg.c similarity index 96% rename from pico-key/egg.c rename to pico-key/easter-egg.c index 9ade330..9eae776 100644 --- a/pico-key/egg.c +++ b/pico-key/easter-egg.c @@ -3,7 +3,7 @@ * maybe this is an easter egg ;) */ -#include "egg.h" +#include "easter-egg.h" void specialMessage() { printf("\nWhat did you expect to be here???\n"); diff --git a/pico-key/easter-egg.h b/pico-key/easter-egg.h new file mode 100644 index 0000000..e39a29d --- /dev/null +++ b/pico-key/easter-egg.h @@ -0,0 +1,16 @@ +/** + * egg.h + * special header? +*/ + +#ifndef EASTER_EGG_H +#define EASTER_EGG_H + +#include + +char* specialChoice[10]; + +void specialMessage(); +void game(); + +#endif // EASTER_EGG_H \ No newline at end of file diff --git a/pico-key/egg.h b/pico-key/egg.h deleted file mode 100644 index 0c1392f..0000000 --- a/pico-key/egg.h +++ /dev/null @@ -1,6 +0,0 @@ -/** - * egg.h - * special header? -*/ - -#include \ No newline at end of file diff --git a/pico-key/pico-key.h b/pico-key/pico-key.h new file mode 100644 index 0000000..78bed23 --- /dev/null +++ b/pico-key/pico-key.h @@ -0,0 +1,31 @@ +/** + * pico-key.h + * main stuff +*/ + +#ifndef PICO_KEY_H +#define PICO_KEY_H + +// config +#include "config.h" + +// duckyscript +#include "duckyscript.h" + +// :) +#include "easter-egg.h" + +// libraries +#include +#include +#include +#include + +// sdk +#include "pico/stdio.h" +#include "pico/stdlib.h" +#include "pico/malloc.h" +#include "hardware/uart.h" +#include "hardware/gpio.h" + +#endif // PICO_KEY_H \ No newline at end of file From ac81bac11d65ead336e977a0355d69cb69bad043 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Tue, 2 Apr 2024 15:05:09 -0700 Subject: [PATCH 18/23] fixed include --- pico-key/pico-key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index b30ad05..7f4c476 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -15,7 +15,7 @@ #include "duckyscript.h" // :) -#include "egg.h" +#include "easter-egg.h" // libraries #include From afc2f6a4cf94d02ddd88804ef267c9b4d01a9938 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Tue, 2 Apr 2024 21:59:57 -0700 Subject: [PATCH 19/23] header formatting --- pico-key/duckyscript.h | 2 ++ pico-key/pico-key.h | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/pico-key/duckyscript.h b/pico-key/duckyscript.h index bc8ced7..46f66e3 100644 --- a/pico-key/duckyscript.h +++ b/pico-key/duckyscript.h @@ -118,4 +118,6 @@ typedef struct { char key; } keyCommand; +void run(); + #endif // DUCKYSCRIPT_H \ No newline at end of file diff --git a/pico-key/pico-key.h b/pico-key/pico-key.h index 78bed23..deeed46 100644 --- a/pico-key/pico-key.h +++ b/pico-key/pico-key.h @@ -28,4 +28,13 @@ #include "hardware/uart.h" #include "hardware/gpio.h" +int main(); +void boot(); +void buildScript(); +void testScript(); +void read(); +void fakeUSB(); +void misc(); +void options(); + #endif // PICO_KEY_H \ No newline at end of file From aef490c585c26d9e10eab79fbcf3ae270e4bbf89 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Tue, 2 Apr 2024 22:00:05 -0700 Subject: [PATCH 20/23] moved function --- pico-key/pico-key.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index 7f4c476..1ba8c29 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -30,27 +30,6 @@ #include "hardware/uart.h" #include "hardware/gpio.h" -void boot() { - // boot logo - char coolArt[] = "pico-key..."; - char author[] = "by dj1ch"; - - // print this ^^ - printf("\n%s\n", coolArt); - sleep(1); - printf("%s\n", author); - - // board info - boardInfo(); - - if (RUN_ON_STARTUP) { - read(); - return 0; - } else { - // do nothing - } -} - int main() { boot(); while (true) { @@ -98,13 +77,34 @@ int main() { return 0; } +void boot() { + // boot logo + char coolArt[] = "pico-key..."; + char author[] = "by dj1ch"; + + // print this ^^ + printf("\n%s\n", coolArt); + sleep(1); + printf("%s\n", author); + + // board info + boardInfo(); + + if (config.run_on_startup) { + read(); + return 0; + } else { + // do nothing + } +} + void buildScript() { printf("\nPayloads are built here, but can also be modified using a file manager."); printf("Every time you press enter it will be written to the file.\n"); printf("Type 'exit' to stop.\n"); // assume it's named payload.dd - FILE *file = fopen(PAYLOAD_LOCATION, "w"); + FILE *file = fopen(config.payload_location, "w"); if (file == NULL) { printf("Failed to open payload.dd! :(\n"); From f1b6e2ebdde434c301ec0a70c773b7278b4a1556 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Tue, 2 Apr 2024 22:45:04 -0700 Subject: [PATCH 21/23] headers --- pico-key/pico-key.c | 78 ++------------------------------------------- pico-key/pico-key.h | 14 ++------ 2 files changed, 5 insertions(+), 87 deletions(-) diff --git a/pico-key/pico-key.c b/pico-key/pico-key.c index 1ba8c29..52b4e0a 100644 --- a/pico-key/pico-key.c +++ b/pico-key/pico-key.c @@ -8,27 +8,7 @@ * old pr w/ python is here: https://github.com/dj1ch/pico-key/pull/1/commits/5d4c65106c6aa490b7eb047827c1ed3a00a21377 */ -// config -#include "config.h" - -// duckyscript -#include "duckyscript.h" - -// :) -#include "easter-egg.h" - -// libraries -#include -#include -#include -#include - -// sdk -#include "pico/stdio.h" -#include "pico/stdlib.h" -#include "pico/malloc.h" -#include "hardware/uart.h" -#include "hardware/gpio.h" +#include "pico-key.h" int main() { boot(); @@ -77,27 +57,6 @@ int main() { return 0; } -void boot() { - // boot logo - char coolArt[] = "pico-key..."; - char author[] = "by dj1ch"; - - // print this ^^ - printf("\n%s\n", coolArt); - sleep(1); - printf("%s\n", author); - - // board info - boardInfo(); - - if (config.run_on_startup) { - read(); - return 0; - } else { - // do nothing - } -} - void buildScript() { printf("\nPayloads are built here, but can also be modified using a file manager."); printf("Every time you press enter it will be written to the file.\n"); @@ -175,33 +134,7 @@ void testScript() { read(scriptPath); } } -} - -// crap i gotta build a new compiler for this :/ -void read(const char* filePath) { - FILE *file = fopen(filePath, "r"); - - if (file == NULL) { - perror("Can't open '%s' :/", filePath); - return; - } - - char line[256]; - while (fgets(line, sizeof(line), file)) { - char *command = strtok(line, " \t\n"); - - char *param = strtok(NULL, "\n"); - while (param && strtok(NULL, "\n")) { - strcat(command, " "); - strcat(command, param); - param = strtok(NULL, "\n"); - } - - run(command); - } - - fclose(filePath); -} +} void fakeUSB() { bool led = false; @@ -283,11 +216,4 @@ void options() { if (strcmp(choiceC, "1") == 0) { boardInfo(); } -} - -void boardInfo() { - // we can only really print memory here - printf("\nBoard info:\n"); - printf(malloc_stats() + " bytes"); - printf(checkConfig()); } \ No newline at end of file diff --git a/pico-key/pico-key.h b/pico-key/pico-key.h index deeed46..ccc3653 100644 --- a/pico-key/pico-key.h +++ b/pico-key/pico-key.h @@ -1,35 +1,27 @@ /** * pico-key.h - * main stuff + * main header for main stuff */ #ifndef PICO_KEY_H #define PICO_KEY_H -// config #include "config.h" - -// duckyscript +#include "boot.h" #include "duckyscript.h" - -// :) #include "easter-egg.h" -// libraries -#include +#include #include #include #include -// sdk #include "pico/stdio.h" #include "pico/stdlib.h" -#include "pico/malloc.h" #include "hardware/uart.h" #include "hardware/gpio.h" int main(); -void boot(); void buildScript(); void testScript(); void read(); From 870bad15bcec0f993e7006c7424c9f29d0a0088e Mon Sep 17 00:00:00 2001 From: dj1ch Date: Tue, 2 Apr 2024 22:45:37 -0700 Subject: [PATCH 22/23] using sdk's stdio --- pico-key/config.h | 2 +- pico-key/duckyscript.c | 26 ++++++++++++++++++++++++++ pico-key/duckyscript.h | 4 ++-- pico-key/easter-egg.h | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/pico-key/config.h b/pico-key/config.h index 0324ca8..6a39b51 100644 --- a/pico-key/config.h +++ b/pico-key/config.h @@ -6,8 +6,8 @@ #ifndef CONFIG_H #define CONFIG_H -#include #include +#include "pico/stdio.h" // default config params #define LED_PIN PICO_DEFAULT_LED_PIN diff --git a/pico-key/duckyscript.c b/pico-key/duckyscript.c index 2a3bf5f..cd127a6 100644 --- a/pico-key/duckyscript.c +++ b/pico-key/duckyscript.c @@ -9,4 +9,30 @@ int run(const char* command) { return 0; +} + +// crap i gotta build a new compiler for this :/ +void read(const char* filePath) { + FILE *file = fopen(filePath, "r"); + + if (file == NULL) { + perror("Can't open '%s' :/", filePath); + return; + } + + char line[256]; + while (fgets(line, sizeof(line), file)) { + char *command = strtok(line, " \t\n"); + + char *param = strtok(NULL, "\n"); + while (param && strtok(NULL, "\n")) { + strcat(command, " "); + strcat(command, param); + param = strtok(NULL, "\n"); + } + + run(command); + } + + fclose(filePath); } \ No newline at end of file diff --git a/pico-key/duckyscript.h b/pico-key/duckyscript.h index 46f66e3..c1382ff 100644 --- a/pico-key/duckyscript.h +++ b/pico-key/duckyscript.h @@ -6,8 +6,8 @@ #ifndef DUCKYSCRIPT_H #define DUCKYSCRIPT_H -#include -#include +#include +#include "pico/stdio.h" // control keys #define WINDOWS 0x08 diff --git a/pico-key/easter-egg.h b/pico-key/easter-egg.h index e39a29d..8484d71 100644 --- a/pico-key/easter-egg.h +++ b/pico-key/easter-egg.h @@ -6,7 +6,7 @@ #ifndef EASTER_EGG_H #define EASTER_EGG_H -#include +#include "pico/stdio.h" char* specialChoice[10]; From 6904d8af8aea605d07e63d0bac6a1f855b5a6098 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Tue, 2 Apr 2024 22:45:53 -0700 Subject: [PATCH 23/23] added boot.c and .h --- pico-key/boot.c | 34 ++++++++++++++++++++++++++++++++++ pico-key/boot.h | 16 ++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 pico-key/boot.c create mode 100644 pico-key/boot.h diff --git a/pico-key/boot.c b/pico-key/boot.c new file mode 100644 index 0000000..50e70d2 --- /dev/null +++ b/pico-key/boot.c @@ -0,0 +1,34 @@ +/** + * boot.c + * "bootup" process to run after the firmware is loaded +*/ + +#include "boot.h" + +int boot() { + // boot logo + char coolArt[] = "pico-key..."; + char author[] = "by dj1ch"; + + // print this ^^ + printf("\n%s\n", coolArt); + sleep(1); + printf("%s\n", author); + + // board info + boardInfo(); + + if (config.run_on_startup) { + read(); + return 0; + } else { + // do nothing + } +} + +void boardInfo() { + // we can only really print memory here + printf("\nBoard info:\n"); + printf(malloc_stats() + " bytes"); + printf(checkConfig()); +} \ No newline at end of file diff --git a/pico-key/boot.h b/pico-key/boot.h new file mode 100644 index 0000000..0ada610 --- /dev/null +++ b/pico-key/boot.h @@ -0,0 +1,16 @@ +/** + * boot.h + * headers for boot.c +*/ + +#ifndef BOOT_H +#define BOOT_H + +#include "config.h" +#include "pico/stdio.h" +#include "pico/malloc.h" + +int boot(); +void boardInfo(); + +#endif // BOOT_H \ No newline at end of file