From 71277e159f5eee17f3defb60fcf7bde48746361b Mon Sep 17 00:00:00 2001 From: master_roby3 Date: Tue, 19 Sep 2023 09:09:25 +0000 Subject: [PATCH] Upload files to "/" --- hexdump.cxx | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 hexdump.cxx diff --git a/hexdump.cxx b/hexdump.cxx new file mode 100644 index 0000000..1b96cf6 --- /dev/null +++ b/hexdump.cxx @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include +#include + +std::string convert_ASCII(std::string hex){ + std::string ascii = ""; + for (size_t i = 0; i < hex.length(); i += 2){ + //taking two characters from hex string + std::string part = hex.substr(i, 2); + //changing it into base 16 + char ch = stoul(part, nullptr, 16); + //putting it into the ASCII string + ascii += ch; + } + reverse(ascii.begin(), ascii.end()); + return ascii; +} + +int main(int argc, char** argv){ + + std::string filename = argv[1]; + std::ifstream in(filename, std::ios::binary); + + while(!in.eof()){ + uint32_t word; + in.read((char*) &word, sizeof(word)); + + std::stringstream ss; + ss << std::hex << word; + std::string str; + ss >> str; + + std::cout << "0x" << std::hex + << std::setw(8) << std::setfill('0') + << word << "\t" << convert_ASCII(str) << std::endl; + } + + in.close(); + + return 0; +}