Skip to content

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

add method to parse mac

Geo1f9cac9ec46a
diff --git a/src/Transformers/ArgTransformer.cpp b/src/Transformers/ArgTransformer.cpp
index 43f7eca9..ca73c240 100644
--- a/src/Transformers/ArgTransformer.cpp
+++ b/src/Transformers/ArgTransformer.cpp
@@ -324,4 +324,31 @@ std::string ArgTransformer::toAsciiLine(uint32_t startAddr, const std::vector<ui
}
return line.str();
+}
+
+bool ArgTransformer::parseMac(const std::string& s, std::array<uint8_t,6>& out) {
+ // Accept "AA:BB:CC:DD:EE:FF" or "AABBCCDDEEFF"
+ std::string hex;
+ hex.reserve(12);
+ for (char c : s) {
+ if (c == ':' || c == '-') continue;
+ if (!isxdigit((unsigned char)c)) return false;
+ hex.push_back(c);
+ }
+ if (hex.size() != 12) return false;
+
+ auto hexVal = [](char c)->uint8_t {
+ if (c >= '0' && c <= '9') return (uint8_t)(c - '0');
+ if (c >= 'a' && c <= 'f') return (uint8_t)(10 + c - 'a');
+ if (c >= 'A' && c <= 'F') return (uint8_t)(10 + c - 'A');
+ return 0xFF;
+ };
+
+ for (int i=0; i<6; ++i) {
+ uint8_t hi = hexVal(hex[2*i]);
+ uint8_t lo = hexVal(hex[2*i+1]);
+ if (hi == 0xFF || lo == 0xFF) return false;
+ out[i] = (uint8_t)((hi<<4) | lo);
+ }
+ return true;
}
\ No newline at end of file
diff --git a/src/Transformers/ArgTransformer.h b/src/Transformers/ArgTransformer.h
index aec9a638..2130b893 100644
--- a/src/Transformers/ArgTransformer.h
+++ b/src/Transformers/ArgTransformer.h
@@ -32,4 +32,5 @@ public:
std::string formatFloat(double value, int decimals);
std::string toAsciiLine(uint32_t address, const std::vector<uint8_t>& line);
std::string toAsciiLine(uint32_t startAddr, const std::vector<uint16_t>& words);
+ bool parseMac(const std::string& s, std::array<uint8_t,6>& out);
};