#include #include #include #include #include namespace hex::plugin::builtin { namespace { ImColor entropyMiniMapVisualizer(const std::vector &data) { std::array frequencies = { 0 }; for (u8 byte : data) frequencies[byte] += 1; double entropy = 0.0; for (u32 frequency : frequencies) { if (frequency == 0) continue; double probability = static_cast(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(hue) / 0.75F, 0.8F, 1.0F); } return color; } ImColor zerosMiniMapVisualizer(const std::vector &data) { u32 zerosCount = 0; for (u8 byte : data) { if (byte == 0x00) zerosCount += 1; } return ImColor::HSV(0.0F, 0.0F, 1.0F - (double(zerosCount) / data.size())); } ImColor byteTypeMiniMapVisualizer(const std::vector &data) { u8 asciiCount = 0; for (u8 byte : data) { if (std::isprint(byte)) asciiCount += 1; } return ImColor::HSV(0.5F, 0.5F, (double(asciiCount) / data.size())); } } void registerMiniMapVisualizers() { ContentRegistry::HexEditor::addMiniMapVisualizer("hex.builtin.minimap_visualizer.entropy", entropyMiniMapVisualizer); ContentRegistry::HexEditor::addMiniMapVisualizer("hex.builtin.minimap_visualizer.zeros", zerosMiniMapVisualizer); ContentRegistry::HexEditor::addMiniMapVisualizer("hex.builtin.minimap_visualizer.ascii", byteTypeMiniMapVisualizer); } }