Fix computing hashes and entropy of the file

This commit is contained in:
Anton Kochkov 2021-10-18 17:03:26 +08:00 committed by Anton Kochkov
parent e96c53aeeb
commit 0786f49842

View File

@ -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("<b>%1:</b>").arg(key.toUpper());
QString label = QString("<b>%1:</b>").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("<b>Entropy:</b>")), entropyLineEdit);
}
QJsonObject analinfo = Core()->cmdj("aaij").object();
setPlainText(ui->functionsLineEdit, QString::number(analinfo["fcns"].toInt()));
setPlainText(ui->xRefsLineEdit, QString::number(analinfo["xrefs"].toInt()));