feat: Added option to copy custom encoding strings from hex view

This commit is contained in:
WerWolv
2023-01-28 21:12:35 +01:00
parent c861bf9a5e
commit c6e1f45dc3
5 changed files with 25 additions and 2 deletions

View File

@@ -132,6 +132,10 @@ namespace hex::plugin::builtin::ui {
this->m_characterCellPadding = characterCellPadding;
}
[[nodiscard]] const std::optional<EncodingFile>& getCustomEncoding() const {
return this->m_currCustomEncoding;
}
void setCustomEncoding(EncodingFile encoding) {
this->m_currCustomEncoding = std::move(encoding);
}

View File

@@ -655,6 +655,7 @@
"hex.builtin.view.hex_editor.copy.cpp": "C++ Array",
"hex.builtin.view.hex_editor.copy.crystal": "Crystal Array",
"hex.builtin.view.hex_editor.copy.csharp": "C# Array",
"hex.builtin.view.hex_editor.copy.custom_encoding": "Custom Encoding",
"hex.builtin.view.hex_editor.copy.go": "Go Array",
"hex.builtin.view.hex_editor.copy.hex_view": "Hex View",
"hex.builtin.view.hex_editor.copy.html": "HTML",

View File

@@ -985,6 +985,23 @@ namespace hex::plugin::builtin {
if (ImGui::MenuItem("hex.builtin.view.hex_editor.copy.address"_lang))
ImGui::SetClipboardText(hex::format("0x{:08X}", selection->getStartAddress()).c_str());
auto &customEncoding = this->m_hexEditor.getCustomEncoding();
if (ImGui::MenuItem("hex.builtin.view.hex_editor.copy.custom_encoding"_lang, "", false, customEncoding.has_value())) {
std::vector<u8> buffer(customEncoding->getLongestSequence(), 0x00);
std::string string;
u64 offset = selection->getStartAddress();
while (offset < selection->getEndAddress()) {
provider->read(offset, buffer.data(), std::min(buffer.size(), selection->size - (offset - selection->getStartAddress())));
auto [result, size] = customEncoding->getEncodingFor(buffer);
string += result;
offset += size;
};
ImGui::SetClipboardText(string.c_str());
}
ImGui::Separator();
for (const auto &[unlocalizedName, callback] : ContentRegistry::DataFormatter::getEntries()) {