From 91e18ab90443faafc0acf911855fdee47bbcc330 Mon Sep 17 00:00:00 2001 From: Nav Date: Wed, 2 Feb 2022 20:51:26 +0000 Subject: [PATCH] Added signed integer data type for focused memory regions --- .../FocusedMemoryRegion.hpp | 1 + .../HexViewerWidget/ValueAnnotationItem.cpp | 41 ++++++++++++++++--- .../MemoryRegionManager/FocusedRegionItem.cpp | 2 + .../MemoryRegionManager/FocusedRegionItem.hpp | 1 + src/ProjectSettings.hpp | 1 + 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp index 818cb243..dc59d23c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp @@ -10,6 +10,7 @@ namespace Bloom { UNKNOWN, UNSIGNED_INTEGER, + SIGNED_INTEGER, ASCII_STRING, }; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ValueAnnotationItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ValueAnnotationItem.cpp index 244f8380..fe6b9c7d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ValueAnnotationItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ValueAnnotationItem.cpp @@ -26,9 +26,7 @@ void ValueAnnotationItem::paint(QPainter* painter, const QStyleOptionGraphicsIte void ValueAnnotationItem::refreshLabelText() { this->update(); - const auto& data = this->value; - - if (data.empty()) { + if (this->value.empty()) { this->labelText = QString(ValueAnnotationItem::DEFAULT_LABEL_TEXT); return; } @@ -36,16 +34,49 @@ void ValueAnnotationItem::refreshLabelText() { switch (this->focusedMemoryRegion.dataType) { case MemoryRegionDataType::UNSIGNED_INTEGER: { std::uint64_t integerValue = 0; - for (const auto& byte : data) { + for (const auto& byte : this->value) { integerValue = (integerValue << 8) | byte; } this->labelText = QString::number(integerValue); break; } + case MemoryRegionDataType::SIGNED_INTEGER: { + const auto valueSize = this->value.size(); + + if (valueSize == 1) { + this->labelText = QString::number(static_cast(this->value[0])); + break; + } + + if (valueSize == 2) { + this->labelText = QString::number(static_cast((this->value[0] << 8) | this->value[1])); + break; + } + + if (valueSize <= 4) { + std::int32_t integerValue = 0; + for (const auto& byte : this->value) { + integerValue = (integerValue << 8) | byte; + } + + this->labelText = QString::number(integerValue); + break; + } + + if (valueSize <= 8) { + std::int64_t integerValue = 0; + for (const auto& byte : this->value) { + integerValue = (integerValue << 8) | byte; + } + + this->labelText = QString::number(integerValue); + break; + } + } case MemoryRegionDataType::ASCII_STRING: { // Replace non-ASCII chars with '?' - auto asciiData = data; + auto asciiData = this->value; std::replace_if( asciiData.begin(), diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp index 06421077..af60c02d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp @@ -65,6 +65,8 @@ void FocusedRegionItem::initFormInputs() { this->dataTypeInput->setCurrentText(FocusedRegionItem::dataTypeOptionsByName.at("unsigned_integer").text); break; } + case MemoryRegionDataType::SIGNED_INTEGER: { + this->dataTypeInput->setCurrentText(FocusedRegionItem::dataTypeOptionsByName.at("signed_integer").text); break; } case MemoryRegionDataType::ASCII_STRING: { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp index d5135ee5..719a608e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp @@ -43,6 +43,7 @@ namespace Bloom::Widgets >({ {"other", DataTypeOption("Other", MemoryRegionDataType::UNKNOWN)}, {"unsigned_integer", DataTypeOption("Unsigned Integer", MemoryRegionDataType::UNSIGNED_INTEGER)}, + {"signed_integer", DataTypeOption("Signed Integer", MemoryRegionDataType::SIGNED_INTEGER)}, {"ascii", DataTypeOption("ASCII String", MemoryRegionDataType::ASCII_STRING)}, }); }; diff --git a/src/ProjectSettings.hpp b/src/ProjectSettings.hpp index ab8c2d28..8c55faac 100644 --- a/src/ProjectSettings.hpp +++ b/src/ProjectSettings.hpp @@ -38,6 +38,7 @@ namespace Bloom static const inline BiMap regionDataTypesByName = { {MemoryRegionDataType::UNKNOWN, "other"}, {MemoryRegionDataType::UNSIGNED_INTEGER, "unsigned_int"}, + {MemoryRegionDataType::SIGNED_INTEGER, "signed_int"}, {MemoryRegionDataType::ASCII_STRING, "ascii_string"}, };