A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
add identify cmd for I2C
Geoadbb2dcd29e5
diff --git a/src/Controllers/I2cController.cpp b/src/Controllers/I2cController.cppindex 368eb0ba..2923c9ff 100644--- a/src/Controllers/I2cController.cpp+++ b/src/Controllers/I2cController.cpp@@ -1,9 +1,23 @@#include "I2cController.h"-I2cController::I2cController(ITerminalView& terminalView, IInput& terminalInput,- I2cService& i2cService, ArgTransformer& argTransformer,- UserInputManager& userInputManager, I2cEepromShell& eepromShell)- : terminalView(terminalView), terminalInput(terminalInput), i2cService(i2cService), argTransformer(argTransformer), userInputManager(userInputManager), eepromShell(eepromShell) {}+/*+Constructor+*/+I2cController::I2cController(+ ITerminalView& terminalView,+ IInput& terminalInput,+ I2cService& i2cService,+ ArgTransformer& argTransformer,+ UserInputManager& userInputManager,+ I2cEepromShell& eepromShell+)+ : terminalView(terminalView),+ terminalInput(terminalInput),+ i2cService(i2cService),+ argTransformer(argTransformer),+ userInputManager(userInputManager),+ eepromShell(eepromShell)+{}/*Entry point to handle I2C command@@ -12,6 +26,7 @@ void I2cController::handleCommand(const TerminalCommand& cmd) {if (cmd.getRoot() == "scan") handleScan();else if (cmd.getRoot() == "sniff") handleSniff();else if (cmd.getRoot() == "ping") handlePing(cmd);+ else if (cmd.getRoot() == "identify") handleIdentify(cmd);else if (cmd.getRoot() == "write") handleWrite(cmd);else if (cmd.getRoot() == "read") handleRead(cmd);else if (cmd.getRoot() == "dump") handleDump(cmd);@@ -495,6 +510,40 @@ void I2cController::printHexDump(uint16_t start, uint16_t len,terminalView.println("");}+/*+Identify+*/+void I2cController::handleIdentify(const TerminalCommand& cmd) {+ // Validate subcommand+ if (!argTransformer.isValidNumber(cmd.getSubcommand())) {+ terminalView.println("Usage: identify <addr>");+ return;+ }++ // Parse I2C address+ uint8_t address = argTransformer.parseHexOrDec(cmd.getSubcommand());+ uint16_t start = 0x00;+ uint16_t len = 256;++ std::stringstream ss;+ ss << "\n\r 📟 I2C " + cmd.getSubcommand() + " Identification Result\n";++ // Search for known addresses+ bool matchFound = false;+ for (size_t i = 0; i < knownAddressesCount; ++i) {+ if (i2cKnownAddresses[i].address == address) {+ matchFound = true;+ ss << "\r ➤ Could be: - [" << i2cKnownAddresses[i].type << "] " << i2cKnownAddresses[i].component << "\n";+ }+ }++ if (!matchFound) {+ ss << "\r ➤ No match found for address 0x" << argTransformer.toHex(address) << "\n";+ }++ terminalView.println(ss.str());+}+/*Recover*/@@ -728,6 +777,7 @@ void I2cController::handleHelp() {terminalView.println("Unknown I2C command. Usage:");terminalView.println(" scan");terminalView.println(" ping <addr>");+ terminalView.println(" identify <addr>");terminalView.println(" sniff");terminalView.println(" slave <addr>");terminalView.println(" read <addr> <reg>");diff --git a/src/Controllers/I2cController.h b/src/Controllers/I2cController.hindex c10b942d..b9446c71 100644--- a/src/Controllers/I2cController.h+++ b/src/Controllers/I2cController.h@@ -13,8 +13,7 @@#include "Managers/UserInputManager.h"#include "Vendors/i2c_sniffer.h"#include "Shells/I2cEepromShell.h"--struct I2cSniffState;+#include "Data/I2cKnownAdresses.h"class I2cController {public:@@ -36,8 +35,8 @@ private:I2cService& i2cService;ArgTransformer& argTransformer;UserInputManager& userInputManager;- GlobalState& state = GlobalState::getInstance();I2cEepromShell& eepromShell;+ GlobalState& state = GlobalState::getInstance();bool configured = false;// Ping an I2C address@@ -79,6 +78,9 @@ private:// Recover I2C bus if stuckvoid handleRecover();+ // Identify I2C device based on address+ void handleIdentify(const TerminalCommand& cmd);+// Dump I2C registers contentvoid handleDump(const TerminalCommand& cmd);void performRegisterRead(uint8_t addr, uint16_t, uint16_t len,diff --git a/src/Controllers/UtilityController.cpp b/src/Controllers/UtilityController.cppindex 4fcf7fa3..857b65a0 100644--- a/src/Controllers/UtilityController.cpp+++ b/src/Controllers/UtilityController.cpp@@ -307,6 +307,7 @@ void UtilityController::handleHelp() {terminalView.println(" 5. I2C:");terminalView.println(" scan - Find devices");terminalView.println(" ping <addr> - Check ACK");+ terminalView.println(" identify <addr> - Identify device");terminalView.println(" sniff - View traffic");terminalView.println(" slave <addr> - Emulate I2C device");terminalView.println(" read <addr> <reg> - Read register");