summaryrefslogtreecommitdiffstats
path: root/genhex.cpp
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2020-12-04 02:18:33 -0500
committerMalfurious <m@lfurio.us>2020-12-04 02:18:33 -0500
commit62981e7731466535dab214ef2571ae117673f242 (patch)
treee8bbc41f36c813eee0f1db895af73fe1a951179a /genhex.cpp
parent81a9656d3bffc7bd247aaf177a5153b96e4d4319 (diff)
downloadlib-des-gnux-62981e7731466535dab214ef2571ae117673f242.tar.gz
lib-des-gnux-62981e7731466535dab214ef2571ae117673f242.zip
Commit genhex program
This is a utility program from my shellcoding repository. It uses the dissassembly output from objdump to auto-format a payload from an assembled object file. Signed-off-by: Malfurious <m@lfurio.us>
Diffstat (limited to 'genhex.cpp')
-rw-r--r--genhex.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/genhex.cpp b/genhex.cpp
new file mode 100644
index 0000000..a37f91e
--- /dev/null
+++ b/genhex.cpp
@@ -0,0 +1,33 @@
+#include <iostream>
+#include <string>
+
+/*
+ * 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;
+}