From 0786f49842adf7de827c3d1e377e0ab8e5268af4 Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Mon, 18 Oct 2021 17:03:26 +0800 Subject: [PATCH] Fix computing hashes and entropy of the file --- src/widgets/Dashboard.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/widgets/Dashboard.cpp b/src/widgets/Dashboard.cpp index 6f547e4b..c641b8b0 100644 --- a/src/widgets/Dashboard.cpp +++ b/src/widgets/Dashboard.cpp @@ -75,8 +75,9 @@ void Dashboard::updateContents() setBool(this->ui->relocsEdit, item2, "relocs"); // Add file hashes, analysis info and libraries - - QJsonObject hashes = Core()->cmdj("itj").object(); + RzCoreLocked core(Core()); + RzBinFile *bf = rz_bin_cur(core->bin); + RzList *hashes = rz_bin_file_compute_hashes(core->bin, bf, UT64_MAX); // Delete hashesWidget if it isn't null to avoid duplicate components if (hashesWidget) { @@ -90,14 +91,16 @@ void Dashboard::updateContents() ui->hashesVerticalLayout->addWidget(hashesWidget); // Add hashes as a pair of Hash Name : Hash Value. - for (const QString &key : hashes.keys()) { + RzListIter *iter; + RzBinFileHash *hash; + CutterRzListForeach (hashes, iter, RzBinFileHash, hash) { // Create a bold QString with the hash name uppercased - QString label = QString("%1:").arg(key.toUpper()); + QString label = QString("%1:").arg(QString(hash->type).toUpper()); // Define a Read-Only line edit to display the hash value QLineEdit *hashLineEdit = new QLineEdit(); hashLineEdit->setReadOnly(true); - hashLineEdit->setText(hashes.value(key).toString()); + hashLineEdit->setText(hash->hex); // Set cursor position to begining to avoid long hashes (e.g sha256) // to look truncated at the begining @@ -107,23 +110,6 @@ void Dashboard::updateContents() hashesLayout->addRow(new QLabel(label), hashLineEdit); } - // Add the Entropy value of the file to the dashboard - { - // Scope for TempConfig - TempConfig tempConfig; - tempConfig.set("io.va", false); - - // Calculate the Entropy of the entire binary from offset 0 to $s - // where $s is the size of the entire file - QString entropy = Core()->cmdRawAt("ph entropy $s", 0).trimmed(); - - // Define a Read-Only line edit to display the entropy value - QLineEdit *entropyLineEdit = new QLineEdit(); - entropyLineEdit->setReadOnly(true); - entropyLineEdit->setText(entropy); - hashesLayout->addRow(new QLabel(tr("Entropy:")), entropyLineEdit); - } - QJsonObject analinfo = Core()->cmdj("aaij").object(); setPlainText(ui->functionsLineEdit, QString::number(analinfo["fcns"].toInt())); setPlainText(ui->xRefsLineEdit, QString::number(analinfo["xrefs"].toInt()));