mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
feat: Added Minimap to Hex Editor
This commit is contained in:
57
plugins/builtin/source/content/minimap_visualizers.cpp
Normal file
57
plugins/builtin/source/content/minimap_visualizers.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
||||
#include <wolv/utils/string.hpp>
|
||||
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
namespace {
|
||||
|
||||
ImColor entropyMiniMapVisualizer(const std::vector<u8> &data) {
|
||||
std::array<u32, 256> frequencies = { 0 };
|
||||
for (u8 byte : data)
|
||||
frequencies[byte]++;
|
||||
|
||||
double entropy = 0.0;
|
||||
for (u32 frequency : frequencies) {
|
||||
if (frequency == 0)
|
||||
continue;
|
||||
|
||||
double probability = static_cast<double>(frequency) / data.size();
|
||||
entropy -= probability * std::log2(probability);
|
||||
}
|
||||
|
||||
// Calculate color
|
||||
ImColor color = ImColor::HSV(0.0F, 0.0F, 1.0F);
|
||||
|
||||
if (entropy > 0.0) {
|
||||
double hue = std::clamp(entropy / 8.0, 0.0, 1.0);
|
||||
color = ImColor::HSV(static_cast<float>(hue) / 0.75F, 0.8F, 1.0F);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
ImColor zerosMiniMapVisualizer(const std::vector<u8> &data) {
|
||||
u32 zerosCount = 0;
|
||||
for (u8 byte : data) {
|
||||
if (byte == 0x00)
|
||||
zerosCount++;
|
||||
}
|
||||
|
||||
return ImColor::HSV(0.0F, 0.0F, 1.0F - (double(zerosCount) / data.size()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void registerMiniMapVisualizers() {
|
||||
ContentRegistry::HexEditor::addMiniMapVisualizer("hex.builtin.minimap_visualizer.entropy", entropyMiniMapVisualizer);
|
||||
ContentRegistry::HexEditor::addMiniMapVisualizer("hex.builtin.minimap_visualizer.zeros", zerosMiniMapVisualizer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
void registerEventHandlers();
|
||||
void registerDataVisualizers();
|
||||
void registerMiniMapVisualizers();
|
||||
void registerDataInspectorEntries();
|
||||
void registerToolEntries();
|
||||
void registerPatternLanguageFunctions();
|
||||
@@ -86,6 +87,7 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
|
||||
|
||||
registerEventHandlers();
|
||||
registerDataVisualizers();
|
||||
registerMiniMapVisualizers();
|
||||
registerDataInspectorEntries();
|
||||
registerToolEntries();
|
||||
registerPatternLanguageFunctions();
|
||||
|
||||
Reference in New Issue
Block a user