diff --git a/include/views/view_hexeditor.hpp b/include/views/view_hexeditor.hpp index b1564f781..88c359ef6 100644 --- a/include/views/view_hexeditor.hpp +++ b/include/views/view_hexeditor.hpp @@ -56,6 +56,7 @@ namespace hex { void copyString(); void copyLanguageArray(Language language); void copyHexView(); + void copyHexViewHTML(); }; diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index f75507df9..f62452e9e 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -102,7 +102,7 @@ namespace hex { std::string str; for (const auto &byte : buffer) - str += hex::format("%02x ", byte); + str += hex::format("%02X ", byte); str.pop_back(); ImGui::SetClipboardText(str.c_str()); @@ -136,7 +136,7 @@ namespace hex { str += "const unsigned char data[" + std::to_string(buffer.size()) + "] = { "; for (const auto &byte : buffer) - str += hex::format("0x%02x, ", byte); + str += hex::format("0x%02X, ", byte); // Remove trailing comma str.pop_back(); @@ -148,7 +148,7 @@ namespace hex { str += "constexpr std::array data = { "; for (const auto &byte : buffer) - str += hex::format("0x%02x, ", byte); + str += hex::format("0x%02X, ", byte); // Remove trailing comma str.pop_back(); @@ -160,7 +160,7 @@ namespace hex { str += "final byte[] data = { "; for (const auto &byte : buffer) - str += hex::format("0x%02x, ", byte); + str += hex::format("0x%02X, ", byte); // Remove trailing comma str.pop_back(); @@ -172,7 +172,7 @@ namespace hex { str += "const byte[] data = { "; for (const auto &byte : buffer) - str += hex::format("0x%02x, ", byte); + str += hex::format("0x%02X, ", byte); // Remove trailing comma str.pop_back(); @@ -184,7 +184,7 @@ namespace hex { str += "let data: [u8, " + std::to_string(buffer.size()) + "] = [ "; for (const auto &byte : buffer) - str += hex::format("0x%02x, ", byte); + str += hex::format("0x%02X, ", byte); // Remove trailing comma str.pop_back(); @@ -196,7 +196,7 @@ namespace hex { str += "data = bytes([ "; for (const auto &byte : buffer) - str += hex::format("0x%02x, ", byte); + str += hex::format("0x%02X, ", byte); // Remove trailing comma str.pop_back(); @@ -208,7 +208,7 @@ namespace hex { str += "const data = new Uint8Array([ "; for (const auto &byte : buffer) - str += hex::format("0x%02x, ", byte); + str += hex::format("0x%02X, ", byte); // Remove trailing comma str.pop_back(); @@ -234,13 +234,13 @@ namespace hex { for (u32 col = start >> 4; col <= (end >> 4); col++) { - str += hex::format("%08lx ", col << 4); + str += hex::format("%08lX ", col << 4); for (u64 i = 0 ; i < 16; i++) { if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF)) str += " "; else - str += hex::format("%02lx ", buffer[((col << 4) - start) + i]); + str += hex::format("%02lX ", buffer[((col << 4) - start) + i]); if ((i & 0xF) == 0x7) str += " "; @@ -266,6 +266,69 @@ namespace hex { ImGui::SetClipboardText(str.c_str()); } + void ViewHexEditor::copyHexViewHTML() { + size_t start = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd); + size_t end = std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd); + + size_t copySize = (end - start) + 1; + + std::vector buffer(copySize, 0x00); + this->m_dataProvider->read(start, buffer.data(), buffer.size()); + + std::string str = +R"( +
+ + + + Hex View  00 01 02 03 04 05 06 07  08 09 0A 0B 0C 0D 0E 0F
+)"; + + + for (u32 col = start >> 4; col <= (end >> 4); col++) { + str += hex::format(" %08lX  ", col << 4); + for (u64 i = 0 ; i < 16; i++) { + + if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF)) + str += "   "; + else + str += hex::format("%02lX ", buffer[((col << 4) - start) + i]); + + if ((i & 0xF) == 0x7) + str += " "; + } + + str += "  "; + + for (u64 i = 0 ; i < 16; i++) { + + if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF)) + str += " "; + else { + u8 c = buffer[((col << 4) - start) + i]; + char displayChar = (c < 32 || c >= 128) ? '.' : c; + str += hex::format("%c", displayChar); + } + } + + str += "
\n"; + } + + str += +R"( +
+
+)"; + + + ImGui::SetClipboardText(str.c_str()); + } + void ViewHexEditor::createMenu() { if (ImGui::BeginMenu("File")) { @@ -287,7 +350,7 @@ namespace hex { } if (ImGui::BeginMenu("Edit")) { - if (ImGui::BeginMenu("Copy as...")) { + if (ImGui::BeginMenu("Copy as...", this->m_memoryEditor.DataPreviewAddr != -1 && this->m_memoryEditor.DataPreviewAddrEnd != -1)) { if (ImGui::MenuItem("Bytes", "CTRL + ALT + C")) this->copyBytes(); if (ImGui::MenuItem("Hex String", "CTRL + SHIFT + C")) @@ -314,6 +377,8 @@ namespace hex { if (ImGui::MenuItem("Editor View")) this->copyHexView(); + if (ImGui::MenuItem("HTML")) + this->copyHexViewHTML(); ImGui::EndMenu(); }