From 75c74abf9249f6aee6dc22c4dbc345c4840181aa Mon Sep 17 00:00:00 2001 From: Malfurious Date: Mon, 21 Dec 2020 00:57:45 -0500 Subject: Create tools directory Signed-off-by: Malfurious --- tools/genhex.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tools/genhex.cpp (limited to 'tools/genhex.cpp') diff --git a/tools/genhex.cpp b/tools/genhex.cpp new file mode 100644 index 0000000..a37f91e --- /dev/null +++ b/tools/genhex.cpp @@ -0,0 +1,33 @@ +#include +#include + +/* + * Read in all of stdin (should be piped from objdump), look for bytecode hex, + * and print this code, escaped in a C-string literal, to stdout. + * + * EG output: "\x01\x02\x03\x04" + */ + +int main() +{ + std::string tmp; + unsigned int hex; + + std::cout << "\""; + + while (true) + { + std::cin >> tmp; + + if (std::cin.eof()) + break; + + if (tmp.size() == 2 && + tmp.find(":") == std::string::npos && + sscanf(tmp.c_str(), "%x", &hex) > 0) + std::cout << "\\x" << tmp; + } + + std::cout << "\"\n"; + return 0; +} -- cgit v1.2.3