本帖最后由 cheeks 于 2022-1-16 19:37 编辑
usb调试器
我该如何解决这个问题 XD
Arduino Leonardo
text section exceeds available space in board
项目使用了 31778 字节,占用了 (110%) 程序存储空间。最大为 28672 字节。
全局变量使用了1719字节,(67%)的动态内存,余留841字节局部变量。最大为2560字节。
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
为开发板 Arduino Leonardo 编译时出错。
- #include <Keyboard.h>
- #include <SPI.h>
- #include <SD.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);
- File myFile;
- boolean first = true;
- String fileName="payload.txt";
- int SD_mode = 0;
- Sd2Card card;
- SdVolume volume;
- SdFile root;
- String bufferStr = "";
- String last = "";
- int defaultDelay = 0;
- int key1 = 8;
- int key2 = 6;
- int key3 = 12 ;
- int key4 = 4;
- int LedA = 9;
- int LedB = 10;
- int enablestorage = 7;
- int keystatus = 0;
- int delaytime = 60;
- int SW2 = A5;
- int JoystickPush = A4;
- int JoystickRight = 5;
- int JoystickLeft = 11;
- int Buzzer = 13;
- const int chipSelect = PIN_SPI_SS;
- int modeSelect()
- {
- display.println("Payload Select");
- display.println("1.se_mode");
- display.println("2.duck_mode");
- display.println("3.wifi_mode");
- display.display();
- int mode = 2;
- while (!digitalRead(SW2))
- {
- if (digitalRead(JoystickLeft))
- {
- delay(10);
- if (digitalRead(JoystickRight))
- {
- mode = 1;
- }
- else{}
- }
- else if (digitalRead(JoystickRight))
- {
- delay(10);
- if (digitalRead(JoystickRight))
- {
- mode= 3;
- }
- else{}
- }
- else if(digitalRead(JoystickPush))
- {
- delay(10);
- if (digitalRead(JoystickPush))
- {
- mode= 2;
- }
- else{}
- }
- display.clearDisplay();
- display.println("Payload Select");
- if (mode == 1)
- {
- display.println("1.SE_MODE");
- }
- else
- {
- display.println("1.se_mode");
- }
- if (mode == 2)
- {
- display.println("2.DUCK_MODE");
- }
- else
- {
- display.println("2.duck_mode");
- }
- if (mode == 3)
- {
- display.println("3.WIFI_MODE");
- }
- else
- {
- display.println("3.wifi_mode");
- }
- display.display();
- }
- return mode;
- }
- void buzzer(int times)
- {
- for (int i = 1; i <= times; i++)
- {
- digitalWrite(Buzzer, HIGH);
- delay(100);
- digitalWrite(Buzzer, LOW);
- delay(200);
- }
- }
- void led(bool led1, bool led2)
- {
- digitalWrite(LedA, led1);
- digitalWrite(LedB, led2);
- }
- void breakpoint()
- {
- while(!digitalRead(JoystickPush))
- {
- delay(30);
- }
- }
- void runPayload(int mode,int Payload_X)
- {
- if (mode == 3)
- {
- wifiduck();
- }
- else if(mode==2)
- {
- const char x[]={Payload_X};
- fileName.replace("payload",x);
- fileName.replace(fileName,".txt");
- rubberducky(fileName);
- }
- {
- switch(Payload_X)
- {
- case 0:
- {
- //payload0
- break;
- }
- case 1:
- {
- //payload1
- break;
- }
- case 2:
- {
- //payload2
- break;
- }
- case 3:
- {
- //payload3
- break;
- }
- case 4:
- {
- //payload4
- break;
- }
- case 5:
- {
- //payload5
- break;
- }
- case 6:
- {
- //payload6
- break;
- }
- case 7:
- {
- //payload7
- break;
- }
- case 8:
- {
- //payload8
- break;
- }
- case 9:
- {
- //payload9
- break;
- }
- case 10:
- {
- //payload10
- break;
- }
- case 11:
- {
- //payload11
- break;
- }
- case 12:
- {
- //payload12
- break;
- }
- case 13:
- {
- //payload13
- break;
- }
- case 14:
- {
- //payload14
- break;
- }
- case 15:
- {
- //payload15
- break;
- }
- }
- }
- }
- void rubberducky(String duckyScript)
- {
-
- if (!SD.begin(PIN_SPI_SS)) {
- return;
- }
- myFile = SD.open(duckyScript);
- if (myFile) {
- Keyboard.begin();
- String line = "";
- while (myFile.available()) {
- char m = myFile.read();
- if (m == '\n') {
- Line(line);
- line = "";
- }
- else if ((int) m != 13)
- {
- line += m;
- }
- }
- Line(line);
- myFile.close();
- } else {
- }
- Keyboard.end();
- }
- void wifiduck()
- {
- Keyboard.begin();
- while (1)
- {
- if(Serial1.available()) {
- bufferStr = Serial1.readStringUntil("END");
- }
-
- if(bufferStr.length() > 0){
-
- bufferStr.replace("\r","\n");
- bufferStr.replace("\n\n","\n");
-
- while(bufferStr.length() > 0){
- int latest_return = bufferStr.indexOf("\n");
- if(latest_return == -1){
- Line(bufferStr);
- bufferStr = "";
- } else{
- Line(bufferStr.substring(0, latest_return));
- last=bufferStr.substring(0, latest_return);
- bufferStr = bufferStr.substring(latest_return + 1);
- }
- }
-
- bufferStr = "";
- Serial1.write(0x99);
- }
- }
- }
- void Line(String l)
- {
- int space_1 = l.indexOf(" ");
- if (space_1 == -1)
- {
- 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
- {
- String remain = l;
- while (remain.length() > 0)
- {
- int latest_space = remain.indexOf(" ");
- if (latest_space == -1)
- {
- Press(remain);
- remain = "";
- }
- else
- {
- Press(remain.substring(0, latest_space));
- remain = remain.substring(latest_space + 1);
- }
- delay(5);
- }
- }
- Keyboard.releaseAll();
- }
- void Press(String b)
- {
- if(b.length() == 1) Keyboard.press(char(b[0]));
- else if (b.equals("ENTER")) Keyboard.press(KEY_RETURN);
- else if (b.equals("CTRL")) Keyboard.press(KEY_LEFT_CTRL);
- else if (b.equals("SHIFT")) Keyboard.press(KEY_LEFT_SHIFT);
- else if (b.equals("ALT")) Keyboard.press(KEY_LEFT_ALT);
- else if (b.equals("GUI")) Keyboard.press(KEY_LEFT_GUI);
- else if (b.equals("UP") || b.equals("UPARROW")) Keyboard.press(KEY_UP_ARROW);
- else if (b.equals("DOWN") || b.equals("DOWNARROW")) Keyboard.press(KEY_DOWN_ARROW);
- else if (b.equals("LEFT") || b.equals("LEFTARROW")) Keyboard.press(KEY_LEFT_ARROW);
- else if (b.equals("RIGHT") || b.equals("RIGHTARROW")) Keyboard.press(KEY_RIGHT_ARROW);
- else if (b.equals("DELETE")) Keyboard.press(KEY_DELETE);
- else if (b.equals("PAGEUP")) Keyboard.press(KEY_PAGE_UP);
- else if (b.equals("PAGEDOWN")) Keyboard.press(KEY_PAGE_DOWN);
- else if (b.equals("HOME")) Keyboard.press(KEY_HOME);
- else if (b.equals("ESC")) Keyboard.press(KEY_ESC);
- else if (b.equals("INSERT")) Keyboard.press(KEY_INSERT);
- else if (b.equals("TAB")) Keyboard.press(KEY_TAB);
- else if (b.equals("END")) Keyboard.press(KEY_END);
- else if (b.equals("CAPSLOCK")) Keyboard.press(KEY_CAPS_LOCK);
- else if (b.equals("F1")) Keyboard.press(KEY_F1);
- else if (b.equals("F2")) Keyboard.press(KEY_F2);
- else if (b.equals("F3")) Keyboard.press(KEY_F3);
- else if (b.equals("F4")) Keyboard.press(KEY_F4);
- else if (b.equals("F5")) Keyboard.press(KEY_F5);
- else if (b.equals("F6")) Keyboard.press(KEY_F6);
- else if (b.equals("F7")) Keyboard.press(KEY_F7);
- else if (b.equals("F8")) Keyboard.press(KEY_F8);
- else if (b.equals("F9")) Keyboard.press(KEY_F9);
- else if (b.equals("F10")) Keyboard.press(KEY_F10);
- else if (b.equals("F11")) Keyboard.press(KEY_F11);
- else if (b.equals("F12")) Keyboard.press(KEY_F12);
- else if (b.equals("SPACE")) Keyboard.press(' ');
- }
- void setup()
- {
- pinMode(key1, INPUT);
- pinMode(key2, INPUT);
- pinMode(key3, INPUT);
- pinMode(key4, INPUT);
- pinMode(LedA, OUTPUT);
- pinMode(LedB, OUTPUT);
- pinMode(enablestorage, OUTPUT);
- pinMode(SW2, INPUT);
- pinMode(JoystickPush, INPUT);
- pinMode(JoystickRight, INPUT);
- pinMode(JoystickLeft, INPUT);
- pinMode(Buzzer, OUTPUT);
- //对外设进行初始化
- digitalWrite(enablestorage, HIGH);
- digitalWrite(LedA, LOW);
- digitalWrite(LedB, LOW);
- Serial1.begin(57200);
- //开启串口
- delay(100);
- display.begin(SSD1306_SWITCHCAPVCC,0x3C);
- display.display();
- delay(1000);
- display.clearDisplay();
- display.display();
- display.setTextColor(WHITE);
- display.setTextSize(1);
- display.setCursor(0,0);
-
- int mode=modeSelect();
- int k1 = digitalRead(key1);
- int k2 = digitalRead(key2);
- int k3 = digitalRead(key3);
- int k4 = digitalRead(key4);
- int payload = k1 * 1 + k2 * 2 + k3 * 4 + k4 * 8;
- runPayload(mode,payload);
- //attachInterrupt(digitalPinToInterrupt(SW2), breakpoint, HIGH);
- }
- void loop()
- {
- }
复制代码
|