Added copy hex view as HTML option
This commit is contained in:
parent
920b32b432
commit
302caba403
@ -56,6 +56,7 @@ namespace hex {
|
|||||||
void copyString();
|
void copyString();
|
||||||
void copyLanguageArray(Language language);
|
void copyLanguageArray(Language language);
|
||||||
void copyHexView();
|
void copyHexView();
|
||||||
|
void copyHexViewHTML();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ namespace hex {
|
|||||||
|
|
||||||
std::string str;
|
std::string str;
|
||||||
for (const auto &byte : buffer)
|
for (const auto &byte : buffer)
|
||||||
str += hex::format("%02x ", byte);
|
str += hex::format("%02X ", byte);
|
||||||
str.pop_back();
|
str.pop_back();
|
||||||
|
|
||||||
ImGui::SetClipboardText(str.c_str());
|
ImGui::SetClipboardText(str.c_str());
|
||||||
@ -136,7 +136,7 @@ namespace hex {
|
|||||||
str += "const unsigned char data[" + std::to_string(buffer.size()) + "] = { ";
|
str += "const unsigned char data[" + std::to_string(buffer.size()) + "] = { ";
|
||||||
|
|
||||||
for (const auto &byte : buffer)
|
for (const auto &byte : buffer)
|
||||||
str += hex::format("0x%02x, ", byte);
|
str += hex::format("0x%02X, ", byte);
|
||||||
|
|
||||||
// Remove trailing comma
|
// Remove trailing comma
|
||||||
str.pop_back();
|
str.pop_back();
|
||||||
@ -148,7 +148,7 @@ namespace hex {
|
|||||||
str += "constexpr std::array<unsigned char, " + std::to_string(buffer.size()) + "> data = { ";
|
str += "constexpr std::array<unsigned char, " + std::to_string(buffer.size()) + "> data = { ";
|
||||||
|
|
||||||
for (const auto &byte : buffer)
|
for (const auto &byte : buffer)
|
||||||
str += hex::format("0x%02x, ", byte);
|
str += hex::format("0x%02X, ", byte);
|
||||||
|
|
||||||
// Remove trailing comma
|
// Remove trailing comma
|
||||||
str.pop_back();
|
str.pop_back();
|
||||||
@ -160,7 +160,7 @@ namespace hex {
|
|||||||
str += "final byte[] data = { ";
|
str += "final byte[] data = { ";
|
||||||
|
|
||||||
for (const auto &byte : buffer)
|
for (const auto &byte : buffer)
|
||||||
str += hex::format("0x%02x, ", byte);
|
str += hex::format("0x%02X, ", byte);
|
||||||
|
|
||||||
// Remove trailing comma
|
// Remove trailing comma
|
||||||
str.pop_back();
|
str.pop_back();
|
||||||
@ -172,7 +172,7 @@ namespace hex {
|
|||||||
str += "const byte[] data = { ";
|
str += "const byte[] data = { ";
|
||||||
|
|
||||||
for (const auto &byte : buffer)
|
for (const auto &byte : buffer)
|
||||||
str += hex::format("0x%02x, ", byte);
|
str += hex::format("0x%02X, ", byte);
|
||||||
|
|
||||||
// Remove trailing comma
|
// Remove trailing comma
|
||||||
str.pop_back();
|
str.pop_back();
|
||||||
@ -184,7 +184,7 @@ namespace hex {
|
|||||||
str += "let data: [u8, " + std::to_string(buffer.size()) + "] = [ ";
|
str += "let data: [u8, " + std::to_string(buffer.size()) + "] = [ ";
|
||||||
|
|
||||||
for (const auto &byte : buffer)
|
for (const auto &byte : buffer)
|
||||||
str += hex::format("0x%02x, ", byte);
|
str += hex::format("0x%02X, ", byte);
|
||||||
|
|
||||||
// Remove trailing comma
|
// Remove trailing comma
|
||||||
str.pop_back();
|
str.pop_back();
|
||||||
@ -196,7 +196,7 @@ namespace hex {
|
|||||||
str += "data = bytes([ ";
|
str += "data = bytes([ ";
|
||||||
|
|
||||||
for (const auto &byte : buffer)
|
for (const auto &byte : buffer)
|
||||||
str += hex::format("0x%02x, ", byte);
|
str += hex::format("0x%02X, ", byte);
|
||||||
|
|
||||||
// Remove trailing comma
|
// Remove trailing comma
|
||||||
str.pop_back();
|
str.pop_back();
|
||||||
@ -208,7 +208,7 @@ namespace hex {
|
|||||||
str += "const data = new Uint8Array([ ";
|
str += "const data = new Uint8Array([ ";
|
||||||
|
|
||||||
for (const auto &byte : buffer)
|
for (const auto &byte : buffer)
|
||||||
str += hex::format("0x%02x, ", byte);
|
str += hex::format("0x%02X, ", byte);
|
||||||
|
|
||||||
// Remove trailing comma
|
// Remove trailing comma
|
||||||
str.pop_back();
|
str.pop_back();
|
||||||
@ -234,13 +234,13 @@ namespace hex {
|
|||||||
|
|
||||||
|
|
||||||
for (u32 col = start >> 4; col <= (end >> 4); col++) {
|
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++) {
|
for (u64 i = 0 ; i < 16; i++) {
|
||||||
|
|
||||||
if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF))
|
if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF))
|
||||||
str += " ";
|
str += " ";
|
||||||
else
|
else
|
||||||
str += hex::format("%02lx ", buffer[((col << 4) - start) + i]);
|
str += hex::format("%02lX ", buffer[((col << 4) - start) + i]);
|
||||||
|
|
||||||
if ((i & 0xF) == 0x7)
|
if ((i & 0xF) == 0x7)
|
||||||
str += " ";
|
str += " ";
|
||||||
@ -266,6 +266,69 @@ namespace hex {
|
|||||||
ImGui::SetClipboardText(str.c_str());
|
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  00 01 02 03 04 05 06 07  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>  <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 += "   ";
|
||||||
|
else
|
||||||
|
str += hex::format("%02lX ", buffer[((col << 4) - start) + i]);
|
||||||
|
|
||||||
|
if ((i & 0xF) == 0x7)
|
||||||
|
str += " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
str += "</span>  <span class=\"textcolumn\">";
|
||||||
|
|
||||||
|
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 += "</span><br/>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
str +=
|
||||||
|
R"(
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
)";
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::SetClipboardText(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void ViewHexEditor::createMenu() {
|
void ViewHexEditor::createMenu() {
|
||||||
|
|
||||||
if (ImGui::BeginMenu("File")) {
|
if (ImGui::BeginMenu("File")) {
|
||||||
@ -287,7 +350,7 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::BeginMenu("Edit")) {
|
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"))
|
if (ImGui::MenuItem("Bytes", "CTRL + ALT + C"))
|
||||||
this->copyBytes();
|
this->copyBytes();
|
||||||
if (ImGui::MenuItem("Hex String", "CTRL + SHIFT + C"))
|
if (ImGui::MenuItem("Hex String", "CTRL + SHIFT + C"))
|
||||||
@ -314,6 +377,8 @@ namespace hex {
|
|||||||
|
|
||||||
if (ImGui::MenuItem("Editor View"))
|
if (ImGui::MenuItem("Editor View"))
|
||||||
this->copyHexView();
|
this->copyHexView();
|
||||||
|
if (ImGui::MenuItem("HTML"))
|
||||||
|
this->copyHexViewHTML();
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user