mirror of https://github.com/WerWolv/ImHex.git
Compare commits
2 Commits
986252d97f
...
0d7740773e
Author | SHA1 | Date |
---|---|---|
WerWolv | 0d7740773e | |
WerWolv | e4fbb1b640 |
|
@ -1 +1 @@
|
|||
Subproject commit f69cafb1d618ef79a5ea01be8b225f0340380a2f
|
||||
Subproject commit 10a7c78737088bc0b0632cc8fb7132d5be32c42d
|
|
@ -24,6 +24,7 @@ namespace hex::plugin::builtin {
|
|||
float m_averageEntropy = 0;
|
||||
float m_highestBlockEntropy = 0;
|
||||
std::vector<float> m_blockEntropy;
|
||||
u64 m_blockEntropyProcessedCount = 0;
|
||||
|
||||
double m_entropyHandlePosition;
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ namespace hex::plugin::builtin {
|
|||
float entropy = 0;
|
||||
|
||||
for (auto count : valueCounts) {
|
||||
if (count == 0) continue;
|
||||
if (count == 0) [[unlikely]]
|
||||
continue;
|
||||
|
||||
float probability = static_cast<float>(count) / blockSize;
|
||||
|
||||
|
@ -78,7 +79,7 @@ namespace hex::plugin::builtin {
|
|||
this->m_analyzerTask = TaskManager::createTask("hex.builtin.view.information.analyzing", 0, [this](auto &task) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
task.setMaxValue(provider->getActualSize());
|
||||
task.setMaxValue(provider->getSize());
|
||||
|
||||
this->m_analyzedRegion = { provider->getBaseAddress(), provider->getBaseAddress() + provider->getSize() };
|
||||
|
||||
|
@ -92,14 +93,17 @@ namespace hex::plugin::builtin {
|
|||
this->m_dataValid = true;
|
||||
|
||||
{
|
||||
this->m_blockSize = std::max<u32>(std::ceil(provider->getActualSize() / 2048.0F), 256);
|
||||
this->m_blockSize = std::max<u32>(std::ceil(provider->getSize() / 2048.0F), 256);
|
||||
|
||||
std::array<ImU64, 256> blockValueCounts = { 0 };
|
||||
|
||||
this->m_blockEntropy.clear();
|
||||
this->m_blockEntropy.resize(provider->getSize() / this->m_blockSize);
|
||||
this->m_valueCounts.fill(0);
|
||||
this->m_blockEntropyProcessedCount = 0;
|
||||
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
reader.setEndAddress(provider->getBaseAddress() + provider->getSize());
|
||||
|
||||
u64 count = 0;
|
||||
for (u8 byte : reader) {
|
||||
|
@ -108,7 +112,8 @@ namespace hex::plugin::builtin {
|
|||
|
||||
count++;
|
||||
if ((count % this->m_blockSize) == 0) [[unlikely]] {
|
||||
this->m_blockEntropy.push_back(calculateEntropy(blockValueCounts, this->m_blockSize));
|
||||
this->m_blockEntropy[this->m_blockEntropyProcessedCount] = calculateEntropy(blockValueCounts, this->m_blockSize);
|
||||
this->m_blockEntropyProcessedCount += 1;
|
||||
blockValueCounts = { 0 };
|
||||
task.update(count);
|
||||
}
|
||||
|
@ -230,7 +235,7 @@ namespace hex::plugin::builtin {
|
|||
ImPlot::SetupAxes("hex.builtin.common.address"_lang, "hex.builtin.view.information.entropy"_lang, ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock);
|
||||
ImPlot::SetupAxesLimits(0, this->m_blockEntropy.size(), -0.1F, 1.1F, ImGuiCond_Always);
|
||||
|
||||
ImPlot::PlotLine("##entropy_line", this->m_blockEntropy.data(), this->m_blockEntropy.size());
|
||||
ImPlot::PlotLine("##entropy_line", this->m_blockEntropy.data(), this->m_blockEntropyProcessedCount);
|
||||
|
||||
if (ImPlot::DragLineX(1, &this->m_entropyHandlePosition, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
|
||||
u64 address = u64(std::max<double>(this->m_entropyHandlePosition, 0) * this->m_blockSize) + provider->getBaseAddress();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <content/helpers/math_evaluator.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <implot.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
|
||||
namespace hex::plugin::builtin::ui {
|
||||
|
@ -129,6 +130,32 @@ namespace hex::plugin::builtin::ui {
|
|||
}
|
||||
}
|
||||
|
||||
void drawVisualizer(const std::string &visualizer, pl::ptrn::Pattern &pattern, pl::ptrn::Iteratable &iteratable) {
|
||||
if (visualizer == "line_plot") {
|
||||
if (ImPlot::BeginPlot("##plot", ImVec2(400, 250), ImPlotFlags_NoChild | ImPlotFlags_CanvasOnly)) {
|
||||
|
||||
ImPlot::SetupAxes("X", "Y", ImPlotAxisFlags_AutoFit, ImPlotAxisFlags_AutoFit);
|
||||
|
||||
ImPlot::PlotLineG("##line", [](void *data, int idx) -> ImPlotPoint {
|
||||
auto &iteratable = *static_cast<pl::ptrn::Iteratable *>(data);
|
||||
return { static_cast<double>(idx), pl::core::Token::literalToFloatingPoint(iteratable.getEntry(idx)->getValue()) };
|
||||
}, &iteratable, iteratable.getEntryCount());
|
||||
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
} else if (visualizer == "image") {
|
||||
std::vector<u8> data;
|
||||
data.resize(pattern.getSize());
|
||||
|
||||
pattern.getEvaluator()->readData(pattern.getOffset(), data.data(), data.size(), pattern.getSection());
|
||||
static ImGui::Texture texture;
|
||||
texture = ImGui::Texture(data.data(), data.size());
|
||||
|
||||
if (texture.isValid())
|
||||
ImGui::Image(texture, texture.getSize());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PatternDrawer::makeSelectable(const pl::ptrn::Pattern &pattern) {
|
||||
|
@ -460,7 +487,7 @@ namespace hex::plugin::builtin::ui {
|
|||
|
||||
if (open) {
|
||||
int id = 1;
|
||||
pattern.forEachEntry(0, pattern.getMembers().size(), [&](u64, auto *member){
|
||||
pattern.forEachEntry(0, pattern.getEntryCount(), [&](u64, auto *member){
|
||||
ImGui::PushID(id);
|
||||
this->draw(*member);
|
||||
ImGui::PopID();
|
||||
|
@ -577,6 +604,16 @@ namespace hex::plugin::builtin::ui {
|
|||
ImGui::TableNextColumn();
|
||||
makeSelectable(pattern);
|
||||
drawCommentTooltip(pattern);
|
||||
if (const auto &visualizer = pattern.getAttributeValue("hex::visualize"); visualizer.has_value()) {
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
|
||||
ImGui::BeginTooltip();
|
||||
|
||||
drawVisualizer(visualizer.value(), pattern, iteratable);
|
||||
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
if (pattern.isSealed())
|
||||
drawColorColumn(pattern);
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue