Added signed integer data type for focused memory regions

This commit is contained in:
Nav
2022-02-02 20:51:26 +00:00
parent a58b0eb80b
commit 91e18ab904
5 changed files with 41 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ namespace Bloom
{ {
UNKNOWN, UNKNOWN,
UNSIGNED_INTEGER, UNSIGNED_INTEGER,
SIGNED_INTEGER,
ASCII_STRING, ASCII_STRING,
}; };

View File

@@ -26,9 +26,7 @@ void ValueAnnotationItem::paint(QPainter* painter, const QStyleOptionGraphicsIte
void ValueAnnotationItem::refreshLabelText() { void ValueAnnotationItem::refreshLabelText() {
this->update(); this->update();
const auto& data = this->value; if (this->value.empty()) {
if (data.empty()) {
this->labelText = QString(ValueAnnotationItem::DEFAULT_LABEL_TEXT); this->labelText = QString(ValueAnnotationItem::DEFAULT_LABEL_TEXT);
return; return;
} }
@@ -36,16 +34,49 @@ void ValueAnnotationItem::refreshLabelText() {
switch (this->focusedMemoryRegion.dataType) { switch (this->focusedMemoryRegion.dataType) {
case MemoryRegionDataType::UNSIGNED_INTEGER: { case MemoryRegionDataType::UNSIGNED_INTEGER: {
std::uint64_t integerValue = 0; std::uint64_t integerValue = 0;
for (const auto& byte : data) { for (const auto& byte : this->value) {
integerValue = (integerValue << 8) | byte; integerValue = (integerValue << 8) | byte;
} }
this->labelText = QString::number(integerValue); this->labelText = QString::number(integerValue);
break; break;
} }
case MemoryRegionDataType::SIGNED_INTEGER: {
const auto valueSize = this->value.size();
if (valueSize == 1) {
this->labelText = QString::number(static_cast<int8_t>(this->value[0]));
break;
}
if (valueSize == 2) {
this->labelText = QString::number(static_cast<int16_t>((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: { case MemoryRegionDataType::ASCII_STRING: {
// Replace non-ASCII chars with '?' // Replace non-ASCII chars with '?'
auto asciiData = data; auto asciiData = this->value;
std::replace_if( std::replace_if(
asciiData.begin(), asciiData.begin(),

View File

@@ -65,6 +65,8 @@ void FocusedRegionItem::initFormInputs() {
this->dataTypeInput->setCurrentText(FocusedRegionItem::dataTypeOptionsByName.at("unsigned_integer").text); this->dataTypeInput->setCurrentText(FocusedRegionItem::dataTypeOptionsByName.at("unsigned_integer").text);
break; break;
} }
case MemoryRegionDataType::SIGNED_INTEGER: {
this->dataTypeInput->setCurrentText(FocusedRegionItem::dataTypeOptionsByName.at("signed_integer").text);
break; break;
} }
case MemoryRegionDataType::ASCII_STRING: { case MemoryRegionDataType::ASCII_STRING: {

View File

@@ -43,6 +43,7 @@ namespace Bloom::Widgets
>({ >({
{"other", DataTypeOption("Other", MemoryRegionDataType::UNKNOWN)}, {"other", DataTypeOption("Other", MemoryRegionDataType::UNKNOWN)},
{"unsigned_integer", DataTypeOption("Unsigned Integer", MemoryRegionDataType::UNSIGNED_INTEGER)}, {"unsigned_integer", DataTypeOption("Unsigned Integer", MemoryRegionDataType::UNSIGNED_INTEGER)},
{"signed_integer", DataTypeOption("Signed Integer", MemoryRegionDataType::SIGNED_INTEGER)},
{"ascii", DataTypeOption("ASCII String", MemoryRegionDataType::ASCII_STRING)}, {"ascii", DataTypeOption("ASCII String", MemoryRegionDataType::ASCII_STRING)},
}); });
}; };

View File

@@ -38,6 +38,7 @@ namespace Bloom
static const inline BiMap<MemoryRegionDataType, QString> regionDataTypesByName = { static const inline BiMap<MemoryRegionDataType, QString> regionDataTypesByName = {
{MemoryRegionDataType::UNKNOWN, "other"}, {MemoryRegionDataType::UNKNOWN, "other"},
{MemoryRegionDataType::UNSIGNED_INTEGER, "unsigned_int"}, {MemoryRegionDataType::UNSIGNED_INTEGER, "unsigned_int"},
{MemoryRegionDataType::SIGNED_INTEGER, "signed_int"},
{MemoryRegionDataType::ASCII_STRING, "ascii_string"}, {MemoryRegionDataType::ASCII_STRING, "ascii_string"},
}; };