mirror of https://github.com/WerWolv/ImHex.git
Compare commits
No commits in common. "0d7740773edd1022712128e01fb3be27e4c84bef" and "986252d97f0649fa9458c7e82d569bd417d5835e" have entirely different histories.
0d7740773e
...
986252d97f
|
@ -1 +1 @@
|
||||||
Subproject commit 10a7c78737088bc0b0632cc8fb7132d5be32c42d
|
Subproject commit f69cafb1d618ef79a5ea01be8b225f0340380a2f
|
|
@ -24,7 +24,6 @@ namespace hex::plugin::builtin {
|
||||||
float m_averageEntropy = 0;
|
float m_averageEntropy = 0;
|
||||||
float m_highestBlockEntropy = 0;
|
float m_highestBlockEntropy = 0;
|
||||||
std::vector<float> m_blockEntropy;
|
std::vector<float> m_blockEntropy;
|
||||||
u64 m_blockEntropyProcessedCount = 0;
|
|
||||||
|
|
||||||
double m_entropyHandlePosition;
|
double m_entropyHandlePosition;
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,7 @@ namespace hex::plugin::builtin {
|
||||||
float entropy = 0;
|
float entropy = 0;
|
||||||
|
|
||||||
for (auto count : valueCounts) {
|
for (auto count : valueCounts) {
|
||||||
if (count == 0) [[unlikely]]
|
if (count == 0) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
float probability = static_cast<float>(count) / blockSize;
|
float probability = static_cast<float>(count) / blockSize;
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ namespace hex::plugin::builtin {
|
||||||
this->m_analyzerTask = TaskManager::createTask("hex.builtin.view.information.analyzing", 0, [this](auto &task) {
|
this->m_analyzerTask = TaskManager::createTask("hex.builtin.view.information.analyzing", 0, [this](auto &task) {
|
||||||
auto provider = ImHexApi::Provider::get();
|
auto provider = ImHexApi::Provider::get();
|
||||||
|
|
||||||
task.setMaxValue(provider->getSize());
|
task.setMaxValue(provider->getActualSize());
|
||||||
|
|
||||||
this->m_analyzedRegion = { provider->getBaseAddress(), provider->getBaseAddress() + provider->getSize() };
|
this->m_analyzedRegion = { provider->getBaseAddress(), provider->getBaseAddress() + provider->getSize() };
|
||||||
|
|
||||||
|
@ -93,17 +92,14 @@ namespace hex::plugin::builtin {
|
||||||
this->m_dataValid = true;
|
this->m_dataValid = true;
|
||||||
|
|
||||||
{
|
{
|
||||||
this->m_blockSize = std::max<u32>(std::ceil(provider->getSize() / 2048.0F), 256);
|
this->m_blockSize = std::max<u32>(std::ceil(provider->getActualSize() / 2048.0F), 256);
|
||||||
|
|
||||||
std::array<ImU64, 256> blockValueCounts = { 0 };
|
std::array<ImU64, 256> blockValueCounts = { 0 };
|
||||||
|
|
||||||
this->m_blockEntropy.clear();
|
this->m_blockEntropy.clear();
|
||||||
this->m_blockEntropy.resize(provider->getSize() / this->m_blockSize);
|
|
||||||
this->m_valueCounts.fill(0);
|
this->m_valueCounts.fill(0);
|
||||||
this->m_blockEntropyProcessedCount = 0;
|
|
||||||
|
|
||||||
auto reader = prv::BufferedReader(provider);
|
auto reader = prv::BufferedReader(provider);
|
||||||
reader.setEndAddress(provider->getBaseAddress() + provider->getSize());
|
|
||||||
|
|
||||||
u64 count = 0;
|
u64 count = 0;
|
||||||
for (u8 byte : reader) {
|
for (u8 byte : reader) {
|
||||||
|
@ -112,8 +108,7 @@ namespace hex::plugin::builtin {
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
if ((count % this->m_blockSize) == 0) [[unlikely]] {
|
if ((count % this->m_blockSize) == 0) [[unlikely]] {
|
||||||
this->m_blockEntropy[this->m_blockEntropyProcessedCount] = calculateEntropy(blockValueCounts, this->m_blockSize);
|
this->m_blockEntropy.push_back(calculateEntropy(blockValueCounts, this->m_blockSize));
|
||||||
this->m_blockEntropyProcessedCount += 1;
|
|
||||||
blockValueCounts = { 0 };
|
blockValueCounts = { 0 };
|
||||||
task.update(count);
|
task.update(count);
|
||||||
}
|
}
|
||||||
|
@ -235,7 +230,7 @@ namespace hex::plugin::builtin {
|
||||||
ImPlot::SetupAxes("hex.builtin.common.address"_lang, "hex.builtin.view.information.entropy"_lang, ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock);
|
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::SetupAxesLimits(0, this->m_blockEntropy.size(), -0.1F, 1.1F, ImGuiCond_Always);
|
||||||
|
|
||||||
ImPlot::PlotLine("##entropy_line", this->m_blockEntropy.data(), this->m_blockEntropyProcessedCount);
|
ImPlot::PlotLine("##entropy_line", this->m_blockEntropy.data(), this->m_blockEntropy.size());
|
||||||
|
|
||||||
if (ImPlot::DragLineX(1, &this->m_entropyHandlePosition, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
|
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();
|
u64 address = u64(std::max<double>(this->m_entropyHandlePosition, 0) * this->m_blockSize) + provider->getBaseAddress();
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include <content/helpers/math_evaluator.hpp>
|
#include <content/helpers/math_evaluator.hpp>
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <implot.h>
|
|
||||||
#include <hex/ui/imgui_imhex_extensions.h>
|
#include <hex/ui/imgui_imhex_extensions.h>
|
||||||
|
|
||||||
namespace hex::plugin::builtin::ui {
|
namespace hex::plugin::builtin::ui {
|
||||||
|
@ -130,32 +129,6 @@ 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) {
|
void PatternDrawer::makeSelectable(const pl::ptrn::Pattern &pattern) {
|
||||||
|
@ -487,7 +460,7 @@ namespace hex::plugin::builtin::ui {
|
||||||
|
|
||||||
if (open) {
|
if (open) {
|
||||||
int id = 1;
|
int id = 1;
|
||||||
pattern.forEachEntry(0, pattern.getEntryCount(), [&](u64, auto *member){
|
pattern.forEachEntry(0, pattern.getMembers().size(), [&](u64, auto *member){
|
||||||
ImGui::PushID(id);
|
ImGui::PushID(id);
|
||||||
this->draw(*member);
|
this->draw(*member);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
@ -604,16 +577,6 @@ namespace hex::plugin::builtin::ui {
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
makeSelectable(pattern);
|
makeSelectable(pattern);
|
||||||
drawCommentTooltip(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())
|
if (pattern.isSealed())
|
||||||
drawColorColumn(pattern);
|
drawColorColumn(pattern);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue