New private method in Dashboard to display text (#1390)

This commit is contained in:
Romeu Gomes 2019-03-25 09:24:18 +00:00 committed by xarkes
parent 8d6622ac81
commit eac91ed9c8
3 changed files with 74 additions and 61 deletions

View File

@ -38,77 +38,46 @@ void Dashboard::updateContents()
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());
this->ui->sizeEdit->setText(qhelpers::formatBytecount(item["size"].toDouble()));
this->ui->fdEdit->setText(QString::number(item["fd"].toDouble()));
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()));
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());
this->ui->bitsEdit->setText(QString::number(item2["bits"].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()));
if (!item2["relro"].isUndefined()) {
QString relro = item2["relro"].toString().section(QLatin1Char(' '), 0, 0);
relro[0] = relro[0].toUpper();
this->ui->relroEdit->setText(relro);
setPlainText(this->ui->relroEdit, relro);
}
this->ui->baddrEdit->setText(RAddressString(item2["baddr"].toVariant().toULongLong()));
setPlainText(this->ui->baddrEdit, RAddressString(item2["baddr"].toVariant().toULongLong()));
if (item2["va"].toBool() == true) {
this->ui->vaEdit->setText("True");
} else {
this->ui->vaEdit->setText("False");
}
if (item2["canary"].toBool() == true) {
this->ui->canaryEdit->setText("True");
} else {
this->ui->canaryEdit->setText("False");
}
if (item2["crypto"].toBool() == true) {
this->ui->cryptoEdit->setText("True");
} else {
this->ui->cryptoEdit->setText("False");
}
if (item2["nx"].toBool() == true) {
this->ui->nxEdit->setText("True");
} else {
this->ui->nxEdit->setText("False");
}
if (item2["pic"].toBool() == true) {
this->ui->picEdit->setText("True");
} else {
this->ui->picEdit->setText("False");
}
if (item2["static"].toBool() == true) {
this->ui->staticEdit->setText("True");
} else {
this->ui->staticEdit->setText("False");
}
if (item2["stripped"].toBool() == true) {
this->ui->strippedEdit->setText("True");
} else {
this->ui->strippedEdit->setText("False");
}
if (item2["relocs"].toBool() == true) {
this->ui->relocsEdit->setText("True");
} else {
this->ui->relocsEdit->setText("False");
}
// 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");
// Add file hashes and libraries
QJsonObject hashes = Core()->cmdj("itj").object();
ui->md5Edit->setText(hashes["md5"].toString());
ui->sha1Edit->setText(hashes["sha1"].toString());
setPlainText(ui->md5Edit, hashes["md5"].toString());
setPlainText(ui->sha1Edit, hashes["sha1"].toString());
QStringList libs = Core()->cmdList("il");
if (!libs.isEmpty()) {
@ -210,3 +179,37 @@ void Dashboard::on_versioninfoButton_clicked()
infoDialog->show();
}
}
/**
* @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"));
}
}

View File

@ -4,6 +4,11 @@
#include <memory>
#include "CutterDockWidget.h"
QT_BEGIN_NAMESPACE
QT_FORWARD_DECLARE_CLASS(QLineEdit)
QT_FORWARD_DECLARE_CLASS(QJsonObject)
QT_END_NAMESPACE
class MainWindow;
namespace Ui {
@ -25,6 +30,8 @@ private slots:
private:
std::unique_ptr<Ui::Dashboard> ui;
void setPlainText(QLineEdit *textBox, const QString &text);
void setBool(QLineEdit *textBox, const QJsonObject &jsonObject, const QString &key);
};
#endif // DASHBOARD_H

View File

@ -827,7 +827,7 @@
</widget>
</item>
<item row="8" column="1">
<widget class="QLineEdit" name="compiledEdit">
<widget class="QLineEdit" name="compilationDateEdit">
<property name="text">
<string>--</string>
</property>
@ -860,6 +860,9 @@
<property name="frame">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>