2017-10-02 16:18:40 +00:00
|
|
|
#include "Dashboard.h"
|
|
|
|
#include "ui_Dashboard.h"
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/Helpers.h"
|
|
|
|
#include "common/JsonModel.h"
|
|
|
|
#include "common/JsonTreeItem.h"
|
|
|
|
#include "common/TempConfig.h"
|
2018-05-01 18:53:14 +00:00
|
|
|
#include "dialogs/VersionInfoDialog.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/MainWindow.h"
|
2018-11-10 09:17:52 +00:00
|
|
|
#include "CutterTreeView.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonDocument>
|
2017-04-13 15:14:02 +00:00
|
|
|
#include <QFile>
|
2017-04-25 23:30:36 +00:00
|
|
|
#include <QLayoutItem>
|
2018-03-17 19:26:51 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QTreeWidget>
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
Dashboard::Dashboard(MainWindow *main, QAction *action) :
|
|
|
|
CutterDockWidget(main, action),
|
|
|
|
ui(new Ui::Dashboard)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(updateContents()));
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 09:41:28 +00:00
|
|
|
Dashboard::~Dashboard() {}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void Dashboard::updateContents()
|
|
|
|
{
|
2018-02-10 22:31:15 +00:00
|
|
|
QJsonDocument docu = Core()->getFileInfo();
|
|
|
|
QJsonObject item = docu.object()["core"].toObject();
|
|
|
|
QJsonObject item2 = docu.object()["bin"].toObject();
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2019-03-25 09:24:18 +00:00
|
|
|
setPlainText(this->ui->fileEdit, item["file"].toString());
|
|
|
|
setPlainText(this->ui->formatEdit, item["format"].toString());
|
|
|
|
setPlainText(this->ui->modeEdit, item["mode"].toString());
|
|
|
|
setPlainText(this->ui->typeEdit, item["type"].toString());
|
|
|
|
setPlainText(this->ui->sizeEdit, qhelpers::formatBytecount(item["size"].toDouble()));
|
|
|
|
setPlainText(this->ui->fdEdit, QString::number(item["fd"].toDouble()));
|
|
|
|
|
|
|
|
setPlainText(this->ui->archEdit, item2["arch"].toString());
|
|
|
|
setPlainText(this->ui->langEdit, item2["lang"].toString().toUpper());
|
|
|
|
setPlainText(this->ui->classEdit, item2["class"].toString());
|
|
|
|
setPlainText(this->ui->machineEdit, item2["machine"].toString());
|
|
|
|
setPlainText(this->ui->osEdit, item2["os"].toString());
|
|
|
|
setPlainText(this->ui->subsysEdit, item2["subsys"].toString());
|
|
|
|
setPlainText(this->ui->endianEdit, item2["endian"].toString());
|
|
|
|
setPlainText(this->ui->compilationDateEdit, item2["compiled"].toString());
|
|
|
|
setPlainText(this->ui->compilerEdit, item2["compiler"].toString());
|
|
|
|
setPlainText(this->ui->bitsEdit, QString::number(item2["bits"].toDouble()));
|
2017-06-08 22:40:43 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!item2["relro"].isUndefined()) {
|
2019-03-23 10:54:34 +00:00
|
|
|
QString relro = item2["relro"].toString().section(QLatin1Char(' '), 0, 0);
|
2017-07-02 11:11:02 +00:00
|
|
|
relro[0] = relro[0].toUpper();
|
2019-03-25 09:24:18 +00:00
|
|
|
setPlainText(this->ui->relroEdit, relro);
|
2017-06-08 22:28:42 +00:00
|
|
|
}
|
2017-06-02 16:35:26 +00:00
|
|
|
|
2019-03-25 09:24:18 +00:00
|
|
|
setPlainText(this->ui->baddrEdit, RAddressString(item2["baddr"].toVariant().toULongLong()));
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2019-03-25 09:24:18 +00:00
|
|
|
// set booleans
|
|
|
|
setBool(this->ui->vaEdit, item2, "va");
|
|
|
|
setBool(this->ui->canaryEdit, item2, "canary");
|
|
|
|
setBool(this->ui->cryptoEdit, item2, "crypto");
|
|
|
|
setBool(this->ui->nxEdit, item2, "nx");
|
|
|
|
setBool(this->ui->picEdit, item2, "pic");
|
|
|
|
setBool(this->ui->staticEdit, item2, "static");
|
|
|
|
setBool(this->ui->strippedEdit, item2, "stripped");
|
|
|
|
setBool(this->ui->relocsEdit, item2, "relocs");
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2019-09-28 20:46:41 +00:00
|
|
|
// Add file hashes, analysis info and libraries
|
2019-03-24 09:39:54 +00:00
|
|
|
QJsonObject hashes = Core()->cmdj("itj").object();
|
2019-03-25 09:24:18 +00:00
|
|
|
setPlainText(ui->md5Edit, hashes["md5"].toString());
|
|
|
|
setPlainText(ui->sha1Edit, hashes["sha1"].toString());
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2019-09-28 20:46:41 +00:00
|
|
|
QJsonObject analinfo = Core()->cmdj("aaij").object();
|
|
|
|
setPlainText(ui->functionsLineEdit, QString::number(analinfo["fcns"].toInt()));
|
|
|
|
setPlainText(ui->xRefsLineEdit, QString::number(analinfo["xrefs"].toInt()));
|
|
|
|
setPlainText(ui->callsLineEdit, QString::number(analinfo["calls"].toInt()));
|
|
|
|
setPlainText(ui->stringsLineEdit, QString::number(analinfo["strings"].toInt()));
|
|
|
|
setPlainText(ui->symbolsLineEdit, QString::number(analinfo["symbols"].toInt()));
|
|
|
|
setPlainText(ui->importsLineEdit, QString::number(analinfo["imports"].toInt()));
|
|
|
|
setPlainText(ui->coverageLineEdit, QString::number(analinfo["covrage"].toInt()) + " bytes");
|
|
|
|
setPlainText(ui->codeSizeLineEdit, QString::number(analinfo["codesz"].toInt()) + " bytes");
|
|
|
|
setPlainText(ui->percentageLineEdit, QString::number(analinfo["percent"].toInt()) + "%");
|
|
|
|
|
2019-03-23 10:54:34 +00:00
|
|
|
QStringList libs = Core()->cmdList("il");
|
|
|
|
if (!libs.isEmpty()) {
|
|
|
|
libs.removeFirst();
|
|
|
|
libs.removeLast();
|
2017-04-03 08:21:45 +00:00
|
|
|
}
|
2017-04-25 23:30:36 +00:00
|
|
|
|
|
|
|
// dunno: why not label->setText(lines.join("\n")?
|
2018-03-21 20:32:32 +00:00
|
|
|
while (ui->verticalLayout_2->count() > 0) {
|
2017-04-25 23:30:36 +00:00
|
|
|
QLayoutItem *item = ui->verticalLayout_2->takeAt(0);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (item != nullptr) {
|
2017-04-25 23:30:36 +00:00
|
|
|
QWidget *w = item->widget();
|
2018-03-21 20:32:32 +00:00
|
|
|
if (w != nullptr) {
|
2017-04-25 23:30:36 +00:00
|
|
|
w->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-23 10:54:34 +00:00
|
|
|
for (const QString &lib : libs) {
|
2017-03-29 10:18:37 +00:00
|
|
|
QLabel *label = new QLabel(this);
|
|
|
|
label->setText(lib);
|
|
|
|
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2019-12-06 17:52:08 +00:00
|
|
|
label->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->verticalLayout_2->addWidget(label);
|
|
|
|
}
|
2017-04-25 23:30:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
QSpacerItem *spacer = new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding);
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->verticalLayout_2->addSpacerItem(spacer);
|
|
|
|
|
|
|
|
// Add entropy value
|
2018-05-04 10:50:57 +00:00
|
|
|
{
|
|
|
|
// Scope for TempConfig
|
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("io.va", false);
|
|
|
|
QString entropy = Core()->cmd("ph entropy $s @ 0").trimmed();
|
|
|
|
ui->lblEntropy->setText(entropy);
|
|
|
|
}
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
// Get stats for the graphs
|
2018-04-12 06:33:30 +00:00
|
|
|
QStringList stats = Core()->getStats();
|
2018-05-05 12:58:26 +00:00
|
|
|
|
|
|
|
// Check if signature info and version info available
|
2018-09-30 20:00:53 +00:00
|
|
|
if (Core()->getSignatureInfo().isEmpty()) {
|
2018-05-05 12:58:26 +00:00
|
|
|
ui->certificateButton->setEnabled(false);
|
|
|
|
}
|
2018-09-30 20:00:53 +00:00
|
|
|
if (Core()->getFileVersionInfo().isEmpty()) {
|
2018-05-05 12:58:26 +00:00
|
|
|
ui->versioninfoButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2018-03-17 19:26:51 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
void Dashboard::on_certificateButton_clicked()
|
|
|
|
{
|
2018-03-17 19:26:51 +00:00
|
|
|
static QDialog *viewDialog = nullptr;
|
2018-11-10 09:17:52 +00:00
|
|
|
static CutterTreeView *view = nullptr;
|
2018-03-17 19:26:51 +00:00
|
|
|
static JsonModel *model = nullptr;
|
|
|
|
static QString qstrCertificates;
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!viewDialog) {
|
2018-03-17 19:26:51 +00:00
|
|
|
viewDialog = new QDialog(this);
|
2018-11-10 09:17:52 +00:00
|
|
|
view = new CutterTreeView(viewDialog);
|
2018-03-17 19:26:51 +00:00
|
|
|
model = new JsonModel();
|
2018-05-05 12:58:26 +00:00
|
|
|
QJsonDocument qjsonCertificatesDoc = Core()->getSignatureInfo();
|
2018-03-17 19:26:51 +00:00
|
|
|
qstrCertificates = qjsonCertificatesDoc.toJson(QJsonDocument::Compact);
|
|
|
|
}
|
2018-05-05 12:58:26 +00:00
|
|
|
if (!viewDialog->isVisible()) {
|
|
|
|
std::string strCertificates = qstrCertificates.toUtf8().constData();
|
|
|
|
model->loadJson(QByteArray::fromStdString(strCertificates));
|
|
|
|
view->setModel(model);
|
|
|
|
view->expandAll();
|
|
|
|
view->resize(900, 600);
|
|
|
|
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
sizePolicy.setHorizontalStretch(0);
|
|
|
|
sizePolicy.setVerticalStretch(0);
|
|
|
|
sizePolicy.setHeightForWidth(view->sizePolicy().hasHeightForWidth());
|
|
|
|
viewDialog->setSizePolicy(sizePolicy);
|
|
|
|
viewDialog->setMinimumSize(QSize(900, 600));
|
|
|
|
viewDialog->setMaximumSize(QSize(900, 600));
|
|
|
|
viewDialog->setSizeGripEnabled(false);
|
|
|
|
viewDialog->setWindowTitle("Certificates");
|
|
|
|
viewDialog->show();
|
2018-03-21 20:32:32 +00:00
|
|
|
}
|
2018-04-12 06:33:30 +00:00
|
|
|
}
|
2018-05-01 18:53:14 +00:00
|
|
|
|
|
|
|
void Dashboard::on_versioninfoButton_clicked()
|
|
|
|
{
|
|
|
|
|
|
|
|
static QDialog *infoDialog = nullptr;
|
|
|
|
|
2018-09-30 20:00:53 +00:00
|
|
|
if (!infoDialog) {
|
2018-05-01 18:53:14 +00:00
|
|
|
infoDialog = new VersionInfoDialog(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!infoDialog->isVisible()) {
|
|
|
|
infoDialog->show();
|
|
|
|
}
|
|
|
|
}
|
2019-03-25 09:24:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the text of a QLineEdit. If no text, then "N/A" is set.
|
|
|
|
* @param textBox
|
|
|
|
* @param text
|
|
|
|
*/
|
|
|
|
void Dashboard::setPlainText(QLineEdit *textBox, const QString &text)
|
|
|
|
{
|
|
|
|
if (!text.isEmpty()) {
|
|
|
|
textBox->setText(text);
|
|
|
|
} else {
|
|
|
|
textBox->setText(tr("N/A"));
|
|
|
|
}
|
|
|
|
|
|
|
|
textBox->setCursorPosition(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the text of a QLineEdit as True, False or N/A if it does not exist
|
|
|
|
* @param textBox
|
|
|
|
* @param isTrue
|
|
|
|
*/
|
|
|
|
void Dashboard::setBool(QLineEdit *textBox, const QJsonObject &jsonObject, const QString &key)
|
|
|
|
{
|
|
|
|
if (jsonObject.contains(key)) {
|
|
|
|
if (jsonObject[key].toBool()) {
|
|
|
|
setPlainText(textBox, tr("True"));
|
|
|
|
} else {
|
|
|
|
setPlainText(textBox, tr("False"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setPlainText(textBox, tr("N/A"));
|
|
|
|
}
|
|
|
|
}
|