diff --git a/CMakeLists.txt b/CMakeLists.txt index 627f4f28..b0bdc113 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,6 +191,7 @@ add_executable(Bloom # Target memory inspection pane src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp + src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemContainerGraphicsView.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp new file mode 100644 index 00000000..91469983 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "MemoryRegion.hpp" + +namespace Bloom +{ + class ExcludedMemoryRegion: public MemoryRegion + { + public: + explicit ExcludedMemoryRegion( + const QString& name, + const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetMemoryAddressRange& addressRange + ): MemoryRegion(name, MemoryRegionType::EXCLUDED, memoryDescriptor, addressRange) {}; + }; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp new file mode 100644 index 00000000..b45af1c6 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include + +#include "MemoryRegion.hpp" + +namespace Bloom +{ + enum class MemoryRegionDataType: std::uint8_t + { + UNKNOWN, + INTEGER, + ASCII_STRING, + }; + + class FocusedMemoryRegion: public MemoryRegion + { + public: + MemoryRegionDataType dataType = MemoryRegionDataType::UNKNOWN; + + explicit FocusedMemoryRegion( + const QString& name, + const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetMemoryAddressRange& addressRange + ): MemoryRegion(name, MemoryRegionType::FOCUSED, memoryDescriptor, addressRange) {}; + }; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp new file mode 100644 index 00000000..6a9dbdd8 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp @@ -0,0 +1,27 @@ +#include "MemoryRegion.hpp" + +using namespace Bloom; + +using Bloom::Targets::TargetMemoryAddressRange; + +TargetMemoryAddressRange MemoryRegion::getAbsoluteAddressRange() const { + if (this->addressRangeType == MemoryRegionAddressType::ABSOLUTE) { + return this->addressRange; + } + + return TargetMemoryAddressRange( + this->addressRange.startAddress + this->memoryDescriptor.addressRange.startAddress, + this->addressRange.endAddress + this->memoryDescriptor.addressRange.startAddress + ); +} + +TargetMemoryAddressRange MemoryRegion::getRelativeAddressRange() const { + if (this->addressRangeType == MemoryRegionAddressType::RELATIVE) { + return this->addressRange; + } + + return TargetMemoryAddressRange( + this->addressRange.startAddress - this->memoryDescriptor.addressRange.startAddress, + this->addressRange.endAddress - this->memoryDescriptor.addressRange.startAddress + ); +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp new file mode 100644 index 00000000..2ac3e0f6 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include +#include +#include +#include + +#include "src/Targets/TargetMemory.hpp" +#include "src/Helpers/DateTime.hpp" + +namespace Bloom +{ + enum class MemoryRegionType: std::uint8_t + { + FOCUSED, + EXCLUDED, + }; + + enum class MemoryRegionAddressType: std::uint8_t + { + ABSOLUTE, + RELATIVE, + }; + + class MemoryRegion + { + public: + std::size_t id = MemoryRegion::lastId++; + QString name; + QDateTime createdDate = DateTime::currentDateTime(); + MemoryRegionType type; + const Targets::TargetMemoryDescriptor& memoryDescriptor; + Targets::TargetMemoryAddressRange addressRange; + MemoryRegionAddressType addressRangeType = MemoryRegionAddressType::ABSOLUTE; + + MemoryRegion( + QString name, + MemoryRegionType type, + const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetMemoryAddressRange& addressRange + ): name(std::move(name)), type(type), memoryDescriptor(memoryDescriptor), addressRange(addressRange) {}; + + bool operator == (const MemoryRegion& other) const { + return this->id == other.id; + } + + bool operator != (const MemoryRegion& other) const { + return !(*this == other); + } + + [[nodiscard]] bool intersectsWith(const MemoryRegion& other) const { + return this->getAbsoluteAddressRange().intersectsWith(other.getAbsoluteAddressRange()); + } + + [[nodiscard]] Targets::TargetMemoryAddressRange getAbsoluteAddressRange() const; + [[nodiscard]] Targets::TargetMemoryAddressRange getRelativeAddressRange() const; + + private: + static inline std::atomic lastId = 0; + }; +}