Port Sections information to the Rizin API (#2785)

This commit is contained in:
Anton Kochkov 2021-11-13 21:02:57 +08:00 committed by GitHub
parent 4061887bfe
commit 896be642ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 19 deletions

2
rizin

@ -1 +1 @@
Subproject commit 5fda91650c1665ba06b0b5f9b36d4959e9fb5362 Subproject commit 18db8301a4cb3b3bc4ab026bcf9b822eb03f86e4

View File

@ -3121,28 +3121,44 @@ QList<SectionDescription> CutterCore::getAllSections()
CORE_LOCK(); CORE_LOCK();
QList<SectionDescription> sections; QList<SectionDescription> sections;
QJsonDocument sectionsDoc = cmdj("iSj entropy"); RzBinObject *o = rz_bin_cur_object(core->bin);
QJsonObject sectionsObj = sectionsDoc.object(); if (!o) {
QJsonArray sectionsArray = sectionsObj[RJsonKey::sections].toArray(); return sections;
}
for (const QJsonValue &value : sectionsArray) { RzList *sects = rz_bin_object_get_sections(o);
QJsonObject sectionObject = value.toObject(); if (!sects) {
return sections;
QString name = sectionObject[RJsonKey::name].toString(); }
if (name.isEmpty()) RzList *hashnames = rz_list_newf(free);
if (!hashnames) {
return sections;
}
rz_list_push(hashnames, rz_str_new("entropy"));
RzListIter *it;
RzBinSection *sect;
CutterRzListForeach (sects, it, RzBinSection, sect) {
if (RZ_STR_ISEMPTY(sect->name))
continue; continue;
SectionDescription section; SectionDescription section;
section.name = name; section.name = sect->name;
section.vaddr = sectionObject[RJsonKey::vaddr].toVariant().toULongLong(); section.vaddr = sect->vaddr;
section.vsize = sectionObject[RJsonKey::vsize].toVariant().toULongLong(); section.vsize = sect->vsize;
section.paddr = sectionObject[RJsonKey::paddr].toVariant().toULongLong(); section.paddr = sect->paddr;
section.size = sectionObject[RJsonKey::size].toVariant().toULongLong(); section.size = sect->size;
section.perm = sectionObject[RJsonKey::perm].toString(); section.perm = rz_str_rwx_i(sect->perm);
section.entropy = sectionObject[RJsonKey::entropy].toString(); HtPP *digests = rz_core_bin_section_digests(core, sect, hashnames);
if (!digests) {
continue;
}
const char *entropy = (const char*)ht_pp_find(digests, "entropy", NULL);
section.entropy = rz_str_get(entropy);
ht_pp_free(digests);
sections << section; sections << section;
} }
rz_list_free(sects);
return sections; return sections;
} }
@ -3151,9 +3167,19 @@ QStringList CutterCore::getSectionList()
CORE_LOCK(); CORE_LOCK();
QStringList ret; QStringList ret;
QJsonArray sectionsArray = cmdj("iSj").array(); RzBinObject *o = rz_bin_cur_object(core->bin);
for (const QJsonValue &value : sectionsArray) { if (!o) {
ret << value.toObject()[RJsonKey::name].toString(); return ret;
}
RzList *sects = rz_bin_object_get_sections(o);
if (!sects) {
return ret;
}
RzListIter *it;
RzBinSection *sect;
CutterRzListForeach (sects, it, RzBinSection, sect) {
ret << sect->name;
} }
return ret; return ret;
} }