cutter/src/widgets/Dashboard.cpp

213 lines
6.6 KiB
C++
Raw Normal View History

#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"
#include "dialogs/VersionInfoDialog.h"
#include "core/MainWindow.h"
#include "CutterTreeView.h"
#include <QDebug>
#include <QJsonArray>
#include <QStringList>
#include <QJsonObject>
#include <QJsonDocument>
#include <QFile>
#include <QLayoutItem>
#include <QString>
#include <QMessageBox>
#include <QDialog>
#include <QTreeWidget>
Dashboard::Dashboard(MainWindow *main, QAction *action) :
CutterDockWidget(main, action),
ui(new Ui::Dashboard)
{
ui->setupUi(this);
connect(Core(), SIGNAL(refreshAll()), this, SLOT(updateContents()));
}
2017-10-02 09:41:28 +00:00
Dashboard::~Dashboard() {}
2017-04-09 19:55:06 +00:00
void Dashboard::updateContents()
{
QJsonDocument docu = Core()->getFileInfo();
QJsonObject item = docu.object()["core"].toObject();
QJsonObject item2 = docu.object()["bin"].toObject();
this->ui->fileEdit->setText(item["file"].toString());
this->ui->formatEdit->setText(item["format"].toString());
this->ui->modeEdit->setText(item["mode"].toString());
this->ui->typeEdit->setText(item["type"].toString());
2018-02-04 17:27:48 +00:00
this->ui->sizeEdit->setText(qhelpers::formatBytecount(item["size"].toDouble()));
2017-04-09 19:55:06 +00:00
this->ui->fdEdit->setText(QString::number(item["fd"].toDouble()));
this->ui->archEdit->setText(item2["arch"].toString());
this->ui->langEdit->setText(item2["lang"].toString().toUpper());
this->ui->classEdit->setText(item2["class"].toString());
this->ui->machineEdit->setText(item2["machine"].toString());
this->ui->osEdit->setText(item2["os"].toString());
this->ui->subsysEdit->setText(item2["subsys"].toString());
this->ui->endianEdit->setText(item2["endian"].toString());
this->ui->compiledEdit->setText(item2["compiled"].toString());
this->ui->compilerEdit->setText(item2["compiler"].toString());
2017-04-09 19:55:06 +00:00
this->ui->bitsEdit->setText(QString::number(item2["bits"].toDouble()));
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);
relro[0] = relro[0].toUpper();
this->ui->relroEdit->setText(relro);
}
2017-06-02 16:35:26 +00:00
2018-10-17 06:36:41 +00:00
this->ui->baddrEdit->setText(RAddressString(item2["baddr"].toVariant().toULongLong()));
2018-03-21 20:32:32 +00:00
if (item2["va"].toBool() == true) {
this->ui->vaEdit->setText("True");
2018-03-21 20:32:32 +00:00
} else {
this->ui->vaEdit->setText("False");
}
2018-03-21 20:32:32 +00:00
if (item2["canary"].toBool() == true) {
this->ui->canaryEdit->setText("True");
2018-03-21 20:32:32 +00:00
} else {
this->ui->canaryEdit->setText("False");
}
2018-03-21 20:32:32 +00:00
if (item2["crypto"].toBool() == true) {
this->ui->cryptoEdit->setText("True");
2018-03-21 20:32:32 +00:00
} else {
this->ui->cryptoEdit->setText("False");
}
2018-03-21 20:32:32 +00:00
if (item2["nx"].toBool() == true) {
this->ui->nxEdit->setText("True");
2018-03-21 20:32:32 +00:00
} else {
this->ui->nxEdit->setText("False");
}
2018-03-21 20:32:32 +00:00
if (item2["pic"].toBool() == true) {
this->ui->picEdit->setText("True");
2018-03-21 20:32:32 +00:00
} else {
this->ui->picEdit->setText("False");
}
2018-03-21 20:32:32 +00:00
if (item2["static"].toBool() == true) {
this->ui->staticEdit->setText("True");
2018-03-21 20:32:32 +00:00
} else {
this->ui->staticEdit->setText("False");
}
2018-03-21 20:32:32 +00:00
if (item2["stripped"].toBool() == true) {
this->ui->strippedEdit->setText("True");
2018-03-21 20:32:32 +00:00
} else {
this->ui->strippedEdit->setText("False");
}
2018-03-21 20:32:32 +00:00
if (item2["relocs"].toBool() == true) {
this->ui->relocsEdit->setText("True");
2018-03-21 20:32:32 +00:00
} else {
this->ui->relocsEdit->setText("False");
}
// Add file hashes and libraries
2019-03-24 09:39:54 +00:00
QJsonObject hashes = Core()->cmdj("itj").object();
ui->md5Edit->setText(hashes["md5"].toString());
ui->sha1Edit->setText(hashes["sha1"].toString());
2019-03-23 10:54:34 +00:00
QStringList libs = Core()->cmdList("il");
if (!libs.isEmpty()) {
libs.removeFirst();
libs.removeLast();
}
// dunno: why not label->setText(lines.join("\n")?
2018-03-21 20:32:32 +00:00
while (ui->verticalLayout_2->count() > 0) {
QLayoutItem *item = ui->verticalLayout_2->takeAt(0);
2018-03-21 20:32:32 +00:00
if (item != nullptr) {
QWidget *w = item->widget();
2018-03-21 20:32:32 +00:00
if (w != nullptr) {
w->deleteLater();
}
delete item;
}
}
2019-03-23 10:54:34 +00:00
for (const QString &lib : libs) {
QLabel *label = new QLabel(this);
label->setText(lib);
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
ui->verticalLayout_2->addWidget(label);
}
2017-04-09 19:55:06 +00:00
QSpacerItem *spacer = new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding);
ui->verticalLayout_2->addSpacerItem(spacer);
// Add entropy value
{
// Scope for TempConfig
TempConfig tempConfig;
tempConfig.set("io.va", false);
QString entropy = Core()->cmd("ph entropy $s @ 0").trimmed();
ui->lblEntropy->setText(entropy);
}
// Get stats for the graphs
2018-04-12 06:33:30 +00:00
QStringList stats = Core()->getStats();
// Check if signature info and version info available
2018-09-30 20:00:53 +00:00
if (Core()->getSignatureInfo().isEmpty()) {
ui->certificateButton->setEnabled(false);
}
2018-09-30 20:00:53 +00:00
if (Core()->getFileVersionInfo().isEmpty()) {
ui->versioninfoButton->setEnabled(false);
}
}
2018-03-21 20:32:32 +00:00
void Dashboard::on_certificateButton_clicked()
{
static QDialog *viewDialog = nullptr;
static CutterTreeView *view = nullptr;
static JsonModel *model = nullptr;
static QString qstrCertificates;
2018-03-21 20:32:32 +00:00
if (!viewDialog) {
viewDialog = new QDialog(this);
view = new CutterTreeView(viewDialog);
model = new JsonModel();
QJsonDocument qjsonCertificatesDoc = Core()->getSignatureInfo();
qstrCertificates = qjsonCertificatesDoc.toJson(QJsonDocument::Compact);
}
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
}
void Dashboard::on_versioninfoButton_clicked()
{
static QDialog *infoDialog = nullptr;
2018-09-30 20:00:53 +00:00
if (!infoDialog) {
infoDialog = new VersionInfoDialog(this);
}
if (!infoDialog->isVisible()) {
infoDialog->show();
}
}