USBNova/USBNova.ino

128 lines
4.2 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"
#include "src/tasks/tasks.h"
2022-07-20 15:11:14 -07:00
#include "src/cli/cli.h"
2022-07-16 03:44:41 -07:00
void update() {
led::update();
// cli::update();
}
void setup() {
2022-07-16 03:44:41 -07:00
// Start Serial (for debug)
debug_init();
2022-07-16 03:44:41 -07:00
// Initialize memory and check for problems
if (!msc::init()) {
led::setColor(255, 0, 0, 200);
2022-07-16 03:44:41 -07:00
return;
}
2022-07-16 03:44:41 -07:00
// Load setting and set USB Device IDs
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-16 03:44:41 -07:00
// Read mode from selector switch
selector::init();
// Start Keyboard
2022-11-11 03:13:44 -08:00
if (selector::mode() == ATTACK || preferences::hidEnabled()) {
hid::init();
}
2022-07-16 03:44:41 -07:00
2022-07-06 14:21:07 -07:00
// Start USB Drive
2022-07-16 03:44:41 -07:00
if (preferences::mscEnabled() || (selector::mode() == SETUP)){
msc::enableDrive();
}
2022-07-06 14:21:07 -07:00
2022-07-16 03:44:41 -07:00
// Start LED
2022-07-15 16:06:25 -07:00
led::init();
led::setEnable(preferences::ledEnabled());
2022-07-16 03:44:41 -07:00
if (selector::mode() == SETUP) {
led::setColor(preferences::getSetupColor());
} else {
led::setColor(preferences::getAttackColor());
}
// Attack settings
2022-07-15 16:06:25 -07:00
keyboard::setLocale(locale::get(preferences::getDefaultLayout().c_str()));
duckparser::setDefaultDelay(preferences::getDefaultDelay());
2022-07-14 13:30:00 -07:00
2022-07-16 03:44:41 -07:00
// Format Flash (if specified in preferences.json)
2022-07-15 15:36:31 -07:00
if ((selector::mode() == SETUP) && preferences::getFormat()) {
led::setColor(255, 255, 255);
2022-07-16 02:53:03 -07:00
msc::format(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
}
// Create main_script.txt if it doesn't exist yet
if (!msc::exists(preferences::getMainScript().c_str())) {
msc::write(preferences::getMainScript().c_str(), "# Hello World\n", 14);
}
2022-07-13 13:58:16 -07:00
2022-07-16 03:44:41 -07:00
// Setup background tasks
tasks::setCallback(update);
2022-07-15 16:06:25 -07:00
// Make sure we don't start with a mode change
selector::changed();
2022-07-16 03:44:41 -07:00
// Start attack
if (selector::mode() == ATTACK && !preferences::getRunOnIndicator()) {
2022-07-16 16:43:15 -07:00
delay(preferences::getInitialDelay()); // Wait to give computer time to init keyboard
2022-07-16 03:44:41 -07:00
attack::start(); // Start keystroke injection attack
led::setColor(preferences::getIdleColor()); // Set LED to green
2022-07-15 16:06:25 -07:00
}
2022-07-20 15:11:14 -07:00
// Setup CLI
cli::init();
2022-07-16 03:44:41 -07:00
debugln("[Started]");
}
2022-07-16 03:44:41 -07:00
void loop() {
taks:update();
2022-07-20 15:11:14 -07:00
cli::update();
2022-10-31 12:53:17 -07:00
if(selector::read() != ATTACK) return;
// Only start the attack if run-on-indicator is disabled, or indicator actually changed
if(preferences::getRunOnIndicator() && hid::indicatorChanged()) {
2022-11-08 13:54:13 -08:00
delay(100);
2022-10-31 12:53:17 -07:00
attack::start(); // Run script
led::setColor(preferences::getIdleColor()); // Set LED to green
} else if (selector::changed()) {
2022-07-16 03:44:41 -07:00
// ========== Setup Mode ========== //
2022-11-11 03:13:44 -08:00
if (selector::mode() == SETUP && preferences::hidEnabled()) {
2022-07-16 03:44:41 -07:00
preferences::load(); // Reload the settings (in case the main script path changed)
// Attack settings
keyboard::setLocale(locale::get(preferences::getDefaultLayout().c_str()));
duckparser::setDefaultDelay(preferences::getDefaultDelay());
2022-07-16 03:44:41 -07:00
attack::start(); // Start keystroke injection attack
led::setColor(preferences::getSetupColor()); // Set LED to blue
}
2022-07-16 03:44:41 -07:00
// ========== Attack Mode ========== //
else if (selector::mode() == ATTACK) {
// Only start the attack if run-on-indicator is disabled, or indicator actually changed
2022-10-31 12:53:17 -07:00
attack::start(); // Run script
led::setColor(preferences::getIdleColor()); // Set LED to green
}
}
}