2017-10-12 19:55:15 +00:00
|
|
|
#include "SidebarWidget.h"
|
|
|
|
#include "ui_SidebarWidget.h"
|
|
|
|
#include "DisassemblerGraphView.h"
|
|
|
|
|
|
|
|
#include "utils/Helpers.h"
|
2017-11-20 20:11:56 +00:00
|
|
|
#include "utils/TempConfig.h"
|
2017-10-12 19:55:15 +00:00
|
|
|
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QFontDialog>
|
|
|
|
#include <QScrollBar>
|
|
|
|
#include <QShortcut>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QSettings>
|
2018-04-18 09:13:08 +00:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
2017-10-12 19:55:15 +00:00
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
SidebarWidget::SidebarWidget(MainWindow *main, QAction *action) :
|
2018-03-21 20:32:32 +00:00
|
|
|
CutterDockWidget(main, action),
|
|
|
|
ui(new Ui::SidebarWidget)
|
2017-10-12 19:55:15 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
// Add margin to function name line edit
|
|
|
|
ui->fcnNameEdit->setTextMargins(5, 0, 0, 0);
|
|
|
|
|
|
|
|
setScrollMode();
|
2017-11-19 12:56:10 +00:00
|
|
|
|
|
|
|
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
|
|
|
|
connect(Core(), SIGNAL(flagsChanged()), this, SLOT(refresh()));
|
|
|
|
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refresh()));
|
|
|
|
connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refresh()));
|
|
|
|
|
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refresh()));
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SidebarWidget::~SidebarWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SidebarWidget::on_seekChanged(RVA addr)
|
|
|
|
{
|
|
|
|
refresh(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SidebarWidget::refresh(RVA addr)
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (addr == RVA_INVALID)
|
2017-11-19 12:56:10 +00:00
|
|
|
addr = Core()->getOffset();
|
2017-10-12 19:55:15 +00:00
|
|
|
|
2017-12-20 22:50:26 +00:00
|
|
|
updateRefs(addr);
|
2017-10-12 19:55:15 +00:00
|
|
|
setFcnName(addr);
|
|
|
|
fillOffsetInfo(RAddressString(addr));
|
2018-04-18 09:13:08 +00:00
|
|
|
fillRegistersInfo();
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 07:54:06 +00:00
|
|
|
void SidebarWidget::on_xrefFromTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
2017-11-26 13:40:24 +00:00
|
|
|
{
|
2018-04-23 07:54:06 +00:00
|
|
|
if (column < 0)
|
|
|
|
return;
|
|
|
|
|
2017-11-26 13:40:24 +00:00
|
|
|
XrefDescription xref = item->data(0, Qt::UserRole).value<XrefDescription>();
|
|
|
|
Core()->seek(xref.to);
|
|
|
|
}
|
|
|
|
|
2018-04-23 07:54:06 +00:00
|
|
|
void SidebarWidget::on_xrefToTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
2017-11-26 13:40:24 +00:00
|
|
|
{
|
2018-04-23 07:54:06 +00:00
|
|
|
if (column < 0)
|
|
|
|
return;
|
|
|
|
|
2017-11-26 13:40:24 +00:00
|
|
|
XrefDescription xref = item->data(0, Qt::UserRole).value<XrefDescription>();
|
|
|
|
Core()->seek(xref.from);
|
|
|
|
}
|
2017-10-12 19:55:15 +00:00
|
|
|
|
|
|
|
void SidebarWidget::on_offsetToolButton_clicked()
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (ui->offsetToolButton->isChecked()) {
|
2017-10-12 19:55:15 +00:00
|
|
|
ui->offsetTreeWidget->hide();
|
|
|
|
ui->offsetToolButton->setArrowType(Qt::RightArrow);
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2017-10-12 19:55:15 +00:00
|
|
|
ui->offsetTreeWidget->show();
|
|
|
|
ui->offsetToolButton->setArrowType(Qt::DownArrow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 13:40:24 +00:00
|
|
|
void SidebarWidget::on_opcodeDescToolButton_clicked()
|
2017-10-12 19:55:15 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (ui->opcodeDescToolButton->isChecked()) {
|
2017-11-26 13:40:24 +00:00
|
|
|
ui->opcodeDescText->hide();
|
|
|
|
ui->opcodeDescToolButton->setArrowType(Qt::RightArrow);
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2017-11-26 13:40:24 +00:00
|
|
|
ui->opcodeDescText->show();
|
|
|
|
ui->opcodeDescToolButton->setArrowType(Qt::DownArrow);
|
|
|
|
}
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
2017-11-26 13:40:24 +00:00
|
|
|
void SidebarWidget::on_xrefFromToolButton_clicked()
|
2017-10-12 19:55:15 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (ui->xrefFromToolButton->isChecked()) {
|
2017-11-26 13:40:24 +00:00
|
|
|
ui->xrefFromTreeWidget->hide();
|
|
|
|
ui->xrefFromToolButton->setArrowType(Qt::RightArrow);
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2017-11-26 13:40:24 +00:00
|
|
|
ui->xrefFromTreeWidget->show();
|
|
|
|
ui->xrefFromToolButton->setArrowType(Qt::DownArrow);
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 13:40:24 +00:00
|
|
|
void SidebarWidget::on_xrefToToolButton_clicked()
|
2017-10-12 19:55:15 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (ui->xrefToToolButton->isChecked()) {
|
2017-11-26 13:40:24 +00:00
|
|
|
ui->xrefToTreeWidget->hide();
|
|
|
|
ui->xrefToToolButton->setArrowType(Qt::RightArrow);
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2017-11-26 13:40:24 +00:00
|
|
|
ui->xrefToTreeWidget->show();
|
|
|
|
ui->xrefToToolButton->setArrowType(Qt::DownArrow);
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 09:13:08 +00:00
|
|
|
void SidebarWidget::on_regInfoToolButton_clicked()
|
|
|
|
{
|
|
|
|
if (ui->regInfoToolButton->isChecked()) {
|
|
|
|
ui->regInfoTreeWidget->hide();
|
|
|
|
ui->regInfoToolButton->setArrowType(Qt::RightArrow);
|
|
|
|
} else {
|
|
|
|
ui->regInfoTreeWidget->show();
|
|
|
|
ui->regInfoToolButton->setArrowType(Qt::DownArrow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 22:50:26 +00:00
|
|
|
void SidebarWidget::updateRefs(RVA addr)
|
2017-10-12 19:55:15 +00:00
|
|
|
{
|
|
|
|
// refs = calls q hace esa funcion
|
2017-11-19 12:56:10 +00:00
|
|
|
QList<XrefDescription> refs = Core()->getXRefs(addr, false, false);
|
2017-10-12 19:55:15 +00:00
|
|
|
|
|
|
|
// xrefs = calls a esa funcion
|
2017-11-19 12:56:10 +00:00
|
|
|
QList<XrefDescription> xrefs = Core()->getXRefs(addr, true, false);
|
2017-10-12 19:55:15 +00:00
|
|
|
|
|
|
|
// Update disasm side bar
|
2017-12-20 22:50:26 +00:00
|
|
|
this->fillRefs(refs, xrefs);
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 22:50:26 +00:00
|
|
|
void SidebarWidget::fillRefs(QList<XrefDescription> refs, QList<XrefDescription> xrefs)
|
2017-10-12 19:55:15 +00:00
|
|
|
{
|
2017-11-20 20:11:56 +00:00
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("scr.html", false)
|
2018-03-21 20:32:32 +00:00
|
|
|
.set("scr.color", COLOR_MODE_DISABLED);
|
2017-11-20 20:11:56 +00:00
|
|
|
|
2017-11-26 13:40:24 +00:00
|
|
|
ui->xrefFromTreeWidget->clear();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int i = 0; i < refs.size(); ++i) {
|
2017-10-12 19:55:15 +00:00
|
|
|
XrefDescription xref = refs[i];
|
|
|
|
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
2017-11-28 11:26:52 +00:00
|
|
|
tempItem->setText(0, xref.to_str);
|
2017-11-28 11:22:48 +00:00
|
|
|
tempItem->setText(1, Core()->disassembleSingleInstruction(xref.to));
|
2017-10-12 19:55:15 +00:00
|
|
|
tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref));
|
2017-11-19 12:56:10 +00:00
|
|
|
QString tooltip = Core()->cmd("pdi 10 @ " + QString::number(xref.to)).trimmed();
|
2017-10-12 19:55:15 +00:00
|
|
|
tempItem->setToolTip(0, tooltip);
|
|
|
|
tempItem->setToolTip(1, tooltip);
|
2017-11-26 13:40:24 +00:00
|
|
|
ui->xrefFromTreeWidget->insertTopLevelItem(0, tempItem);
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
// Adjust columns to content
|
2018-04-01 08:25:31 +00:00
|
|
|
qhelpers::adjustColumns(ui->xrefFromTreeWidget, 0);
|
2017-10-12 19:55:15 +00:00
|
|
|
|
2017-11-26 13:40:24 +00:00
|
|
|
ui->xrefToTreeWidget->clear();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int i = 0; i < xrefs.size(); ++i) {
|
2017-10-12 19:55:15 +00:00
|
|
|
XrefDescription xref = xrefs[i];
|
|
|
|
|
|
|
|
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
2017-11-28 11:26:52 +00:00
|
|
|
tempItem->setText(0, xref.from_str);
|
2017-11-19 12:56:10 +00:00
|
|
|
tempItem->setText(1, Core()->disassembleSingleInstruction(xref.from));
|
2017-10-12 19:55:15 +00:00
|
|
|
tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref));
|
2017-11-19 12:56:10 +00:00
|
|
|
QString tooltip = Core()->cmd("pdi 10 @ " + QString::number(xref.from)).trimmed();
|
2017-10-12 19:55:15 +00:00
|
|
|
|
|
|
|
// TODO wtf is this?
|
|
|
|
//tempItem->setToolTip(0, this->core->cmd("pdi 10 @ " + tooltip).trimmed());
|
|
|
|
//tempItem->setToolTip(1, this->core->cmd("pdi 10 @ " + tooltip).trimmed());
|
|
|
|
|
2017-11-26 13:40:24 +00:00
|
|
|
ui->xrefToTreeWidget->insertTopLevelItem(0, tempItem);
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
// Adjust columns to content
|
2018-04-01 08:25:31 +00:00
|
|
|
qhelpers::adjustColumns(ui->xrefToTreeWidget, 0);
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SidebarWidget::fillOffsetInfo(QString off)
|
|
|
|
{
|
2017-11-20 20:11:56 +00:00
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("scr.html", false)
|
2018-03-21 20:32:32 +00:00
|
|
|
.set("scr.color", COLOR_MODE_DISABLED);
|
2017-11-20 20:11:56 +00:00
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
ui->offsetTreeWidget->clear();
|
2018-10-17 06:36:41 +00:00
|
|
|
QString raw = Core()->cmd(QString("ao@") + off).trimmed();
|
2017-10-12 19:55:15 +00:00
|
|
|
QList<QString> lines = raw.split("\n", QString::SkipEmptyParts);
|
2018-05-04 07:58:32 +00:00
|
|
|
for (QString line : lines) {
|
2018-03-21 20:32:32 +00:00
|
|
|
QList<QString> eles = line.split(":", QString::SkipEmptyParts);
|
2018-10-17 06:36:41 +00:00
|
|
|
if (eles.length() < 2) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
|
|
|
tempItem->setText(0, eles.at(0).toUpper());
|
|
|
|
tempItem->setText(1, eles.at(1));
|
|
|
|
ui->offsetTreeWidget->insertTopLevelItem(0, tempItem);
|
|
|
|
}
|
2017-10-12 19:55:15 +00:00
|
|
|
|
|
|
|
// Adjust column to contents
|
2018-04-01 08:25:31 +00:00
|
|
|
qhelpers::adjustColumns(ui->offsetTreeWidget, 0);
|
2017-10-12 19:55:15 +00:00
|
|
|
|
|
|
|
// Add opcode description
|
2018-07-04 00:15:20 +00:00
|
|
|
QStringList description = Core()->cmd("aod @ " + off).split(": ");
|
2018-03-21 20:32:32 +00:00
|
|
|
if (description.length() >= 2) {
|
2017-10-12 19:55:15 +00:00
|
|
|
ui->opcodeDescText->setPlainText("# " + description[0] + ":\n" + description[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SidebarWidget::setFcnName(RVA addr)
|
|
|
|
{
|
|
|
|
RAnalFunction *fcn;
|
|
|
|
QString addr_string;
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
fcn = Core()->functionAt(addr);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (fcn) {
|
2017-11-19 12:56:10 +00:00
|
|
|
QString segment = Core()->cmd("S. @ " + QString::number(addr)).split(" ").last();
|
2017-10-12 19:55:15 +00:00
|
|
|
addr_string = segment.trimmed() + ":" + fcn->name;
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2017-11-19 12:56:10 +00:00
|
|
|
addr_string = Core()->cmdFunctionAt(addr);
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui->fcnNameEdit->setText(addr_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SidebarWidget::setScrollMode()
|
|
|
|
{
|
2017-11-26 13:40:24 +00:00
|
|
|
qhelpers::setVerticalScrollMode(ui->xrefFromTreeWidget);
|
|
|
|
qhelpers::setVerticalScrollMode(ui->xrefToTreeWidget);
|
2017-10-24 08:18:16 +00:00
|
|
|
}
|
2018-04-18 09:13:08 +00:00
|
|
|
|
|
|
|
void SidebarWidget::fillRegistersInfo()
|
|
|
|
{
|
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("scr.html", false)
|
|
|
|
.set("scr.color", COLOR_MODE_DISABLED);
|
|
|
|
|
|
|
|
ui->regInfoTreeWidget->clear();
|
|
|
|
|
|
|
|
QJsonObject jsonRoot = Core()->getRegistersInfo().object();
|
2018-05-04 07:58:32 +00:00
|
|
|
for (QString key : jsonRoot.keys()) {
|
2018-04-18 09:13:08 +00:00
|
|
|
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
|
|
|
QString tempString;
|
|
|
|
tempItem->setText(0, key.toUpper());
|
2018-05-04 07:58:32 +00:00
|
|
|
for (QJsonValue value : jsonRoot[key].toArray()) {
|
2018-04-18 09:13:08 +00:00
|
|
|
tempString.append(value.toString() + " ");
|
|
|
|
}
|
|
|
|
tempItem->setText(1, tempString);
|
|
|
|
ui->regInfoTreeWidget->addTopLevelItem(tempItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust columns to content
|
|
|
|
qhelpers::adjustColumns(ui->regInfoTreeWidget, 0);
|
|
|
|
}
|