File: DecompilerContextMenu.cpp

package info (click to toggle)
radare2-cutter 1.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,768 kB
  • sloc: cpp: 38,432; python: 507; sh: 505; xml: 115; makefile: 89; ansic: 10; javascript: 3
file content (600 lines) | stat: -rw-r--r-- 22,363 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
#include "DecompilerContextMenu.h"
#include "dialogs/preferences/PreferencesDialog.h"
#include "MainWindow.h"
#include "dialogs/BreakpointsDialog.h"
#include "dialogs/CommentsDialog.h"
#include "dialogs/EditVariablesDialog.h"
#include "dialogs/XrefsDialog.h"
#include "common/Configuration.h"

#include <QtCore>
#include <QShortcut>
#include <QJsonArray>
#include <QClipboard>
#include <QApplication>
#include <QPushButton>
#include <QInputDialog>

DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWindow)
    :   QMenu(parent),
        mainWindow(mainWindow),
        curHighlightedWord(QString()),
        offset(0),
        decompiledFunctionAddress(RVA_INVALID),
        isTogglingBreakpoints(false),
        annotationHere(nullptr),
        actionCopy(tr("Copy"), this),
        actionCopyInstructionAddress(tr("Copy instruction address (<address>)"), this),
        actionCopyReferenceAddress(tr("Copy address of [flag] (<address>)"), this),
        actionShowInSubmenu(tr("Show in"), this),
        actionAddComment(tr("Add Comment"), this),
        actionDeleteComment(tr("Delete comment"), this),
        actionRenameThingHere(tr("Rename function at cursor"), this),
        actionDeleteName(tr("Delete <name>"), this),
        actionEditFunctionVariables(tr("Edit variable <name of variable>"), this),
        actionXRefs(tr("Show X-Refs"), this),
        actionToggleBreakpoint(tr("Add/remove breakpoint"), this),
        actionAdvancedBreakpoint(tr("Advanced breakpoint"), this),
        breakpointsInLineMenu(new QMenu(this)),
        actionContinueUntil(tr("Continue until line"), this),
        actionSetPC(tr("Set PC"), this)
{
    setActionCopy(); // Sets all three copy actions
    addSeparator();

    setActionShowInSubmenu();
    copySeparator = addSeparator();

    setActionAddComment();
    setActionDeleteComment();

    setActionRenameThingHere();
    setActionDeleteName();

    setActionXRefs();

    setActionEditFunctionVariables();

    addSeparator();
    addBreakpointMenu();
    addDebugMenu();

    setShortcutContextInActions(this);

    connect(this, &DecompilerContextMenu::aboutToShow,
            this, &DecompilerContextMenu::aboutToShowSlot);
    connect(this, &DecompilerContextMenu::aboutToHide,
            this, &DecompilerContextMenu::aboutToHideSlot);
}

DecompilerContextMenu::~DecompilerContextMenu()
{
}

void DecompilerContextMenu::setAnnotationHere(RCodeAnnotation *annotation)
{
    annotationHere = annotation;
}

void DecompilerContextMenu::setCurHighlightedWord(QString word)
{
    curHighlightedWord = word;
}

void DecompilerContextMenu::setOffset(RVA newOffset)
{
    offset = newOffset;
}

void DecompilerContextMenu::setDecompiledFunctionAddress(RVA functionAddr)
{
    decompiledFunctionAddress = functionAddr;
}

void DecompilerContextMenu::setFirstOffsetInLine(RVA firstOffset)
{
    firstOffsetInLine = firstOffset;
}

RVA DecompilerContextMenu::getFirstOffsetInLine()
{
    return firstOffsetInLine;
}

void DecompilerContextMenu::setAvailableBreakpoints(QVector<RVA> offsetList)
{
    availableBreakpoints = offsetList;
}

void DecompilerContextMenu::setupBreakpointsInLineMenu()
{
    breakpointsInLineMenu->clear();
    for (auto curOffset : this->availableBreakpoints) {
        QAction *action = breakpointsInLineMenu->addAction(RAddressString(curOffset));
        connect(action, &QAction::triggered, this, [this, curOffset] {
            BreakpointsDialog::editBreakpoint(Core()->getBreakpointAt(curOffset),
                                              this);
        });
    }
}

void DecompilerContextMenu::setShortcutContextInActions(QMenu *menu)
{
    for (QAction *action : menu->actions()) {
        if (action->isSeparator()) {
            //Do nothing
        } else if (action->menu()) {
            setShortcutContextInActions(action->menu());
        } else {
            action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        }
    }
}

void DecompilerContextMenu::setIsTogglingBreakpoints(bool isToggling)
{
    isTogglingBreakpoints = isToggling;
}

bool DecompilerContextMenu::getIsTogglingBreakpoints()
{
    return isTogglingBreakpoints;
}

void DecompilerContextMenu::aboutToHideSlot()
{
    actionAddComment.setVisible(true);
    actionRenameThingHere.setVisible(true);
    actionRenameThingHere.setEnabled(true);
    actionDeleteName.setVisible(false);
    actionEditFunctionVariables.setVisible(true);
    actionEditFunctionVariables.setEnabled(true);
    actionXRefs.setVisible(true);
    setToolTipsVisible(false);
}

void DecompilerContextMenu::aboutToShowSlot()
{
    if (this->firstOffsetInLine != RVA_MAX) {
        actionShowInSubmenu.setVisible(true);
        QString comment = Core()->cmdRawAt("CC.", this->firstOffsetInLine);
        actionAddComment.setVisible(true);
        if (comment.isEmpty()) {
            actionDeleteComment.setVisible(false);
            actionAddComment.setText(tr("Add Comment"));
        } else {
            actionDeleteComment.setVisible(true);
            actionAddComment.setText(tr("Edit Comment"));
        }
    } else {
        actionShowInSubmenu.setVisible(false);
        actionAddComment.setVisible(false);
        actionDeleteComment.setVisible(false);
    }

    setupBreakpointsInLineMenu();

    // Only show debug options if we are currently debugging
    debugMenu->menuAction()->setVisible(Core()->currentlyDebugging);

    bool hasBreakpoint = !this->availableBreakpoints.isEmpty();
    int numberOfBreakpoints = this->availableBreakpoints.size();
    if (numberOfBreakpoints == 0) {
        actionToggleBreakpoint.setText(tr("Add breakpoint"));
    } else if (numberOfBreakpoints == 1) {
        actionToggleBreakpoint.setText(tr("Remove breakpoint"));
    } else {
        actionToggleBreakpoint.setText(tr("Remove all breakpoints in line"));
    }
    if (numberOfBreakpoints > 1) {
        actionAdvancedBreakpoint.setMenu(breakpointsInLineMenu);
    } else {
        actionAdvancedBreakpoint.setMenu(nullptr);
    }
    actionAdvancedBreakpoint.setText(hasBreakpoint ?
                                     tr("Edit breakpoint") : tr("Advanced breakpoint"));

    QString progCounterName = Core()->getRegisterName("PC").toUpper();
    actionSetPC.setText(tr("Set %1 here").arg(progCounterName));

    if (!annotationHere
            || annotationHere->type ==
            R_CODE_ANNOTATION_TYPE_CONSTANT_VARIABLE) { // If constant, don't show rename and targeted show-in
        actionRenameThingHere.setVisible(false);
        copySeparator->setVisible(false);
    } else {
        copySeparator->setVisible(true);
        if (annotationHere->type == R_CODE_ANNOTATION_TYPE_FUNCTION_NAME) {
            actionRenameThingHere.setText(tr("Rename function %1").arg(QString(
                                                                           annotationHere->reference.name)));
        } else if (annotationHere->type == R_CODE_ANNOTATION_TYPE_GLOBAL_VARIABLE) {
            RFlagItem *flagDetails = r_flag_get_i(Core()->core()->flags, annotationHere->reference.offset);
            if (flagDetails) {
                actionRenameThingHere.setText(tr("Rename %1").arg(QString(flagDetails->name)));
                actionDeleteName.setText(tr("Remove %1").arg(QString(flagDetails->name)));
                actionDeleteName.setVisible(true);
            } else {
                actionRenameThingHere.setText(tr("Add name to %1").arg(curHighlightedWord));
            }
        }
    }
    actionCopyInstructionAddress.setText(tr("Copy instruction address (%1)").arg(RAddressString(
                                                                                     offset)));
    if (isReference()) {
        actionCopyReferenceAddress.setVisible(true);
        RVA referenceAddr = annotationHere->reference.offset;
        RFlagItem *flagDetails = r_flag_get_i(Core()->core()->flags, referenceAddr);
        if (annotationHere->type == R_CODE_ANNOTATION_TYPE_FUNCTION_NAME) {
            actionCopyReferenceAddress.setText(tr("Copy address of %1 (%2)").arg
                                               (QString(annotationHere->reference.name), RAddressString(referenceAddr)));
        } else if (flagDetails) {
            actionCopyReferenceAddress.setText(tr("Copy address of %1 (%2)").arg
                                               (flagDetails->name, RAddressString(referenceAddr)));
        } else {
            actionCopyReferenceAddress.setText(tr("Copy address (%1)").arg(RAddressString(referenceAddr)));
        }
    } else {
        actionXRefs.setVisible(false);
        actionCopyReferenceAddress.setVisible(false);
    }
    if (actionShowInSubmenu.menu() != nullptr) {
        actionShowInSubmenu.menu()->deleteLater();
    }
    actionShowInSubmenu.setMenu(mainWindow->createShowInMenu(this, offset));
    updateTargetMenuActions();

    if (!isFunctionVariable()) {
        actionEditFunctionVariables.setVisible(false);
    } else {
        actionEditFunctionVariables.setText(tr("Edit variable %1").arg(QString(
                                                                           annotationHere->variable.name)));
        actionRenameThingHere.setText(tr("Rename variable %1").arg(QString(annotationHere->variable.name)));
        if (!variablePresentInR2()) {
            actionEditFunctionVariables.setDisabled(true);
            actionRenameThingHere.setDisabled(true);
            setToolTipsVisible(true);
        }
    }
}

// Set up actions

void DecompilerContextMenu::setActionCopy() // Set all three copy actions
{
    connect(&actionCopy, &QAction::triggered, this, &DecompilerContextMenu::actionCopyTriggered);
    addAction(&actionCopy);
    actionCopy.setShortcut(QKeySequence::Copy);

    connect(&actionCopyInstructionAddress, &QAction::triggered, this,
            &DecompilerContextMenu::actionCopyInstructionAddressTriggered);
    addAction(&actionCopyInstructionAddress);

    connect(&actionCopyReferenceAddress, &QAction::triggered, this,
            &DecompilerContextMenu::actionCopyReferenceAddressTriggered);
    addAction(&actionCopyReferenceAddress);
    actionCopyReferenceAddress.setShortcut({Qt::CTRL + Qt::SHIFT + Qt::Key_C});
}

void DecompilerContextMenu::setActionShowInSubmenu()
{
    addAction(&actionShowInSubmenu);
}

void DecompilerContextMenu::setActionAddComment()
{
    connect(&actionAddComment, &QAction::triggered, this,
            &DecompilerContextMenu::actionAddCommentTriggered);
    addAction(&actionAddComment);
    actionAddComment.setShortcut(Qt::Key_Semicolon);
}

void DecompilerContextMenu::setActionDeleteComment()
{
    connect(&actionDeleteComment, &QAction::triggered, this,
            &DecompilerContextMenu::actionDeleteCommentTriggered);
    addAction(&actionDeleteComment);
}

void DecompilerContextMenu::setActionXRefs()
{
    connect(&actionXRefs, &QAction::triggered, this, &DecompilerContextMenu::actionXRefsTriggered);
    addAction(&actionXRefs);
    actionXRefs.setShortcut(Qt::Key_X);
}

void DecompilerContextMenu::setActionRenameThingHere()
{
    actionRenameThingHere.setShortcut({Qt::Key_N});
    connect(&actionRenameThingHere, &QAction::triggered, this,
            &DecompilerContextMenu::actionRenameThingHereTriggered);
    addAction(&actionRenameThingHere);
    actionRenameThingHere.setToolTip(tr("Can't rename this variable.<br>"
                                        "Only local variables defined in disassembly can be renamed."));
}

void DecompilerContextMenu::setActionDeleteName()
{
    connect(&actionDeleteName, &QAction::triggered, this,
            &DecompilerContextMenu::actionDeleteNameTriggered);
    addAction(&actionDeleteName);
    actionDeleteName.setVisible(false);
}

void DecompilerContextMenu::setActionEditFunctionVariables()
{
    connect(&actionEditFunctionVariables, &QAction::triggered, this,
            &DecompilerContextMenu::actionEditFunctionVariablesTriggered);
    addAction(&actionEditFunctionVariables);
    actionEditFunctionVariables.setShortcut(Qt::Key_Y);
    actionEditFunctionVariables.setToolTip(tr("Can't edit this variable.<br>"
                                              "Only local variables defined in disassembly can be edited."));
}

void DecompilerContextMenu::setActionToggleBreakpoint()
{
    connect(&actionToggleBreakpoint, &QAction::triggered, this,
            &DecompilerContextMenu::actionToggleBreakpointTriggered);
    actionToggleBreakpoint.setShortcuts({Qt::Key_F2, Qt::CTRL + Qt::Key_B});
}

void DecompilerContextMenu::setActionAdvancedBreakpoint()
{
    connect(&actionAdvancedBreakpoint, &QAction::triggered, this,
            &DecompilerContextMenu::actionAdvancedBreakpointTriggered);
    actionAdvancedBreakpoint.setShortcut({Qt::CTRL + Qt::Key_F2});
}

void DecompilerContextMenu::setActionContinueUntil()
{
    connect(&actionContinueUntil, &QAction::triggered, this,
            &DecompilerContextMenu::actionContinueUntilTriggered);
}

void DecompilerContextMenu::setActionSetPC()
{
    connect(&actionSetPC, &QAction::triggered, this, &DecompilerContextMenu::actionSetPCTriggered);
}

// Set up action responses

void DecompilerContextMenu::actionCopyTriggered()
{
    emit copy();
}

void DecompilerContextMenu::actionCopyInstructionAddressTriggered()
{
    QClipboard *clipboard = QApplication::clipboard();
    clipboard->setText(RAddressString(offset));
}

void DecompilerContextMenu::actionCopyReferenceAddressTriggered()
{
    QClipboard *clipboard = QApplication::clipboard();
    clipboard->setText(RAddressString(annotationHere->reference.offset));
}

void DecompilerContextMenu::actionAddCommentTriggered()
{
    CommentsDialog::addOrEditComment(this->firstOffsetInLine, this);
}

void DecompilerContextMenu::actionDeleteCommentTriggered()
{
    Core()->delComment(this->firstOffsetInLine);
}

void DecompilerContextMenu::actionRenameThingHereTriggered()
{
    if (!annotationHere || annotationHere->type == R_CODE_ANNOTATION_TYPE_CONSTANT_VARIABLE) {
        return;
    }
    RCoreLocked core = Core()->core();
    bool ok;
    auto type = annotationHere->type;
    if (type == R_CODE_ANNOTATION_TYPE_FUNCTION_NAME) {
        QString currentName(annotationHere->reference.name);
        RVA func_addr = annotationHere->reference.offset;
        RAnalFunction *func = Core()->functionAt(func_addr);
        if (func == NULL) {
            QString function_name = QInputDialog::getText(this,
                                                          tr("Define this function at %2").arg(RAddressString(func_addr)),
                                                          tr("Function name:"), QLineEdit::Normal, currentName, &ok);
            if (ok && !function_name.isEmpty()) {
                Core()->createFunctionAt(func_addr, function_name);
            }
        } else {
            QString newName = QInputDialog::getText(this->mainWindow, tr("Rename function %2").arg(currentName),
                                                    tr("Function name:"), QLineEdit::Normal, currentName, &ok);
            if (ok && !newName.isEmpty()) {
                Core()->renameFunction(func_addr, newName);
            }
        }
    } else if (type == R_CODE_ANNOTATION_TYPE_GLOBAL_VARIABLE) {
        RVA var_addr = annotationHere->reference.offset;
        RFlagItem *flagDetails = r_flag_get_i(core->flags, var_addr);
        if (flagDetails) {
            QString newName = QInputDialog::getText(this, tr("Rename %2").arg(flagDetails->name),
                                                    tr("Enter name"), QLineEdit::Normal, flagDetails->name, &ok);
            if (ok && !newName.isEmpty()) {
                Core()->renameFlag(flagDetails->name, newName);
            }
        } else {
            QString newName = QInputDialog::getText(this, tr("Add name to %2").arg(curHighlightedWord),
                                                    tr("Enter name"), QLineEdit::Normal, curHighlightedWord, &ok);
            if (ok && !newName.isEmpty()) {
                Core()->addFlag(var_addr, newName, 1);
            }
        }
    } else if (isFunctionVariable()) {
        if (!variablePresentInR2()) {
            // Show can't rename this variable dialog
            QMessageBox::critical(this, tr("Rename local variable %1").arg(QString(
                                                                               annotationHere->variable.name)),
                                  tr("Can't rename this variable. "
                                     "Only local variables defined in disassembly can be renamed."));
            return;
        }
        QString oldName(annotationHere->variable.name);
        QString newName = QInputDialog::getText(this, tr("Rename %2").arg(oldName),
                                                tr("Enter name"), QLineEdit::Normal, oldName, &ok);
        if (ok && !newName.isEmpty()) {
            Core()->renameFunctionVariable(newName, oldName, decompiledFunctionAddress);
        }
    }
}

void DecompilerContextMenu::actionDeleteNameTriggered()
{
    Core()->delFlag(annotationHere->reference.offset);
}

void DecompilerContextMenu::actionEditFunctionVariablesTriggered()
{
    if (!isFunctionVariable()) {
        return;
    } else if (!variablePresentInR2()) {
        QMessageBox::critical(this, tr("Edit local variable %1").arg(QString(
                                                                         annotationHere->variable.name)),
                              tr("Can't edit this variable. "
                                 "Only local variables defined in disassembly can be edited."));
        return;
    }
    EditVariablesDialog dialog(decompiledFunctionAddress, QString(annotationHere->variable.name), this);
    dialog.exec();
}

void DecompilerContextMenu::actionXRefsTriggered()
{
    if (!isReference()) {
        return;
    }
    XrefsDialog dialog(mainWindow, nullptr);
    QString displayString = (annotationHere->type == R_CODE_ANNOTATION_TYPE_FUNCTION_NAME) ? QString(
                                annotationHere->reference.name) : RAddressString(annotationHere->reference.offset);
    dialog.fillRefsForAddress(annotationHere->reference.offset, displayString, false);
    dialog.exec();
}

void DecompilerContextMenu::actionToggleBreakpointTriggered()
{
    if (!this->availableBreakpoints.isEmpty()) {
        setIsTogglingBreakpoints(true);
        for (auto offsetToRemove : this->availableBreakpoints) {
            Core()->toggleBreakpoint(offsetToRemove);
        }
        this->availableBreakpoints.clear();
        setIsTogglingBreakpoints(false);
        return;
    }
    if (this->firstOffsetInLine == RVA_MAX)
        return;

    Core()->toggleBreakpoint(this->firstOffsetInLine);
}

void DecompilerContextMenu::actionAdvancedBreakpointTriggered()
{
    if (!availableBreakpoints.empty()) {
        // Edit the earliest breakpoint in the line
        BreakpointsDialog::editBreakpoint(Core()->getBreakpointAt(this->availableBreakpoints.first()),
                                          this);
    } else {
        // Add a breakpoint to the earliest offset in the line
        BreakpointsDialog::createNewBreakpoint(this->firstOffsetInLine, this);
    }
}

void DecompilerContextMenu::actionContinueUntilTriggered()
{
    Core()->continueUntilDebug(RAddressString(offset));
}

void DecompilerContextMenu::actionSetPCTriggered()
{
    QString progCounterName = Core()->getRegisterName("PC");
    Core()->setRegister(progCounterName, RAddressString(offset).toUpper());
}

// Set up menus

void DecompilerContextMenu::addBreakpointMenu()
{
    breakpointMenu = addMenu(tr("Breakpoint"));

    setActionToggleBreakpoint();
    breakpointMenu->addAction(&actionToggleBreakpoint);
    setActionAdvancedBreakpoint();
    breakpointMenu->addAction(&actionAdvancedBreakpoint);
}

void DecompilerContextMenu::addDebugMenu()
{
    debugMenu = addMenu(tr("Debug"));

    setActionContinueUntil();
    debugMenu->addAction(&actionContinueUntil);
    setActionSetPC();
    debugMenu->addAction(&actionSetPC);
}

void DecompilerContextMenu::updateTargetMenuActions()
{
    for (auto action : showTargetMenuActions) {
        removeAction(action);
        auto menu = action->menu();
        if (menu) {
            menu->deleteLater();
        }
        action->deleteLater();
    }
    showTargetMenuActions.clear();
    RCoreLocked core = Core()->core();
    if (isReference()) {
        QString name;
        QMenu *menu;
        if (annotationHere->type == R_CODE_ANNOTATION_TYPE_GLOBAL_VARIABLE
                || annotationHere->type == R_CODE_ANNOTATION_TYPE_CONSTANT_VARIABLE) {
            menu = mainWindow->createShowInMenu(this, annotationHere->reference.offset,
                                                MainWindow::AddressTypeHint::Data);
            RVA var_addr = annotationHere->reference.offset;
            RFlagItem *flagDetails = r_flag_get_i(core->flags, var_addr);
            if (flagDetails) {
                name = tr("Show %1 in").arg(flagDetails->name);
            } else {
                name = tr("Show %1 in").arg(RAddressString(annotationHere->reference.offset));
            }
        } else if (annotationHere->type == R_CODE_ANNOTATION_TYPE_FUNCTION_NAME) {
            menu = mainWindow->createShowInMenu(this, annotationHere->reference.offset,
                                                MainWindow::AddressTypeHint::Function);
            name = tr("%1 (%2)").arg(QString(annotationHere->reference.name),
                                     RAddressString(annotationHere->reference.offset));
        }
        auto action = new QAction(name, this);
        showTargetMenuActions.append(action);
        action->setMenu(menu);
        insertActions(copySeparator, showTargetMenuActions);
    }
}

bool DecompilerContextMenu::isReference()
{
    return (annotationHere && r_annotation_is_reference(annotationHere));
}

bool DecompilerContextMenu::isFunctionVariable()
{
    return (annotationHere && r_annotation_is_variable(annotationHere));
}

bool DecompilerContextMenu::variablePresentInR2()
{
    QString variableName(annotationHere->variable.name);
    QList<VariableDescription> variables = Core()->getVariables(offset);
    for (const VariableDescription &var : variables) {
        if (var.name == variableName) {
            return true;
        }
    }
    return false;
}