Skip to content

Commit 0afaf5a

Browse files
committed
GUI: More caching in disassembly view
1 parent c56f0d4 commit 0afaf5a

File tree

2 files changed

+63
-44
lines changed

2 files changed

+63
-44
lines changed

src/gui/Src/BasicView/Disassembly.cpp

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ void Disassembly::updateColors()
6060
mInstructionHighlightColor = ConfigColor("InstructionHighlightColor");
6161
mSelectionColor = ConfigColor("DisassemblySelectionColor");
6262
mCipBackgroundColor = ConfigColor("DisassemblyCipBackgroundColor");
63+
mCipColor = ConfigColor("DisassemblyCipColor");
6364
mBreakpointBackgroundColor = ConfigColor("DisassemblyBreakpointBackgroundColor");
6465
mBreakpointColor = ConfigColor("DisassemblyBreakpointColor");
65-
mCipColor = ConfigColor("DisassemblyCipColor");
6666
mHardwareBreakpointBackgroundColor = ConfigColor("DisassemblyHardwareBreakpointBackgroundColor");
6767
mHardwareBreakpointColor = ConfigColor("DisassemblyHardwareBreakpointColor");
6868
mBookmarkBackgroundColor = ConfigColor("DisassemblyBookmarkBackgroundColor");
@@ -73,6 +73,12 @@ void Disassembly::updateColors()
7373
mSelectedAddressColor = ConfigColor("DisassemblySelectedAddressColor");
7474
mAddressBackgroundColor = ConfigColor("DisassemblyAddressBackgroundColor");
7575
mAddressColor = ConfigColor("DisassemblyAddressColor");
76+
mBytesColor = ConfigColor("DisassemblyBytesColor");
77+
mModifiedBytesColor = ConfigColor("DisassemblyModifiedBytesColor");
78+
mAutoCommentColor = ConfigColor("DisassemblyAutoCommentColor");
79+
mAutoCommentBackgroundColor = ConfigColor("DisassemblyAutoCommentBackgroundColor");
80+
mCommentColor = ConfigColor("DisassemblyCommentColor");
81+
mCommentBackgroundColor = ConfigColor("DisassemblyCommentBackgroundColor");
7682

7783
CapstoneTokenizer::UpdateColors();
7884
mDisasm->UpdateConfig();
@@ -220,26 +226,26 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
220226
{
221227
if(bpxtype & bp_normal) //normal breakpoint
222228
{
223-
painter->setPen(QPen(ConfigColor("DisassemblyBreakpointColor")));
224-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyBreakpointBackgroundColor"))); //fill red
229+
painter->setPen(QPen(mBreakpointColor));
230+
painter->fillRect(QRect(x, y, w, h), QBrush(mBreakpointBackgroundColor)); //fill red
225231
}
226232
else if(bpxtype & bp_hardware) //hardware breakpoint only
227233
{
228-
painter->setPen(QPen(ConfigColor("DisassemblyHardwareBreakpointColor")));
229-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyHardwareBreakpointBackgroundColor"))); //fill red
234+
painter->setPen(QPen(mHardwareBreakpointColor));
235+
painter->fillRect(QRect(x, y, w, h), QBrush(mHardwareBreakpointBackgroundColor)); //fill red
230236
}
231237
else //other cases (memory breakpoint in disassembly) -> do as normal
232238
{
233239
QColor background;
234240
if(wIsSelected)
235241
{
236-
background = ConfigColor("DisassemblySelectedAddressBackgroundColor");
237-
painter->setPen(QPen(ConfigColor("DisassemblySelectedAddressColor"))); //black address (DisassemblySelectedAddressColor)
242+
background = mSelectedAddressBackgroundColor;
243+
painter->setPen(QPen(mSelectedAddressColor)); //black address (DisassemblySelectedAddressColor)
238244
}
239245
else
240246
{
241-
background = ConfigColor("DisassemblyAddressBackgroundColor");
242-
painter->setPen(QPen(ConfigColor("DisassemblyAddressColor")));
247+
background = mAddressBackgroundColor;
248+
painter->setPen(QPen(mAddressColor));
243249
}
244250
if(background.alpha())
245251
painter->fillRect(QRect(x, y, w, h), QBrush(background)); //fill background
@@ -253,50 +259,50 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
253259
{
254260
if(bpxtype == bp_none) //label + bookmark
255261
{
256-
painter->setPen(QPen(ConfigColor("DisassemblyLabelColor"))); //red -> address + label text
257-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyBookmarkBackgroundColor"))); //fill label background
262+
painter->setPen(QPen(mLabelColor)); //red -> address + label text
263+
painter->fillRect(QRect(x, y, w, h), QBrush(mBookmarkBackgroundColor)); //fill label background
258264
}
259265
else //label+breakpoint+bookmark
260266
{
261-
QColor color = ConfigColor("DisassemblyBookmarkBackgroundColor");
267+
QColor color = mBookmarkBackgroundColor;
262268
if(!color.alpha()) //we don't want transparent text
263-
color = ConfigColor("DisassemblyAddressColor");
269+
color = mAddressColor;
264270
painter->setPen(QPen(color));
265271
if(bpxtype & bp_normal) //label + bookmark + normal breakpoint
266272
{
267-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyBreakpointBackgroundColor"))); //fill red
273+
painter->fillRect(QRect(x, y, w, h), QBrush(mBreakpointBackgroundColor)); //fill red
268274
}
269275
else if(bpxtype & bp_hardware) //label + bookmark + hardware breakpoint only
270276
{
271-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyHardwareBreakpointBackgroundColor"))); //fill ?
277+
painter->fillRect(QRect(x, y, w, h), QBrush(mHardwareBreakpointBackgroundColor)); //fill ?
272278
}
273279
}
274280
}
275281
else //bookmark, no label
276282
{
277283
if(bpxtype == bp_none) //bookmark only
278284
{
279-
painter->setPen(QPen(ConfigColor("DisassemblyBookmarkColor"))); //black address
280-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyBookmarkBackgroundColor"))); //fill bookmark color
285+
painter->setPen(QPen(mBookmarkColor)); //black address
286+
painter->fillRect(QRect(x, y, w, h), QBrush(mBookmarkBackgroundColor)); //fill bookmark color
281287
}
282288
else //bookmark + breakpoint
283289
{
284-
QColor color = ConfigColor("DisassemblyBookmarkBackgroundColor");
290+
QColor color = mBookmarkBackgroundColor;
285291
if(!color.alpha()) //we don't want transparent text
286-
color = ConfigColor("DisassemblyAddressColor");
292+
color = mAddressColor;
287293
painter->setPen(QPen(color));
288294
if(bpxtype & bp_normal) //bookmark + normal breakpoint
289295
{
290-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyBreakpointBackgroundColor"))); //fill red
296+
painter->fillRect(QRect(x, y, w, h), QBrush(mBreakpointBackgroundColor)); //fill red
291297
}
292298
else if(bpxtype & bp_hardware) //bookmark + hardware breakpoint only
293299
{
294-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyHardwareBreakpointBackgroundColor"))); //fill red
300+
painter->fillRect(QRect(x, y, w, h), QBrush(mHardwareBreakpointBackgroundColor)); //fill red
295301
}
296302
else //other cases (bookmark + memory breakpoint in disassembly) -> do as normal
297303
{
298-
painter->setPen(QPen(ConfigColor("DisassemblyBookmarkColor"))); //black address (DisassemblySelectedAddressColor)
299-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyBookmarkBackgroundColor"))); //fill bookmark color
304+
painter->setPen(QPen(mBookmarkColor)); //black address
305+
painter->fillRect(QRect(x, y, w, h), QBrush(mBookmarkBackgroundColor)); //fill bookmark color
300306
}
301307
}
302308
}
@@ -339,8 +345,6 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
339345
int jumpsize = paintJumpsGraphic(painter, x + funcsize, y - 1, wRVA); //jump line
340346

341347
//draw bytes
342-
QColor bytesColor = ConfigColor("DisassemblyBytesColor");
343-
QColor patchedBytesColor = ConfigColor("DisassemblyModifiedBytesColor");
344348
QList<RichTextPainter::CustomRichText_t> richBytes;
345349
RichTextPainter::CustomRichText_t space;
346350
space.highlight = false;
@@ -354,7 +358,7 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
354358
if(i)
355359
richBytes.push_back(space);
356360
curByte.text = QString("%1").arg((unsigned char)(mInstBuffer.at(rowOffset).dump.at(i)), 2, 16, QChar('0')).toUpper();
357-
curByte.textColor = DbgFunctions()->PatchGet(cur_addr + i) ? patchedBytesColor : bytesColor;
361+
curByte.textColor = DbgFunctions()->PatchGet(cur_addr + i) ? mModifiedBytesColor : mBytesColor;
358362
richBytes.push_back(curByte);
359363
}
360364
RichTextPainter::paintRichText(painter, x, y, getColumnWidth(col), getRowHeight(), jumpsize + funcsize, &richBytes, getCharWidth());
@@ -417,14 +421,14 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
417421
QColor backgroundColor;
418422
if(comment[0] == '\1') //automatic comment
419423
{
420-
penColor = ConfigColor("DisassemblyAutoCommentColor");
421-
backgroundColor = ConfigColor("DisassemblyAutoCommentBackgroundColor");
424+
penColor = mAutoCommentColor;
425+
backgroundColor = mAutoCommentBackgroundColor;
422426
commentText = QString(comment + 1);
423427
}
424428
else //user comment
425429
{
426-
penColor = ConfigColor("DisassemblyCommentColor");
427-
backgroundColor = ConfigColor("DisassemblyCommentBackgroundColor");
430+
penColor = mCommentColor;
431+
backgroundColor = mCommentBackgroundColor;
428432
commentText = comment;
429433
}
430434
painter->setPen(penColor);
@@ -674,28 +678,27 @@ void Disassembly::keyPressEvent(QKeyEvent* event)
674678
*/
675679
dsint Disassembly::sliderMovedHook(int type, dsint value, dsint delta)
676680
{
677-
dsint wNewValue;
678681

679-
if(type == QAbstractSlider::SliderNoAction) // QAbstractSlider::SliderNoAction is used to disassembe at a specific address
680-
{
681-
wNewValue = value + delta;
682-
}
683-
else if(type == QAbstractSlider::SliderMove) // If it's a slider action, disassemble one instruction back and one instruction next in order to be aligned on a real instruction
682+
// QAbstractSlider::SliderNoAction is used to disassembe at a specific address
683+
if(type == QAbstractSlider::SliderNoAction)
684+
return value + delta;
685+
686+
// If it's a slider action, disassemble one instruction back and one instruction next in order to be aligned on a real instruction
687+
if(type == QAbstractSlider::SliderMove)
684688
{
689+
dsint wNewValue = 0;
690+
685691
if(value + delta > 0)
686692
{
687693
wNewValue = getInstructionRVA(value + delta, -1);
688694
wNewValue = getInstructionRVA(wNewValue, 1);
689695
}
690-
else
691-
wNewValue = 0;
692-
}
693-
else // For other actions, disassemble according to the delta
694-
{
695-
wNewValue = getInstructionRVA(value, delta);
696+
697+
return wNewValue;
696698
}
697699

698-
return wNewValue;
700+
// For other actions, disassemble according to the delta
701+
return getInstructionRVA(value, delta);
699702
}
700703

701704

src/gui/Src/BasicView/Disassembly.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,37 @@ public slots:
140140
// Configuration
141141
QColor mInstructionHighlightColor;
142142
QColor mSelectionColor;
143+
143144
QColor mCipBackgroundColor;
145+
QColor mCipColor;
146+
144147
QColor mBreakpointBackgroundColor;
145148
QColor mBreakpointColor;
146-
QColor mCipColor;
149+
147150
QColor mHardwareBreakpointBackgroundColor;
148151
QColor mHardwareBreakpointColor;
152+
149153
QColor mBookmarkBackgroundColor;
150154
QColor mBookmarkColor;
155+
151156
QColor mLabelColor;
152157
QColor mLabelBackgroundColor;
158+
153159
QColor mSelectedAddressBackgroundColor;
154160
QColor mSelectedAddressColor;
155161
QColor mAddressBackgroundColor;
156162
QColor mAddressColor;
157163

164+
QColor mBytesColor;
165+
QColor mModifiedBytesColor;
166+
167+
QColor mAutoCommentColor;
168+
QColor mAutoCommentBackgroundColor;
169+
170+
QColor mCommentColor;
171+
QColor mCommentBackgroundColor;
172+
173+
// Misc
158174
bool mRvaDisplayEnabled;
159175
duint mRvaDisplayBase;
160176
dsint mRvaDisplayPageBase;

0 commit comments

Comments
 (0)