A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
Working responsive UI
Andrei Vladescu18e159b5a4c9
diff --git a/src/Abstracts/ANetworkController.cpp b/src/Abstracts/ANetworkController.cppindex fcb4cbcf..8040fa89 100644--- a/src/Abstracts/ANetworkController.cpp+++ b/src/Abstracts/ANetworkController.cpp@@ -81,7 +81,7 @@ void ANetworkController::handlePing(const TerminalCommand &cmd)}icmpService.startPingTask(host, pingCount, pingTimeout, pingInterval);- while (!icmpService.isReady())+ while (!icmpService.isPingReady())vTaskDelay(pdMS_TO_TICKS(50));terminalView.print(icmpService.getReport());@@ -126,8 +126,7 @@ void ANetworkController::handleDiscovery(const TerminalCommand &cmd)const std::string deviceIP = phy_interface == phy_interface_t::phy_wifi ? wifiService.getLocalIP() : ethernetService.getLocalIP();icmpService.startDiscoveryTask(deviceIP);- while (!icmpService.isReady()) {- terminalView.print("HERE");+ while (!icmpService.isDiscoveryReady()) {// Display logsauto batch = icmpService.fetchICMPLog();for (auto& ln : batch) {@@ -155,6 +154,7 @@ void ANetworkController::handleDiscovery(const TerminalCommand &cmd)}ICMPService::clearICMPLogging();+ icmpService.clearDiscoveryFlag();//terminalView.println(icmpService.getReport());}diff --git a/src/Services/ICMPService.cpp b/src/Services/ICMPService.cppindex c1346d6c..a238e56b 100644--- a/src/Services/ICMPService.cpp+++ b/src/Services/ICMPService.cpp@@ -27,6 +27,12 @@ struct ICMPTaskParamsICMPService *service;};+struct DiscoveryTaskParams+{+ std::string deviceIP;+ ICMPService *service;+};+ICMPService::ICMPService() {}ICMPService::~ICMPService()@@ -37,7 +43,7 @@ ICMPService::~ICMPService()void ICMPService::cleanupICMPService(){// Reset last results- ready = false;+ pingReady = false;pingRC = ping_rc_t::ping_error;pingMedianMs = -1;pingTX = 0;@@ -86,20 +92,18 @@ static int median_ms(std::vector<uint32_t> &v)return (int)((v[n / 2 - 1] + v[n / 2] + 1) / 2);}-void ICMPService::startDiscoveryTask(const std::string deviceIP)-{- std::string deviceDiscoveryReport = "Discovery: scanning network for devices...\r\n";- std::string deviceIPcopy = deviceIP;+void ICMPService::discoveryTask(void* params){+ auto* taskParams = static_cast<DiscoveryTaskParams*>(params);+ std::string deviceIP = taskParams->deviceIP;+ ICMPService* service = taskParams->service;ip4_addr_t targetIP;- TaskHandle_t pingTaskHandle = nullptr;uint32_t targetsResponded = 0;- pushICMPLog("Discovery: scanning network for devices...");+ pushICMPLog("Discovery: Scanning network for devices...");- if (!ip4addr_aton(deviceIPcopy.c_str(), &targetIP))+ if (!ip4addr_aton(deviceIP.c_str(), &targetIP)){pushICMPLog("Discovery: failed to parse IP address " + deviceIP);- report = "Discovery: failed to parse IP address " + deviceIP + "\r\n";return;}@@ -114,7 +118,6 @@ void ICMPService::startDiscoveryTask(const std::string deviceIP)if (ICMPService::getICMPServiceStatus() == true){pushICMPLog("Discovery: stopped by user");- report = "Discovery: stopped by user\r\n";return;}@@ -129,31 +132,38 @@ void ICMPService::startDiscoveryTask(const std::string deviceIP)ip4addr_ntoa_r(&targetIP, targetIPCStr, sizeof(targetIPCStr));std::string targetIPStr(targetIPCStr);- this->cleanupICMPService();- auto *params = new ICMPTaskParams{targetIPStr, 1, 100, 100, this};- xTaskCreatePinnedToCore(pingAPI, "ICMPPing", 4096, params, 1, &pingTaskHandle, 1);+ service->cleanupICMPService();+ auto *params = new ICMPTaskParams{targetIPStr, 2, 150, 100, service};+ xTaskCreatePinnedToCore(pingAPI, "ICMPPing", 4096, params, 1, nullptr, 1);- while (!this->ready)+ while (!service->pingReady){vTaskDelay(pdMS_TO_TICKS(10));}- if (this->pingRC == ping_rc_t::ping_ok){+ if (service->pingRC == ping_rc_t::ping_ok){pushICMPLog("Device found: " + targetIPStr);- deviceDiscoveryReport += "Device found: " + targetIPStr + "\r\n";targetsResponded++;}- deviceDiscoveryReport.append(report);}pushICMPLog(std::to_string(targetsResponded) + " devices up, pinged " +std::to_string(254 - targetsResponded) + " devices down");- deviceDiscoveryReport += std::to_string(targetsResponded) + " devices up, pinged " +- std::to_string(254 - targetsResponded) + " devices down\r\n";-- // Put all the results here, can be called with getReport- report = std::move(deviceDiscoveryReport);- ready = true;+ service->discoveryReady = true;++ delete taskParams;+ vTaskDelete(nullptr);+}++void ICMPService::startDiscoveryTask(const std::string deviceIP)+{+ report.clear();+ discoveryReady = false;+ stopICMPFlag = false;++ // Start job+ auto* p = new DiscoveryTaskParams{deviceIP, this};+ xTaskCreatePinnedToCore(discoveryTask, "ICMPDiscover", 8192, p, 1, nullptr, 0);}void ICMPService::startPingTask(const std::string &targetIP, int count, int timeout_ms, int interval_ms)@@ -168,7 +178,7 @@ void ICMPService::startPingTask(const std::string &targetIP, int count, int timethis};xTaskCreatePinnedToCore(pingAPI, "ICMPPing", 4096, params, 1, nullptr, 1);- while(!this->ready)+ while(!this->pingReady)vTaskDelay(pdMS_TO_TICKS(10));// Prepare the report@@ -198,7 +208,7 @@ void ICMPService::pingAPI(void *pvParams)if (!resolve_ipv4_to_ip_addr(params->targetIP, target)){service->pingRC = ping_rc_t::ping_resolve_fail;- service->ready = true;+ service->pingReady = true;delete params;vTaskDelete(nullptr);return;@@ -241,7 +251,7 @@ void ICMPService::pingAPI(void *pvParams)if (esp_ping_new_session(&config, &cbs, &h) != ESP_OK){service->pingRC = ping_rc_t::ping_session_fail;- service->ready = true;+ service->pingReady = true;delete params;vTaskDelete(nullptr);return;@@ -271,7 +281,7 @@ void ICMPService::pingAPI(void *pvParams)else if (service->pingRX == 0)service->pingRC = ping_rc_t::ping_timeout;- service->ready = true;+ service->pingReady = true;delete params;vTaskDelete(nullptr);diff --git a/src/Services/ICMPService.h b/src/Services/ICMPService.hindex e83c8d3c..08d1fe1c 100644--- a/src/Services/ICMPService.h+++ b/src/Services/ICMPService.h@@ -17,7 +17,6 @@ enum ping_rc_t {ping_error};-class ICMPService {public:ICMPService();@@ -27,16 +26,18 @@ public:void startPingTask(const std::string& host, int count = 5, int timeout_ms = 1000, int interval_ms = 200);// Discovery of devicesvoid startDiscoveryTask(const std::string deviceIP);+ static void discoveryTask(void* params);// Results- bool isReady() const { return ready; }+ bool isPingReady() const { return pingReady; }ping_rc_t lastRc() const { return pingRC; }int lastMedianMs() const { return pingMedianMs; }int lastSent() const { return pingTX; }int lastRecv() const { return pingRX; }const std::string& getReport() const { return report; }std::string getPingHelp() const;-+ bool isDiscoveryReady() const { return discoveryReady; }+// Task entrystatic void pingAPI(void *pvParams);@@ -44,14 +45,16 @@ public:std::vector<std::string> fetchICMPLog();static void clearICMPLogging();static void stopICMPService();+ void clearDiscoveryFlag() { discoveryReady = false; }private:- bool ready = false;+ bool pingReady = false;int pingMedianMs = -1;int pingTX = 0;int pingRX = 0;std::string report;ping_rc_t pingRC = ping_rc_t::ping_error;+ bool discoveryReady = false;// Log buffer thread safestatic portMUX_TYPE icmpMux;diff --git a/src/Services/NmapService.cpp b/src/Services/NmapService.cppindex 4565b08f..6350d79b 100644--- a/src/Services/NmapService.cpp+++ b/src/Services/NmapService.cpp@@ -335,7 +335,7 @@ void NmapService::scanTarget(const std::string &host, const std::vector<uint16_t// TODO show if host is up + latency?if (icmpService != nullptr){icmpService->startPingTask(host, 1, 1000, 200);- while (!icmpService->isReady())+ while (!icmpService->isPingReady())vTaskDelay(pdMS_TO_TICKS(50));if (icmpService->lastRc() == ping_rc_t::ping_ok) {this->report.append("Host is up (").append(std::to_string(icmpService->lastMedianMs())).append("ms latency).\r\n");