1
0
mirror of synced 2025-02-06 14:14:22 +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,6 +791,7 @@ namespace hex {
ImPlot::PlotLine(Names[i], m_xBlockTypeDistributions.data(), m_yBlockTypeDistributionsSampled[i].data(), m_xBlockTypeDistributions.size());
}
if (m_showAnnotations) {
u32 id = 1;
for (const auto &annotation : m_annotationRegions) {
const auto &region = annotation.region;
@ -821,6 +822,7 @@ namespace hex {
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
// but just a set of bytes, we won't be able to use the drag bar correctly.
@ -951,6 +953,10 @@ namespace hex {
m_handlePosition = filePosition;
}
void enableAnnotations(bool enabled) {
m_showAnnotations = enabled;
}
private:
static std::array<float, 12> calculateTypeDistribution(const std::array<ImU64, 256> &valueCounts, size_t blockSize) {
std::array<ImU64, 12> counts = {};
@ -1042,8 +1048,9 @@ namespace hex {
}
void addRegion(const UnlocalizedString &name, Region region, ImColor color) {
auto existingRegion = std::ranges::find_if(m_annotationRegions, [&region](const AnnotationRegion &annotation) {
return annotation.region.getEndAddress() + 1 == region.getStartAddress();
const auto existingRegion = std::ranges::find_if(m_annotationRegions, [this, &region](const AnnotationRegion &annotation) {
auto difference = i64(region.getEndAddress()) - i64(annotation.region.getEndAddress());
return difference > 0 && difference < i64(m_blockSize * 32);
});
if (existingRegion != m_annotationRegions.end()) {
@ -1096,5 +1103,7 @@ namespace hex {
std::vector<AnnotationRegion> m_annotationRegions;
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.lowest_entropy": "Lowest block entropy",
"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.sample_size": "Sample size",
"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(),
provider->getBaseAddress(), provider->getActualSize());
m_byteTypesDistribution.enableAnnotations(m_showAnnotations);
// Create a handle to the file
auto reader = prv::ProviderReader(provider);
reader.seek(region.getStartAddress());
@ -194,6 +196,7 @@ namespace hex::plugin::builtin {
void drawSettings() override {
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 {
@ -320,11 +323,13 @@ namespace hex::plugin::builtin {
InformationSection::load(data);
m_inputChunkSize = data.value("block_size", 0);
m_showAnnotations = data.value("annotations", true);
}
nlohmann::json store() override {
auto result = InformationSection::store();
result["block_size"] = m_inputChunkSize;
result["annotations"] = m_showAnnotations;
return result;
}
@ -341,6 +346,8 @@ namespace hex::plugin::builtin {
u64 m_lowestBlockEntropyAddress = 0x00;
double m_plainTextCharacterPercentage = -1.0;
bool m_showAnnotations = true;
DiagramByteDistribution m_byteDistribution;
DiagramByteTypesDistribution m_byteTypesDistribution;
DiagramChunkBasedEntropyAnalysis m_chunkBasedEntropy;