diff --git a/DIP Switches Example Code.ino b/DIP Switches Example Code.ino index b12f179..eb0eaab 100644 --- a/DIP Switches Example Code.ino +++ b/DIP Switches Example Code.ino @@ -1,12 +1,11 @@ /* - * Author: Seytonic + * Author: Seytonic,Draguve * https://twitter.com/seytonic + * https://twitter.com/draguve * https://www.youtube.com/seytonic * GIT: * https://github.com/Seytonic/Duckduino-microSD */ - - #include #include #include @@ -14,52 +13,62 @@ File myFile; boolean first = true; +String DEFAULT_FILE_NAME = "script.txt"; +unsigned long thisLineStartPos=0; +unsigned long lastLineStartPos; +void setup() { + String dip = ""; // Name of the file that will be opened -void setup() { - String dip = ""; // Name of the file that will be opened - - // Sets the given pins as switches for the dip switches - pinMode(6, INPUT_PULLUP); - pinMode(7, INPUT_PULLUP); - pinMode(8, INPUT_PULLUP); - pinMode(9, INPUT_PULLUP); - - // Switches are checked, dip string is contructed - if (digitalRead(6) == LOW){dip += "1";} else {dip += "0";} - if (digitalRead(7) == LOW){dip += "1";} else {dip += "0";} - if (digitalRead(8) == LOW){dip += "1";} else {dip += "0";} - if (digitalRead(9) == LOW){dip += "1";} else {dip += "0";} + // Sets the given pins as switches for the dip switches + pinMode(6, INPUT_PULLUP); + pinMode(7, INPUT_PULLUP); + pinMode(8, INPUT_PULLUP); + pinMode(9, INPUT_PULLUP); - dip += ".txt"; + // Switches are checked, dip string is contructed + if (digitalRead(6) == LOW){dip += "1";} else {dip += "0";} + if (digitalRead(7) == LOW){dip += "1";} else {dip += "0";} + if (digitalRead(8) == LOW){dip += "1";} else {dip += "0";} + if (digitalRead(9) == LOW){dip += "1";} else {dip += "0";} + dip += ".txt"; + //Keyboard.begin(); if (!SD.begin(4)) { + Keyboard.print("Problem"); return; } - - // Desired file is opened + myFile = SD.open(dip); if (myFile) { Keyboard.begin(); - String line = ""; while (myFile.available()) { char m = myFile.read(); if (m == '\n'){ Line(line); line = ""; + lastLineStartPos = thisLineStartPos; + thisLineStartPos = myFile.position(); } else if((int) m != 13) { line += m; } + if(line.length()==7){ + if(line.equals("STRING ")){ + unsigned long strPos = myFile.position(); + printString(strPos); + line = ""; + lastLineStartPos = thisLineStartPos; + thisLineStartPos = myFile.position(); + } + } } Line(line); - myFile.close(); } else { } - Keyboard.end(); } @@ -70,18 +79,88 @@ void Line(String l) { Press(l); } - else if (l.substring(0,space_1) == "STRING") - { - Keyboard.print(l.substring(space_1 + 1)); - } else if (l.substring(0,space_1) == "DELAY") { int delaytime = l.substring(space_1 + 1).toInt(); delay(delaytime); } - else if(l.substring(0,space_1) == "REM"){} - else + else if (l.substring(0,space_1) == "DEFAULT_DELAY"||l.substring(0,space_1) == "DEFAULTDELAY") { + delay(100); + } + else if(l.substring(0,space_1) == "REM"){} + else if(l.substring(0,space_1) == "CPY"){ + File cpyFile = SD.open(l.substring(space_1+1)); + if (cpyFile) { + while (cpyFile.available()) { + Keyboard.write(cpyFile.read()); + } + cpyFile.close(); + } + } + else if(l.substring(0,space_1) == "REPLAY" || l.substring(0,space_1) == "REPEAT"){ + unsigned long toGoTo = myFile.position(); + myFile.seek(lastLineStartPos); + String nline=""; + bool isString = false; + int noOfTimes = l.substring(space_1+1).toInt(); + bool foundLine=false; + while(!foundLine){ + char m = myFile.read(); + if (m == '\n'){ + foundLine=true; + } + else if((int) m != 13) + { + nline += m; + } + if(nline.length()==7){ + if(nline.equals("STRING ")){ + isString=true; + foundLine=true; + } + } + } + if(isString){ + unsigned long stringPos = myFile.position(); + for(int i=0;i1 && pin<=10 && pin!=4 && pin!=6 && pin!=7 && pin!=8 && pin!=9){ + pinMode(pin,INPUT_PULLUP); + bool allowed = false; + while(!allowed){ + if(digitalRead(pin) == LOW){ + allowed=true; + } + } + } + } + else if(l.substring(0,space_1) == "HIGH"){ + int pin = l.substring(space_1+1).toInt(); + if(pin>1 && pin<=10 && pin!=4 && pin!=6 && pin!=7 && pin!=8 && pin!=9){ + pinMode(pin,OUTPUT); + digitalWrite(pin,HIGH); + } + } + else if(l.substring(0,space_1) == "LOW"){ + int pin = l.substring(space_1+1).toInt(); + if(pin>1 && pin<=10 && pin!=4 && pin!=6 && pin!=7 && pin!=8 && pin!=9){ + pinMode(pin,OUTPUT); + digitalWrite(pin,LOW); + } + } + else{ String remain = l; while(remain.length() > 0) @@ -100,10 +179,23 @@ void Line(String l) delay(5); } } - Keyboard.releaseAll(); } +void printString(unsigned long strPos){ + myFile.seek(strPos); + bool lineEnding=false; + while(!lineEnding){ + char m = myFile.read(); + if(m!='\n'){ + Keyboard.write(m); + }else{ + lineEnding=true; + } + } + //myFile.seek(strPos); +} + void Press(String b) { @@ -116,7 +208,7 @@ void Press(String b) { Keyboard.press(KEY_RETURN); } - else if (b.equals("CTRL")) + else if (b.equals("CTRL")||b.equals("CONTROL")) { Keyboard.press(KEY_LEFT_CTRL); } @@ -128,7 +220,7 @@ void Press(String b) { Keyboard.press(KEY_LEFT_ALT); } - else if (b.equals("GUI")) + else if (b.equals("GUI") || b.equals("WINDOWS") || b.equals("COMMAND")) { Keyboard.press(KEY_LEFT_GUI); } @@ -148,7 +240,7 @@ void Press(String b) { Keyboard.press(KEY_RIGHT_ARROW); } - else if (b.equals("DELETE")) + else if (b.equals("DELETE")|| b.equals("DEL")) { Keyboard.press(KEY_DELETE); } @@ -164,7 +256,7 @@ void Press(String b) { Keyboard.press(KEY_HOME); } - else if (b.equals("ESC")) + else if (b.equals("ESC") || b.equals("ESCAPE")) { Keyboard.press(KEY_ESC); } @@ -180,7 +272,7 @@ void Press(String b) { Keyboard.press(KEY_END); } - else if (b.equals("CAPSLOCK")) + else if (b.equals("CAPSLOCK") || b.equals("CAPS")) { Keyboard.press(KEY_CAPS_LOCK); } @@ -232,6 +324,15 @@ void Press(String b) { Keyboard.press(KEY_F12); } + else if (b.equals("SPACE")) + { + Keyboard.press(' '); + } + else if (b.equals("MENU") || b.equals("APP")) + { + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F10); + } } void loop() { diff --git a/Duckduino-microSD/Duckduino-microSD.ino b/Duckduino-microSD/Duckduino-microSD.ino index b28360f..9026740 100644 --- a/Duckduino-microSD/Duckduino-microSD.ino +++ b/Duckduino-microSD/Duckduino-microSD.ino @@ -1,12 +1,11 @@ /* - * Author: Seytonic + * Author: Seytonic,Draguve * https://twitter.com/seytonic + * https://twitter.com/draguve * https://www.youtube.com/seytonic * GIT: * https://github.com/Seytonic/Duckduino-microSD */ - - #include #include #include @@ -15,35 +14,45 @@ File myFile; boolean first = true; String DEFAULT_FILE_NAME = "script.txt"; - +unsigned long thisLineStartPos=0; +unsigned long lastLineStartPos; void setup() { - + //Keyboard.begin(); if (!SD.begin(4)) { + Keyboard.print("Problem"); return; } - + myFile = SD.open(DEFAULT_FILE_NAME); if (myFile) { Keyboard.begin(); - String line = ""; while (myFile.available()) { char m = myFile.read(); if (m == '\n'){ Line(line); line = ""; + lastLineStartPos = thisLineStartPos; + thisLineStartPos = myFile.position(); } else if((int) m != 13) { line += m; } + if(line.length()==7){ + if(line.equals("STRING ")){ + unsigned long strPos = myFile.position(); + printString(strPos); + line = ""; + lastLineStartPos = thisLineStartPos; + thisLineStartPos = myFile.position(); + } + } } Line(line); - myFile.close(); } else { } - Keyboard.end(); } @@ -54,18 +63,88 @@ void Line(String l) { Press(l); } - else if (l.substring(0,space_1) == "STRING") - { - Keyboard.print(l.substring(space_1 + 1)); - } else if (l.substring(0,space_1) == "DELAY") { int delaytime = l.substring(space_1 + 1).toInt(); delay(delaytime); } - else if(l.substring(0,space_1) == "REM"){} - else + else if (l.substring(0,space_1) == "DEFAULT_DELAY"||l.substring(0,space_1) == "DEFAULTDELAY") { + delay(100); + } + else if(l.substring(0,space_1) == "REM"){} + else if(l.substring(0,space_1) == "CPY"){ + File cpyFile = SD.open(l.substring(space_1+1)); + if (cpyFile) { + while (cpyFile.available()) { + Keyboard.write(cpyFile.read()); + } + cpyFile.close(); + } + } + else if(l.substring(0,space_1) == "REPLAY" || l.substring(0,space_1) == "REPEAT"){ + unsigned long toGoTo = myFile.position(); + myFile.seek(lastLineStartPos); + String nline=""; + bool isString = false; + int noOfTimes = l.substring(space_1+1).toInt(); + bool foundLine=false; + while(!foundLine){ + char m = myFile.read(); + if (m == '\n'){ + foundLine=true; + } + else if((int) m != 13) + { + nline += m; + } + if(nline.length()==7){ + if(nline.equals("STRING ")){ + isString=true; + foundLine=true; + } + } + } + if(isString){ + unsigned long stringPos = myFile.position(); + for(int i=0;i1 && pin<=10 && pin!=4){ + pinMode(pin,INPUT_PULLUP); + bool allowed = false; + while(!allowed){ + if(digitalRead(pin) == LOW){ + allowed=true; + } + } + } + } + else if(l.substring(0,space_1) == "HIGH"){ + int pin = l.substring(space_1+1).toInt(); + if(pin>1 && pin<=10 && pin!=4){ + pinMode(pin,OUTPUT); + digitalWrite(pin,HIGH); + } + } + else if(l.substring(0,space_1) == "LOW"){ + int pin = l.substring(space_1+1).toInt(); + if(pin>1 && pin<=10 && pin!=4){ + pinMode(pin,OUTPUT); + digitalWrite(pin,LOW); + } + } + else{ String remain = l; while(remain.length() > 0) @@ -84,10 +163,23 @@ void Line(String l) delay(5); } } - Keyboard.releaseAll(); } +void printString(unsigned long strPos){ + myFile.seek(strPos); + bool lineEnding=false; + while(!lineEnding){ + char m = myFile.read(); + if(m!='\n'){ + Keyboard.write(m); + }else{ + lineEnding=true; + } + } + //myFile.seek(strPos); +} + void Press(String b) { @@ -100,7 +192,7 @@ void Press(String b) { Keyboard.press(KEY_RETURN); } - else if (b.equals("CTRL")) + else if (b.equals("CTRL")||b.equals("CONTROL")) { Keyboard.press(KEY_LEFT_CTRL); } @@ -112,7 +204,7 @@ void Press(String b) { Keyboard.press(KEY_LEFT_ALT); } - else if (b.equals("GUI")) + else if (b.equals("GUI") || b.equals("WINDOWS") || b.equals("COMMAND")) { Keyboard.press(KEY_LEFT_GUI); } @@ -132,7 +224,7 @@ void Press(String b) { Keyboard.press(KEY_RIGHT_ARROW); } - else if (b.equals("DELETE")) + else if (b.equals("DELETE")|| b.equals("DEL")) { Keyboard.press(KEY_DELETE); } @@ -148,7 +240,7 @@ void Press(String b) { Keyboard.press(KEY_HOME); } - else if (b.equals("ESC")) + else if (b.equals("ESC") || b.equals("ESCAPE")) { Keyboard.press(KEY_ESC); } @@ -164,7 +256,7 @@ void Press(String b) { Keyboard.press(KEY_END); } - else if (b.equals("CAPSLOCK")) + else if (b.equals("CAPSLOCK") || b.equals("CAPS")) { Keyboard.press(KEY_CAPS_LOCK); } @@ -219,10 +311,14 @@ void Press(String b) else if (b.equals("SPACE")) { Keyboard.press(' '); - } + } + else if (b.equals("MENU") || b.equals("APP")) + { + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F10); + } } void loop() { // nothing happens after setup } - diff --git a/README.md b/README.md index 6bee96d..fa6ef19 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ Once the arduino has been programmed, you need only deal with ducky scripts on a ## Setup -[![video link](http://imgur.com/2a1fe002-68fa-4046-b3a8-83e6fa2a22fc)](https://www.youtube.com/watch?v=ksvo1WDYQ7s) +[![video link](http://img.youtube.com/vi/ksvo1WDYQ7s/mqdefault.jpg)](https://www.youtube.com/watch?v=ksvo1WDYQ7s) The instructions are for an arduino pro micro, it should work on any arduino using an atmega32u4 chip such as the leonardo. -Simply upload Duckduino-microSD to your arduino, forma your microSD to FAT32 and save your script on the microSD card titled script.txt +Simply upload Duckduino-microSD to your arduino, format your microSD to FAT32 and save your script on the microSD card titled script.txt Lastly, connect a microsd breakout board using the pins below ``` Arduino ||| microSD module @@ -28,10 +28,23 @@ D4 ---> CS ``` ## Keep in mind... -Long lines of strings may crash the arduino due to taking up too much RAM, if you have a line "STRING ..." over 300 characters then split it into separate lines of strings, this won't affect how your script runs, it just reduces how much of your script is held in memory at any one time. +~~Long lines of strings may crash the arduino due to taking up too much RAM, if you have a line "STRING ..." over 300 characters then split it into separate lines of strings, this won't affect how your script runs, it just reduces how much of your script is held in memory at any one time.~~ +**Should Now Run With Strings Larger than 300** I have seen some ducky scripts that put hyphens (-) in between keys to be pressed simultaneously eg."CTRL-ALT DELETE". Note that when using duckduino-microSD you must not use hyphens and instead just use spaces eg."CTRL ALT DELETE" -The following duckyscript features are not yet implemented: DEFAULT_DELAY, REPLAY. This project uses arduino's inbuilt keyboard.h library, any keys not implemented in that will not work with this. eg: PRINTSCREEN. +~~The following duckyscript features are not yet implemented: DEFAULT_DELAY, REPLAY~~. +REPLAY,DEFAULT_DELAY And MENU Now Work -This has only been tested on the following microSD module, I'm sure others will work, though no guarantees. +This project uses arduino's inbuilt keyboard.h library, any keys not implemented in that will not work with this. eg: PRINTSCREEN. + +**Script Commands Also Added** +``` +HIGH x ||| Puts Pin x To High Logic Level +LOW x ||| Puts Pin x to Low Logic Level +CPY filename.extension ||| Writes The Contents of the file to the host +PULLUP x / WAIT_PULLUP x ||| Executes The Rest Of the Code After Pin x is connected to Ground + +``` + +This has only been tested on the following microSD module,Also Works With This SD Card Reader ,I'm sure others will work, though no guarantees.