Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

add method to read and validate hex from user

Geo88026bd5351a
diff --git a/src/Managers/UserInputManager.cpp b/src/Managers/UserInputManager.cpp
index 1663ad4f..1dbb73b4 100644
--- a/src/Managers/UserInputManager.cpp
+++ b/src/Managers/UserInputManager.cpp
@@ -110,9 +110,13 @@ uint8_t UserInputManager::readValidatedUint8(const std::string& label, uint8_t d
return readValidatedUint8(label, defaultVal, 0, 255);
}
-uint32_t UserInputManager::readValidatedUint32(const std::string& label, uint32_t def) {
+uint32_t UserInputManager::readValidatedUint32(const std::string& label, uint32_t def, bool hex) {
while (true) {
- terminalView.print(label + " [" + std::to_string(def) + "]: ");
+ if (hex) {
+ terminalView.print(label + " [0x" + argTransformer.toHex(def) + "]: ");
+ } else {
+ terminalView.print(label + " [" + std::to_string(def) + "]: ");
+ }
std::string input = getLine();
if (input.empty()) return def;
@@ -124,6 +128,46 @@ uint32_t UserInputManager::readValidatedUint32(const std::string& label, uint32_
}
}
+uint32_t UserInputManager::readValidatedHex(
+ const std::string& label,
+ int def,
+ int min,
+ int max)
+{
+ while (true) {
+
+ terminalView.print(
+ label + " [0x" + argTransformer.toHex(def) + "]: "
+ );
+
+ std::string input = getLine();
+
+ // ENTER → default
+ if (input.empty())
+ return def;
+
+ // Check valid number (hex or dec)
+ if (!argTransformer.isValidNumber(input)) {
+ terminalView.println("❌ Invalid number.");
+ continue;
+ }
+
+ // Parse hex or dec
+ uint32_t val = argTransformer.parseHexOrDec32(input);
+
+ if (val < (uint32_t)min || val > (uint32_t)max) {
+ terminalView.println(
+ "❌ Out of range (0x" +
+ argTransformer.toHex(min) + " - 0x" +
+ argTransformer.toHex(max) + ")"
+ );
+ continue;
+ }
+
+ return val;
+ }
+}
+
char UserInputManager::readCharChoice(const std::string& label, char def, const std::vector<char>& allowed) {
while (true) {
terminalView.print(label + " [" + def + "]: ");
diff --git a/src/Managers/UserInputManager.h b/src/Managers/UserInputManager.h
index d16f5295..30d4d090 100644
--- a/src/Managers/UserInputManager.h
+++ b/src/Managers/UserInputManager.h
@@ -18,9 +18,9 @@ public:
std::string readSanitizedString(const std::string& label, const std::string& def, bool onlyLetter = false);
uint8_t readValidatedUint8(const std::string& label, uint8_t def, uint8_t min, uint8_t max);
uint8_t readValidatedUint8(const std::string& label, uint8_t defaultVal);
- uint32_t readValidatedUint32(const std::string& label, uint32_t def);
+ uint32_t readValidatedUint32(const std::string& label, uint32_t def, bool hex=false);
int readValidatedInt(const std::string& label, int def, int min = -127, int max = 127);
-
+ uint32_t readValidatedHex(const std::string& label, int def, int min, int max);
char readCharChoice(const std::string& label, char def, const std::vector<char>& allowed);
bool readYesNo(const std::string& label, bool def);
uint8_t readModeNumber();