GUI: implemented byte highlighting (related to issue #175)
This commit is contained in:
parent
81edb1ecc4
commit
ac0a0e3933
|
@ -51,6 +51,20 @@ void HexDump::updateColors()
|
|||
backgroundColor = ConfigColor("HexDumpBackgroundColor");
|
||||
textColor = ConfigColor("HexDumpTextColor");
|
||||
selectionColor = ConfigColor("HexDumpSelectionColor");
|
||||
|
||||
mModifiedBytesColor = ConfigColor("HexDumpModifiedBytesColor");
|
||||
mModifiedBytesBackgroundColor = ConfigColor("HexDumpModifiedBytesBackgroundColor");
|
||||
mRestoredBytesColor = ConfigColor("HexDumpRestoredBytesColor");
|
||||
mRestoredBytesBackgroundColor = ConfigColor("HexDumpRestoredBytesBackgroundColor");
|
||||
mByte00Color = ConfigColor("HexDumpByte00Color");
|
||||
mByte00BackgroundColor = ConfigColor("HexDumpByte00BackgroundColor");
|
||||
mByte7FColor = ConfigColor("HexDumpByte7FColor");
|
||||
mByte7FBackgroundColor = ConfigColor("HexDumpByte7FBackgroundColor");
|
||||
mByteFFColor = ConfigColor("HexDumpByteFFColor");
|
||||
mByteFFBackgroundColor = ConfigColor("HexDumpByteFFBackgroundColor");
|
||||
mByteIsPrintColor = ConfigColor("HexDumpByteIsPrintColor");
|
||||
mByteIsPrintBackgroundColor = ConfigColor("HexDumpByteIsPrintBackgroundColor");
|
||||
|
||||
reloadData();
|
||||
}
|
||||
|
||||
|
@ -614,8 +628,14 @@ void HexDump::getColumnRichText(int col, dsint rva, RichTextPainter::List & rich
|
|||
{
|
||||
RichTextPainter::CustomRichText_t curData;
|
||||
curData.highlight = false;
|
||||
curData.flags = RichTextPainter::FlagColor;
|
||||
curData.flags = RichTextPainter::FlagAll;
|
||||
curData.textColor = textColor;
|
||||
curData.textBackground = Qt::transparent;
|
||||
|
||||
RichTextPainter::CustomRichText_t spaceData;
|
||||
spaceData.highlight = false;
|
||||
spaceData.flags = RichTextPainter::FlagNone;
|
||||
|
||||
if(!col) //address
|
||||
{
|
||||
curData.text = makeAddrText(rvaToVa(rva));
|
||||
|
@ -625,7 +645,6 @@ void HexDump::getColumnRichText(int col, dsint rva, RichTextPainter::List & rich
|
|||
{
|
||||
const ColumnDescriptor_t & desc = mDescriptor.at(col - 1);
|
||||
int wI;
|
||||
QString wStr = "";
|
||||
|
||||
int wByteCount = getSizeOf(desc.data.itemSize);
|
||||
int wBufferByteCount = desc.itemCount * wByteCount;
|
||||
|
@ -633,8 +652,6 @@ void HexDump::getColumnRichText(int col, dsint rva, RichTextPainter::List & rich
|
|||
wBufferByteCount = wBufferByteCount > (dsint)(mMemPage->getSize() - rva) ? mMemPage->getSize() - rva : wBufferByteCount;
|
||||
|
||||
byte_t* wData = new byte_t[wBufferByteCount];
|
||||
//byte_t wData[mDescriptor.at(col).itemCount * wByteCount];
|
||||
|
||||
mMemPage->read(wData, rva, wBufferByteCount);
|
||||
|
||||
if(desc.textCodec) //convert the row bytes to unicode
|
||||
|
@ -650,26 +667,37 @@ void HexDump::getColumnRichText(int col, dsint rva, RichTextPainter::List & rich
|
|||
}
|
||||
else
|
||||
{
|
||||
QColor highlightColor = ConfigColor("HexDumpModifiedBytesColor");
|
||||
|
||||
for(wI = 0; wI < desc.itemCount && (rva + wI) < (dsint)mMemPage->getSize(); wI++)
|
||||
{
|
||||
int maxLen = getStringMaxLength(mDescriptor.at(col - 1).data);
|
||||
QString append = " ";
|
||||
if(!maxLen)
|
||||
append = "";
|
||||
if((rva + wI + wByteCount - 1) < (dsint)mMemPage->getSize())
|
||||
wStr = toString(desc.data, (void*)(wData + wI * wByteCount)).rightJustified(maxLen, ' ') + append;
|
||||
else
|
||||
wStr = QString("?").rightJustified(maxLen, ' ') + append;
|
||||
curData.text = wStr;
|
||||
dsint start = rvaToVa(rva + wI * wByteCount);
|
||||
dsint end = start + wByteCount - 1;
|
||||
if(DbgFunctions()->PatchInRange(start, end))
|
||||
curData.textColor = highlightColor;
|
||||
else
|
||||
curData.text.clear();
|
||||
curData.textColor = textColor;
|
||||
curData.textBackground = Qt::transparent;
|
||||
curData.highlight = false;
|
||||
curData.flags = RichTextPainter::FlagAll;
|
||||
|
||||
int maxLen = getStringMaxLength(desc.data);
|
||||
if((rva + wI + wByteCount - 1) < (dsint)mMemPage->getSize())
|
||||
{
|
||||
toString(desc.data, rva + wI * wByteCount, wData + wI * wByteCount, curData);//).rightJustified(maxLen, ' ') + append;
|
||||
if(curData.text.length() < maxLen)
|
||||
{
|
||||
spaceData.text = QString(' ').repeated(maxLen - curData.text.length());
|
||||
richText.push_back(spaceData);
|
||||
}
|
||||
richText.push_back(curData);
|
||||
if(maxLen)
|
||||
{
|
||||
spaceData.text = QString(' ');
|
||||
richText.push_back(spaceData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
curData.text = QString("?").rightJustified(maxLen, ' ');
|
||||
if(maxLen)
|
||||
curData.text.append(' ');
|
||||
richText.push_back(curData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -677,39 +705,37 @@ void HexDump::getColumnRichText(int col, dsint rva, RichTextPainter::List & rich
|
|||
}
|
||||
}
|
||||
|
||||
QString HexDump::toString(DataDescriptor_t desc, void* data) //convert data to string
|
||||
void HexDump::toString(DataDescriptor_t desc, duint rva, byte_t* data, RichTextPainter::CustomRichText_t & richText) //convert data to string
|
||||
{
|
||||
QString wStr = "";
|
||||
|
||||
switch(desc.itemSize)
|
||||
{
|
||||
case Byte:
|
||||
{
|
||||
wStr = byteToString(*((byte_t*)data), desc.byteMode);
|
||||
byteToString(rva, *((byte_t*)data), desc.byteMode, richText);
|
||||
}
|
||||
break;
|
||||
|
||||
case Word:
|
||||
{
|
||||
wStr = wordToString(*((uint16*)data), desc.wordMode);
|
||||
wordToString(rva, *((uint16*)data), desc.wordMode, richText);
|
||||
}
|
||||
break;
|
||||
|
||||
case Dword:
|
||||
{
|
||||
wStr = dwordToString(*((uint32*)data), desc.dwordMode);
|
||||
dwordToString(rva, *((uint32*)data), desc.dwordMode, richText);
|
||||
}
|
||||
break;
|
||||
|
||||
case Qword:
|
||||
{
|
||||
wStr = qwordToString(*((uint64*)data), desc.qwordMode);
|
||||
qwordToString(rva, *((uint64*)data), desc.qwordMode, richText);
|
||||
}
|
||||
break;
|
||||
|
||||
case Tword:
|
||||
{
|
||||
wStr = twordToString(data, desc.twordMode);
|
||||
twordToString(rva, data, desc.twordMode, richText);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -720,10 +746,16 @@ QString HexDump::toString(DataDescriptor_t desc, void* data) //convert data to s
|
|||
break;
|
||||
}
|
||||
|
||||
return wStr;
|
||||
if(desc.itemSize == Byte) //byte patches are handled in byteToString
|
||||
return;
|
||||
|
||||
dsint start = rvaToVa(rva);
|
||||
dsint end = start + getSizeOf(desc.itemSize) - 1;
|
||||
if(DbgFunctions()->PatchInRange(start, end))
|
||||
richText.textColor = ConfigColor("HexDumpModifiedBytesColor");
|
||||
}
|
||||
|
||||
QString HexDump::byteToString(byte_t byte, ByteViewMode_e mode)
|
||||
void HexDump::byteToString(duint rva, byte_t byte, ByteViewMode_e mode, RichTextPainter::CustomRichText_t & richText)
|
||||
{
|
||||
QString wStr = "";
|
||||
|
||||
|
@ -767,12 +799,53 @@ QString HexDump::byteToString(byte_t byte, ByteViewMode_e mode)
|
|||
break;
|
||||
}
|
||||
|
||||
return wStr;
|
||||
richText.text = wStr;
|
||||
|
||||
DBGPATCHINFO patchInfo;
|
||||
if(DbgFunctions()->PatchGetEx(rvaToVa(rva), &patchInfo))
|
||||
{
|
||||
if(byte == patchInfo.newbyte)
|
||||
{
|
||||
richText.textColor = mModifiedBytesColor;
|
||||
richText.textBackground = mModifiedBytesBackgroundColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
richText.textColor = mRestoredBytesColor;
|
||||
richText.textBackground = mRestoredBytesBackgroundColor;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(byte)
|
||||
{
|
||||
case 0x00:
|
||||
richText.textColor = mByte00Color;
|
||||
richText.textBackground = mByte00BackgroundColor;
|
||||
break;
|
||||
case 0x7F:
|
||||
richText.textColor = mByte7FColor;
|
||||
richText.textBackground = mByte7FBackgroundColor;
|
||||
break;
|
||||
case 0xFF:
|
||||
richText.textColor = mByteFFColor;
|
||||
richText.textBackground = mByteFFBackgroundColor;
|
||||
break;
|
||||
default:
|
||||
if(isprint(byte) || isspace(byte))
|
||||
{
|
||||
richText.textColor = mByteIsPrintColor;
|
||||
richText.textBackground = mByteIsPrintBackgroundColor;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString HexDump::wordToString(uint16 word, WordViewMode_e mode)
|
||||
void HexDump::wordToString(duint rva, uint16 word, WordViewMode_e mode, RichTextPainter::CustomRichText_t & richText)
|
||||
{
|
||||
QString wStr = "";
|
||||
Q_UNUSED(rva);
|
||||
QString wStr;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
|
@ -813,12 +886,13 @@ QString HexDump::wordToString(uint16 word, WordViewMode_e mode)
|
|||
break;
|
||||
}
|
||||
|
||||
return wStr;
|
||||
richText.text = wStr;
|
||||
}
|
||||
|
||||
QString HexDump::dwordToString(uint32 dword, DwordViewMode_e mode)
|
||||
void HexDump::dwordToString(duint rva, uint32 dword, DwordViewMode_e mode, RichTextPainter::CustomRichText_t & richText)
|
||||
{
|
||||
QString wStr = "";
|
||||
Q_UNUSED(rva);
|
||||
QString wStr;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
|
@ -853,12 +927,13 @@ QString HexDump::dwordToString(uint32 dword, DwordViewMode_e mode)
|
|||
break;
|
||||
}
|
||||
|
||||
return wStr;
|
||||
richText.text = wStr;
|
||||
}
|
||||
|
||||
QString HexDump::qwordToString(uint64 qword, QwordViewMode_e mode)
|
||||
void HexDump::qwordToString(duint rva, uint64 qword, QwordViewMode_e mode, RichTextPainter::CustomRichText_t & richText)
|
||||
{
|
||||
QString wStr = "";
|
||||
Q_UNUSED(rva);
|
||||
QString wStr;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
|
@ -893,12 +968,13 @@ QString HexDump::qwordToString(uint64 qword, QwordViewMode_e mode)
|
|||
break;
|
||||
}
|
||||
|
||||
return wStr;
|
||||
richText.text = wStr;
|
||||
}
|
||||
|
||||
QString HexDump::twordToString(void* tword, TwordViewMode_e mode)
|
||||
void HexDump::twordToString(duint rva, void* tword, TwordViewMode_e mode, RichTextPainter::CustomRichText_t & richText)
|
||||
{
|
||||
QString wStr = "";
|
||||
Q_UNUSED(rva);
|
||||
QString wStr;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
|
@ -915,52 +991,12 @@ QString HexDump::twordToString(void* tword, TwordViewMode_e mode)
|
|||
break;
|
||||
}
|
||||
|
||||
return wStr;
|
||||
richText.text = wStr;
|
||||
}
|
||||
|
||||
int HexDump::getSizeOf(DataSize_e size)
|
||||
{
|
||||
int wSize = 0;
|
||||
|
||||
switch(size)
|
||||
{
|
||||
case Byte: // 1 Byte
|
||||
{
|
||||
wSize = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case Word: // 2 Bytes
|
||||
{
|
||||
wSize = 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case Dword: // 4 Bytes
|
||||
{
|
||||
wSize = 4;
|
||||
}
|
||||
break;
|
||||
|
||||
case Qword: // 8 Bytes
|
||||
{
|
||||
wSize = 8;
|
||||
}
|
||||
break;
|
||||
|
||||
case Tword: // 10 Bytes
|
||||
{
|
||||
wSize = 10;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
wSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return wSize;
|
||||
return int(size);
|
||||
}
|
||||
|
||||
int HexDump::getStringMaxLength(DataDescriptor_t desc)
|
||||
|
|
|
@ -12,11 +12,11 @@ class HexDump : public AbstractTableView
|
|||
public:
|
||||
enum DataSize_e
|
||||
{
|
||||
Byte,
|
||||
Word,
|
||||
Dword,
|
||||
Qword,
|
||||
Tword
|
||||
Byte = 1,
|
||||
Word = 2,
|
||||
Dword = 4,
|
||||
Qword = 8,
|
||||
Tword = 10
|
||||
};
|
||||
|
||||
enum ByteViewMode_e
|
||||
|
@ -113,13 +113,13 @@ public:
|
|||
virtual void getColumnRichText(int col, dsint rva, RichTextPainter::List & richText);
|
||||
int getSizeOf(DataSize_e size);
|
||||
|
||||
QString toString(DataDescriptor_t desc, void* data);
|
||||
void toString(DataDescriptor_t desc, duint rva, byte_t* data, RichTextPainter::CustomRichText_t & richText);
|
||||
|
||||
QString byteToString(byte_t byte, ByteViewMode_e mode);
|
||||
QString wordToString(uint16 word, WordViewMode_e mode);
|
||||
QString dwordToString(uint32 dword, DwordViewMode_e mode);
|
||||
QString qwordToString(uint64 qword, QwordViewMode_e mode);
|
||||
QString twordToString(void* tword, TwordViewMode_e mode);
|
||||
void byteToString(duint rva, byte_t byte, ByteViewMode_e mode, RichTextPainter::CustomRichText_t & richText);
|
||||
void wordToString(duint rva, uint16 word, WordViewMode_e mode, RichTextPainter::CustomRichText_t & richText);
|
||||
void dwordToString(duint rva, uint32 dword, DwordViewMode_e mode, RichTextPainter::CustomRichText_t & richText);
|
||||
void qwordToString(duint rva, uint64 qword, QwordViewMode_e mode, RichTextPainter::CustomRichText_t & richText);
|
||||
void twordToString(duint rva, void* tword, TwordViewMode_e mode, RichTextPainter::CustomRichText_t & richText);
|
||||
|
||||
int getStringMaxLength(DataDescriptor_t desc);
|
||||
|
||||
|
@ -185,6 +185,19 @@ private:
|
|||
QChar mNonprintReplace;
|
||||
QChar mNullReplace;
|
||||
|
||||
QColor mModifiedBytesColor;
|
||||
QColor mModifiedBytesBackgroundColor;
|
||||
QColor mRestoredBytesColor;
|
||||
QColor mRestoredBytesBackgroundColor;
|
||||
QColor mByte00Color;
|
||||
QColor mByte00BackgroundColor;
|
||||
QColor mByte7FColor;
|
||||
QColor mByte7FBackgroundColor;
|
||||
QColor mByteFFColor;
|
||||
QColor mByteFFBackgroundColor;
|
||||
QColor mByteIsPrintColor;
|
||||
QColor mByteIsPrintBackgroundColor;
|
||||
|
||||
protected:
|
||||
MemoryPage* mMemPage;
|
||||
int mByteOffset;
|
||||
|
|
|
@ -502,7 +502,12 @@ void AppearanceDialog::colorInfoListInit()
|
|||
|
||||
colorInfoListAppend(tr("HexDump:"), "", "");
|
||||
colorInfoListAppend(tr("Text"), "HexDumpTextColor", "");
|
||||
colorInfoListAppend(tr("Modified Bytes"), "HexDumpModifiedBytesColor", "");
|
||||
colorInfoListAppend(tr("Modified Bytes"), "HexDumpModifiedBytesColor", "HexDumpModifiedBytesBackgroundColor");
|
||||
colorInfoListAppend(tr("Restored Bytes"), "HexDumpRestoredBytesColor", "HexDumpRestoredBytesBackgroundColor");
|
||||
colorInfoListAppend(tr("0x00 Bytes"), "HexDumpByte00Color", "HexDumpByte00BackgroundColor");
|
||||
colorInfoListAppend(tr("0x7F Bytes"), "HexDumpByte7FColor", "HexDumpByte7FBackgroundColor");
|
||||
colorInfoListAppend(tr("0xFF Bytes"), "HexDumpByteFFColor", "HexDumpByteFFBackgroundColor");
|
||||
colorInfoListAppend(tr("IsPrint Bytes"), "HexDumpByteIsPrintColor", "HexDumpByteIsPrintBackgroundColor");
|
||||
colorInfoListAppend(tr("Background"), "HexDumpBackgroundColor", "");
|
||||
colorInfoListAppend(tr("Selection"), "HexDumpSelectionColor", "");
|
||||
colorInfoListAppend(tr("Addresses"), "HexDumpAddressColor", "HexDumpAddressBackgroundColor");
|
||||
|
|
|
@ -151,6 +151,17 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false)
|
|||
|
||||
defaultColors.insert("HexDumpTextColor", QColor("#000000"));
|
||||
defaultColors.insert("HexDumpModifiedBytesColor", QColor("#FF0000"));
|
||||
defaultColors.insert("HexDumpModifiedBytesBackgroundColor", Qt::transparent);
|
||||
defaultColors.insert("HexDumpRestoredBytesColor", QColor("#808080"));
|
||||
defaultColors.insert("HexDumpRestoredBytesBackgroundColor", Qt::transparent);
|
||||
defaultColors.insert("HexDumpByte00Color", QColor("#008000"));
|
||||
defaultColors.insert("HexDumpByte00BackgroundColor", Qt::transparent);
|
||||
defaultColors.insert("HexDumpByte7FColor", QColor("#808000"));
|
||||
defaultColors.insert("HexDumpByte7FBackgroundColor", Qt::transparent);
|
||||
defaultColors.insert("HexDumpByteFFColor", QColor("#800000"));
|
||||
defaultColors.insert("HexDumpByteFFBackgroundColor", Qt::transparent);
|
||||
defaultColors.insert("HexDumpByteIsPrintColor", QColor("#800080"));
|
||||
defaultColors.insert("HexDumpByteIsPrintBackgroundColor", Qt::transparent);
|
||||
defaultColors.insert("HexDumpBackgroundColor", QColor("#FFF8F0"));
|
||||
defaultColors.insert("HexDumpSelectionColor", QColor("#C0C0C0"));
|
||||
defaultColors.insert("HexDumpAddressColor", QColor("#000000"));
|
||||
|
|
Loading…
Reference in New Issue