From e71091f4a8e3f2c86d09a5518162d1992dea2701 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 29 Jan 2022 02:51:46 +0100 Subject: [PATCH] pattern: Fixed endian setting applied to structs not applying to its members --- .../include/hex/pattern_language/ast_node.hpp | 4 +- .../hex/pattern_language/pattern_data.hpp | 45 +++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/lib/libimhex/include/hex/pattern_language/ast_node.hpp b/lib/libimhex/include/hex/pattern_language/ast_node.hpp index b88d372dc..f4b1fe188 100644 --- a/lib/libimhex/include/hex/pattern_language/ast_node.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast_node.hpp @@ -472,7 +472,9 @@ namespace hex::pl { if (!this->m_name.empty()) pattern->setTypeName(this->m_name); - pattern->setEndian(this->m_endian.value_or(evaluator->getDefaultEndian())); + + if (this->m_endian.has_value()) + pattern->setEndian(this->m_endian.value()); } return patterns; diff --git a/lib/libimhex/include/hex/pattern_language/pattern_data.hpp b/lib/libimhex/include/hex/pattern_language/pattern_data.hpp index f44915628..721442c5a 100644 --- a/lib/libimhex/include/hex/pattern_language/pattern_data.hpp +++ b/lib/libimhex/include/hex/pattern_language/pattern_data.hpp @@ -123,8 +123,9 @@ namespace hex::pl { } [[nodiscard]] bool hasOverriddenColor() const { return this->m_manualColor; } - [[nodiscard]] std::endian getEndian() const { return this->m_endian; } - void setEndian(std::endian endian) { this->m_endian = endian; } + [[nodiscard]] std::endian getEndian() const { return this->m_endian.value_or(this->getEvaluator()->getDefaultEndian()); } + virtual void setEndian(std::endian endian) { this->m_endian = endian; } + [[nodiscard]] bool hasOverriddenEndian() const { return this->m_endian.has_value(); } [[nodiscard]] std::string getDisplayName() const { return this->m_displayName.value_or(this->m_variableName); } void setDisplayName(const std::string &name) { this->m_displayName = name; } @@ -301,7 +302,7 @@ namespace hex::pl { } protected: - std::endian m_endian = std::endian::native; + std::optional m_endian; bool m_hidden = false; private: @@ -456,6 +457,12 @@ namespace hex::pl { return this->m_pointedAt->getPattern(offset); } + void setEndian(std::endian endian) override { + this->m_pointedAt->setEndian(endian); + + PatternData::setEndian(endian); + } + private: PatternData *m_pointedAt = nullptr; u64 m_pointedAtAddress = 0; @@ -899,6 +906,14 @@ namespace hex::pl { return (*iter)->getPattern(offset); } + void setEndian(std::endian endian) override { + for (auto &entry : this->m_entries) { + entry->setEndian(endian); + } + + PatternData::setEndian(endian); + } + private: std::vector m_entries; u64 m_displayEnd = 50; @@ -1048,6 +1063,12 @@ namespace hex::pl { } } + void setEndian(std::endian endian) override { + this->m_template->setEndian(endian); + + PatternData::setEndian(endian); + } + private: PatternData *m_template; mutable PatternData *m_highlightTemplate; @@ -1186,6 +1207,15 @@ namespace hex::pl { return (*iter)->getPattern(offset); } + void setEndian(std::endian endian) override { + for (auto &member : this->m_members) { + if (!member->hasOverriddenEndian()) + member->setEndian(endian); + } + + PatternData::setEndian(endian); + } + private: std::vector m_members; std::vector m_sortedMembers; @@ -1324,6 +1354,15 @@ namespace hex::pl { ; } + void setEndian(std::endian endian) override { + for (auto &member : this->m_members) { + if (!member->hasOverriddenEndian()) + member->setEndian(endian); + } + + PatternData::setEndian(endian); + } + private: std::vector m_members; std::vector m_sortedMembers;