1
0
mirror of synced 2024-11-25 00:00:27 +01:00

Added copy hex view as HTML option

This commit is contained in:
WerWolv 2020-11-20 15:15:43 +01:00
parent 920b32b432
commit 302caba403
2 changed files with 77 additions and 11 deletions

View File

@ -56,6 +56,7 @@ namespace hex {
void copyString();
void copyLanguageArray(Language language);
void copyHexView();
void copyHexViewHTML();
};

View File

@ -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<unsigned char, " + std::to_string(buffer.size()) + "> 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<u8> buffer(copySize, 0x00);
this->m_dataProvider->read(start, buffer.data(), buffer.size());
std::string str =
R"(
<div>
<style type="text/css">
.offsetheader { color:#0000A0; line-height:200% }
.offsetcolumn { color:#0000A0 }
.hexcolumn { color:#000000 }
.textcolumn { color:#000000 }
</style>
<code>
<span class="offsetheader">Hex View&nbsp&nbsp00 01 02 03 04 05 06 07&nbsp 08 09 0A 0B 0C 0D 0E 0F</span><br/>
)";
for (u32 col = start >> 4; col <= (end >> 4); col++) {
str += hex::format(" <span class=\"offsetcolumn\">%08lX</span>&nbsp&nbsp<span class=\"hexcolumn\">", col << 4);
for (u64 i = 0 ; i < 16; i++) {
if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF))
str += "&nbsp&nbsp ";
else
str += hex::format("%02lX ", buffer[((col << 4) - start) + i]);
if ((i & 0xF) == 0x7)
str += "&nbsp";
}
str += "</span>&nbsp&nbsp<span class=\"textcolumn\">";
for (u64 i = 0 ; i < 16; i++) {
if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF))
str += "&nbsp";
else {
u8 c = buffer[((col << 4) - start) + i];
char displayChar = (c < 32 || c >= 128) ? '.' : c;
str += hex::format("%c", displayChar);
}
}
str += "</span><br/>\n";
}
str +=
R"(
</code>
</div>
)";
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();
}