Skip to content

Commit

Permalink
Fixed attack crashed on debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacehuhn committed Jul 24, 2022
1 parent f823e92 commit c6e3f89
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/attack/attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace attack {
if (!msc::getInLine()) cur_pos = msc::getPosition();
len = msc::readLine(buffer, READ_BUFFER);
debugln(len);
debugln(std::string(buffer, len-1).c_str());
//debugln(std::string(buffer, len-1).c_str());

// Reached end of file
if (len == 0) {
Expand Down Expand Up @@ -93,6 +93,8 @@ namespace attack {

debugln("OK");
}

debugln("Attack finished");
}

void start() {
Expand Down
8 changes: 7 additions & 1 deletion src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ namespace cli {
// help
cli.addCmd("help", [](cmd* c) {
Serial.println("[ = Available Commands =]");
Serial.println(cli.toString());
Serial.print(cli.toString());
Serial.println("Enter any BadUSB Scripts to run it.");
Serial.println();
}).setDescription(" Get a list of available commands.");

// version
Expand Down Expand Up @@ -131,6 +132,11 @@ namespace cli {
Command cmd(c);
Argument arg = cmd.getArgument(0);
attack::start(arg.getValue().c_str());
if(selector::mode() == SETUP) {
led::setColor(preferences::getSetupColor());
} else {
led::setColor(preferences::getIdleColor());
}
}).setDescription(" Start a BadUSB Script.");
}

Expand Down
14 changes: 8 additions & 6 deletions src/msc/msc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,28 @@ namespace msc {
return fatfs.exists(filename);
}

bool open(const char* path) {
bool open(const char* path, bool add_to_stack) {
debug("Open new file: ");
debugln(path);

// Check if filepath isn't empty
if (!path) return false;

// If the stack isn't empty, save the current position
if (!file_stack.empty()) {
if (add_to_stack && !file_stack.empty()) {
file_stack.top().pos = file.curPosition();
}

// If a file is already open, close it
if (file.isOpen()) file.close();

// Create a new file element and push it to the stack
file_element_t file_element;
file_element.path = std::string(path);
file_element.pos = 0;
file_stack.push(file_element);
if(add_to_stack) {
file_element_t file_element;
file_element.path = std::string(path);
file_element.pos = 0;
file_stack.push(file_element);
}

// Open file and return whether it was successful
return file.open(path);
Expand Down
2 changes: 1 addition & 1 deletion src/msc/msc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace msc {
bool changed();
bool exists(const char* filename);

bool open(const char* path);
bool open(const char* path, bool add_to_stack = true);
bool openNextFile();

void close();
Expand Down
2 changes: 1 addition & 1 deletion src/preferences/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace preferences {
DynamicJsonDocument config_doc(JSON_SIZE);

// Open the file and read it into a buffer
if (!msc::open(PREFERENCES_PATH)) return;
if (!msc::open(PREFERENCES_PATH), false) return;
msc::read(buffer, JSON_SIZE);

// Deserialize the JSON document
Expand Down

0 comments on commit c6e3f89

Please sign in to comment.