Convert to rizin APIs (#2973)

`rz_core_bin_get_compile_time`, `ij`/`CutterCore::getFileInfo()`,
`aaij`, `iVj`, `iEj`, `izzj`, `iMj`, `aeim-`, `aei-`, `tc`,
`rz_core_config_variable_spaces`, `o`, `oodf`
This commit is contained in:
billow 2022-07-02 21:49:13 +08:00 committed by GitHub
parent 91fce8220b
commit e4db94eb87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 310 additions and 190 deletions

View File

@ -8,26 +8,18 @@
void openIssue() void openIssue()
{ {
RzCoreLocked core(Core());
RzBinFile *bf = rz_bin_cur(core->bin);
RzBinInfo *info = rz_bin_get_info(core->bin);
RzBinPlugin *plugin = rz_bin_file_cur_plugin(bf);
QString url, osInfo, format, arch, type; QString url, osInfo, format, arch, type;
// Pull in info needed for git issue // Pull in info needed for git issue
osInfo = QSysInfo::productType() + " " osInfo = QSysInfo::productType() + " "
+ (QSysInfo::productVersion() == "unknown" ? "" : QSysInfo::productVersion()); + (QSysInfo::productVersion() == "unknown" ? "" : QSysInfo::productVersion());
CutterJson docu = Core()->getFileInfo(); format = plugin && RZ_STR_ISNOTEMPTY(plugin->name) ? plugin->name : "N/A";
CutterJson coreObj = docu["core"]; arch = info && RZ_STR_ISNOTEMPTY(info->arch) ? info->arch : "N/A";
CutterJson binObj = docu["bin"]; type = info && RZ_STR_ISNOTEMPTY(info->type) ? info->type : "N/A";
if (binObj.size()) {
format = coreObj["format"].toString();
arch = binObj["arch"].toString();
if (binObj["type"].valid()) {
type = coreObj["type"].toString();
} else {
type = "N/A";
}
} else {
format = coreObj["format"].toString();
arch = "N/A";
type = "N/A";
}
url = "https://github.com/rizinorg/cutter/issues/new?&body=**Environment information**\n* " url = "https://github.com/rizinorg/cutter/issues/new?&body=**Environment information**\n* "
"Operating System: " "Operating System: "
+ osInfo + "\n* Cutter version: " + CUTTER_VERSION_FULL + "\n* Obtained from:\n" + osInfo + "\n* Cutter version: " + CUTTER_VERSION_FULL + "\n* Obtained from:\n"

View File

@ -681,7 +681,7 @@ bool CutterCore::mapFile(QString path, RVA mapaddr)
{ {
CORE_LOCK(); CORE_LOCK();
RVA addr = mapaddr != RVA_INVALID ? mapaddr : 0; RVA addr = mapaddr != RVA_INVALID ? mapaddr : 0;
ut64 baddr = Core()->getFileInfo()["bin"]["baddr"].toUt64(); ut64 baddr = rz_bin_get_baddr(core->bin);
if (rz_core_file_open(core, path.toUtf8().constData(), RZ_PERM_RX, addr)) { if (rz_core_file_open(core, path.toUtf8().constData(), RZ_PERM_RX, addr)) {
rz_core_bin_load(core, path.toUtf8().constData(), baddr); rz_core_bin_load(core, path.toUtf8().constData(), baddr);
} else { } else {
@ -1434,16 +1434,6 @@ bool CutterCore::registerDecompiler(Decompiler *decompiler)
return true; return true;
} }
CutterJson CutterCore::getFileInfo()
{
return cmdj("ij");
}
CutterJson CutterCore::getFileVersionInfo()
{
return cmdj("iVj");
}
QString CutterCore::getSignatureInfo() QString CutterCore::getSignatureInfo()
{ {
CORE_LOCK(); CORE_LOCK();
@ -1456,9 +1446,23 @@ QString CutterCore::getSignatureInfo()
if (!signature) { if (!signature) {
return {}; return {};
} }
auto sig = parseJson(signature, nullptr);
if (sig.size() == 0) {
return {};
}
return fromOwnedCharPtr(signature); return fromOwnedCharPtr(signature);
} }
bool CutterCore::existsFileInfo()
{
CORE_LOCK();
const RzBinInfo *info = rz_bin_get_info(core->bin);
if (!(info && info->rclass)) {
return false;
}
return strncmp("pe", info->rclass, 2) == 0 || strncmp("elf", info->rclass, 3) == 0;
}
// Utility function to check if a telescoped item exists and add it with prefixes to the desc // Utility function to check if a telescoped item exists and add it with prefixes to the desc
static inline const QString appendVar(QString &dst, const QString val, const QString prepend_val, static inline const QString appendVar(QString &dst, const QString val, const QString prepend_val,
const QString append_val) const QString append_val)
@ -2133,9 +2137,15 @@ void CutterCore::attachDebug(int pid)
offsetPriorDebugging = getOffset(); offsetPriorDebugging = getOffset();
} }
QString attach_command = currentlyOpenFile.isEmpty() ? "o" : "oodf"; CORE_LOCK();
// attach to process with dbg plugin setConfig("cfg.debug", true);
asyncCmd("e cfg.debug=true;" + attach_command + " dbg://" + QString::number(pid), debugTask); auto uri = rz_str_newf("dbg://%d", pid);
if (currentlyOpenFile.isEmpty()) {
rz_core_file_open_load(core, uri, 0, RZ_PERM_R, false);
} else {
rz_core_file_reopen_remote_debug(core, uri, 0);
}
free(uri);
emit debugTaskStateChanged(); emit debugTaskStateChanged();
@ -2189,7 +2199,8 @@ void CutterCore::stopDebug()
CORE_LOCK(); CORE_LOCK();
if (currentlyEmulating) { if (currentlyEmulating) {
cmdEsil("aeim- ; aei-"); rz_core_analysis_esil_init_mem_del(core, NULL, UT64_MAX, UT32_MAX);
rz_core_analysis_esil_deinit(core);
resetWriteCache(); resetWriteCache();
rz_core_debug_clear_register_flags(core); rz_core_debug_clear_register_flags(core);
rz_core_analysis_esil_trace_stop(core); rz_core_analysis_esil_trace_stop(core);
@ -3173,21 +3184,38 @@ QList<ImportDescription> CutterCore::getAllImports()
QList<ExportDescription> CutterCore::getAllExports() QList<ExportDescription> CutterCore::getAllExports()
{ {
CORE_LOCK(); CORE_LOCK();
QList<ExportDescription> ret; RzBinFile *bf = rz_bin_cur(core->bin);
if (!bf) {
for (CutterJson exportObject : cmdj("iEj")) { return {};
ExportDescription exp; }
const RzList *symbols = rz_bin_object_get_symbols(bf->o);
exp.vaddr = exportObject[RJsonKey::vaddr].toRVA(); if (!symbols) {
exp.paddr = exportObject[RJsonKey::paddr].toRVA(); return {};
exp.size = exportObject[RJsonKey::size].toRVA();
exp.type = exportObject[RJsonKey::type].toString();
exp.name = exportObject[RJsonKey::name].toString();
exp.flag_name = exportObject[RJsonKey::flagname].toString();
ret << exp;
} }
QString lang = getConfigi("bin.demangle") ? getConfig("bin.lang") : "";
bool va = core->io->va || core->bin->is_debugger;
QList<ExportDescription> ret;
for (const auto &symbol : CutterRzList<RzBinSymbol>(symbols)) {
if (!(symbol->name && rz_core_sym_is_export(symbol))) {
continue;
}
RzBinSymNames sn = {};
rz_core_sym_name_init(core, &sn, symbol, lang.isEmpty() ? NULL : lang.toUtf8().constData());
ExportDescription exportDescription;
exportDescription.vaddr = rva(bf->o, symbol->paddr, symbol->vaddr, va);
exportDescription.paddr = symbol->paddr;
exportDescription.size = symbol->size;
exportDescription.type = symbol->type;
exportDescription.name = sn.symbolname;
exportDescription.flag_name = sn.nameflag;
ret << exportDescription;
rz_core_sym_name_fini(&sn);
}
return ret; return ret;
} }
@ -3343,22 +3371,37 @@ QList<RelocDescription> CutterCore::getAllRelocs()
QList<StringDescription> CutterCore::getAllStrings() QList<StringDescription> CutterCore::getAllStrings()
{ {
return parseStringsJson(cmdjTask("izzj")); CORE_LOCK();
} RzBinFile *bf = rz_bin_cur(core->bin);
if (!bf) {
return {};
}
RzBinObject *obj = rz_bin_cur_object(core->bin);
if (!obj) {
return {};
}
RzList *l = rz_core_bin_whole_strings(core, bf);
if (!l) {
return {};
}
int va = core->io->va || core->bin->is_debugger;
RzStrEscOptions opt = {};
opt.show_asciidot = false;
opt.esc_bslash = true;
opt.esc_double_quotes = true;
QList<StringDescription> CutterCore::parseStringsJson(const CutterJson &doc)
{
QList<StringDescription> ret; QList<StringDescription> ret;
for (const auto &str : CutterRzList<RzBinString>(l)) {
auto section = obj ? rz_bin_get_section_at(obj, str->paddr, 0) : NULL;
for (CutterJson value : doc) {
StringDescription string; StringDescription string;
string.string = rz_str_escape_utf8_keep_printable(str->string, &opt);
string.string = value[RJsonKey::string].toString(); string.vaddr = obj ? rva(obj, str->paddr, str->vaddr, va) : str->paddr;
string.vaddr = value[RJsonKey::vaddr].toRVA(); string.type = str->type;
string.type = value[RJsonKey::type].toString(); string.size = str->size;
string.size = value[RJsonKey::size].toUt64(); string.length = str->length;
string.length = value[RJsonKey::length].toUt64(); string.section = section ? section->name : "";
string.section = value[RJsonKey::section].toString();
ret << string; ret << string;
} }
@ -3917,8 +3960,7 @@ QString CutterCore::getTypeAsC(QString name)
return output; return output;
} }
char *earg = rz_cmd_escape_arg(name.toUtf8().constData(), RZ_CMD_ESCAPE_ONE_ARG); char *earg = rz_cmd_escape_arg(name.toUtf8().constData(), RZ_CMD_ESCAPE_ONE_ARG);
// TODO: use API for `tc` command once available QString result = fromOwnedCharPtr(rz_core_types_as_c(core, earg, true));
QString result = cmd(QString("tc %1").arg(earg));
free(earg); free(earg);
return result; return result;
} }
@ -4495,19 +4537,15 @@ QByteArray CutterCore::ioRead(RVA addr, int len)
QStringList CutterCore::getConfigVariableSpaces(const QString &key) QStringList CutterCore::getConfigVariableSpaces(const QString &key)
{ {
CORE_LOCK(); CORE_LOCK();
QStringList stringList; RzList *list = rz_core_config_in_space(core, key.toUtf8().constData());
for (const auto &node : CutterRzList<RzConfigNode>(core->config->nodes)) { if (!list) {
stringList.push_back(node->name); return {};
} }
if (!key.isEmpty()) { QStringList stringList;
stringList = stringList.filter(QRegularExpression(QString("^%0\\..*").arg(key))); for (const auto &x : CutterRzList<char>(list)) {
std::transform(stringList.begin(), stringList.end(), stringList.begin(), stringList << x;
[](const QString &x) { return x.split('.').last(); });
} else {
std::transform(stringList.begin(), stringList.end(), stringList.begin(),
[](const QString &x) { return x.split('.').first(); });
} }
stringList.removeDuplicates(); rz_list_free(list);
return stringList; return stringList;
} }

View File

@ -569,9 +569,8 @@ public:
bool registerDecompiler(Decompiler *decompiler); bool registerDecompiler(Decompiler *decompiler);
RVA getOffsetJump(RVA addr); RVA getOffsetJump(RVA addr);
CutterJson getFileInfo();
QString getSignatureInfo(); QString getSignatureInfo();
CutterJson getFileVersionInfo(); bool existsFileInfo();
void setGraphEmpty(bool empty); void setGraphEmpty(bool empty);
bool isGraphEmpty(); bool isGraphEmpty();
@ -688,8 +687,6 @@ public:
QList<XrefDescription> getXRefs(RVA addr, bool to, bool whole_function, QList<XrefDescription> getXRefs(RVA addr, bool to, bool whole_function,
const QString &filterType = QString()); const QString &filterType = QString());
QList<StringDescription> parseStringsJson(const CutterJson &doc);
void handleREvent(int type, void *data); void handleREvent(int type, void *data);
/* Signals related */ /* Signals related */

View File

@ -23,145 +23,213 @@ VersionInfoDialog::~VersionInfoDialog() {}
void VersionInfoDialog::fillVersionInfo() void VersionInfoDialog::fillVersionInfo()
{ {
RzCoreLocked core(Core());
CutterJson doc = Core()->getFileVersionInfo(); const RzBinInfo *info = rz_bin_get_info(core->bin);
if (!info || !info->rclass) {
return;
}
// Case ELF // Case ELF
if (doc["verneed"].valid()) { if (strncmp("elf", info->rclass, 3) == 0) {
CutterJson verneed = doc["verneed"].first();
CutterJson versym = doc["versym"].first();
// Set labels // Set labels
ui->leftLabel->setText("Version symbols"); ui->leftLabel->setText("Version symbols");
ui->rightLabel->setText("Version need"); ui->rightLabel->setText("Version need");
// Left tree Sdb *sdb = sdb_ns_path(core->sdb, "bin/cur/info/versioninfo/versym", 0);
QTreeWidgetItem *secNameItemL = new QTreeWidgetItem(); if (!sdb) {
secNameItemL->setText(0, "Section name:"); return;
secNameItemL->setText(1, versym["section_name"].toString()); }
ui->leftTreeWidget->addTopLevelItem(secNameItemL);
// Left tree
QTreeWidgetItem *addrItemL = new QTreeWidgetItem(); QTreeWidgetItem *addrItemL = new QTreeWidgetItem();
addrItemL->setText(0, "Address:"); addrItemL->setText(0, "Address:");
addrItemL->setText(1, RzAddressString(versym["address"].toRVA())); addrItemL->setText(1, RzAddressString(sdb_num_get(sdb, "addr", 0)));
ui->leftTreeWidget->addTopLevelItem(addrItemL); ui->leftTreeWidget->addTopLevelItem(addrItemL);
QTreeWidgetItem *offItemL = new QTreeWidgetItem(); QTreeWidgetItem *offItemL = new QTreeWidgetItem();
offItemL->setText(0, "Offset:"); offItemL->setText(0, "Offset:");
offItemL->setText(1, RzAddressString(versym["offset"].toRVA())); offItemL->setText(1, RzAddressString(sdb_num_get(sdb, "offset", 0)));
ui->leftTreeWidget->addTopLevelItem(offItemL); ui->leftTreeWidget->addTopLevelItem(offItemL);
QTreeWidgetItem *linkItemL = new QTreeWidgetItem();
linkItemL->setText(0, "Link:");
linkItemL->setText(1, QString::number(versym["link"].toRVA()));
ui->leftTreeWidget->addTopLevelItem(linkItemL);
QTreeWidgetItem *linkNameItemL = new QTreeWidgetItem();
linkNameItemL->setText(0, "Link section name:");
linkNameItemL->setText(1, versym["link_section_name"].toString());
ui->leftTreeWidget->addTopLevelItem(linkNameItemL);
QTreeWidgetItem *entriesItemL = new QTreeWidgetItem(); QTreeWidgetItem *entriesItemL = new QTreeWidgetItem();
entriesItemL->setText(0, "Entries:"); entriesItemL->setText(0, "Entries:");
for (CutterJson obj : versym["entries"]) { const ut64 num_entries = sdb_num_get(sdb, "num_entries", 0);
QTreeWidgetItem *tempItem = new QTreeWidgetItem(); for (size_t i = 0; i < num_entries; ++i) {
tempItem->setText(0, RzAddressString(obj["idx"].toRVA())); auto key = QString("entry%0").arg(i);
tempItem->setText(1, obj["value"].toString()); const char *const value = sdb_const_get(sdb, key.toStdString().c_str(), 0);
entriesItemL->addChild(tempItem); if (!value) {
continue;
}
auto item = new QTreeWidgetItem();
item->setText(0, RzAddressString(i));
item->setText(1, value);
entriesItemL->addChild(item);
} }
ui->leftTreeWidget->addTopLevelItem(entriesItemL); ui->leftTreeWidget->addTopLevelItem(entriesItemL);
// Adjust columns to content // Adjust columns to content
qhelpers::adjustColumns(ui->leftTreeWidget, 0); qhelpers::adjustColumns(ui->leftTreeWidget, 0);
sdb = sdb_ns_path(core->sdb, "bin/cur/info/versioninfo/verneed", 0);
// Right tree // Right tree
QTreeWidgetItem *secNameItemR = new QTreeWidgetItem();
secNameItemR->setText(0, "Section name:");
secNameItemR->setText(1, verneed["section_name"].toString());
ui->rightTreeWidget->addTopLevelItem(secNameItemR);
QTreeWidgetItem *addrItemR = new QTreeWidgetItem(); QTreeWidgetItem *addrItemR = new QTreeWidgetItem();
addrItemR->setText(0, "Address:"); addrItemR->setText(0, "Address:");
addrItemR->setText(1, RzAddressString(verneed["address"].toRVA())); addrItemR->setText(1, RzAddressString(sdb_num_get(sdb, "addr", 0)));
ui->rightTreeWidget->addTopLevelItem(addrItemR); ui->rightTreeWidget->addTopLevelItem(addrItemR);
QTreeWidgetItem *offItemR = new QTreeWidgetItem(); QTreeWidgetItem *offItemR = new QTreeWidgetItem();
offItemR->setText(0, "Offset:"); offItemR->setText(0, "Offset:");
offItemR->setText(1, RzAddressString(verneed["offset"].toRVA())); offItemR->setText(1, RzAddressString(sdb_num_get(sdb, "offset", 0)));
ui->rightTreeWidget->addTopLevelItem(offItemR); ui->rightTreeWidget->addTopLevelItem(offItemR);
QTreeWidgetItem *linkItemR = new QTreeWidgetItem();
linkItemR->setText(0, "Link:");
linkItemR->setText(1, QString::number(verneed["link"].toSt64()));
ui->rightTreeWidget->addTopLevelItem(linkItemR);
QTreeWidgetItem *linkNameItemR = new QTreeWidgetItem();
linkNameItemR->setText(0, "Link section name:");
linkNameItemR->setText(1, verneed["link_section_name"].toString());
ui->rightTreeWidget->addTopLevelItem(linkNameItemR);
QTreeWidgetItem *entriesItemR = new QTreeWidgetItem(); QTreeWidgetItem *entriesItemR = new QTreeWidgetItem();
entriesItemR->setText(0, "Entries:"); entriesItemR->setText(0, "Entries:");
for (CutterJson parentObj : verneed["entries"]) { for (size_t num_version = 0;; num_version++) {
QTreeWidgetItem *parentItem = new QTreeWidgetItem(); auto path_version =
QString parentString; QString("bin/cur/info/versioninfo/verneed/version%0").arg(num_version);
parentItem->setText(0, RzAddressString(parentObj["idx"].toRVA())); sdb = sdb_ns_path(core->sdb, path_version.toStdString().c_str(), 0);
parentString.append("Version: " + QString::number(parentObj["vn_version"].toSt64()) if (!sdb) {
+ "\t"); break;
parentString.append("File: " + parentObj["file_name"].toString()); }
parentItem->setText(1, parentString); const char *filename = sdb_const_get(sdb, "file_name", 0);
auto *parentItem = new QTreeWidgetItem();
parentItem->setText(0, RzAddressString(sdb_num_get(sdb, "idx", 0)));
parentItem->setText(1,
QString("Version: %0\t"
"File: %1")
.arg(QString::number(sdb_num_get(sdb, "vn_version", 0)),
QString(filename)));
for (CutterJson childObj : parentObj["vernaux"]) { int num_vernaux = 0;
QTreeWidgetItem *childItem = new QTreeWidgetItem(); while (true) {
QString childString; auto path_vernaux =
childItem->setText(0, RzAddressString(childObj["idx"].toRVA())); QString("%0/vernaux%1").arg(path_version, QString::number(num_vernaux++));
childString.append("Name: " + childObj["name"].toString() + "\t"); sdb = sdb_ns_path(core->sdb, path_vernaux.toStdString().c_str(), 0);
childString.append("Flags: " + childObj["flags"].toString() + "\t"); if (!sdb) {
childString.append("Version: " + QString::number(childObj["version"].toSt64())); break;
}
auto *childItem = new QTreeWidgetItem();
childItem->setText(0, RzAddressString(sdb_num_get(sdb, "idx", 0)));
QString childString =
QString("Name: %0\t"
"Flags: %1\t"
"Version: %2\t")
.arg(sdb_const_get(sdb, "name", 0), sdb_const_get(sdb, "flags", 0),
QString::number(sdb_num_get(sdb, "version", 0)));
childItem->setText(1, childString); childItem->setText(1, childString);
parentItem->addChild(childItem); parentItem->addChild(childItem);
} }
entriesItemR->addChild(parentItem); entriesItemR->addChild(parentItem);
} }
ui->rightTreeWidget->addTopLevelItem(entriesItemR);
ui->rightTreeWidget->addTopLevelItem(entriesItemR);
// Adjust columns to content // Adjust columns to content
qhelpers::adjustColumns(ui->rightTreeWidget, 0); qhelpers::adjustColumns(ui->rightTreeWidget, 0);
} }
// Case PE // Case PE
else if (doc["VS_FIXEDFILEINFO"].valid()) { else if (strncmp("pe", info->rclass, 2) == 0) {
CutterJson vs = doc["VS_FIXEDFILEINFO"];
CutterJson strings = doc["StringTable"];
// Set labels // Set labels
ui->leftLabel->setText("VS Fixed file info"); ui->leftLabel->setText("VS Fixed file info");
ui->rightLabel->setText("String table"); ui->rightLabel->setText("String table");
Sdb *sdb = NULL;
// Left tree // Left tree
for (CutterJson property : vs) { auto path_version = QString("bin/cur/info/vs_version_info/VS_VERSIONINFO%0").arg(0);
QTreeWidgetItem *tempItem = new QTreeWidgetItem(); auto path_fixedfileinfo = QString("%0/fixed_file_info").arg(path_version);
tempItem->setText(0, property.key()); sdb = sdb_ns_path(core->sdb, path_fixedfileinfo.toStdString().c_str(), 0);
if (property.type() == RZ_JSON_INTEGER) if (!sdb) {
tempItem->setText(1, RzHexString(property.toRVA())); return;
else
tempItem->setText(1, property.toString());
ui->leftTreeWidget->addTopLevelItem(tempItem);
// Adjust columns to content
qhelpers::adjustColumns(ui->leftTreeWidget, 0);
} }
ut32 file_version_ms = sdb_num_get(sdb, "FileVersionMS", 0);
ut32 file_version_ls = sdb_num_get(sdb, "FileVersionLS", 0);
auto file_version = QString("%0.%1.%2.%3")
.arg(file_version_ms >> 16)
.arg(file_version_ms & 0xFFFF)
.arg(file_version_ls >> 16)
.arg(file_version_ls & 0xFFFF);
ut32 product_version_ms = sdb_num_get(sdb, "ProductVersionMS", 0);
ut32 product_version_ls = sdb_num_get(sdb, "ProductVersionLS", 0);
auto product_version = QString("%0.%1.%2.%3")
.arg(product_version_ms >> 16)
.arg(product_version_ms & 0xFFFF)
.arg(product_version_ls >> 16)
.arg(product_version_ls & 0xFFFF);
auto item = new QTreeWidgetItem();
item->setText(0, "Signature");
item->setText(1, RzHexString(sdb_num_get(sdb, "Signature", 0)));
ui->leftTreeWidget->addTopLevelItem(item);
item = new QTreeWidgetItem();
item->setText(0, "StrucVersion");
item->setText(1, RzHexString(sdb_num_get(sdb, "StrucVersion", 0)));
ui->leftTreeWidget->addTopLevelItem(item);
item = new QTreeWidgetItem();
item->setText(0, "FileVersion");
item->setText(1, file_version);
ui->leftTreeWidget->addTopLevelItem(item);
item = new QTreeWidgetItem();
item->setText(0, "ProductVersion");
item->setText(1, product_version);
ui->leftTreeWidget->addTopLevelItem(item);
item = new QTreeWidgetItem();
item->setText(0, "FileFlagsMask");
item->setText(1, RzHexString(sdb_num_get(sdb, "FileFlagsMask", 0)));
ui->leftTreeWidget->addTopLevelItem(item);
item = new QTreeWidgetItem();
item->setText(0, "FileFlags");
item->setText(1, RzHexString(sdb_num_get(sdb, "FileFlags", 0)));
ui->leftTreeWidget->addTopLevelItem(item);
item = new QTreeWidgetItem();
item->setText(0, "FileOS");
item->setText(1, RzHexString(sdb_num_get(sdb, "FileOS", 0)));
ui->leftTreeWidget->addTopLevelItem(item);
item = new QTreeWidgetItem();
item->setText(0, "FileType");
item->setText(1, RzHexString(sdb_num_get(sdb, "FileType", 0)));
ui->leftTreeWidget->addTopLevelItem(item);
item = new QTreeWidgetItem();
item->setText(0, "FileSubType");
item->setText(1, RzHexString(sdb_num_get(sdb, "FileSubType", 0)));
ui->leftTreeWidget->addTopLevelItem(item);
// Adjust columns to content
qhelpers::adjustColumns(ui->leftTreeWidget, 0);
// Right tree // Right tree
for (CutterJson property : strings) { for (int num_stringtable = 0;; num_stringtable++) {
QTreeWidgetItem *tempItem = new QTreeWidgetItem(); auto path_stringtable = QString("%0/string_file_info/stringtable%1")
tempItem->setText(0, property.key()); .arg(path_version)
tempItem->setText(1, property.toString()); .arg(num_stringtable);
ui->rightTreeWidget->addTopLevelItem(tempItem); sdb = sdb_ns_path(core->sdb, path_stringtable.toStdString().c_str(), 0);
if (!sdb) {
// Adjust columns to content break;
qhelpers::adjustColumns(ui->rightTreeWidget, 0); }
for (int num_string = 0; sdb; num_string++) {
auto path_string = QString("%0/string%1").arg(path_stringtable).arg(num_string);
sdb = sdb_ns_path(core->sdb, path_string.toStdString().c_str(), 0);
if (!sdb) {
continue;
}
int lenkey = 0;
int lenval = 0;
ut8 *key_utf16 = sdb_decode(sdb_const_get(sdb, "key", 0), &lenkey);
ut8 *val_utf16 = sdb_decode(sdb_const_get(sdb, "value", 0), &lenval);
item = new QTreeWidgetItem();
item->setText(0, QString::fromUtf16(reinterpret_cast<const ushort *>(key_utf16)));
item->setText(1, QString::fromUtf16(reinterpret_cast<const ushort *>(val_utf16)));
ui->rightTreeWidget->addTopLevelItem(item);
free(key_utf16);
free(val_utf16);
}
} }
qhelpers::adjustColumns(ui->rightTreeWidget, 0);
} }
} }

View File

@ -32,24 +32,27 @@ Dashboard::~Dashboard() {}
void Dashboard::updateContents() void Dashboard::updateContents()
{ {
CutterJson docu = Core()->getFileInfo(); RzCoreLocked core(Core());
CutterJson item = docu["core"]; int fd = rz_io_fd_get_current(core->io);
CutterJson item2 = docu["bin"]; RzIODesc *desc = rz_io_desc_get(core->io, fd);
setPlainText(this->ui->modeEdit, desc ? rz_str_rwx_i(desc->perm & RZ_PERM_RWX) : "");
setPlainText(this->ui->modeEdit, item["mode"].toString()); RzBinFile *bf = rz_bin_cur(core->bin);
setPlainText(this->ui->compilationDateEdit, item2["compiled"].toString()); if (bf) {
setPlainText(this->ui->compilationDateEdit, rz_core_bin_get_compile_time(bf));
if (!item2["relro"].toString().isEmpty()) { if (bf->o) {
QString relro = item2["relro"].toString().section(QLatin1Char(' '), 0, 0); char *relco_buf = sdb_get(bf->o->kv, "elf.relro", 0);
relro[0] = relro[0].toUpper(); if (RZ_STR_ISNOTEMPTY(relco_buf)) {
setPlainText(this->ui->relroEdit, relro); QString relro = QString(relco_buf).section(QLatin1Char(' '), 0, 0);
} else { relro[0] = relro[0].toUpper();
setPlainText(this->ui->relroEdit, "N/A"); setPlainText(this->ui->relroEdit, relro);
} else {
setPlainText(this->ui->relroEdit, "N/A");
}
}
} }
// Add file hashes, analysis info and libraries // Add file hashes, analysis info and libraries
RzCoreLocked core(Core());
RzBinFile *bf = rz_bin_cur(core->bin);
RzBinInfo *binInfo = rz_bin_get_info(core->bin); RzBinInfo *binInfo = rz_bin_get_info(core->bin);
setPlainText(ui->fileEdit, binInfo ? binInfo->file : ""); setPlainText(ui->fileEdit, binInfo ? binInfo->file : "");
@ -111,16 +114,25 @@ void Dashboard::updateContents()
hashesLayout->addRow(new QLabel(label), hashLineEdit); hashesLayout->addRow(new QLabel(label), hashLineEdit);
} }
CutterJson analinfo = Core()->cmdj("aaij"); st64 fcns = rz_list_length(core->analysis->fcns);
setPlainText(ui->functionsLineEdit, QString::number(analinfo["fcns"].toSt64())); st64 strs = rz_flag_count(core->flags, "str.*");
setPlainText(ui->xRefsLineEdit, QString::number(analinfo["xrefs"].toSt64())); st64 syms = rz_flag_count(core->flags, "sym.*");
setPlainText(ui->callsLineEdit, QString::number(analinfo["calls"].toSt64())); st64 imps = rz_flag_count(core->flags, "sym.imp.*");
setPlainText(ui->stringsLineEdit, QString::number(analinfo["strings"].toSt64())); st64 code = rz_core_analysis_code_count(core);
setPlainText(ui->symbolsLineEdit, QString::number(analinfo["symbols"].toSt64())); st64 covr = rz_core_analysis_coverage_count(core);
setPlainText(ui->importsLineEdit, QString::number(analinfo["imports"].toSt64())); st64 call = rz_core_analysis_calls_count(core);
setPlainText(ui->coverageLineEdit, QString::number(analinfo["covrage"].toSt64()) + " bytes"); ut64 xrfs = rz_analysis_xrefs_count(core->analysis);
setPlainText(ui->codeSizeLineEdit, QString::number(analinfo["codesz"].toSt64()) + " bytes"); double precentage = (code > 0) ? (covr * 100.0 / code) : 0;
setPlainText(ui->percentageLineEdit, QString::number(analinfo["percent"].toSt64()) + "%");
setPlainText(ui->functionsLineEdit, QString::number(fcns));
setPlainText(ui->xRefsLineEdit, QString::number(xrfs));
setPlainText(ui->callsLineEdit, QString::number(call));
setPlainText(ui->stringsLineEdit, QString::number(strs));
setPlainText(ui->symbolsLineEdit, QString::number(syms));
setPlainText(ui->importsLineEdit, QString::number(imps));
setPlainText(ui->coverageLineEdit, QString::number(covr) + " bytes");
setPlainText(ui->codeSizeLineEdit, QString::number(code) + " bytes");
setPlainText(ui->percentageLineEdit, QString::number(precentage) + "%");
// dunno: why not label->setText(lines.join("\n")? // dunno: why not label->setText(lines.join("\n")?
while (ui->verticalLayout_2->count() > 0) { while (ui->verticalLayout_2->count() > 0) {
@ -153,9 +165,7 @@ void Dashboard::updateContents()
if (Core()->getSignatureInfo().isEmpty()) { if (Core()->getSignatureInfo().isEmpty()) {
ui->certificateButton->setEnabled(false); ui->certificateButton->setEnabled(false);
} }
if (!Core()->getFileVersionInfo().size()) { ui->versioninfoButton->setEnabled(Core()->existsFileInfo());
ui->versioninfoButton->setEnabled(false);
}
} }
void Dashboard::on_certificateButton_clicked() void Dashboard::on_certificateButton_clicked()

View File

@ -564,7 +564,18 @@ void FunctionsWidget::refreshTree()
importAddresses.insert(import.plt); importAddresses.insert(import.plt);
} }
mainAdress = (ut64)Core()->cmdj("iMj")["vaddr"].toUt64(); mainAdress = RVA_INVALID;
RzCoreLocked core(Core());
RzBinFile *bf = rz_bin_cur(core->bin);
if (bf) {
const RzBinAddr *binmain =
rz_bin_object_get_special_symbol(bf->o, RZ_BIN_SPECIAL_SYMBOL_MAIN);
if (binmain) {
int va = core->io->va || core->bin->is_debugger;
mainAdress = va ? rz_bin_object_addr_with_base(bf->o, binmain->vaddr)
: binmain->paddr;
}
}
functionModel->updateCurrentIndex(); functionModel->updateCurrentIndex();
functionModel->endResetModel(); functionModel->endResetModel();

View File

@ -259,6 +259,10 @@ void TypesWidget::showTypesContextMenu(const QPoint &pt)
void TypesWidget::on_actionExport_Types_triggered() void TypesWidget::on_actionExport_Types_triggered()
{ {
char *str = rz_core_types_as_c_all(Core()->core(), true);
if (!str) {
return;
}
QString filename = QString filename =
QFileDialog::getSaveFileName(this, tr("Save File"), Config()->getRecentFolder()); QFileDialog::getSaveFileName(this, tr("Save File"), Config()->getRecentFolder());
if (filename.isEmpty()) { if (filename.isEmpty()) {
@ -272,8 +276,8 @@ void TypesWidget::on_actionExport_Types_triggered()
return; return;
} }
QTextStream fileOut(&file); QTextStream fileOut(&file);
// TODO: use API for `tc` command once available fileOut << str;
fileOut << Core()->cmd("tc"); free(str);
file.close(); file.close();
} }