DBG+GUI: fixed comments with format strings (now you can also edit them as format strings)
This commit is contained in:
parent
2db0248c22
commit
8bd6fe8aad
|
@ -207,11 +207,6 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
*addrinfo->comment = 0;
|
||||
if(CommentGet(addr, addrinfo->comment))
|
||||
{
|
||||
if(strstr(addrinfo->comment, "{")) //comment with format string
|
||||
{
|
||||
auto formatted = stringformatinline(addrinfo->comment);
|
||||
strcpy_s(addrinfo->comment, _TRUNCATE, formatted.c_str());
|
||||
}
|
||||
retval = true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -462,31 +462,29 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
|
|||
argsize += paintFunctionGraphic(painter, x, y, funcType, true);
|
||||
}
|
||||
|
||||
char comment[MAX_COMMENT_SIZE] = "";
|
||||
QString comment;
|
||||
bool autoComment = false;
|
||||
char label[MAX_LABEL_SIZE] = "";
|
||||
if(DbgGetCommentAt(cur_addr, comment))
|
||||
if(GetCommentFormat(cur_addr, comment, &autoComment))
|
||||
{
|
||||
QString commentText;
|
||||
QColor backgroundColor;
|
||||
if(comment[0] == '\1') //automatic comment
|
||||
if(autoComment)
|
||||
{
|
||||
painter->setPen(mAutoCommentColor);
|
||||
backgroundColor = mAutoCommentBackgroundColor;
|
||||
commentText = QString(comment + 1);
|
||||
}
|
||||
else //user comment
|
||||
{
|
||||
painter->setPen(mCommentColor);
|
||||
backgroundColor = mCommentBackgroundColor;
|
||||
commentText = comment;
|
||||
}
|
||||
|
||||
int width = getCharWidth() * commentText.length() + 4;
|
||||
int width = getCharWidth() * comment.length() + 4;
|
||||
if(width > w)
|
||||
width = w;
|
||||
if(width)
|
||||
painter->fillRect(QRect(x + argsize + 2, y, width, h), QBrush(backgroundColor)); //fill comment color
|
||||
painter->drawText(QRect(x + argsize + 4, y , w - 4 , h), Qt::AlignVCenter | Qt::AlignLeft, commentText);
|
||||
painter->drawText(QRect(x + argsize + 4, y , w - 4 , h), Qt::AlignVCenter | Qt::AlignLeft, comment);
|
||||
}
|
||||
else if(DbgGetLabelAt(cur_addr, SEG_DEFAULT, label)) // label but no comment
|
||||
{
|
||||
|
|
|
@ -122,14 +122,9 @@ void BreakpointsView::reloadData()
|
|||
mHardBPTable->setCellContent(wI, 7, wBPList.bp[wI].fastResume ? "X" : "");
|
||||
mHardBPTable->setCellContent(wI, 8, QString().fromUtf8(wBPList.bp[wI].commandText));
|
||||
|
||||
char text[MAX_COMMENT_SIZE] = "";
|
||||
if(DbgGetCommentAt(wBPList.bp[wI].addr, text))
|
||||
{
|
||||
if(text[0] == '\1') //automatic comment
|
||||
mHardBPTable->setCellContent(wI, 9, QString(text + 1));
|
||||
else
|
||||
mHardBPTable->setCellContent(wI, 9, QString().fromUtf8(text));
|
||||
}
|
||||
QString comment;
|
||||
if(GetCommentFormat(wBPList.bp[wI].addr, comment))
|
||||
mHardBPTable->setCellContent(wI, 9, comment);
|
||||
else
|
||||
mHardBPTable->setCellContent(wI, 9, "");
|
||||
|
||||
|
@ -168,14 +163,9 @@ void BreakpointsView::reloadData()
|
|||
mSoftBPTable->setCellContent(wI, 7, wBPList.bp[wI].fastResume ? "X" : "");
|
||||
mSoftBPTable->setCellContent(wI, 8, QString().fromUtf8(wBPList.bp[wI].commandText));
|
||||
|
||||
char comment[MAX_COMMENT_SIZE] = "";
|
||||
if(DbgGetCommentAt(wBPList.bp[wI].addr, comment))
|
||||
{
|
||||
if(comment[0] == '\1') //automatic comment
|
||||
mSoftBPTable->setCellContent(wI, 9, QString(comment + 1));
|
||||
else
|
||||
mSoftBPTable->setCellContent(wI, 9, QString().fromUtf8(comment));
|
||||
}
|
||||
QString comment;
|
||||
if(GetCommentFormat(wBPList.bp[wI].addr, comment))
|
||||
mSoftBPTable->setCellContent(wI, 9, comment);
|
||||
else
|
||||
mSoftBPTable->setCellContent(wI, 9, "");
|
||||
}
|
||||
|
@ -213,14 +203,9 @@ void BreakpointsView::reloadData()
|
|||
mMemBPTable->setCellContent(wI, 7, wBPList.bp[wI].fastResume ? "X" : "");
|
||||
mMemBPTable->setCellContent(wI, 8, QString().fromUtf8(wBPList.bp[wI].commandText));
|
||||
|
||||
char comment[MAX_COMMENT_SIZE] = "";
|
||||
if(DbgGetCommentAt(wBPList.bp[wI].addr, comment))
|
||||
{
|
||||
if(comment[0] == '\1') //automatic comment
|
||||
mMemBPTable->setCellContent(wI, 9, QString(comment + 1));
|
||||
else
|
||||
mMemBPTable->setCellContent(wI, 9, QString().fromUtf8(comment));
|
||||
}
|
||||
QString comment;
|
||||
if(GetCommentFormat(wBPList.bp[wI].addr, comment))
|
||||
mMemBPTable->setCellContent(wI, 9, comment);
|
||||
else
|
||||
mMemBPTable->setCellContent(wI, 9, "");
|
||||
}
|
||||
|
|
|
@ -1161,15 +1161,10 @@ void CPUDisassembly::copySelectionSlot(bool copyBytes)
|
|||
QString disassembly;
|
||||
for(const auto & token : instBuffer.at(i).tokens.tokens)
|
||||
disassembly += token.text;
|
||||
char comment[MAX_COMMENT_SIZE] = "";
|
||||
QString fullComment;
|
||||
if(DbgGetCommentAt(cur_addr, comment))
|
||||
{
|
||||
if(comment[0] == '\1') //automatic comment
|
||||
fullComment = " " + QString(comment + 1);
|
||||
else
|
||||
fullComment = " " + QString(comment);
|
||||
}
|
||||
QString comment;
|
||||
if(GetCommentFormat(cur_addr, comment))
|
||||
fullComment = " " + comment;
|
||||
clipboard += address.leftJustified(addressLen, QChar(' '), true);
|
||||
if(copyBytes)
|
||||
clipboard += " | " + bytes.leftJustified(bytesLen, QChar(' '), true);
|
||||
|
|
|
@ -50,14 +50,9 @@ void SEHChainView::updateSEHChain()
|
|||
else
|
||||
label_text = QString(module);
|
||||
setCellContent(i, 2, label_text);
|
||||
char comment[MAX_COMMENT_SIZE] = "";
|
||||
if(DbgGetCommentAt(sehchain.records[i].handler, comment))
|
||||
{
|
||||
if(comment[0] == '\1') //automatic comment
|
||||
setCellContent(i, 3, QString(comment + 1));
|
||||
else
|
||||
setCellContent(i, 3, comment);
|
||||
}
|
||||
QString comment;
|
||||
if(GetCommentFormat(sehchain.records[i].handler, comment))
|
||||
setCellContent(i, 3, comment);
|
||||
}
|
||||
if(sehchain.total)
|
||||
BridgeFree(sehchain.records);
|
||||
|
|
|
@ -94,4 +94,26 @@ static T & ArchValue(T & x32value, T & x64value)
|
|||
#endif //_WIN64
|
||||
}
|
||||
|
||||
static bool GetCommentFormat(duint addr, QString & comment, bool* autoComment = nullptr)
|
||||
{
|
||||
comment.clear();
|
||||
char commentData[MAX_COMMENT_SIZE] = "";
|
||||
if(!DbgGetCommentAt(addr, commentData))
|
||||
return false;
|
||||
auto a = *commentData == '\1';
|
||||
if(autoComment)
|
||||
*autoComment = a;
|
||||
if(!strstr(commentData, "{"))
|
||||
{
|
||||
comment = commentData + a;
|
||||
return true;
|
||||
}
|
||||
char commentFormat[MAX_SETTING_SIZE] = "";
|
||||
if(DbgFunctions()->StringFormatInline(commentData + a, MAX_SETTING_SIZE, commentFormat))
|
||||
comment = commentFormat;
|
||||
else
|
||||
comment = commentData + a;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // STRINGUTIL_H
|
||||
|
|
Loading…
Reference in New Issue