mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-20 13:46:06 +00:00
Some micro optimizations (#1346)
This commit is contained in:
parent
fa6e465bd4
commit
40452c9826
@ -40,7 +40,7 @@ int main(int argc, char *argv[])
|
||||
UpdateWorker *updateWorker = new UpdateWorker;
|
||||
QObject::connect(updateWorker, &UpdateWorker::checkComplete,
|
||||
[=](const QVersionNumber &version, const QString & error) {
|
||||
if (error == "" && version > UpdateWorker::currentVersionNumber()) {
|
||||
if (error.isEmpty() && version > UpdateWorker::currentVersionNumber()) {
|
||||
updateWorker->showUpdateDialog(true);
|
||||
}
|
||||
updateWorker->deleteLater();
|
||||
|
@ -47,7 +47,7 @@ void AsyncTask::run()
|
||||
|
||||
running = true;
|
||||
|
||||
logBuffer = "";
|
||||
logBuffer.clear();
|
||||
emit logChanged(logBuffer);
|
||||
runTask();
|
||||
|
||||
@ -60,7 +60,7 @@ void AsyncTask::run()
|
||||
|
||||
void AsyncTask::log(QString s)
|
||||
{
|
||||
logBuffer += s + "\n";
|
||||
logBuffer += s.append(QLatin1Char('\n'));
|
||||
emit logChanged(logBuffer);
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,8 @@ BasicBlockHighlighter::BasicBlockHighlighter()
|
||||
|
||||
BasicBlockHighlighter::~BasicBlockHighlighter()
|
||||
{
|
||||
for (BasicBlockIt itr = bbMap.begin(); itr != bbMap.end(); itr++) {
|
||||
delete itr->second;
|
||||
for (BasicBlockIt itr = bbMap.begin(); itr != bbMap.end(); ++itr) {
|
||||
delete itr->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ RichTextPainter::List RichTextPainter::fromTextDocument(const QTextDocument &doc
|
||||
List r;
|
||||
|
||||
for (QTextBlock block = doc.begin(); block != doc.end(); block = block.next()) {
|
||||
for (QTextBlock::iterator it = block.begin(); it != block.end(); it++) {
|
||||
for (QTextBlock::iterator it = block.begin(); it != block.end(); ++it) {
|
||||
QTextFragment fragment = it.fragment();
|
||||
QTextCharFormat format = fragment.charFormat();
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
TempConfig::~TempConfig()
|
||||
{
|
||||
for (auto i = resetValues.constBegin(); i != resetValues.constEnd(); i++) {
|
||||
for (auto i = resetValues.constBegin(); i != resetValues.constEnd(); ++i) {
|
||||
switch (i.value().type()) {
|
||||
case QVariant::String:
|
||||
Core()->setConfig(i.key(), i.value().toString());
|
||||
|
@ -96,7 +96,7 @@ void UpdateWorker::showUpdateDialog(bool showDontCheckForUpdatesButton)
|
||||
QStandardPaths::writableLocation(QStandardPaths::HomeLocation) +
|
||||
QDir::separator() + getRepositoryFileName(),
|
||||
QString("%1 (*.%1)").arg(getRepositeryExt()));
|
||||
if (fullFileName != "") {
|
||||
if (!fullFileName.isEmpty()) {
|
||||
QProgressDialog progressDial(tr("Downloading update..."),
|
||||
tr("Cancel"),
|
||||
0, 100);
|
||||
|
@ -226,7 +226,7 @@ QString CutterCore::sdbGet(QString path, QString key)
|
||||
if (val && *val)
|
||||
return val;
|
||||
}
|
||||
return QString("");
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool CutterCore::sdbSet(QString path, QString key, QString val)
|
||||
@ -859,7 +859,7 @@ QString CutterCore::getDecompiledCodePDC(RVA addr)
|
||||
|
||||
bool CutterCore::getR2DecAvailable()
|
||||
{
|
||||
return cmd("e cmd.pdc=?").split('\n').contains(QStringLiteral("r2dec"));
|
||||
return cmdList("e cmd.pdc=?").contains(QStringLiteral("r2dec"));
|
||||
}
|
||||
|
||||
QString CutterCore::getDecompiledCodeR2Dec(RVA addr)
|
||||
@ -1332,13 +1332,8 @@ bool CutterCore::isGraphEmpty()
|
||||
|
||||
void CutterCore::getOpcodes()
|
||||
{
|
||||
QString opcodes = cmd("?O");
|
||||
this->opcodes = opcodes.split("\n");
|
||||
// Remove the last empty element
|
||||
this->opcodes.removeLast();
|
||||
QString registers = cmd("drp~[1]");
|
||||
this->regs = registers.split("\n");
|
||||
this->regs.removeLast();
|
||||
this->opcodes = cmdList("?O");
|
||||
this->regs = cmdList("drp~[1]");
|
||||
}
|
||||
|
||||
void CutterCore::setSettings()
|
||||
@ -1587,7 +1582,7 @@ QList<SymbolDescription> CutterCore::getAllSymbols()
|
||||
SymbolDescription symbol;
|
||||
symbol.vaddr = entry->vaddr;
|
||||
symbol.name = QString("entry") + QString::number(n++);
|
||||
symbol.bind = "";
|
||||
symbol.bind.clear();
|
||||
symbol.type = "entry";
|
||||
ret << symbol;
|
||||
}
|
||||
@ -2333,7 +2328,7 @@ QList<SearchDescription> CutterCore::getAllSearch(QString search_for, QString sp
|
||||
|
||||
SearchDescription exp;
|
||||
|
||||
exp.code = QString("");
|
||||
exp.code.clear();
|
||||
for (const QJsonValue &value2 : searchObject[RJsonKey::opcodes].toArray()) {
|
||||
QJsonObject gadget = value2.toObject();
|
||||
exp.code += gadget[RJsonKey::opcode].toString() + "; ";
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
QString cmdRaw(const QString &str);
|
||||
QJsonDocument cmdj(const char *str);
|
||||
QJsonDocument cmdj(const QString &str) { return cmdj(str.toUtf8().constData()); }
|
||||
QStringList cmdList(const char *str) { return cmd(str).split('\n', QString::SkipEmptyParts); }
|
||||
QStringList cmdList(const char *str) { return cmd(str).split(QLatin1Char('\n'), QString::SkipEmptyParts); }
|
||||
QStringList cmdList(const QString &str) { return cmdList(str.toUtf8().constData()); }
|
||||
QString cmdTask(const QString &str);
|
||||
QJsonDocument cmdjTask(const QString &str);
|
||||
|
@ -92,7 +92,7 @@ void AboutDialog::on_checkForUpdatesButton_clicked()
|
||||
connect(&updateWorker, &UpdateWorker::checkComplete, &waitDialog, &QProgressDialog::cancel);
|
||||
connect(&updateWorker, &UpdateWorker::checkComplete,
|
||||
[&updateWorker](const QVersionNumber &version, const QString & error) {
|
||||
if (error != "") {
|
||||
if (!error.isEmpty()) {
|
||||
QMessageBox::critical(nullptr, tr("Error!"), error);
|
||||
} else {
|
||||
if (version <= UpdateWorker::currentVersionNumber()) {
|
||||
|
@ -119,7 +119,7 @@ ProcessBeingAnalysedProxyModel::ProcessBeingAnalysedProxyModel(ProcessModel *sou
|
||||
QString ProcessBeingAnalysedProxyModel::processPathToFilename(const QString &path) const
|
||||
{
|
||||
// removes the arguments and gets filename from the process path
|
||||
return path.split(" ").first().split("/").last();
|
||||
return path.section(QLatin1Char(' '), 0, 0).section(QLatin1Char('/'), -1);
|
||||
}
|
||||
|
||||
bool ProcessBeingAnalysedProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
|
||||
@ -329,4 +329,4 @@ void AttachProcDialog::on_procBeingAnalyzedView_doubleClicked(const QModelIndex
|
||||
Q_UNUSED(index);
|
||||
|
||||
accept();
|
||||
}
|
||||
}
|
||||
|
@ -55,11 +55,11 @@ void EditFunctionDialog::setStackSizeText(const QString &stackSize)
|
||||
ui->stackSizeLineEdit->setText(stackSize);
|
||||
}
|
||||
|
||||
void EditFunctionDialog::setCallConList(const QStringList callConList) {
|
||||
void EditFunctionDialog::setCallConList(const QStringList &callConList) {
|
||||
ui->callConComboBox->addItems(callConList);
|
||||
}
|
||||
|
||||
void EditFunctionDialog::setCallConSelected(const QString selected) {
|
||||
void EditFunctionDialog::setCallConSelected(const QString &selected) {
|
||||
ui->callConComboBox->setCurrentText(selected);
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,8 @@ public:
|
||||
void setEndAddrText(const QString &endAddr);
|
||||
QString getStackSizeText();
|
||||
void setStackSizeText(const QString &stackSize);
|
||||
void setCallConList(const QStringList callConList);
|
||||
void setCallConSelected(const QString selected);
|
||||
void setCallConList(const QStringList &callConList);
|
||||
void setCallConSelected(const QString &selected);
|
||||
QString getCallConSelected();
|
||||
|
||||
private slots:
|
||||
|
@ -50,7 +50,7 @@ void EditInstructionDialog::updatePreview(const QString &input)
|
||||
result = Core()->assemble(input).trimmed();
|
||||
}
|
||||
|
||||
if (result.isEmpty() || result.contains("\n")) {
|
||||
if (result.isEmpty() || result.contains(QLatin1Char('\n'))) {
|
||||
ui->instructionLabel->setText("Unknown Instruction");
|
||||
} else {
|
||||
ui->instructionLabel->setText(result);
|
||||
|
@ -37,7 +37,7 @@ void EditVariablesDialog::applyFields()
|
||||
|
||||
Core()->cmdRaw(QString("afvt %1 %2").arg(desc.name).arg(ui->typeComboBox->currentText()));
|
||||
|
||||
QString newName = ui->nameEdit->text().replace(" ", "_");
|
||||
QString newName = ui->nameEdit->text().replace(QLatin1Char(' '), QLatin1Char('_'));
|
||||
if (newName != desc.name) {
|
||||
Core()->cmdRaw(QString("afvn %1 %2").arg(newName).arg(desc.name));
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ QString LinkTypeDialog::findLinkedType(RVA address)
|
||||
|
||||
// Extract the given type from returned data
|
||||
// TODO: Implement "tlsj" in radare2 or some other function to directly get linked type
|
||||
QString s = ret.split("\n").first();
|
||||
QString s = ret.section(QLatin1Char('\n'), 0, 0);
|
||||
return s.mid(1, s.size() - 2);
|
||||
}
|
||||
|
||||
|
@ -267,9 +267,7 @@ bool NewFileDialog::fillRecentFilesList()
|
||||
// Get stored files
|
||||
|
||||
// Remove all but the file name
|
||||
const QString sep = QDir::separator();
|
||||
const QStringList name_list = file.split(sep);
|
||||
const QString name = name_list.last();
|
||||
const QString name = file.section(QDir::separator(), -1);
|
||||
|
||||
// Get file info
|
||||
QFileInfo info(file);
|
||||
|
@ -86,17 +86,12 @@ void XrefsDialog::on_toTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int c
|
||||
|
||||
QString XrefsDialog::normalizeAddr(const QString &addr) const
|
||||
{
|
||||
QString r = addr;
|
||||
QString base = addr.split("0x")[1].trimmed();
|
||||
int len = base.length();
|
||||
if (len < 8) {
|
||||
int padding = 8 - len;
|
||||
QString zero = "0";
|
||||
QString zeroes = zero.repeated(padding);
|
||||
r = "0x" + zeroes + base;
|
||||
QString ret = addr;
|
||||
if (addr.length() < 10) {
|
||||
ret = ret.mid(3).rightJustified(8, QLatin1Char('0'));
|
||||
ret.prepend(QLatin1Literal("0x"));
|
||||
}
|
||||
|
||||
return r;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void XrefsDialog::setupPreviewFont()
|
||||
@ -196,7 +191,7 @@ QString XrefsDialog::xrefTypeString(const QString &type)
|
||||
case R_ANAL_REF_TYPE_DATA:
|
||||
return QString("Data");
|
||||
case R_ANAL_REF_TYPE_NULL:
|
||||
return QString("");
|
||||
return QString();
|
||||
case R_ANAL_REF_TYPE_STRING:
|
||||
return QString("String");
|
||||
default:
|
||||
|
@ -290,8 +290,8 @@ void DisassemblyContextMenu::aboutToShowSlot()
|
||||
|
||||
// Get the possible offsets using the "tas" command
|
||||
// TODO: add tasj command to radare2 and then use it here
|
||||
QString ret = Core()->cmd("tas " + memDisp.toString());
|
||||
for (QString val: ret.split("\n")) {
|
||||
QStringList ret = Core()->cmdList("tas " + memDisp.toString());
|
||||
for (const QString &val : ret) {
|
||||
if (val.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -111,8 +111,7 @@ void PluginManager::loadPythonPlugins(const QDir &directory)
|
||||
}
|
||||
QString moduleName;
|
||||
if (fileName.endsWith(".py")) {
|
||||
QStringList l = fileName.split(".py");
|
||||
moduleName = l[0];
|
||||
moduleName = fileName.chopped(3);
|
||||
} else {
|
||||
moduleName = fileName;
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ void BreakpointWidget::addBreakpointDialog()
|
||||
if (dialog.exec()) {
|
||||
QString bps = dialog.getBreakpoints();
|
||||
if (!bps.isEmpty()) {
|
||||
QStringList bpList = bps.split(' ', QString::SkipEmptyParts);
|
||||
QStringList bpList = bps.split(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||
for (const QString &bp : bpList) {
|
||||
Core()->toggleBreakpoint(bp);
|
||||
}
|
||||
|
@ -430,7 +430,7 @@ void ColorSchemePrefWidget::apply()
|
||||
} else {
|
||||
scheme += "ec ";
|
||||
}
|
||||
scheme += curr.optionName + " rgb:" + curr.color.name().remove("#").toLower() + "\n";
|
||||
scheme += curr.optionName + " rgb:" + curr.color.name().remove(QLatin1Char('#')).toLower() + "\n";
|
||||
}
|
||||
ColorSchemeFileWorker().save(scheme, Config()->getColorTheme());
|
||||
Config()->setColorTheme(Config()->getColorTheme());
|
||||
|
@ -56,7 +56,7 @@ void Dashboard::updateContents()
|
||||
this->ui->bitsEdit->setText(QString::number(item2["bits"].toDouble()));
|
||||
|
||||
if (!item2["relro"].isUndefined()) {
|
||||
QString relro = item2["relro"].toString().split(" ").at(0);
|
||||
QString relro = item2["relro"].toString().section(QLatin1Char(' '), 0, 0);
|
||||
relro[0] = relro[0].toUpper();
|
||||
this->ui->relroEdit->setText(relro);
|
||||
}
|
||||
@ -110,11 +110,10 @@ void Dashboard::updateContents()
|
||||
ui->md5Edit->setText(md5);
|
||||
ui->sha1Edit->setText(sha1);
|
||||
|
||||
QString libs = Core()->cmd("il");
|
||||
QStringList lines = libs.split("\n", QString::SkipEmptyParts);
|
||||
if (!lines.isEmpty()) {
|
||||
lines.removeFirst();
|
||||
lines.removeLast();
|
||||
QStringList libs = Core()->cmdList("il");
|
||||
if (!libs.isEmpty()) {
|
||||
libs.removeFirst();
|
||||
libs.removeLast();
|
||||
}
|
||||
|
||||
// dunno: why not label->setText(lines.join("\n")?
|
||||
@ -130,7 +129,7 @@ void Dashboard::updateContents()
|
||||
}
|
||||
}
|
||||
|
||||
for (const QString &lib : lines) {
|
||||
for (const QString &lib : libs) {
|
||||
QLabel *label = new QLabel(this);
|
||||
label->setText(lib);
|
||||
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
@ -117,7 +117,7 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) :
|
||||
connect(actionStep, &QAction::triggered, Core(), &CutterCore::stepDebug);
|
||||
connect(actionStart, &QAction::triggered, [ = ]() {
|
||||
// check if file is executable before starting debug
|
||||
QString filename = Core()->getConfig("file.path").split(" ").first();
|
||||
QString filename = Core()->getConfig("file.path").section(QLatin1Char(' '), 0, 0);
|
||||
QFileInfo info(filename);
|
||||
if (!Core()->currentlyDebugging && !info.isExecutable()) {
|
||||
QMessageBox msgBox;
|
||||
|
@ -181,8 +181,10 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
case Qt::DecorationRole:
|
||||
if (importAddresses->contains(function.offset) &&
|
||||
(nested ? false : index.column() == ImportColumn))
|
||||
return QIcon(":/img/icons/import_light.svg");
|
||||
(nested ? false : index.column() == ImportColumn)) {
|
||||
const static QIcon importIcon(":/img/icons/import_light.svg");
|
||||
return importIcon;
|
||||
}
|
||||
return QVariant();
|
||||
|
||||
case Qt::FontRole:
|
||||
@ -225,7 +227,7 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
}
|
||||
|
||||
const QStringList &summary = Core()->cmd(QString("pdsf @ %1").arg(function.offset)).split("\n", QString::SkipEmptyParts);
|
||||
const QStringList &summary = Core()->cmdList(QString("pdsf @ %1").arg(function.offset));
|
||||
|
||||
const QFont &fnt = Config()->getFont();
|
||||
QFontMetrics fm{ fnt };
|
||||
@ -252,7 +254,7 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
if (!highlights.isEmpty()) {
|
||||
toolTipContent += tr("<div><strong>Highlights</strong>:<br>%1</div>")
|
||||
.arg(highlights.join("\n").toHtmlEscaped().replace("\n", "<br>"));
|
||||
.arg(highlights.join(QLatin1Char('\n')).toHtmlEscaped().replace(QLatin1Char('\n'), "<br>"));
|
||||
}
|
||||
toolTipContent += "</div></html>";
|
||||
return toolTipContent;
|
||||
|
@ -14,7 +14,7 @@ SdbWidget::SdbWidget(MainWindow *main, QAction *action) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
path = "";
|
||||
path.clear();
|
||||
|
||||
connect(Core(), SIGNAL(refreshAll()), this, SLOT(reload()));
|
||||
reload(nullptr);
|
||||
@ -64,19 +64,19 @@ void SdbWidget::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int colum
|
||||
|
||||
if (column == 0) {
|
||||
if (item->text(0) == "../") {
|
||||
int idx = path.lastIndexOf("/");
|
||||
int idx = path.lastIndexOf(QLatin1Char('/'));
|
||||
if (idx != -1) {
|
||||
newpath = path.mid(0, idx);
|
||||
} else {
|
||||
newpath = "";
|
||||
newpath.clear();
|
||||
}
|
||||
reload(newpath);
|
||||
|
||||
} else if (item->text(0).indexOf("/") != -1) {
|
||||
if (path != "") {
|
||||
newpath = path + "/" + item->text(0).replace("/", "");
|
||||
} else if (item->text(0).indexOf(QLatin1Char('/')) != -1) {
|
||||
if (!path.isEmpty()) {
|
||||
newpath = path + "/" + item->text(0).remove(QLatin1Char('/'));
|
||||
} else {
|
||||
newpath = path + item->text(0).replace("/", "");
|
||||
newpath = path + item->text(0).remove(QLatin1Char('/'));
|
||||
}
|
||||
// enter directory
|
||||
reload(newpath);
|
||||
|
@ -420,12 +420,12 @@ void AddrDockScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
|
||||
RVA AddrDockScene::getAddrFromPos(int posY, bool seek)
|
||||
{
|
||||
QHash<QString, int>::const_iterator i = namePosYMap.constBegin();
|
||||
QHash<QString, int>::const_iterator it;
|
||||
QHash<QString, RVA> addrMap = seek ? seekAddrMap : nameAddrMap;
|
||||
QHash<QString, int> addrSizeMap = seek ? seekAddrSizeMap : nameAddrSizeMap;
|
||||
while (i != namePosYMap.constEnd()) {
|
||||
QString name = i.key();
|
||||
int y = i.value();
|
||||
for (it = namePosYMap.constBegin(); it != namePosYMap.constEnd(); ++it) {
|
||||
QString name = it.key();
|
||||
int y = it.value();
|
||||
int h = nameHeightMap[name];
|
||||
if (posY >= y && y + h >= posY) {
|
||||
if (h == 0) {
|
||||
@ -433,7 +433,6 @@ RVA AddrDockScene::getAddrFromPos(int posY, bool seek)
|
||||
}
|
||||
return addrMap[name] + (float)addrSizeMap[name] * ((float)(posY - y) / (float)h);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -456,17 +455,19 @@ void RawAddrDock::updateDock()
|
||||
int y = 0;
|
||||
int validMinSize = getValidMinSize();
|
||||
proxyModel->sort(2, Qt::AscendingOrder);
|
||||
for (int i = 0; i < proxyModel->rowCount(); i++) {
|
||||
for (int i = 0; i < proxyModel->rowCount(); ++i) {
|
||||
QModelIndex idx = proxyModel->index(i, 0);
|
||||
QString name = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().name;
|
||||
auto desc = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>();
|
||||
|
||||
RVA vaddr = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().vaddr;
|
||||
int vsize = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().vsize;
|
||||
QString name = desc.name;
|
||||
|
||||
RVA vaddr = desc.vaddr;
|
||||
int vsize = desc.vsize;
|
||||
addrDockScene->seekAddrMap[name] = vaddr;
|
||||
addrDockScene->seekAddrSizeMap[name] = vsize;
|
||||
|
||||
RVA addr = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().paddr;
|
||||
int size = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().size;
|
||||
RVA addr = desc.paddr;
|
||||
int size = desc.size;
|
||||
addrDockScene->nameAddrMap[name] = addr;
|
||||
addrDockScene->nameAddrSizeMap[name] = size;
|
||||
|
||||
|
@ -297,7 +297,7 @@ QString VisualNavbar::toolTipForAddress(RVA address)
|
||||
bool first = true;
|
||||
for (const QString §ion : sections) {
|
||||
if (!first) {
|
||||
ret += "\n";
|
||||
ret.append(QLatin1Char('\n'));
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user