fix: Filtering of long strings in find view not working correctly

This commit is contained in:
WerWolv
2023-04-01 11:04:07 +02:00
parent cffd55bdda
commit 60efb6973b
2 changed files with 11 additions and 8 deletions

View File

@@ -110,7 +110,7 @@ namespace hex::plugin::builtin {
static std::tuple<bool, std::variant<u64, i64, float, double>, size_t> parseNumericValueInput(const std::string &input, SearchSettings::Value::Type type);
void runSearch();
std::string decodeValue(prv::Provider *provider, Occurrence occurrence) const;
std::string decodeValue(prv::Provider *provider, Occurrence occurrence, size_t maxBytes = 0xFFFF'FFFF) const;
};
}

View File

@@ -51,7 +51,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
{
const auto value = this->decodeValue(ImHexApi::Provider::get(), occurrence.value);
const auto value = this->decodeValue(ImHexApi::Provider::get(), occurrence.value, 256);
ImGui::ColorButton("##color", ImColor(HighlightColor()));
ImGui::SameLine(0, 10);
@@ -63,7 +63,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextFormatted("{}: ", "hex.builtin.common.region"_lang.get());
ImGui::TextFormatted("{}: ", "hex.builtin.common.region"_lang);
ImGui::TableNextColumn();
ImGui::TextFormatted("[ 0x{:08X} - 0x{:08X} ]", occurrence.value.region.getStartAddress(), occurrence.value.region.getEndAddress());
@@ -72,7 +72,7 @@ namespace hex::plugin::builtin {
if (value != demangledValue) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextFormatted("{}: ", "hex.builtin.view.find.demangled"_lang.get());
ImGui::TextFormatted("{}: ", "hex.builtin.view.find.demangled"_lang);
ImGui::TableNextColumn();
ImGui::TextFormatted("{}", demangledValue);
}
@@ -516,8 +516,8 @@ namespace hex::plugin::builtin {
});
}
std::string ViewFind::decodeValue(prv::Provider *provider, Occurrence occurrence) const {
std::vector<u8> bytes(std::min<size_t>(occurrence.region.getSize(), 128));
std::string ViewFind::decodeValue(prv::Provider *provider, Occurrence occurrence, size_t maxBytes) const {
std::vector<u8> bytes(std::min<size_t>(occurrence.region.getSize(), maxBytes));
provider->read(occurrence.region.getStartAddress(), bytes.data(), bytes.size());
std::string result;
@@ -559,6 +559,9 @@ namespace hex::plugin::builtin {
break;
}
if (occurrence.region.getSize() > maxBytes)
result += "...";
return result;
}
@@ -815,7 +818,7 @@ namespace hex::plugin::builtin {
}
ImGui::PopItemWidth();
if (ImGui::BeginTable("##entries", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
if (ImGui::BeginTable("##entries", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("hex.builtin.common.offset"_lang, 0, -1, ImGui::GetID("offset"));
ImGui::TableSetupColumn("hex.builtin.common.size"_lang, 0, -1, ImGui::GetID("size"));
@@ -867,7 +870,7 @@ namespace hex::plugin::builtin {
ImGui::PushID(i);
auto value = this->decodeValue(provider, foundItem);
auto value = this->decodeValue(provider, foundItem, 256);
ImGui::TextFormatted("{}", value);
ImGui::SameLine();
if (ImGui::Selectable("##line", false, ImGuiSelectableFlags_SpanAllColumns))