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

@@ -20,11 +20,16 @@ namespace Bloom::Widgets
) const {
const auto boundingRect = QRect(0, 0, ByteItem::WIDTH, ByteItem::HEIGHT);
if (!graphicsItem->isEnabled()) {
if (!graphicsItem->isEnabled() || (this->excluded && !this->selected)) {
painter->setOpacity(0.6);
}
if (this->excluded || !hexViewerState->data.has_value()) {
if (this->selected) {
painter->drawPixmap(boundingRect, ByteItem::selectedMissingDataPixmap.value());
return;
}
painter->drawPixmap(boundingRect, ByteItem::missingDataPixmap.value());
return;
}
@@ -284,6 +289,14 @@ namespace Bloom::Widgets
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;
}
}

View File

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

View File

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

View File

@@ -4,10 +4,12 @@ namespace Bloom::Widgets
{
TopLevelGroupItem::TopLevelGroupItem(
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
const HexViewerSharedState& hexViewerState
)
: GroupItem(0, nullptr)
, focusedMemoryRegions(focusedMemoryRegions)
, excludedMemoryRegions(excludedMemoryRegions)
, hexViewerState(hexViewerState)
{
const auto memorySize = this->hexViewerState.memoryDescriptor.size();
@@ -64,6 +66,8 @@ namespace Bloom::Widgets
}
for (auto& [address, byteItem] : this->byteItemsByAddress) {
byteItem.excluded = false;
if (byteItem.parent != nullptr && byteItem.parent != this) {
// This ByteItem is managed by another group
continue;
@@ -73,6 +77,19 @@ namespace Bloom::Widgets
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->refreshValues();
}

View File

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