USBNova/USBNova.ino

111 lines
3.5 KiB
Arduino
Raw Normal View History

#include "config.h"
#include "debug.h"
#include "src/hid/hid.h"
#include "src/hid/keyboard.h"
#include "src/led/led.h"
#include "src/msc/msc.h"
#include "src/selector/selector.h"
2022-07-03 10:13:32 -07:00
#include "src/attack/attack.h"
#include "src/preferences/preferences.h"
2022-07-06 14:32:55 -07:00
#include "src/duckparser/duckparser.h"
2022-07-13 13:09:51 -07:00
#include "src/format/format.h"
#include "src/tasks/tasks.h"
void setup() {
2022-07-15 16:06:25 -07:00
// ===== Initialize the minimum required modules to start the USB device stack ===== //
debug_init();
2022-06-30 12:19:02 -07:00
selector::init();
// Initialize memory and ceck for problems
if (!msc::init()) {
format::start(); // Format the drive
// If it still fails, blink red LED
if (!msc::init()) {
while (true) {
led::setColor(255, 0, 0);
delay(500);
led::setColor(0, 0, 0);
delay(500);
}
}
}
preferences::load();
hid::setID(preferences::getHidVid(), preferences::getHidPid(), preferences::getHidRev());
2022-07-06 14:21:07 -07:00
msc::setID(preferences::getMscVid().c_str(), preferences::getMscPid().c_str(), preferences::getMscRev().c_str());
2022-07-06 15:30:53 -07:00
2022-07-15 16:06:25 -07:00
// ===== Initialize the USB device stack ===== //
// Start Keyboard
hid::init();
2022-07-06 14:21:07 -07:00
// Start USB Drive
2022-07-15 15:36:31 -07:00
if (preferences::mscEnabled() || (selector::mode() == SETUP)) msc::enableDrive();
2022-07-06 14:21:07 -07:00
2022-07-15 16:06:25 -07:00
// ===== Initialize the remaining modules ===== //
led::init();
tasks::setCallback(loop);
led::setEnable(preferences::ledEnabled());
keyboard::setLocale(locale::get(preferences::getDefaultLayout().c_str()));
duckparser::setDefaultDelay(preferences::getDefaultDelay());
2022-07-14 13:30:00 -07:00
2022-07-15 16:06:25 -07:00
// ---
2022-07-14 13:30:00 -07:00
2022-07-13 13:09:51 -07:00
// Format Flash
2022-07-15 15:36:31 -07:00
if ((selector::mode() == SETUP) && preferences::getFormat()) {
led::setColor(255, 255, 255);
2022-07-13 13:09:51 -07:00
format::start(preferences::getDriveName().c_str());
}
// Create preferences file if it doesn't exist yet
if (!msc::exists(PREFERENCES_PATH)) {
2022-07-13 13:58:16 -07:00
preferences::save();
2022-07-13 13:09:51 -07:00
}
2022-07-13 13:58:16 -07:00
2022-07-15 16:06:25 -07:00
// Wait 1s to give the computer time to initialize the keyboard
delay(1000);
// Disable capslock if needed
if (preferences::getDisableCapslock()) {
keyboard::disableCapslock();
delay(10);
hid::indicatorChanged();
}
// ========== Setup Mode ========== //
2022-07-15 15:36:31 -07:00
if (selector::mode() == SETUP) {
2022-07-06 15:56:20 -07:00
led::setColor(preferences::getSetupColor()); // Set LED to blue
while (true) {
2022-07-15 15:36:31 -07:00
if (selector::changed() && selector::read() == ATTACK) {
2022-07-15 16:06:25 -07:00
preferences::load(); // Reload the settings (in case the main script path changed)
attack::start(); // Start keystroke injection attack
led::setColor(preferences::getSetupColor()); // Set LED to blue
}
delay(100);
}
}
// ========== Setup Mode ========== //
2022-07-15 15:36:31 -07:00
else if (selector::mode() == ATTACK) {
// Run on capslock
2022-07-14 15:37:55 -07:00
if (preferences::getRunOnIndicator()) {
while (!hid::indicatorChanged()) {
delay(100);
}
keyboard::disableCapslock();
}
2022-07-15 16:06:25 -07:00
attack::start(); // Start keystroke injection attack
while (true) {
2022-07-15 15:36:31 -07:00
if (selector::changed() && selector::read() == ATTACK) {
2022-07-15 16:06:25 -07:00
attack::start(); // Start keystroke injection attack
}
delay(100);
}
}
2022-07-03 09:41:25 -07:00
debugln("[Finished]");
}
void loop() {
led::update();
}