1
0
mirror of synced 2024-11-13 18:50:53 +01:00

feat: Added option to disable annotations in byte type graph

This commit is contained in:
WerWolv 2024-02-26 21:41:43 +01:00
parent 41935781fb
commit 77550d902c
3 changed files with 44 additions and 27 deletions

View File

@ -791,35 +791,37 @@ namespace hex {
ImPlot::PlotLine(Names[i], m_xBlockTypeDistributions.data(), m_yBlockTypeDistributionsSampled[i].data(), m_xBlockTypeDistributions.size()); ImPlot::PlotLine(Names[i], m_xBlockTypeDistributions.data(), m_yBlockTypeDistributionsSampled[i].data(), m_xBlockTypeDistributions.size());
} }
u32 id = 1; if (m_showAnnotations) {
for (const auto &annotation : m_annotationRegions) { u32 id = 1;
const auto &region = annotation.region; for (const auto &annotation : m_annotationRegions) {
double xMin = region.getStartAddress(); const auto &region = annotation.region;
double xMax = region.getEndAddress(); double xMin = region.getStartAddress();
double yMin = 0.0F; double xMax = region.getEndAddress();
double yMax = 100.0F; double yMin = 0.0F;
double yMax = 100.0F;
ImPlot::DragRect(id, &xMin, &yMin, &xMax, &yMax, annotation.color, ImPlotDragToolFlags_NoFit | ImPlotDragToolFlags_NoInputs); ImPlot::DragRect(id, &xMin, &yMin, &xMax, &yMax, annotation.color, ImPlotDragToolFlags_NoFit | ImPlotDragToolFlags_NoInputs);
const auto min = ImPlot::PlotToPixels(xMin, yMax); const auto min = ImPlot::PlotToPixels(xMin, yMax);
const auto max = ImPlot::PlotToPixels(xMax, yMin); const auto max = ImPlot::PlotToPixels(xMax, yMin);
const auto mousePos = ImPlot::PixelsToPlot(ImGui::GetMousePos()); const auto mousePos = ImPlot::PixelsToPlot(ImGui::GetMousePos());
if (ImGui::IsMouseHoveringRect(min, max)) { if (ImGui::IsMouseHoveringRect(min, max)) {
ImPlot::Annotation(xMin + (xMax - xMin) / 2, mousePos.y, annotation.color, ImVec2(), false, Lang(annotation.unlocalizedName)); ImPlot::Annotation(xMin + (xMax - xMin) / 2, mousePos.y, annotation.color, ImVec2(), false, Lang(annotation.unlocalizedName));
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
ImHexApi::HexEditor::setSelection(annotation.region); ImHexApi::HexEditor::setSelection(annotation.region);
}
} }
id += 1;
} }
id += 1; for (const auto &tag : m_tags) {
} if (tag.axis == ImAxis_X1)
ImPlot::TagX(tag.value, ImGui::GetStyleColorVec4(tag.color), Lang(tag.unlocalizedName));
for (const auto &tag : m_tags) { else if (tag.axis == ImAxis_Y1)
if (tag.axis == ImAxis_X1) ImPlot::TagY(tag.value, ImGui::GetStyleColorVec4(tag.color), Lang(tag.unlocalizedName));
ImPlot::TagX(tag.value, ImGui::GetStyleColorVec4(tag.color), Lang(tag.unlocalizedName)); }
else if (tag.axis == ImAxis_Y1)
ImPlot::TagY(tag.value, ImGui::GetStyleColorVec4(tag.color), Lang(tag.unlocalizedName));
} }
// The parameter updateHandle is used when using the pattern language since we don't have a provider // The parameter updateHandle is used when using the pattern language since we don't have a provider
@ -951,6 +953,10 @@ namespace hex {
m_handlePosition = filePosition; m_handlePosition = filePosition;
} }
void enableAnnotations(bool enabled) {
m_showAnnotations = enabled;
}
private: private:
static std::array<float, 12> calculateTypeDistribution(const std::array<ImU64, 256> &valueCounts, size_t blockSize) { static std::array<float, 12> calculateTypeDistribution(const std::array<ImU64, 256> &valueCounts, size_t blockSize) {
std::array<ImU64, 12> counts = {}; std::array<ImU64, 12> counts = {};
@ -1042,8 +1048,9 @@ namespace hex {
} }
void addRegion(const UnlocalizedString &name, Region region, ImColor color) { void addRegion(const UnlocalizedString &name, Region region, ImColor color) {
auto existingRegion = std::ranges::find_if(m_annotationRegions, [&region](const AnnotationRegion &annotation) { const auto existingRegion = std::ranges::find_if(m_annotationRegions, [this, &region](const AnnotationRegion &annotation) {
return annotation.region.getEndAddress() + 1 == region.getStartAddress(); auto difference = i64(region.getEndAddress()) - i64(annotation.region.getEndAddress());
return difference > 0 && difference < i64(m_blockSize * 32);
}); });
if (existingRegion != m_annotationRegions.end()) { if (existingRegion != m_annotationRegions.end()) {
@ -1096,5 +1103,7 @@ namespace hex {
std::vector<AnnotationRegion> m_annotationRegions; std::vector<AnnotationRegion> m_annotationRegions;
std::vector<Tag> m_tags; std::vector<Tag> m_tags;
bool m_showAnnotations = true;
}; };
} }

View File

@ -842,6 +842,7 @@
"hex.builtin.information_section.info_analysis.highest_entropy": "Highest block entropy", "hex.builtin.information_section.info_analysis.highest_entropy": "Highest block entropy",
"hex.builtin.information_section.info_analysis.lowest_entropy": "Lowest block entropy", "hex.builtin.information_section.info_analysis.lowest_entropy": "Lowest block entropy",
"hex.builtin.information_section.info_analysis": "Information analysis", "hex.builtin.information_section.info_analysis": "Information analysis",
"hex.builtin.information_section.info_analysis.show_annotations": "Show annotations",
"hex.builtin.information_section.relationship_analysis": "Byte Relationship", "hex.builtin.information_section.relationship_analysis": "Byte Relationship",
"hex.builtin.information_section.relationship_analysis.sample_size": "Sample size", "hex.builtin.information_section.relationship_analysis.sample_size": "Sample size",
"hex.builtin.information_section.relationship_analysis.brightness": "Brightness", "hex.builtin.information_section.relationship_analysis.brightness": "Brightness",

View File

@ -164,6 +164,8 @@ namespace hex::plugin::builtin {
m_chunkBasedEntropy.reset(m_inputChunkSize, region.getStartAddress(), region.getEndAddress(), m_chunkBasedEntropy.reset(m_inputChunkSize, region.getStartAddress(), region.getEndAddress(),
provider->getBaseAddress(), provider->getActualSize()); provider->getBaseAddress(), provider->getActualSize());
m_byteTypesDistribution.enableAnnotations(m_showAnnotations);
// Create a handle to the file // Create a handle to the file
auto reader = prv::ProviderReader(provider); auto reader = prv::ProviderReader(provider);
reader.seek(region.getStartAddress()); reader.seek(region.getStartAddress());
@ -194,6 +196,7 @@ namespace hex::plugin::builtin {
void drawSettings() override { void drawSettings() override {
ImGuiExt::InputHexadecimal("hex.builtin.information_section.info_analysis.block_size"_lang, &m_inputChunkSize); ImGuiExt::InputHexadecimal("hex.builtin.information_section.info_analysis.block_size"_lang, &m_inputChunkSize);
ImGui::Checkbox("hex.builtin.information_section.info_analysis.show_annotations"_lang, &m_showAnnotations);
} }
void drawContent() override { void drawContent() override {
@ -319,12 +322,14 @@ namespace hex::plugin::builtin {
void load(const nlohmann::json &data) override { void load(const nlohmann::json &data) override {
InformationSection::load(data); InformationSection::load(data);
m_inputChunkSize = data.value("block_size", 0); m_inputChunkSize = data.value("block_size", 0);
m_showAnnotations = data.value("annotations", true);
} }
nlohmann::json store() override { nlohmann::json store() override {
auto result = InformationSection::store(); auto result = InformationSection::store();
result["block_size"] = m_inputChunkSize; result["block_size"] = m_inputChunkSize;
result["annotations"] = m_showAnnotations;
return result; return result;
} }
@ -341,6 +346,8 @@ namespace hex::plugin::builtin {
u64 m_lowestBlockEntropyAddress = 0x00; u64 m_lowestBlockEntropyAddress = 0x00;
double m_plainTextCharacterPercentage = -1.0; double m_plainTextCharacterPercentage = -1.0;
bool m_showAnnotations = true;
DiagramByteDistribution m_byteDistribution; DiagramByteDistribution m_byteDistribution;
DiagramByteTypesDistribution m_byteTypesDistribution; DiagramByteTypesDistribution m_byteTypesDistribution;
DiagramChunkBasedEntropyAnalysis m_chunkBasedEntropy; DiagramChunkBasedEntropyAnalysis m_chunkBasedEntropy;