Skip to content

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

remove 3wire eeprom methods and use shell instead

Geo817087510f48
diff --git a/src/Controllers/ThreeWireController.cpp b/src/Controllers/ThreeWireController.cpp
index 99bee0a2..92125f24 100644
--- a/src/Controllers/ThreeWireController.cpp
+++ b/src/Controllers/ThreeWireController.cpp
@@ -8,18 +8,20 @@ ThreeWireController::ThreeWireController(
IInput& terminalInput,
UserInputManager& userInputManager,
ThreeWireService& threeWireService,
- ArgTransformer& argTransformer)
+ ArgTransformer& argTransformer,
+ ThreeWireEepromShell& threeWireEepromShell)
: terminalView(terminalView),
terminalInput(terminalInput),
userInputManager(userInputManager),
threeWireService(threeWireService),
- argTransformer(argTransformer) {}
+ argTransformer(argTransformer),
+ threeWireEepromShell(threeWireEepromShell) {}
/*
Entry point for command
*/
void ThreeWireController::handleCommand(const TerminalCommand& cmd) {
- if (cmd.getRoot() == "config") handleConfig();
+ if (cmd.getRoot() == "config") handleConfig();
else if (cmd.getRoot() == "eeprom") handleEeprom(cmd);
else handleHelp();
}
@@ -35,234 +37,7 @@ void ThreeWireController::handleInstruction(const std::vector<ByteCode>& bytecod
EEPROM
*/
void ThreeWireController::handleEeprom(const TerminalCommand& cmd) {
- std::string sub = cmd.getSubcommand();
-
- if (sub == "probe") handleEepromProbe();
- else if (sub == "read") handleEepromRead(cmd);
- else if (sub == "write") handleEepromWrite(cmd);
- else if (sub == "dump") handleEepromDump();
- else if (sub == "erase") handleEepromErase();
- else handleHelp();
-}
-
-/*
-EEPROM Probe
-*/
-void ThreeWireController::handleEepromProbe() {
- bool isOrg8 = state.isThreeWireOrg8();
- bool isBlank = true;
-
- if (isOrg8) {
- std::vector<uint8_t> data = threeWireService.dump8();
- for (uint8_t val : data) {
- if (val != 0xFF) {
- isBlank = false;
- break;
- }
- }
- } else {
- std::vector<uint16_t> data = threeWireService.dump16();
- for (uint16_t val : data) {
- if (val != 0xFFFF) {
- isBlank = false;
- break;
- }
- }
- }
-
- if (!isBlank) {
- terminalView.println("3WIRE EEPROM: Detected ✅");
- } else {
- terminalView.println("3WIRE EEPROM: No EEPROM detected or EEPROM is blank ❌");
- }
-}
-
-/*
-EEPROM Read
-*/
-void ThreeWireController::handleEepromRead(const TerminalCommand& cmd) {
- std::vector<std::string> args = argTransformer.splitArgs(cmd.getArgs());
-
- if (args.empty()) {
- terminalView.println("Usage: eeprom read <addr> [count]");
- return;
- }
-
- if (!argTransformer.isValidNumber(args[0])) {
- terminalView.println("3WIRE EEPROM: Invalid address value. Must be a number.");
- return;
- }
-
- uint16_t addr = argTransformer.parseHexOrDec16(args[0]);
- uint16_t count = 1;
- bool isOrg8 = state.isThreeWireOrg8();
-
- if (args.size() == 2) {
- if (!argTransformer.isValidNumber(args[1])) {
- terminalView.println("Invalid count value. Must be a number.");
- return;
- }
- count = argTransformer.parseHexOrDec16(args[1]);
- if (count == 0) count = 1;
- }
-
- if (count == 1) {
- if (isOrg8) {
- uint8_t val = threeWireService.read8(addr);
- terminalView.println("3WIRE EEPROM: Read 0x" + argTransformer.toHex(addr, 4) +
- " = 0x" + argTransformer.toHex(val, 2));
- } else {
- uint16_t val = threeWireService.read16(addr);
- terminalView.println("3WIRE EEPROM: [READ] 0x" + argTransformer.toHex(addr, 4) +
- " = 0x" + argTransformer.toHex(val, 4));
- }
- } else {
- if (isOrg8) {
- std::vector<uint8_t> values;
- for (uint16_t i = 0; i < count; ++i) {
- values.push_back(threeWireService.read8(addr + i));
- }
- for (size_t i = 0; i < values.size(); i += 16) {
- uint32_t displayAddr = addr + i;
- size_t chunkSize = std::min<size_t>(16, values.size() - i);
- std::vector<uint8_t> chunk(values.begin() + i, values.begin() + i + chunkSize);
- terminalView.println(argTransformer.toAsciiLine(displayAddr, chunk));
- }
- } else {
- std::vector<uint16_t> values;
- for (uint16_t i = 0; i < count; ++i) {
- values.push_back(threeWireService.read16(addr + i));
- }
- for (size_t i = 0; i < values.size(); i += 8) {
- uint32_t displayAddr = (addr + i) * 2;
- size_t chunkSize = std::min<size_t>(8, values.size() - i);
- std::vector<uint16_t> chunk(values.begin() + i, values.begin() + i + chunkSize);
- terminalView.println(argTransformer.toAsciiLine(displayAddr, chunk));
- }
- }
- }
-}
-
-/*
-EEPROM Write
-*/
-void ThreeWireController::handleEepromWrite(const TerminalCommand& cmd) {
- std::vector<std::string> args = argTransformer.splitArgs(cmd.getArgs());
-
- if (args.size() < 1) {
- terminalView.println("Usage: eeprom write <addr> [value]");
- return;
- }
-
- int addr = argTransformer.parseHexOrDec16(args[0]);
-
- bool isOrg8 = state.isThreeWireOrg8();
- threeWireService.writeEnable();
-
- if (args.size() >= 2) {
- uint16_t value = argTransformer.parseHexOrDec16(args[1]);
- if (isOrg8) {
- threeWireService.write8(addr, static_cast<uint8_t>(value));
- terminalView.println("3WIRE EEPROM: Write 0x" + argTransformer.toHex(addr, 4) +
- " = 0x" + argTransformer.toHex(value, 2) + " ✅");
- } else {
- threeWireService.write16(addr, value);
- terminalView.println("3WIRE EEPROM: Write 0x" + argTransformer.toHex(addr, 4) +
- " = 0x" + argTransformer.toHex(value, 4) + " ✅");
- }
-
- } else {
- std::string hexStr = userInputManager.readValidatedHexString("Enter value(s) to write (e.g., AA 01 00 BC)", 0, true);
- std::vector<uint8_t> data = argTransformer.parseHexList(hexStr);
-
- for (size_t i = 0; i < data.size(); ++i) {
- if (isOrg8) {
- threeWireService.write8(addr + i, data[i]);
- terminalView.println("3WIRE EEPROM: Write 0x" + argTransformer.toHex(addr + i, 4) +
- " = 0x" + argTransformer.toHex(data[i], 2) + " ✅");
- } else {
- if (i + 1 >= data.size()) break; // Incomplet
- uint16_t val = (data[i] << 8) | data[i + 1];
- threeWireService.write16(addr + (i / 2), val);
- terminalView.println("3WIRE EEPROM: Write 0x" + argTransformer.toHex(addr + (i / 2), 4) +
- " = 0x" + argTransformer.toHex(val, 4) + " ✅");
- ++i; // Consomme 2 bytes
- }
- }
- }
-
- threeWireService.writeDisable();
-}
-
-/*
-EEPROM Dump
-*/
-void ThreeWireController::handleEepromDump() {
- bool isOrg8 = state.isThreeWireOrg8();
- uint16_t start = 0;
-
- terminalView.println("");
- if (isOrg8) {
- auto data = threeWireService.dump8();
- for (size_t i = start; i < data.size(); i += 16) {
- uint32_t addr = i;
- size_t chunkSize = std::min<size_t>(16, data.size() - i);
- std::vector<uint8_t> chunk(data.begin() + i, data.begin() + i + chunkSize);
- terminalView.println(argTransformer.toAsciiLine(addr, chunk));
- }
- } else {
- auto data = threeWireService.dump16();
- for (size_t i = start; i < data.size(); i += 8) {
- uint32_t addr = i * 2;
- size_t chunkSize = std::min<size_t>(8, data.size() - i);
- std::vector<uint16_t> chunk(data.begin() + i, data.begin() + i + chunkSize);
- terminalView.println(argTransformer.toAsciiLine(addr, chunk));
- }
- }
- terminalView.println("");
-
-}
-
-/*
-EEPROM Erase
-*/
-void ThreeWireController::handleEepromErase() {
-
- auto confirmation = userInputManager.readYesNo("Are you sure you want to erase the EEPROM?", false);
- if (!confirmation) {
- terminalView.println("3WIRE EEPROM: ❌ Erase cancelled.");
- return;
- }
-
- threeWireService.writeEnable();
- threeWireService.eraseAll();
- threeWireService.writeDisable();
- bool isOrg8 = state.isThreeWireOrg8();
- bool success = true;
-
- if (isOrg8) {
- auto data = threeWireService.dump8();
- for (uint8_t val : data) {
- if (val != 0xFF) {
- success = false;
- break;
- }
- }
- } else {
- auto data = threeWireService.dump16();
- for (uint16_t val : data) {
- if (val != 0xFFFF) {
- success = false;
- break;
- }
- }
- }
-
- if (success) {
- terminalView.println("3WIRE EEPROM: ✅ Successfully erased.");
- } else {
- terminalView.println("3WIRE EEPROM: ❌ Erase verification failed.");
- }
+ threeWireEepromShell.run();
}
/*
@@ -270,11 +45,7 @@ Help
*/
void ThreeWireController::handleHelp() {
terminalView.println("Unknown 3WIRE command. Usage:");
- terminalView.println(" eeprom probe");
- terminalView.println(" eeprom read <addr> [count]");
- terminalView.println(" eeprom write <addr> [value]");
- terminalView.println(" eeprom dump");
- terminalView.println(" eeprom erase");
+ terminalView.println(" eeprom");
terminalView.println(" config");
}
@@ -295,27 +66,9 @@ void ThreeWireController::handleConfig() {
uint8_t doPin = userInputManager.readValidatedPinNumber("DO pin", state.getThreeWireDoPin(), forbidden);
state.setThreeWireDoPin(doPin);
- // EEPROM Model
- std::vector<std::string> modelOptions = threeWireService.getSupportedModels();
- int modelIndex = userInputManager.readValidatedChoiceIndex("\nSelect EEPROM model", modelOptions, state.getThreeWireEepromModelIndex());
- int modelId = threeWireService.resolveModelId(modelOptions[modelIndex]);
- terminalView.println("Selected model: " + modelOptions[modelIndex] + " (ID: " + std::to_string(modelId) + ")");
- state.setThreeWireEepromModelIndex(modelIndex);
-
- // Organization
- terminalView.println("\n⚠️ ORG is a physical pin on the EEPROM chip.");
- terminalView.println(" Tie it to GND for 8-bit (x8) organization.");
- terminalView.println(" Tie it to VCC for 16-bit (x16) organization.");
- terminalView.println(" This applies to chips with configurable ORG pins (most of them).");
- terminalView.println(" Fixed organization chips:");
- terminalView.println(" • 93xx56A → always 8-bit");
- terminalView.println(" • 93xx56B → always 16-bit\n");
- bool org8 = userInputManager.readYesNo("EEPROM organization 8 bits ?", false);
- state.setThreeWireOrg8(org8);
-
- // Configure the service
- threeWireService.configure(cs, sk, di, doPin, modelId, org8);
- terminalView.println("3WIRE EEPROM configured.\n");
+ // Configure the service, default value for eeprom
+ threeWireService.configure(cs, sk, di, doPin, 46, state.isThreeWireOrg8());
+ terminalView.println("3WIRE configured.\n");
configured = true;
}
diff --git a/src/Controllers/ThreeWireController.h b/src/Controllers/ThreeWireController.h
index 66e82653..3010875b 100644
--- a/src/Controllers/ThreeWireController.h
+++ b/src/Controllers/ThreeWireController.h
@@ -12,6 +12,7 @@
#include "Models/ByteCode.h"
#include "Managers/UserInputManager.h"
#include "Transformers/ArgTransformer.h"
+#include "Shells/ThreeWireEepromShell.h"
class ThreeWireController {
public:
@@ -20,7 +21,9 @@ public:
IInput& terminalInput,
UserInputManager& userInputManager,
ThreeWireService& threeWireService,
- ArgTransformer& argTransformer);
+ ArgTransformer& argTransformer,
+ ThreeWireEepromShell& threeWireEepromShell
+ );
// Entry point for command handling
void handleCommand(const TerminalCommand& cmd);
@@ -37,6 +40,7 @@ private:
ThreeWireService threeWireService;
UserInputManager& userInputManager;
ArgTransformer& argTransformer;
+ ThreeWireEepromShell& threeWireEepromShell;
GlobalState& state = GlobalState::getInstance();
bool configured = false;
bool org8 = true;
@@ -44,21 +48,6 @@ private:
// Command handlers for eeprom operations
void handleEeprom(const TerminalCommand& cmd);
- // Probe for EEPROM presence
- void handleEepromProbe();
-
- // EEPROM read from start address to count (default 1)
- void handleEepromRead(const TerminalCommand& cmd);
-
- // EEPROM write to address with optional data value (prompt if not provided)
- void handleEepromWrite(const TerminalCommand& cmd);
-
- // EEPROM dump based on model bytes size
- void handleEepromDump();
-
- // EEPROM erase operation based on model bytes size
- void handleEepromErase();
-
// Configuration handler for settings
void handleConfig();
diff --git a/src/Controllers/UtilityController.cpp b/src/Controllers/UtilityController.cpp
index c7122ecf..94fd49b2 100644
--- a/src/Controllers/UtilityController.cpp
+++ b/src/Controllers/UtilityController.cpp
@@ -337,11 +337,7 @@ void UtilityController::handleHelp() {
terminalView.println("");
terminalView.println(" 8. 3WIRE:");
- terminalView.println(" eeprom probe - Detect 93CXX chip presence");
- terminalView.println(" eeprom read <a> [n] - Read value from address");
- terminalView.println(" eeprom write <a> [v] - Write value(s) to address");
- terminalView.println(" eeprom dump - Dump entire EEPROM memory");
- terminalView.println(" eeprom erase - Erase entire EEPROM memory");
+ terminalView.println(" eeprom - EEPROM operations");
terminalView.println(" config - Configure settings");
terminalView.println("");