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

impr: Handle unidentifiable data in the data information view better

This commit is contained in:
WerWolv 2023-07-02 10:27:56 +02:00
parent 28dea8e5bd
commit 39e74c627e
3 changed files with 22 additions and 2 deletions

View File

@ -812,6 +812,10 @@ namespace hex {
// Return the percentage of plain text character inside the analyzed region // Return the percentage of plain text character inside the analyzed region
double getPlainTextCharacterPercentage() { double getPlainTextCharacterPercentage() {
if (this->m_yBlockTypeDistributions[2].empty() || this->m_yBlockTypeDistributions[4].empty())
return -1.0;
double plainTextPercentage = std::reduce(this->m_yBlockTypeDistributions[2].begin(), this->m_yBlockTypeDistributions[2].end()) / this->m_yBlockTypeDistributions[2].size(); double plainTextPercentage = std::reduce(this->m_yBlockTypeDistributions[2].begin(), this->m_yBlockTypeDistributions[2].end()) / this->m_yBlockTypeDistributions[2].size();
return plainTextPercentage + std::reduce(this->m_yBlockTypeDistributions[4].begin(), this->m_yBlockTypeDistributions[4].end()) / this->m_yBlockTypeDistributions[4].size(); return plainTextPercentage + std::reduce(this->m_yBlockTypeDistributions[4].begin(), this->m_yBlockTypeDistributions[4].end()) / this->m_yBlockTypeDistributions[4].size();
} }

View File

@ -816,6 +816,8 @@
"hex.builtin.view.information.magic_db_added": "Magic database added!", "hex.builtin.view.information.magic_db_added": "Magic database added!",
"hex.builtin.view.information.mime": "MIME Type:", "hex.builtin.view.information.mime": "MIME Type:",
"hex.builtin.view.information.name": "Data Information", "hex.builtin.view.information.name": "Data Information",
"hex.builtin.view.information.octet_stream_text": "Unknown",
"hex.builtin.view.information.octet_stream_warning": "application/octet-stream denotes an unknown data type.\n\nThis means that this data has no MIME type associated with it because it's not in a known format.",
"hex.builtin.view.information.region": "Analyzed region", "hex.builtin.view.information.region": "Analyzed region",
"hex.builtin.view.information.plain_text": "This data is most likely plain text.", "hex.builtin.view.information.plain_text": "This data is most likely plain text.",
"hex.builtin.view.information.plain_text_percentage": "Plain text percentage", "hex.builtin.view.information.plain_text_percentage": "Plain text percentage",

View File

@ -199,14 +199,28 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextUnformatted("hex.builtin.view.information.description"_lang); ImGui::TextUnformatted("hex.builtin.view.information.description"_lang);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormattedWrapped("{}", this->m_dataDescription.c_str());
if (this->m_dataDescription == "data") {
ImGui::TextFormattedColored(ImVec4(0.92F, 0.25F, 0.2F, 1.0F), "{} ({})", "hex.builtin.view.information.octet_stream_text"_lang, this->m_dataDescription);
} else {
ImGui::TextFormattedWrapped("{}", this->m_dataDescription);
}
} }
if (!this->m_dataMimeType.empty()) { if (!this->m_dataMimeType.empty()) {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextUnformatted("hex.builtin.view.information.mime"_lang); ImGui::TextUnformatted("hex.builtin.view.information.mime"_lang);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormattedWrapped("{}", this->m_dataMimeType.c_str());
if (this->m_dataMimeType == "application/octet-stream") {
ImGui::TextFormattedColored(ImVec4(0.92F, 0.25F, 0.2F, 1.0F), "{} ({})", "hex.builtin.view.information.octet_stream_text"_lang, this->m_dataMimeType);
ImGui::SameLine();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::HelpHover("hex.builtin.view.information.octet_stream_warning"_lang);
ImGui::PopStyleVar();
} else {
ImGui::TextFormatted("{}", this->m_dataMimeType);
}
} }
ImGui::EndTable(); ImGui::EndTable();