Added CLI yoooo

This commit is contained in:
Spacehuhn 2022-07-23 18:14:15 +02:00
parent ca824905d2
commit f823e92a41
7 changed files with 158 additions and 14 deletions

View File

@ -16,10 +16,10 @@ namespace attack {
// ====== PRIVATE ====== //
// ====== PUBLIC ====== //
void start() {
void start(const char* path) {
// If script doesn't exist, don't do anything
if (!msc::exists(preferences::getMainScript().c_str())) return;
if (!msc::exists(path)) return;
// Set attack color
led::setColor(preferences::getAttackColor());
@ -94,4 +94,8 @@ namespace attack {
debugln("OK");
}
}
void start() {
start(preferences::getMainScript().c_str());
}
}

View File

@ -3,5 +3,6 @@
#pragma once
namespace attack {
void start(const char* path);
void start();
}

View File

@ -5,6 +5,12 @@
#include <SimpleCLI.h>
#include "../duckparser/duckparser.h"
#include "../preferences/preferences.h"
#include "../selector/selector.h"
#include "../led/led.h"
#include "../attack/attack.h"
#include "../msc/msc.h"
#include "../../config.h"
#define BUFFER_SIZE 1024
@ -54,27 +60,78 @@ namespace cli {
// ====== PUBLIC ====== //
void init() {
Serial.begin(115200);
/*
// help
cli.addCmd("format", [](cmd* c) {
cli.help();
// error
cli.setOnError([](cmd_error* e) {
CommandError cmdError(e);
Serial.print("ERROR: ");
Serial.println(cmdError.toString());
if (cmdError.hasCommand()) {
Serial.print("Did you mean \"");
Serial.print(cmdError.getCommand().toString());
Serial.println("\"?");
}
});
// help
cli.addCmd("help", [](cmd* c) {
Serial.println("[ = Available Commands =]");
Serial.println(cli.toString());
Serial.println("Enter any BadUSB Scripts to run it.");
}).setDescription(" Get a list of available commands.");
// version
cli.addCmd("format", [](cmd* c) {
cli.addCmd("version", [](cmd* c) {
Serial.println("[ = USB Nova =]");
Serial.print("Version ");
Serial.println(VERSION);
});
Serial.println("Source: https://github.com/spacehuhntech/usbnova");
Serial.println("Made with <3 by Spacehuhn (spacehuhn.com)");
Serial.println();
}).setDescription(" Print the firmware version.");
// format
cli.addCmd("format", [](cmd* c) {
msc::format();
});
led::setColor(255, 255, 255);
msc::format(preferences::getDriveName().c_str());
preferences::save();
if(selector::mode() == SETUP) {
led::setColor(preferences::getSetupColor());
} else {
led::setColor(preferences::getIdleColor());
}
Serial.println("Done formatting!");
Serial.println();
}).setDescription(" Fromat the internal memory.");
// reset
cli.addCmd("rest", [](cmd* c) {
cli.addCmd("reset", [](cmd* c) {
preferences::reset();
});
*/
preferences::save();
Serial.println("Done resetting!");
Serial.println();
}).setDescription(" Reset the preferences.");
// TODO: preferences
cli.addSingleArgCmd("preferences", [](cmd* c) {
preferences::print();
}).setDescription(" Print preferences.");
// ls
cli.addSingleArgCmd("ls", [](cmd* c) {
msc::print();
}).setDescription(" Show available files on the drive.");
// run
cli.addSingleArgCmd("run", [](cmd* c) {
Command cmd(c);
Argument arg = cmd.getArgument(0);
attack::start(arg.getValue().c_str());
}).setDescription(" Start a BadUSB Script.");
}
void update() {

View File

@ -90,6 +90,27 @@ namespace msc {
bool format(const char* drive_name) {
return format::start(drive_name);
}
void print() {
File file;
FatFile rdir;
rdir.open("/");
// Open next file in root.
// Warning, openNext starts at the current directory position
// so a rewind of the directory may be required.
while(file.openNext(&rdir, O_RDONLY)) {
file.printFileSize(&Serial);
Serial.write(' ');
file.printName(&Serial);
if (file.isDir()) {
// Indicate a directory.
Serial.write('/');
}
Serial.println();
file.close();
}
}
void setID(const char* vid, const char* pid, const char* rev) {
usb_msc.setID(vid, pid, rev); // Max. 8, 16, 4 characters

View File

@ -7,6 +7,7 @@
namespace msc {
bool init();
bool format(const char* drive_name = "USB Nova");
void print();
void setID(const char* vid, const char* pid, const char* rev);
void enableDrive();

View File

@ -193,6 +193,64 @@ namespace preferences {
debug("Saved ");
debugln(PREFERENCES_PATH);
}
void reset() {
enable_msc = false;
enable_led = true;
hid_vid = "239A";
hid_pid = "80CB";
hid_rev = "0100";
msc_vid = "Adafruit";
msc_pid = "External Flash";
msc_rev = "1.0";
default_layout = "US";
default_delay = 5;
main_script = "main.script";
attack_color[0] = 128;
attack_color[1] = 0;
attack_color[2] = 0;
attack_color[3] = 0;
setup_color[0] = 0;
setup_color[1] = 0;
setup_color[2] = 20;
setup_color[3] = 0;
idle_color[0] = 0;
idle_color[1] = 30;
idle_color[2] = 0;
idle_color[3] = 0;
format = false;
drive_name = "USB Nova";
disable_capslock = true;
run_on_indicator = false;
initial_delay = 1000;
}
void print() {
// Create a new JSON document (and string buffer)
DynamicJsonDocument json_doc(JSON_SIZE);
// JsonObject json_obj = json_doc.as<JsonObject>();
std::string json_str = { "" };
// Add values
toJson(json_doc);
// Serialize JSON to buffer
serializeJsonPretty(json_doc, json_str);
json_doc.clear();
// Write the buffer to file (and print results)
debugln(json_str.c_str());
}
bool mscEnabled() {
return enable_msc;

View File

@ -7,6 +7,8 @@
namespace preferences {
void load();
void save();
void reset();
void print();
bool mscEnabled();
bool ledEnabled();