ui: Modernize look and feel of data information view
This commit is contained in:
parent
4460d09140
commit
43988b8a7e
@ -29,10 +29,10 @@ namespace hex::plugin::builtin {
|
||||
std::array<ImU64, 256> m_valueCounts = { 0 };
|
||||
bool m_analyzing = false;
|
||||
|
||||
std::pair<u64, u64> m_analyzedRegion = { 0, 0 };
|
||||
Region m_analyzedRegion = { 0, 0 };
|
||||
|
||||
std::string m_fileDescription;
|
||||
std::string m_mimeType;
|
||||
std::string m_dataDescription;
|
||||
std::string m_dataMimeType;
|
||||
|
||||
void analyze();
|
||||
};
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <hex/providers/provider.hpp>
|
||||
#include <hex/providers/buffered_reader.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
#include <hex/helpers/literals.hpp>
|
||||
@ -32,14 +33,14 @@ namespace hex::plugin::builtin {
|
||||
this->m_averageEntropy = 0;
|
||||
this->m_blockSize = 0;
|
||||
this->m_valueCounts.fill(0x00);
|
||||
this->m_mimeType = "";
|
||||
this->m_fileDescription = "";
|
||||
this->m_dataMimeType.clear();
|
||||
this->m_dataDescription.clear();
|
||||
this->m_analyzedRegion = { 0, 0 };
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventRegionSelected>(this, [this](Region region) {
|
||||
if (this->m_blockSize != 0)
|
||||
this->m_entropyHandlePosition = region.address / this->m_blockSize;
|
||||
this->m_entropyHandlePosition = region.getStartAddress() / this->m_blockSize;
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventProviderDeleted>(this, [this](const auto*) {
|
||||
@ -84,41 +85,49 @@ namespace hex::plugin::builtin {
|
||||
std::thread([this] {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
auto task = ImHexApi::Tasks::createTask("hex.builtin.view.information.analyzing", provider->getSize());
|
||||
auto task = ImHexApi::Tasks::createTask("hex.builtin.view.information.analyzing", provider->getActualSize());
|
||||
|
||||
this->m_analyzedRegion = { provider->getBaseAddress(), provider->getBaseAddress() + provider->getSize() };
|
||||
|
||||
{
|
||||
magic::compile();
|
||||
|
||||
this->m_fileDescription = magic::getDescription(provider);
|
||||
this->m_mimeType = magic::getMIMEType(provider);
|
||||
this->m_dataDescription = magic::getDescription(provider);
|
||||
this->m_dataMimeType = magic::getMIMEType(provider);
|
||||
}
|
||||
|
||||
this->m_dataValid = true;
|
||||
|
||||
{
|
||||
this->m_blockSize = std::max<u32>(std::ceil(provider->getSize() / 2048.0F), 256);
|
||||
std::vector<u8> buffer(this->m_blockSize, 0x00);
|
||||
std::memset(this->m_valueCounts.data(), 0x00, this->m_valueCounts.size() * sizeof(u32));
|
||||
this->m_blockSize = std::max<u32>(std::ceil(provider->getActualSize() / 2048.0F), 256);
|
||||
|
||||
std::array<ImU64, 256> valueCounts = { 0 }, blockValueCounts = { 0 };
|
||||
|
||||
this->m_blockEntropy.clear();
|
||||
this->m_valueCounts.fill(0);
|
||||
|
||||
for (u64 i = 0; i < provider->getSize(); i += this->m_blockSize) {
|
||||
std::array<ImU64, 256> blockValueCounts = { 0 };
|
||||
provider->read(i + provider->getBaseAddress(), buffer.data(), std::min(u64(this->m_blockSize), provider->getSize() - i));
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
|
||||
for (size_t j = 0; j < this->m_blockSize; j++) {
|
||||
blockValueCounts[buffer[j]]++;
|
||||
this->m_valueCounts[buffer[j]]++;
|
||||
}
|
||||
u64 count = 0;
|
||||
for (u8 byte : reader) {
|
||||
valueCounts[byte]++;
|
||||
blockValueCounts[byte]++;
|
||||
|
||||
count++;
|
||||
if ((count % this->m_blockSize) == 0) [[unlikely]] {
|
||||
this->m_blockEntropy.push_back(calculateEntropy(blockValueCounts, this->m_blockSize));
|
||||
task.update(i);
|
||||
blockValueCounts = { 0 };
|
||||
task.update(count);
|
||||
}
|
||||
}
|
||||
|
||||
this->m_averageEntropy = calculateEntropy(this->m_valueCounts, provider->getSize());
|
||||
this->m_valueCounts = valueCounts;
|
||||
|
||||
this->m_averageEntropy = calculateEntropy(valueCounts, provider->getSize());
|
||||
if (!this->m_blockEntropy.empty())
|
||||
this->m_highestBlockEntropy = *std::max_element(this->m_blockEntropy.begin(), this->m_blockEntropy.end());
|
||||
else
|
||||
this->m_highestBlockEntropy = 0;
|
||||
}
|
||||
|
||||
this->m_analyzing = false;
|
||||
@ -129,15 +138,11 @@ namespace hex::plugin::builtin {
|
||||
if (ImGui::Begin(View::toWindowName("hex.builtin.view.information.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
if (ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav)) {
|
||||
|
||||
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (ImHexApi::Provider::isValid() && provider->isReadable()) {
|
||||
ImGui::TextUnformatted("hex.builtin.view.information.control"_lang);
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::BeginDisabled(this->m_analyzing);
|
||||
{
|
||||
if (ImGui::Button("hex.builtin.view.information.analyze"_lang))
|
||||
if (ImGui::Button("hex.builtin.view.information.analyze"_lang, ImVec2(ImGui::GetContentRegionAvailWidth(), 0)))
|
||||
this->analyze();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
@ -148,39 +153,66 @@ namespace hex::plugin::builtin {
|
||||
ImGui::NewLine();
|
||||
}
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::TextUnformatted("hex.builtin.view.information.region"_lang);
|
||||
ImGui::Separator();
|
||||
|
||||
for (auto &[name, value] : provider->getDataInformation()) {
|
||||
ImGui::LabelText(name.c_str(), "%s", value.c_str());
|
||||
}
|
||||
|
||||
if (this->m_dataValid) {
|
||||
|
||||
ImGui::LabelText("hex.builtin.view.information.region"_lang, "%s", hex::format("0x{:X} - 0x{:X}", this->m_analyzedRegion.first, this->m_analyzedRegion.second).c_str());
|
||||
// Analyzed region
|
||||
ImGui::Header("hex.builtin.view.information.region"_lang, true);
|
||||
|
||||
if (ImGui::BeginTable("information", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg)) {
|
||||
ImGui::TableSetupColumn("type");
|
||||
ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
|
||||
for (auto &[name, value] : provider->getDataInformation()) {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormatted("{}", name);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormattedWrapped("{}", value);
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormatted("{}", "hex.builtin.view.information.region"_lang);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormatted("0x{:X} - 0x{:X}", this->m_analyzedRegion.getStartAddress(), this->m_analyzedRegion.getEndAddress());
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::NewLine();
|
||||
|
||||
if (!this->m_fileDescription.empty() || !this->m_mimeType.empty()) {
|
||||
ImGui::TextUnformatted("hex.builtin.view.information.magic"_lang);
|
||||
ImGui::Separator();
|
||||
}
|
||||
// Magic information
|
||||
if (!(this->m_dataDescription.empty() && this->m_dataMimeType.empty())) {
|
||||
ImGui::Header("hex.builtin.view.information.magic"_lang);
|
||||
|
||||
if (!this->m_fileDescription.empty()) {
|
||||
if (ImGui::BeginTable("magic", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg)) {
|
||||
ImGui::TableSetupColumn("type");
|
||||
ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
|
||||
if (!this->m_dataDescription.empty()) {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted("hex.builtin.view.information.description"_lang);
|
||||
ImGui::TextFormattedWrapped("{}", this->m_fileDescription.c_str());
|
||||
ImGui::NewLine();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormattedWrapped("{}", this->m_dataDescription.c_str());
|
||||
}
|
||||
|
||||
if (!this->m_mimeType.empty()) {
|
||||
if (!this->m_dataMimeType.empty()) {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted("hex.builtin.view.information.mime"_lang);
|
||||
ImGui::TextFormattedWrapped("{}", this->m_mimeType.c_str());
|
||||
ImGui::NewLine();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormattedWrapped("{}", this->m_dataMimeType.c_str());
|
||||
}
|
||||
|
||||
ImGui::TextUnformatted("hex.builtin.view.information.info_analysis"_lang);
|
||||
ImGui::Separator();
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
|
||||
// Information analysis
|
||||
{
|
||||
|
||||
ImGui::Header("hex.builtin.view.information.info_analysis"_lang);
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImGui::GetColorU32(ImGuiCol_WindowBg));
|
||||
ImPlot::PushStyleColor(ImPlotCol_FrameBg, ImGui::GetColorU32(ImGuiCol_WindowBg));
|
||||
@ -194,8 +226,7 @@ namespace hex::plugin::builtin {
|
||||
return result;
|
||||
}();
|
||||
|
||||
|
||||
ImPlot::PlotBars<ImU64>("##bytes", x.data(), this->m_valueCounts.data(), x.size(), 0.67);
|
||||
ImPlot::PlotBars<ImU64>("##bytes", x.data(), this->m_valueCounts.data(), x.size(), 1.0);
|
||||
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
@ -221,10 +252,32 @@ namespace hex::plugin::builtin {
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
ImGui::NewLine();
|
||||
}
|
||||
|
||||
ImGui::LabelText("hex.builtin.view.information.block_size"_lang, "%s", hex::format("hex.builtin.view.information.block_size.desc"_lang, this->m_blockEntropy.size(), this->m_blockSize).c_str());
|
||||
ImGui::LabelText("hex.builtin.view.information.file_entropy"_lang, "%.8f", this->m_averageEntropy);
|
||||
ImGui::LabelText("hex.builtin.view.information.highest_entropy"_lang, "%.8f", this->m_highestBlockEntropy);
|
||||
// Entropy information
|
||||
if (ImGui::BeginTable("entropy", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg)) {
|
||||
ImGui::TableSetupColumn("type");
|
||||
ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormatted("{}", "hex.builtin.view.information.block_size"_lang);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormatted("hex.builtin.view.information.block_size.desc"_lang, this->m_blockEntropy.size(), this->m_blockSize);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormatted("{}", "hex.builtin.view.information.file_entropy"_lang);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormatted("{:.8f}", this->m_averageEntropy);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormatted("{}", "hex.builtin.view.information.highest_entropy"_lang);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextFormatted("{:.8f}", this->m_highestBlockEntropy);
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
if (this->m_averageEntropy > 0.83 && this->m_highestBlockEntropy > 0.9) {
|
||||
ImGui::NewLine();
|
||||
|
Loading…
Reference in New Issue
Block a user