Rename functions and flags in Raw Command, Fix #230

This commit is contained in:
Florian Märkl 2017-12-20 23:50:26 +01:00
parent ec2dfe83f7
commit aad3797159
7 changed files with 23 additions and 31 deletions

View File

@ -203,6 +203,13 @@ QString CutterCore::cmd(const QString &str)
return o;
}
QString CutterCore::cmdRaw(const QString &str)
{
QString cmdStr = str;
cmdStr.replace('\"', "\\\"");
return cmd("\"" + cmdStr + "\"");
}
QJsonDocument CutterCore::cmdj(const QString &str)
{
CORE_LOCK();
@ -322,10 +329,10 @@ void CutterCore::analyze(int level, QList<QString> advanced)
}
}
void CutterCore::renameFunction(QString old_name, QString new_name)
void CutterCore::renameFunction(const QString &oldName, const QString &newName)
{
cmd("afn " + new_name + " " + old_name);
emit functionRenamed(old_name, new_name);
cmdRaw("afn " + newName + " " + oldName);
emit functionRenamed(oldName, newName);
}
void CutterCore::delFunction(RVA addr)
@ -336,7 +343,7 @@ void CutterCore::delFunction(RVA addr)
void CutterCore::renameFlag(QString old_name, QString new_name)
{
cmd("fr " + old_name + " " + new_name);
cmdRaw("fr " + old_name + " " + new_name);
emit flagsChanged();
}

View File

@ -206,12 +206,13 @@ public:
int fcnEndBbs(RVA addr);
static QString sanitizeStringForCommand(QString s);
QString cmd(const QString &str);
QString cmdRaw(const QString &str);
QJsonDocument cmdj(const QString &str);
QStringList cmdList(const QString &str) { auto l = cmd(str).split("\n"); l.removeAll(""); return l; }
QList<DisassemblyLine> disassembleLines(RVA offset, int lines);
void renameFunction(QString prev_name, QString new_name);
void renameFunction(const QString &oldName, const QString &newName);
void delFunction(RVA addr);
void renameFlag(QString old_name, QString new_name);
void delFlag(RVA addr);
@ -346,7 +347,7 @@ public:
signals:
void refreshAll();
void functionRenamed(QString prev_name, QString new_name);
void functionRenamed(const QString &prev_name, const QString &new_name);
void varsChanged();
void functionsChanged();
void flagsChanged();

View File

@ -22,7 +22,7 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
// Signals that require a refresh all
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshView()));
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshView()));
connect(Core(), SIGNAL(functionRenamed(QString, QString)), this, SLOT(refreshView()));
connect(Core(), SIGNAL(functionRenamed(const QString &, const QString &)), this, SLOT(refreshView()));
connect(Core(), SIGNAL(flagsChanged()), this, SLOT(refreshView()));
connect(Core(), SIGNAL(varsChanged()), this, SLOT(refreshView()));
connect(Core(), SIGNAL(instructionChanged(RVA)), this, SLOT(refreshView()));

View File

@ -109,7 +109,7 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent)
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(flagsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(functionsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(functionRenamed(QString, QString)), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(functionRenamed(const QString &, const QString &)), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(varsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), &CutterCore::instructionChanged, this, [this](RVA offset) {

View File

@ -25,7 +25,7 @@ FunctionModel::FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *i
{
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(seekChanged(RVA)));
connect(Core(), SIGNAL(functionRenamed(QString, QString)), this, SLOT(functionRenamed(QString, QString)));
connect(Core(), SIGNAL(functionRenamed(const QString &, const QString &)), this, SLOT(functionRenamed(QString, QString)));
}
QModelIndex FunctionModel::index(int row, int column, const QModelIndex &parent) const

View File

@ -56,7 +56,7 @@ void SidebarWidget::refresh(RVA addr)
if(addr == RVA_INVALID)
addr = Core()->getOffset();
get_refs_data(addr);
updateRefs(addr);
setFcnName(addr);
fillOffsetInfo(RAddressString(addr));
}
@ -129,7 +129,7 @@ void SidebarWidget::on_xrefToToolButton_clicked()
}
}
void SidebarWidget::get_refs_data(RVA addr)
void SidebarWidget::updateRefs(RVA addr)
{
// refs = calls q hace esa funcion
QList<XrefDescription> refs = Core()->getXRefs(addr, false, false);
@ -137,28 +137,12 @@ void SidebarWidget::get_refs_data(RVA addr)
// xrefs = calls a esa funcion
QList<XrefDescription> xrefs = Core()->getXRefs(addr, true, false);
// Data for the disasm side graph
QList<int> data;
//qDebug() << "Refs:" << refs.size();
data << refs.size();
//qDebug() << "XRefs:" << xrefs.size();
data << xrefs.size();
//qDebug() << "CC: " << this->core->fcnCyclomaticComplexity(offset.toLong(&ok, 16));
//data << this->core->fcnCyclomaticComplexity(offset.toLong(&ok, 16));
data << Core()->getCycloComplex(addr);
//qDebug() << "BB: " << this->core->fcnBasicBlockCount(offset.toLong(&ok, 16));
data << Core()->fcnBasicBlockCount(addr);
data << Core()->fcnEndBbs(addr);
//qDebug() << "MEOW: " + this->core->fcnEndBbs(offset);
// Update disasm side bar
this->fill_refs(refs, xrefs, data);
this->fillRefs(refs, xrefs);
}
void SidebarWidget::fill_refs(QList<XrefDescription> refs, QList<XrefDescription> xrefs, QList<int> graph_data)
void SidebarWidget::fillRefs(QList<XrefDescription> refs, QList<XrefDescription> xrefs)
{
Q_UNUSED(graph_data);
TempConfig tempConfig;
tempConfig.set("scr.html", false)
.set("scr.color", false);

View File

@ -37,8 +37,8 @@ private:
std::unique_ptr<Ui::SidebarWidget> ui;
void setFcnName(RVA addr);
void get_refs_data(RVA addr);
void fill_refs(QList<XrefDescription> refs, QList<XrefDescription> xrefs, QList<int> graph_data);
void updateRefs(RVA addr);
void fillRefs(QList<XrefDescription> refs, QList<XrefDescription> xrefs);
void fillOffsetInfo(QString off);
void setScrollMode();