mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Convert Rizin command calls to the API (#2968)
* `es` * `il` * `wcr` * `.ar-` * `aets-` * `drp` * `ahts` * `e <val>=?` * `fo`
This commit is contained in:
parent
aa222b53df
commit
06c8f15ce0
@ -92,7 +92,7 @@ JSDecDecompiler::JSDecDecompiler(QObject *parent) : Decompiler("jsdec", "jsdec",
|
|||||||
|
|
||||||
bool JSDecDecompiler::isAvailable()
|
bool JSDecDecompiler::isAvailable()
|
||||||
{
|
{
|
||||||
return Core()->cmdList("es").contains("jsdec");
|
return Core()->getConfigVariableSpaces().contains("jsdec");
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSDecDecompiler::decompileAt(RVA addr)
|
void JSDecDecompiler::decompileAt(RVA addr)
|
||||||
|
@ -1199,7 +1199,21 @@ void CutterCore::message(const QString &msg, bool debug)
|
|||||||
QString CutterCore::getConfig(const char *k)
|
QString CutterCore::getConfig(const char *k)
|
||||||
{
|
{
|
||||||
CORE_LOCK();
|
CORE_LOCK();
|
||||||
return QString(rz_config_get(core->config, k));
|
return { rz_config_get(core->config, k) };
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CutterCore::getConfigOptions(const char *k)
|
||||||
|
{
|
||||||
|
CORE_LOCK();
|
||||||
|
RzConfigNode *node = rz_config_node_get(core->config, k);
|
||||||
|
if (!(node && node->options)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
QStringList list;
|
||||||
|
for (const auto &s : CutterRzList<char>(node->options)) {
|
||||||
|
list << s;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CutterCore::setConfig(const char *k, const QVariant &v)
|
void CutterCore::setConfig(const char *k, const QVariant &v)
|
||||||
@ -2146,11 +2160,15 @@ void CutterCore::stopDebug()
|
|||||||
currentlyRemoteDebugging = false;
|
currentlyRemoteDebugging = false;
|
||||||
emit debugTaskStateChanged();
|
emit debugTaskStateChanged();
|
||||||
|
|
||||||
|
CORE_LOCK();
|
||||||
if (currentlyEmulating) {
|
if (currentlyEmulating) {
|
||||||
cmdEsil("aeim-; aei-; wcr; .ar-; aets-");
|
cmdEsil("aeim- ; aei-");
|
||||||
|
resetWriteCache();
|
||||||
|
rz_core_debug_clear_register_flags(core);
|
||||||
|
rz_core_analysis_esil_trace_stop(core);
|
||||||
currentlyEmulating = false;
|
currentlyEmulating = false;
|
||||||
} else {
|
} else {
|
||||||
rz_core_debug_process_close(core());
|
rz_core_debug_process_close(core);
|
||||||
currentlyAttachedToPID = -1;
|
currentlyAttachedToPID = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2870,8 +2888,17 @@ bool CutterCore::isGraphEmpty()
|
|||||||
|
|
||||||
void CutterCore::getOpcodes()
|
void CutterCore::getOpcodes()
|
||||||
{
|
{
|
||||||
|
CORE_LOCK();
|
||||||
this->opcodes = cmdList("?O");
|
this->opcodes = cmdList("?O");
|
||||||
this->regs = cmdList("drp~[1]");
|
|
||||||
|
this->regs = {};
|
||||||
|
const RzList *rs = rz_reg_get_list(core->dbg->reg, RZ_REG_TYPE_ANY);
|
||||||
|
if (!rs) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const auto &r : CutterRzList<RzRegItem>(rs)) {
|
||||||
|
this->regs.push_back(r->name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CutterCore::setSettings()
|
void CutterCore::setSettings()
|
||||||
@ -4430,3 +4457,23 @@ QByteArray CutterCore::ioRead(RVA addr, int len)
|
|||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList CutterCore::getConfigVariableSpaces(const QString &key)
|
||||||
|
{
|
||||||
|
CORE_LOCK();
|
||||||
|
QStringList stringList;
|
||||||
|
for (const auto &node : CutterRzList<RzConfigNode>(core->config->nodes)) {
|
||||||
|
stringList.push_back(node->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!key.isEmpty()) {
|
||||||
|
stringList = stringList.filter(QRegularExpression(QString("^%0\\..*").arg(key)));
|
||||||
|
std::transform(stringList.begin(), stringList.end(), stringList.begin(),
|
||||||
|
[](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();
|
||||||
|
return stringList;
|
||||||
|
}
|
||||||
|
@ -393,10 +393,12 @@ public:
|
|||||||
QString getConfig(const char *k);
|
QString getConfig(const char *k);
|
||||||
QString getConfig(const QString &k) { return getConfig(k.toUtf8().constData()); }
|
QString getConfig(const QString &k) { return getConfig(k.toUtf8().constData()); }
|
||||||
QString getConfigDescription(const char *k);
|
QString getConfigDescription(const char *k);
|
||||||
|
QStringList getConfigOptions(const char *k);
|
||||||
QStringList getColorThemes();
|
QStringList getColorThemes();
|
||||||
QHash<QString, QColor> getTheme();
|
QHash<QString, QColor> getTheme();
|
||||||
QStringList getThemeKeys();
|
QStringList getThemeKeys();
|
||||||
bool setColor(const QString &key, const QString &color);
|
bool setColor(const QString &key, const QString &color);
|
||||||
|
QStringList getConfigVariableSpaces(const QString &key = "");
|
||||||
|
|
||||||
/* Assembly\Hexdump related methods */
|
/* Assembly\Hexdump related methods */
|
||||||
QByteArray assemble(const QString &code);
|
QByteArray assemble(const QString &code);
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
(char *)it != (char *)(vec)->a + ((vec)->len * (vec)->elem_size); \
|
(char *)it != (char *)(vec)->a + ((vec)->len * (vec)->elem_size); \
|
||||||
it = (type *)((char *)it + (vec)->elem_size))
|
it = (type *)((char *)it + (vec)->elem_size))
|
||||||
|
|
||||||
template<typename T> class CutterPVector
|
template<typename T>
|
||||||
|
class CutterPVector
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const RzPVector *const vec;
|
const RzPVector *const vec;
|
||||||
@ -39,8 +40,17 @@ public:
|
|||||||
public:
|
public:
|
||||||
iterator(T **p) : p(p) {}
|
iterator(T **p) : p(p) {}
|
||||||
iterator(const iterator &o) : p(o.p) {}
|
iterator(const iterator &o) : p(o.p) {}
|
||||||
iterator &operator++() { p++; return *this; }
|
iterator &operator++()
|
||||||
iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
|
{
|
||||||
|
p++;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
iterator operator++(int)
|
||||||
|
{
|
||||||
|
iterator tmp(*this);
|
||||||
|
operator++();
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
bool operator==(const iterator &rhs) const { return p == rhs.p; }
|
bool operator==(const iterator &rhs) const { return p == rhs.p; }
|
||||||
bool operator!=(const iterator &rhs) const { return p != rhs.p; }
|
bool operator!=(const iterator &rhs) const { return p != rhs.p; }
|
||||||
T *operator*() { return *p; }
|
T *operator*() { return *p; }
|
||||||
@ -51,6 +61,57 @@ public:
|
|||||||
iterator end() const { return iterator(reinterpret_cast<T **>(vec->v.a) + vec->v.len); }
|
iterator end() const { return iterator(reinterpret_cast<T **>(vec->v.a) + vec->v.len); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class CutterRzList
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const RzList *const list;
|
||||||
|
|
||||||
|
public:
|
||||||
|
class iterator : public std::iterator<std::input_iterator_tag, T *>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
RzListIter *iter;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit iterator(RzListIter *iter) : iter(iter) {}
|
||||||
|
iterator(const iterator &o) : iter(o.iter) {}
|
||||||
|
iterator &operator++()
|
||||||
|
{
|
||||||
|
if (!iter) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
iter = iter->n;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
iterator operator++(int)
|
||||||
|
{
|
||||||
|
iterator tmp(*this);
|
||||||
|
operator++();
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
bool operator==(const iterator &rhs) const { return iter == rhs.iter; }
|
||||||
|
bool operator!=(const iterator &rhs) const { return iter != rhs.iter; }
|
||||||
|
T *operator*()
|
||||||
|
{
|
||||||
|
if (!iter) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return reinterpret_cast<T *>(iter->data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit CutterRzList(const RzList *l) : list(l) {}
|
||||||
|
iterator begin() const
|
||||||
|
{
|
||||||
|
if (!list) {
|
||||||
|
return iterator(nullptr);
|
||||||
|
}
|
||||||
|
return iterator(list->head);
|
||||||
|
}
|
||||||
|
iterator end() const { return iterator(nullptr); }
|
||||||
|
};
|
||||||
|
|
||||||
// Global information for Cutter
|
// Global information for Cutter
|
||||||
#define APPNAME "Cutter"
|
#define APPNAME "Cutter"
|
||||||
|
|
||||||
|
@ -641,7 +641,11 @@ void MainWindow::finalizeOpen()
|
|||||||
core->updateSeek();
|
core->updateSeek();
|
||||||
refreshAll();
|
refreshAll();
|
||||||
// Add fortune message
|
// Add fortune message
|
||||||
core->message("\n" + core->cmdRaw("fo"));
|
char *fortune = rz_core_fortune_get_random(core->core());
|
||||||
|
if (fortune) {
|
||||||
|
core->message("\n" + QString(fortune));
|
||||||
|
free(fortune);
|
||||||
|
}
|
||||||
|
|
||||||
// hide all docks before showing window to avoid false positive for refreshDeferrer
|
// hide all docks before showing window to avoid false positive for refreshDeferrer
|
||||||
for (auto dockWidget : dockWidgets) {
|
for (auto dockWidget : dockWidgets) {
|
||||||
|
@ -40,7 +40,7 @@ InitialOptionsDialog::InitialOptionsDialog(MainWindow *main)
|
|||||||
updateCPUComboBox();
|
updateCPUComboBox();
|
||||||
|
|
||||||
// os combo box
|
// os combo box
|
||||||
for (const auto &plugin : core->cmdList("e asm.os=?")) {
|
for (const auto &plugin : Core()->getConfigOptions("asm.os")) {
|
||||||
ui->kernelComboBox->addItem(plugin, plugin);
|
ui->kernelComboBox->addItem(plugin, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ AsmOptionsWidget::AsmOptionsWidget(PreferencesDialog *dialog)
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
ui->syntaxComboBox->blockSignals(true);
|
ui->syntaxComboBox->blockSignals(true);
|
||||||
for (const auto &syntax : Core()->cmdList("e asm.syntax=?"))
|
for (const auto &syntax : Core()->getConfigOptions("asm.syntax"))
|
||||||
ui->syntaxComboBox->addItem(syntax, syntax);
|
ui->syntaxComboBox->addItem(syntax, syntax);
|
||||||
ui->syntaxComboBox->blockSignals(false);
|
ui->syntaxComboBox->blockSignals(false);
|
||||||
|
|
||||||
|
@ -524,15 +524,19 @@ void DisassemblyContextMenu::aboutToShowSlot()
|
|||||||
structureOffsetMenu->menuAction()->setVisible(true);
|
structureOffsetMenu->menuAction()->setVisible(true);
|
||||||
structureOffsetMenu->clear();
|
structureOffsetMenu->clear();
|
||||||
|
|
||||||
// Get the possible offsets using the "ahts" command
|
RzCoreLocked core(Core());
|
||||||
// TODO: add ahtj command to Rizin and then use it here
|
RzList *typeoffs = rz_type_db_get_by_offset(core->analysis->typedb, memDisp);
|
||||||
QStringList ret = Core()->cmdList("ahts " + QString::number(memDisp));
|
if (typeoffs) {
|
||||||
for (const QString &val : ret) {
|
for (const auto &ty : CutterRzList<RzTypePath>(typeoffs)) {
|
||||||
if (val.isEmpty()) {
|
if (RZ_STR_ISEMPTY(ty->path)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
structureOffsetMenu->addAction("[" + memBaseReg + " + " + val + "]")->setData(val);
|
structureOffsetMenu->addAction("[" + memBaseReg + " + " + ty->path + "]")
|
||||||
|
->setData(ty->path);
|
||||||
}
|
}
|
||||||
|
rz_list_free(typeoffs);
|
||||||
|
}
|
||||||
|
|
||||||
if (structureOffsetMenu->isEmpty()) {
|
if (structureOffsetMenu->isEmpty()) {
|
||||||
// No possible offset was found so hide the menu
|
// No possible offset was found so hide the menu
|
||||||
structureOffsetMenu->menuAction()->setVisible(false);
|
structureOffsetMenu->menuAction()->setVisible(false);
|
||||||
|
@ -220,8 +220,7 @@ bool CommentsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &ri
|
|||||||
case CommentsModel::OffsetColumn:
|
case CommentsModel::OffsetColumn:
|
||||||
return leftComment.offset < rightComment.offset;
|
return leftComment.offset < rightComment.offset;
|
||||||
case CommentsModel::FunctionColumn:
|
case CommentsModel::FunctionColumn:
|
||||||
return Core()->flagAt(leftComment.offset)
|
return Core()->flagAt(leftComment.offset) < Core()->flagAt(rightComment.offset);
|
||||||
< Core()->flagAt(rightComment.offset);
|
|
||||||
case CommentsModel::CommentColumn:
|
case CommentsModel::CommentColumn:
|
||||||
return leftComment.name < rightComment.name;
|
return leftComment.name < rightComment.name;
|
||||||
default:
|
default:
|
||||||
|
@ -122,12 +122,6 @@ void Dashboard::updateContents()
|
|||||||
setPlainText(ui->codeSizeLineEdit, QString::number(analinfo["codesz"].toSt64()) + " bytes");
|
setPlainText(ui->codeSizeLineEdit, QString::number(analinfo["codesz"].toSt64()) + " bytes");
|
||||||
setPlainText(ui->percentageLineEdit, QString::number(analinfo["percent"].toSt64()) + "%");
|
setPlainText(ui->percentageLineEdit, QString::number(analinfo["percent"].toSt64()) + "%");
|
||||||
|
|
||||||
QStringList libs = Core()->cmdList("il");
|
|
||||||
if (!libs.isEmpty()) {
|
|
||||||
libs.removeFirst();
|
|
||||||
libs.removeLast();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
||||||
QLayoutItem *item = ui->verticalLayout_2->takeAt(0);
|
QLayoutItem *item = ui->verticalLayout_2->takeAt(0);
|
||||||
@ -141,13 +135,16 @@ void Dashboard::updateContents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const QString &lib : libs) {
|
const RzList *libs = rz_bin_object_get_libs(bf->o);
|
||||||
QLabel *label = new QLabel(this);
|
if (libs) {
|
||||||
|
for (const auto &lib : CutterRzList<char>(libs)) {
|
||||||
|
auto *label = new QLabel(this);
|
||||||
label->setText(lib);
|
label->setText(lib);
|
||||||
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
label->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
label->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||||
ui->verticalLayout_2->addWidget(label);
|
ui->verticalLayout_2->addWidget(label);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QSpacerItem *spacer = new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding);
|
QSpacerItem *spacer = new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||||
ui->verticalLayout_2->addSpacerItem(spacer);
|
ui->verticalLayout_2->addSpacerItem(spacer);
|
||||||
|
Loading…
Reference in New Issue
Block a user