Fixed excluded memory regions in hex viewer

This commit is contained in:
Nav
2023-04-09 00:04:16 +01:00
parent ed2365e173
commit 8efacae10b
7 changed files with 57 additions and 7 deletions

View File

@@ -4,14 +4,20 @@ namespace Bloom
{ {
ConstructHexViewerTopLevelGroupItem::ConstructHexViewerTopLevelGroupItem( ConstructHexViewerTopLevelGroupItem::ConstructHexViewerTopLevelGroupItem(
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions, const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
const Widgets::HexViewerSharedState& hexViewerState const Widgets::HexViewerSharedState& hexViewerState
) )
: focusedMemoryRegions(focusedMemoryRegions) : focusedMemoryRegions(focusedMemoryRegions)
, excludedMemoryRegions(excludedMemoryRegions)
, hexViewerState(hexViewerState) , hexViewerState(hexViewerState)
{} {}
void ConstructHexViewerTopLevelGroupItem::run(Services::TargetControllerService&) { void ConstructHexViewerTopLevelGroupItem::run(Services::TargetControllerService&) {
auto* item = new Widgets::TopLevelGroupItem(this->focusedMemoryRegions, this->hexViewerState); auto* item = new Widgets::TopLevelGroupItem(
this->focusedMemoryRegions,
this->excludedMemoryRegions,
this->hexViewerState
);
item->rebuildItemHierarchy(); item->rebuildItemHierarchy();
emit this->topLevelGroupItem(item); emit this->topLevelGroupItem(item);

View File

@@ -17,6 +17,7 @@ namespace Bloom
public: public:
ConstructHexViewerTopLevelGroupItem( ConstructHexViewerTopLevelGroupItem(
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions, const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
const Widgets::HexViewerSharedState& hexViewerState const Widgets::HexViewerSharedState& hexViewerState
); );
@@ -37,5 +38,6 @@ namespace Bloom
private: private:
const Widgets::HexViewerSharedState& hexViewerState; const Widgets::HexViewerSharedState& hexViewerState;
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions; const std::vector<FocusedMemoryRegion>& focusedMemoryRegions;
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions;
}; };
} }

View File

@@ -20,11 +20,16 @@ namespace Bloom::Widgets
) const { ) const {
const auto boundingRect = QRect(0, 0, ByteItem::WIDTH, ByteItem::HEIGHT); const auto boundingRect = QRect(0, 0, ByteItem::WIDTH, ByteItem::HEIGHT);
if (!graphicsItem->isEnabled()) { if (!graphicsItem->isEnabled() || (this->excluded && !this->selected)) {
painter->setOpacity(0.6); painter->setOpacity(0.6);
} }
if (this->excluded || !hexViewerState->data.has_value()) { if (this->excluded || !hexViewerState->data.has_value()) {
if (this->selected) {
painter->drawPixmap(boundingRect, ByteItem::selectedMissingDataPixmap.value());
return;
}
painter->drawPixmap(boundingRect, ByteItem::missingDataPixmap.value()); painter->drawPixmap(boundingRect, ByteItem::missingDataPixmap.value());
return; return;
} }
@@ -284,6 +289,14 @@ namespace Bloom::Widgets
painter.drawText(byteItemRect, Qt::AlignCenter, "??"); painter.drawText(byteItemRect, Qt::AlignCenter, "??");
} }
{
ByteItem::selectedMissingDataPixmap = selectedTemplatePixmap;
auto painter = QPainter(&ByteItem::selectedMissingDataPixmap.value());
painter.setFont(font);
painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, "??");
}
ByteItem::pixmapCachesGenerated = true; ByteItem::pixmapCachesGenerated = true;
} }
} }

View File

@@ -52,6 +52,7 @@ namespace Bloom::Widgets
static inline std::vector<QPixmap> hoveredPrimaryPixmapsByValue = {}; static inline std::vector<QPixmap> hoveredPrimaryPixmapsByValue = {};
static inline std::vector<QPixmap> hoveredPrimaryAsciiPixmapsByValue = {}; static inline std::vector<QPixmap> hoveredPrimaryAsciiPixmapsByValue = {};
static inline std::optional<QPixmap> missingDataPixmap = {}; static inline std::optional<QPixmap> missingDataPixmap = {};
static inline std::optional<QPixmap> selectedMissingDataPixmap = {};
static void generatePixmapCaches(); static void generatePixmapCaches();
}; };

View File

@@ -136,7 +136,11 @@ namespace Bloom::Widgets
void ItemGraphicsScene::init() { void ItemGraphicsScene::init() {
const auto constructHexViewerTopLevelGroupItem = QSharedPointer<ConstructHexViewerTopLevelGroupItem>( const auto constructHexViewerTopLevelGroupItem = QSharedPointer<ConstructHexViewerTopLevelGroupItem>(
new ConstructHexViewerTopLevelGroupItem(this->focusedMemoryRegions, this->state), new ConstructHexViewerTopLevelGroupItem(
this->focusedMemoryRegions,
this->excludedMemoryRegions,
this->state
),
&QObject::deleteLater &QObject::deleteLater
); );
@@ -731,8 +735,10 @@ namespace Bloom::Widgets
auto data = QString(); auto data = QString();
for (const auto& [address, byteItem] : this->selectedByteItemsByAddress) { for (const auto& [address, byteItem] : this->selectedByteItemsByAddress) {
const auto byteIndex = byteItem->startAddress - this->state.memoryDescriptor.addressRange.startAddress; const unsigned char byteValue = byteItem->excluded
data.append("0x" + QString::number((*this->state.data)[byteIndex], 16).rightJustified(2, '0').toUpper() + "\n"); ? 0x00
: (*this->state.data)[byteItem->startAddress - this->state.memoryDescriptor.addressRange.startAddress];
data.append("0x" + QString::number(byteValue, 16).rightJustified(2, '0').toUpper() + "\n");
} }
QApplication::clipboard()->setText(std::move(data)); QApplication::clipboard()->setText(std::move(data));
@@ -746,8 +752,10 @@ namespace Bloom::Widgets
auto data = QString(); auto data = QString();
for (const auto& [address, byteItem] : this->selectedByteItemsByAddress) { for (const auto& [address, byteItem] : this->selectedByteItemsByAddress) {
const auto byteIndex = byteItem->startAddress - this->state.memoryDescriptor.addressRange.startAddress; const unsigned char byteValue = byteItem->excluded
data.append(QString::number((*this->state.data)[byteIndex], 10) + "\n"); ? 0x00
: (*this->state.data)[byteItem->startAddress - this->state.memoryDescriptor.addressRange.startAddress];
data.append(QString::number(byteValue, 10) + "\n");
} }
QApplication::clipboard()->setText(std::move(data)); QApplication::clipboard()->setText(std::move(data));

View File

@@ -4,10 +4,12 @@ namespace Bloom::Widgets
{ {
TopLevelGroupItem::TopLevelGroupItem( TopLevelGroupItem::TopLevelGroupItem(
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions, const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
const HexViewerSharedState& hexViewerState const HexViewerSharedState& hexViewerState
) )
: GroupItem(0, nullptr) : GroupItem(0, nullptr)
, focusedMemoryRegions(focusedMemoryRegions) , focusedMemoryRegions(focusedMemoryRegions)
, excludedMemoryRegions(excludedMemoryRegions)
, hexViewerState(hexViewerState) , hexViewerState(hexViewerState)
{ {
const auto memorySize = this->hexViewerState.memoryDescriptor.size(); const auto memorySize = this->hexViewerState.memoryDescriptor.size();
@@ -64,6 +66,8 @@ namespace Bloom::Widgets
} }
for (auto& [address, byteItem] : this->byteItemsByAddress) { for (auto& [address, byteItem] : this->byteItemsByAddress) {
byteItem.excluded = false;
if (byteItem.parent != nullptr && byteItem.parent != this) { if (byteItem.parent != nullptr && byteItem.parent != this) {
// This ByteItem is managed by another group // This ByteItem is managed by another group
continue; continue;
@@ -73,6 +77,19 @@ namespace Bloom::Widgets
this->items.push_back(&byteItem); this->items.push_back(&byteItem);
} }
for (const auto& excludedRegion : this->excludedMemoryRegions) {
const auto& startAddress = excludedRegion.addressRange.startAddress;
const auto& endAddress = excludedRegion.addressRange.endAddress;
// Sanity check
assert(byteItemsByAddress.contains(startAddress) && byteItemsByAddress.contains(endAddress));
for (auto address = startAddress; address <= endAddress; ++address) {
auto& byteItem = byteItemsByAddress.at(address);
byteItem.excluded = true;
}
}
this->sortItems(); this->sortItems();
this->refreshValues(); this->refreshValues();
} }

View File

@@ -13,6 +13,7 @@
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp"
namespace Bloom::Widgets namespace Bloom::Widgets
{ {
@@ -23,6 +24,7 @@ namespace Bloom::Widgets
TopLevelGroupItem( TopLevelGroupItem(
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions, const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
const HexViewerSharedState& hexViewerState const HexViewerSharedState& hexViewerState
); );
@@ -40,6 +42,7 @@ namespace Bloom::Widgets
private: private:
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions; const std::vector<FocusedMemoryRegion>& focusedMemoryRegions;
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions;
const HexViewerSharedState& hexViewerState; const HexViewerSharedState& hexViewerState;
std::list<FocusedRegionGroupItem> focusedRegionGroupItems; std::list<FocusedRegionGroupItem> focusedRegionGroupItems;