I have a problem with the Atmega32u4 board. I'm creating a program on BadUSB, which, according to assumptions, should do 3 different things. The problem is that in between these activities the computer shuts down. My idea was a simple counter with if statements, but the board doesn't save the current state permanently. I was thinking about detecting the situation he is currently in, but I have no idea how to do it. Could you please help me?
Functionality 1 - locked computer, opening CMD, entering the command.
Turning off the computer
Functionality 2 - unlocked computer, opening CMD, entering the command.
Logging out of the account/unplugging the USB.
Functionality 3 - locked computer, opening CMD, entering the command.
Do you have any ideas how to detect these situations? Or possibly how to save the counter state "permanently"
I made something like this:
int i = 0;
if (i == 0){
//Opening CMD
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('r');
Keyboard.releaseAll();
delay(1000);
Keyboard.print("cmd.exe");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(1000);
//First functionality
Keyboard.print("echo Task 1");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(1000);
i ;
return;
}
else if (i == 1){
//Opening CMD
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('r');
Keyboard.releaseAll();
delay(1000);
Keyboard.print("cmd.exe");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(1000);
//Second functionality
Keyboard.print("echo Task 2");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(1000);
i ;
return;
}
CodePudding user response:
The ATmega32U4 has a 1 kB builtin EEPROM (See Datasheeet here). You can use that to store a persistent state when the chip is turned off. You tagged your question as Arduino, so here is a guide to using EEPROM with Arduino Libraries.