Fix new warnings

- Fix compiler and cppcheck warning
- format with astyle
This commit is contained in:
ballessay 2017-04-28 15:38:01 +02:00 committed by C. Balles
parent ebe33ffe8e
commit f586ab2d4e
11 changed files with 151 additions and 153 deletions

View File

@ -59,7 +59,7 @@ namespace qhelpers
}
QTreeWidgetItem *appendRow(QTreeWidget *tw, const QString &str, const QString &str2,
const QString &str3, const QString &str4, const QString &str5)
const QString &str3, const QString &str4, const QString &str5)
{
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
// Fill dummy hidden column

View File

@ -20,7 +20,7 @@ namespace qhelpers
void adjustColumns(QTreeWidget *tw, int columnCount = 0, int padding = 0);
QTreeWidgetItem *appendRow(QTreeWidget *tw, const QString &str, const QString &str2 = QString(),
const QString &str3 = QString(), const QString &str4 = QString(), const QString &str5 = QString());
const QString &str3 = QString(), const QString &str4 = QString(), const QString &str5 = QString());
void setVerticalScrollMode(QAbstractItemView *tw);
}

View File

@ -58,11 +58,11 @@ int main(int argc, char *argv[])
bool analLevelSpecified = false;
int analLevel = 0;
if(cmdParser.isSet(analOption))
if (cmdParser.isSet(analOption))
{
analLevel = cmdParser.value(analOption).toInt(&analLevelSpecified);
if(!analLevelSpecified || analLevel < 0 || analLevel > 4)
if (!analLevelSpecified || analLevel < 0 || analLevel > 4)
{
printf("%s\n", QObject::tr("Invalid Analysis Level. May be a value between 0 and 4.").toLocal8Bit().constData());
return 1;
@ -72,7 +72,7 @@ int main(int argc, char *argv[])
if (args.empty())
{
if(analLevelSpecified)
if (analLevelSpecified)
{
printf("%s\n", QObject::tr("Filename must be specified to start analysis automatically.").toLocal8Bit().constData());
return 1;
@ -88,7 +88,7 @@ int main(int argc, char *argv[])
o->setAttribute(Qt::WA_DeleteOnClose);
o->show();
if(analLevelSpecified)
if (analLevelSpecified)
o->setupAndStartAnalysis(analLevel);
}

View File

@ -338,7 +338,7 @@ void MainWindow::refreshOmniBar(const QStringList &flags)
omnibar->refresh(flags);
}
void MainWindow::setFilename(QString fn)
void MainWindow::setFilename(const QString &fn)
{
// Add file name to window title
this->filename = fn;
@ -726,12 +726,12 @@ void MainWindow::seek(const QString &offset, const QString &name, bool raise_mem
{
// TODO: remove this method and use the one with RVA only!
if(offset.length() < 2)
if (offset.length() < 2)
return;
bool ok;
RVA addr = offset.mid(2).toULongLong(&ok, 16);
if(!ok)
if (!ok)
return;
seek(addr, name, raise_memory_dock);
@ -754,7 +754,7 @@ void MainWindow::seek(const RVA offset, const QString &name, bool raise_memory_d
this->memoryDock->disasTextEdit->setFocus();
// Rise and shine baby!
if(raise_memory_dock)
if (raise_memory_dock)
this->memoryDock->raise();
}
@ -905,7 +905,7 @@ void MainWindow::on_actionhide_bottomPannel_triggered()
}
}
void MainWindow::send_to_notepad(QString txt)
void MainWindow::send_to_notepad(const QString &txt)
{
this->notepadDock->appendPlainText("```\n" + txt + "\n```");
}

View File

@ -54,7 +54,7 @@ public:
void start_web_server();
void closeEvent(QCloseEvent *event);
void readSettings();
void setFilename(QString fn);
void setFilename(const QString &fn);
//void setCore(QRCore *core);
void seek(const QString &offset, const QString &name = NULL, bool raise_memory_dock = false);
void seek(const RVA offset, const QString &name = NULL, bool raise_memory_dock = false);
@ -64,7 +64,7 @@ public:
void get_refs(const QString &offset);
void add_output(QString msg);
void add_debug_output(QString msg);
void send_to_notepad(QString txt);
void send_to_notepad(const QString &txt);
void setWebServerState(bool start);
void raiseMemoryDock();
void toggleSideBarTheme();

View File

@ -230,7 +230,7 @@ QJsonDocument QRCore::cmdj(const QString &str)
QJsonParseError jsonError;
QJsonDocument doc = res ? QJsonDocument::fromJson(resString.toUtf8(), &jsonError) : QJsonDocument();
if(jsonError.error != QJsonParseError::NoError)
if (jsonError.error != QJsonParseError::NoError)
{
eprintf("Failed to parse JSON: %s\n", jsonError.errorString().toLocal8Bit().constData());
eprintf("%s\n", resString.toLocal8Bit().constData());
@ -856,7 +856,7 @@ QList<RVA> QRCore::getSeekHistory()
QList<RVA> ret;
QJsonArray jsonArray = cmdj("sj").array();
foreach(QJsonValue value, jsonArray)
foreach (QJsonValue value, jsonArray)
ret << value.toVariant().toULongLong();
return ret;
@ -869,7 +869,7 @@ QList<FunctionDescription> QRCore::getAllFunctions()
QJsonArray jsonArray = cmdj("aflj").array();
foreach(QJsonValue value, jsonArray)
foreach (QJsonValue value, jsonArray)
{
QJsonObject jsonObject = value.toObject();
@ -893,7 +893,7 @@ QList<ImportDescription> QRCore::getAllImports()
QJsonArray importsArray = cmdj("iij").array();
foreach(QJsonValue value, importsArray)
foreach (QJsonValue value, importsArray)
{
QJsonObject importObject = value.toObject();
@ -951,18 +951,18 @@ QList<SymbolDescription> QRCore::getAllSymbols()
}
QList<CommentDescription> QRCore::getAllComments(QString filterType)
QList<CommentDescription> QRCore::getAllComments(const QString &filterType)
{
CORE_LOCK();
QList<CommentDescription> ret;
QJsonArray commentsArray = cmdj("CCj").array();
for(QJsonValue value : commentsArray)
for (QJsonValue value : commentsArray)
{
QJsonObject commentObject = value.toObject();
QString type = commentObject["type"].toString();
if(type != filterType)
if (type != filterType)
continue;
CommentDescription comment;
@ -1022,4 +1022,4 @@ QList<StringDescription> QRCore::getAllStrings()
}
return ret;
}
}

View File

@ -178,7 +178,7 @@ public:
QList<FunctionDescription> getAllFunctions();
QList<ImportDescription> getAllImports();
QList<SymbolDescription> getAllSymbols();
QList<CommentDescription> getAllComments(QString type);
QList<CommentDescription> getAllComments(const QString &filterType);
QList<RelocDescription> getAllRelocs();
QList<StringDescription> getAllStrings();

View File

@ -14,23 +14,23 @@
#include <QResource>
FunctionModel::FunctionModel(QList<FunctionDescription> *functions, QSet<RVA> *import_addresses, bool nested, QFont default_font, QFont highlight_font, MainWindow *main, QObject *parent)
: functions(functions),
import_addresses(import_addresses),
main(main),
nested(nested),
default_font(default_font),
highlight_font(highlight_font),
QAbstractItemModel(parent)
{
current_index = -1;
: QAbstractItemModel(parent),
main(main),
functions(functions),
import_addresses(import_addresses),
highlight_font(highlight_font),
default_font(default_font),
nested(nested),
current_index(-1)
{
connect(main, SIGNAL(cursorAddressChanged(RVA)), this, SLOT(cursorAddressChanged(RVA)));
connect(main->core, SIGNAL(functionRenamed(QString, QString)), this, SLOT(functionRenamed(QString, QString)));
}
QModelIndex FunctionModel::index(int row, int column, const QModelIndex &parent) const
{
if(!parent.isValid())
if (!parent.isValid())
return createIndex(row, column, (quintptr)0); // root function nodes have id = 0
return createIndex(row, column, (quintptr)(parent.row() + 1)); // sub-nodes have id = function index + 1
@ -38,23 +38,23 @@ QModelIndex FunctionModel::index(int row, int column, const QModelIndex &parent)
QModelIndex FunctionModel::parent(const QModelIndex &index) const
{
if(!index.isValid() || index.column() != 0)
if (!index.isValid() || index.column() != 0)
return QModelIndex();
if(index.internalId() == 0) // root function node
if (index.internalId() == 0) // root function node
return QModelIndex();
else // sub-node
return this->index((int)(index.internalId()-1), 0);
return this->index((int)(index.internalId() - 1), 0);
}
int FunctionModel::rowCount(const QModelIndex &parent) const
{
if(!parent.isValid())
if (!parent.isValid())
return functions->count();
if(nested)
if (nested)
{
if(parent.internalId() == 0)
if (parent.internalId() == 0)
return 3; // sub-nodes for nested functions
return 0;
}
@ -62,9 +62,9 @@ int FunctionModel::rowCount(const QModelIndex &parent) const
return 0;
}
int FunctionModel::columnCount(const QModelIndex &parent) const
int FunctionModel::columnCount(const QModelIndex &/*parent*/) const
{
if(nested)
if (nested)
return 1;
else
return 4;
@ -73,12 +73,12 @@ int FunctionModel::columnCount(const QModelIndex &parent) const
QVariant FunctionModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
if (!index.isValid())
return QVariant();
int function_index;
bool subnode;
if(index.internalId() != 0) // sub-node
if (index.internalId() != 0) // sub-node
{
function_index = index.parent().row();
subnode = true;
@ -91,90 +91,90 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
const FunctionDescription &function = functions->at(function_index);
if(function_index >= functions->count())
if (function_index >= functions->count())
return QVariant();
switch(role)
switch (role)
{
case Qt::DisplayRole:
if(nested)
case Qt::DisplayRole:
if (nested)
{
if (subnode)
{
if(subnode)
switch (index.row())
{
switch(index.row())
{
case 0:
return tr("Offset: %1").arg(RAddressString(function.offset));
case 1:
return tr("Size: %1").arg(RSizeString(function.size));
case 2:
return tr("Import: %1").arg(import_addresses->contains(function.offset) ? tr("true") : tr("false"));
default:
return QVariant();
}
case 0:
return tr("Offset: %1").arg(RAddressString(function.offset));
case 1:
return tr("Size: %1").arg(RSizeString(function.size));
case 2:
return tr("Import: %1").arg(import_addresses->contains(function.offset) ? tr("true") : tr("false"));
default:
return QVariant();
}
else
return function.name;
}
else
{
switch(index.column())
{
case 0:
return RAddressString(function.offset);
case 1:
return RSizeString(function.size);
case 3:
return function.name;
default:
return QVariant();
}
}
case Qt::DecorationRole:
if(import_addresses->contains(function.offset) &&
(nested ? false :index.column() == 2))
return QIcon(":/img/icons/import_light.svg");
return QVariant();
case Qt::FontRole:
if(current_index == function_index)
return highlight_font;
return default_font;
case Qt::ToolTipRole:
return function.name;
}
else
{
QList<QString> info = main->core->cmd("afi @ " + function.name).split("\n");
if (info.length() > 2)
switch (index.column())
{
QString size = info[4].split(" ")[1];
QString complex = info[8].split(" ")[1];
QString bb = info[11].split(" ")[1];
return QString("Summary:\n\n Size: " + size +
"\n Cyclomatic complexity: " + complex +
"\n Basic blocks: " + bb +
"\n\nDisasm preview:\n\n" + main->core->cmd("pdi 10 @ " + function.name) +
"\nStrings:\n\n" + main->core->cmd("pdsf @ " + function.name));
case 0:
return RAddressString(function.offset);
case 1:
return RSizeString(function.size);
case 3:
return function.name;
default:
return QVariant();
}
return QVariant();
}
case FunctionDescriptionRole:
return QVariant::fromValue(function);
case Qt::DecorationRole:
if (import_addresses->contains(function.offset) &&
(nested ? false : index.column() == 2))
return QIcon(":/img/icons/import_light.svg");
return QVariant();
case IsImportRole:
return import_addresses->contains(function.offset);
case Qt::FontRole:
if (current_index == function_index)
return highlight_font;
return default_font;
default:
return QVariant();
case Qt::ToolTipRole:
{
QList<QString> info = main->core->cmd("afi @ " + function.name).split("\n");
if (info.length() > 2)
{
QString size = info[4].split(" ")[1];
QString complex = info[8].split(" ")[1];
QString bb = info[11].split(" ")[1];
return QString("Summary:\n\n Size: " + size +
"\n Cyclomatic complexity: " + complex +
"\n Basic blocks: " + bb +
"\n\nDisasm preview:\n\n" + main->core->cmd("pdi 10 @ " + function.name) +
"\nStrings:\n\n" + main->core->cmd("pdsf @ " + function.name));
}
return QVariant();
}
case FunctionDescriptionRole:
return QVariant::fromValue(function);
case IsImportRole:
return import_addresses->contains(function.offset);
default:
return QVariant();
}
}
QVariant FunctionModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role == Qt::DisplayRole && orientation == Qt::Horizontal)
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
{
if(nested)
if (nested)
{
return tr("Name");
}
@ -182,16 +182,16 @@ QVariant FunctionModel::headerData(int section, Qt::Orientation orientation, int
{
switch (section)
{
case 0:
return tr("Offset");
case 1:
return tr("Size");
case 2:
return tr("Imp.");
case 3:
return tr("Name");
default:
return QVariant();
case 0:
return tr("Offset");
case 1:
return tr("Size");
case 2:
return tr("Imp.");
case 3:
return tr("Name");
default:
return QVariant();
}
}
}
@ -213,7 +213,7 @@ void FunctionModel::endReloadFunctions()
void FunctionModel::cursorAddressChanged(RVA)
{
updateCurrentIndex();
emit dataChanged(index(0, 0), index(rowCount()-1, columnCount()-1));
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
void FunctionModel::updateCurrentIndex()
@ -223,12 +223,12 @@ void FunctionModel::updateCurrentIndex()
int index = -1;
RVA offset = 0;
for(int i=0; i<functions->count(); i++)
for (int i = 0; i < functions->count(); i++)
{
const FunctionDescription &function = functions->at(i);
if(function.contains(addr)
&& function.offset >= offset)
if (function.contains(addr)
&& function.offset >= offset)
{
offset = function.offset;
index = i;
@ -238,15 +238,15 @@ void FunctionModel::updateCurrentIndex()
current_index = index;
}
void FunctionModel::functionRenamed(QString prev_name, QString new_name)
void FunctionModel::functionRenamed(const QString &prev_name, const QString &new_name)
{
for(int i=0; i<functions->count(); i++)
for (int i = 0; i < functions->count(); i++)
{
FunctionDescription &function = (*functions)[i];
if(function.name == prev_name)
if (function.name == prev_name)
{
function.name = new_name;
emit dataChanged(index(i, 0), index(i, columnCount()-1));
emit dataChanged(index(i, 0), index(i, columnCount() - 1));
}
}
}
@ -255,7 +255,7 @@ void FunctionModel::functionRenamed(QString prev_name, QString new_name)
FunctionSortFilterProxyModel::FunctionSortFilterProxyModel(FunctionModel *source_model, QObject *parent)
: QSortFilterProxyModel(parent)
: QSortFilterProxyModel(parent)
{
setSourceModel(source_model);
setFilterCaseSensitivity(Qt::CaseInsensitive);
@ -272,17 +272,17 @@ bool FunctionSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &
bool FunctionSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
if(!left.isValid() || !right.isValid())
if (!left.isValid() || !right.isValid())
return false;
if(left.parent().isValid() || right.parent().isValid())
if (left.parent().isValid() || right.parent().isValid())
return false;
FunctionDescription left_function = left.data(FunctionModel::FunctionDescriptionRole).value<FunctionDescription>();
FunctionDescription right_function = right.data(FunctionModel::FunctionDescriptionRole).value<FunctionDescription>();
if(static_cast<FunctionModel *>(sourceModel())->isNested())
if (static_cast<FunctionModel *>(sourceModel())->isNested())
{
return left_function.name < right_function.name;
}
@ -290,24 +290,24 @@ bool FunctionSortFilterProxyModel::lessThan(const QModelIndex &left, const QMode
{
switch (left.column())
{
case 0:
return left_function.offset < right_function.offset;
case 1:
if (left_function.size != right_function.size)
return left_function.size < right_function.size;
break;
case 2:
{
bool left_is_import = left.data(FunctionModel::IsImportRole).toBool();
bool right_is_import = right.data(FunctionModel::IsImportRole).toBool();
if(!left_is_import && right_is_import)
return true;
break;
}
case 3:
return left_function.name < right_function.name;
default:
return false;
case 0:
return left_function.offset < right_function.offset;
case 1:
if (left_function.size != right_function.size)
return left_function.size < right_function.size;
break;
case 2:
{
bool left_is_import = left.data(FunctionModel::IsImportRole).toBool();
bool right_is_import = right.data(FunctionModel::IsImportRole).toBool();
if (!left_is_import && right_is_import)
return true;
break;
}
case 3:
return left_function.name < right_function.name;
default:
return false;
}
return left_function.offset < right_function.offset;
@ -390,7 +390,7 @@ void FunctionsWidget::refreshTree()
functions = this->main->core->getAllFunctions();
import_addresses.clear();
foreach(ImportDescription import, main->core->getAllImports())
foreach (ImportDescription import, main->core->getAllImports())
import_addresses.insert(import.plt);
function_model->endReloadFunctions();

View File

@ -57,7 +57,7 @@ public:
private slots:
void cursorAddressChanged(RVA addr);
void functionRenamed(QString prev_name, QString new_name);
void functionRenamed(const QString &prev_name, const QString &new_name);
};

View File

@ -310,7 +310,7 @@ void MemoryWidget::highlightHexCurrentLine()
highlightHexWords(cursor.selectedText());
}
void MemoryWidget::highlightHexWords(QString str)
void MemoryWidget::highlightHexWords(const QString &str)
{
QString searchString = str;
QTextDocument *document = ui->hexHexText_2->document();
@ -1582,12 +1582,10 @@ QString MemoryWidget::normalize_addr(QString addr)
void MemoryWidget::setFcnName(RVA addr)
{
RAnalFunction *fcn;
bool ok;
QString addr_string;
fcn = this->main->core->functionAt(addr);
if (ok && fcn)
if (fcn)
{
QString segment = this->main->core->cmd("S. @ " + QString::number(addr)).split(" ").last();
addr_string = segment.trimmed() + ":" + fcn->name;

View File

@ -116,7 +116,7 @@ private:
void setScrollMode();
private slots:
void on_cursorAddressChanged(RVA offset);
void on_cursorAddressChanged(RVA addr);
void highlightCurrentLine();
@ -125,7 +125,7 @@ private slots:
void highlightDecoCurrentLine();
void setFonts(QFont font);
void highlightHexWords(QString str);
void highlightHexWords(const QString &str);
void on_showInfoButton_2_clicked();
void on_actionSettings_menu_1_triggered();
void on_actionHideDisasm_side_panel_triggered();