Use Core() everywhere (#440)

This commit is contained in:
Abdel-Rahman A 2018-04-12 08:33:30 +02:00 committed by xarkes
parent 05fe4e60ea
commit c79106ef84
24 changed files with 57 additions and 57 deletions

View File

@ -9,7 +9,7 @@ AnalThread::AnalThread(OptionsDialog *parent) :
QThread(parent),
level(2),
main(nullptr),
core(CutterCore::getInstance()),
core(Core()),
interrupted(false)
{
}

View File

@ -5,7 +5,7 @@ FlagDialog::FlagDialog(RVA offset, QWidget *parent) :
QDialog(parent),
ui(new Ui::FlagDialog),
offset(offset),
core(CutterCore::getInstance())
core(Core())
{
ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));

View File

@ -253,7 +253,7 @@ bool NewFileDialog::fillRecentFilesList()
bool NewFileDialog::fillProjectsList()
{
CutterCore *core = CutterCore::getInstance();
CutterCore *core = Core();
auto currentDir = Config()->getDirProjects();

View File

@ -12,7 +12,7 @@ OptionsDialog::OptionsDialog(MainWindow *main):
QDialog(0), // parent may not be main
analThread(this),
main(main),
core(CutterCore::getInstance()),
core(Core()),
defaultAnalLevel(1),
ui(new Ui::OptionsDialog)
{

View File

@ -13,7 +13,7 @@ SaveProjectDialog::SaveProjectDialog(bool quit, QWidget *parent) :
{
ui->setupUi(this);
CutterCore *core = CutterCore::getInstance();
CutterCore *core = Core();
if (quit) {
ui->buttonBox->setStandardButtons(QDialogButtonBox::Save

View File

@ -13,7 +13,7 @@ XrefsDialog::XrefsDialog(QWidget *parent) :
addr(0),
func_name(QString::null),
ui(new Ui::XrefsDialog),
core(CutterCore::getInstance())
core(Core())
{
ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));

View File

@ -8,7 +8,7 @@ Highlighter::Highlighter(QTextDocument *parent) :
{
HighlightingRule rule;
core = CutterCore::getInstance();
core = Core();
keywordFormat.setForeground(QColor(65, 131, 215));
keywordFormat.setFontWeight(QFont::Bold);

View File

@ -256,8 +256,8 @@ void ClassesWidget::refreshClasses()
{
model->beginReload();
classes = getSource() == Source::BIN
? CutterCore::getInstance()->getAllClassesFromBin()
: CutterCore::getInstance()->getAllClassesFromFlags();
? Core()->getAllClassesFromBin()
: Core()->getAllClassesFromFlags();
model->endReload();
qhelpers::adjustColumns(ui->classesTreeView, 3, 0);
@ -268,5 +268,5 @@ void ClassesWidget::refreshClasses()
void ClassesWidget::on_classesTreeView_doubleClicked(const QModelIndex &index)
{
RVA offset = index.data(ClassesModel::OffsetRole).value<RVA>();
CutterCore::getInstance()->seek(offset);
Core()->seek(offset);
}

View File

@ -39,7 +39,7 @@ void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *it
{
// Get offset and name of item double clicked
CommentDescription comment = item->data(0, Qt::UserRole).value<CommentDescription>();
CutterCore::getInstance()->seek(comment.offset);
Core()->seek(comment.offset);
}
void CommentsWidget::on_nestedCmtsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int)
@ -51,7 +51,7 @@ void CommentsWidget::on_nestedCmtsTreeWidget_itemDoubleClicked(QTreeWidgetItem *
// Get offset and name of item double clicked
CommentDescription comment = item->data(0, Qt::UserRole).value<CommentDescription>();
CutterCore::getInstance()->seek(comment.offset);
Core()->seek(comment.offset);
}
@ -139,11 +139,11 @@ QMap<QString, QList<QList<QString>>> CutterCore::getNestedComments()
void CommentsWidget::refreshTree()
{
ui->nestedCmtsTreeWidget->clear();
QList<CommentDescription> comments = CutterCore::getInstance()->getAllComments("CCu");
QList<CommentDescription> comments = Core()->getAllComments("CCu");
QMap<QString, QList<CommentDescription>> nestedComments;
for (CommentDescription comment : comments) {
QString fcn_name = CutterCore::getInstance()->cmdFunctionAt(comment.offset);
QString fcn_name = Core()->cmdFunctionAt(comment.offset);
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, RAddressString(comment.offset));
item->setText(1, fcn_name);

View File

@ -173,7 +173,7 @@ void ConsoleWidget::on_inputLineEdit_returnPressed()
QString input = ui->inputLineEdit->text();
if (!input.isEmpty()) {
if (!isForbidden(input)) {
QString res = CutterCore::getInstance()->cmd(input);
QString res = Core()->cmd(input);
QString cmd_line = "[" + RAddressString(Core()->getOffset()) + "]> " + input + "\n";
ui->outputTextEdit->appendPlainText(cmd_line + res);
scrollOutputToEnd();

View File

@ -103,12 +103,12 @@ void Dashboard::updateContents()
}
// Add file hashes and libraries
QString md5 = CutterCore::getInstance()->cmd("e file.md5");
QString sha1 = CutterCore::getInstance()->cmd("e file.sha1");
QString md5 = Core()->cmd("e file.md5");
QString sha1 = Core()->cmd("e file.sha1");
ui->md5Edit->setText(md5);
ui->sha1Edit->setText(sha1);
QString libs = CutterCore::getInstance()->cmd("il");
QString libs = Core()->cmd("il");
QStringList lines = libs.split("\n", QString::SkipEmptyParts);
if (!lines.isEmpty()) {
lines.removeFirst();
@ -142,11 +142,11 @@ void Dashboard::updateContents()
ui->verticalLayout_2->addSpacerItem(spacer);
// Add entropy value
QString entropy = CutterCore::getInstance()->cmd("ph entropy").trimmed();
QString entropy = Core()->cmd("ph entropy").trimmed();
ui->lblEntropy->setText(entropy);
// Get stats for the graphs
QStringList stats = CutterCore::getInstance()->getStats();
QStringList stats = Core()->getStats();
}
void Dashboard::on_certificateButton_clicked()
@ -186,4 +186,4 @@ void Dashboard::on_certificateButton_clicked()
QMessageBox::NoButton, this);
msgBoxCertificateInf.exec();
}
}
}

View File

@ -505,7 +505,7 @@ bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
}
if (jump != RVA_INVALID) {
CutterCore::getInstance()->seek(jump);
Core()->seek(jump);
}
return true;

View File

@ -28,7 +28,7 @@ EntrypointWidget::~EntrypointWidget() {}
void EntrypointWidget::fillEntrypoint()
{
ui->entrypointTreeWidget->clear();
for (auto i : CutterCore::getInstance()->getAllEntrypoint()) {
for (auto i : Core()->getAllEntrypoint()) {
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, RAddressString(i.vaddr));
item->setText(1, i.type);
@ -48,5 +48,5 @@ void EntrypointWidget::on_entrypointTreeWidget_itemDoubleClicked(QTreeWidgetItem
int /* column */)
{
EntrypointDescription ep = item->data(0, Qt::UserRole).value<EntrypointDescription>();
CutterCore::getInstance()->seek(ep.vaddr);
Core()->seek(ep.vaddr);
}

View File

@ -148,7 +148,7 @@ ExportsWidget::~ExportsWidget() {}
void ExportsWidget::refreshExports()
{
exports_model->beginReloadExports();
exports = CutterCore::getInstance()->getAllExports();
exports = Core()->getAllExports();
exports_model->endReloadExports();
qhelpers::adjustColumns(ui->exportsTreeView, 3, 0);
@ -163,5 +163,5 @@ void ExportsWidget::setScrollMode()
void ExportsWidget::on_exportsTreeView_doubleClicked(const QModelIndex &index)
{
ExportDescription exp = index.data(ExportsModel::ExportDescriptionRole).value<ExportDescription>();
CutterCore::getInstance()->seek(exp.vaddr);
Core()->seek(exp.vaddr);
}

View File

@ -150,7 +150,7 @@ FlagsWidget::~FlagsWidget() {}
void FlagsWidget::on_flagsTreeView_doubleClicked(const QModelIndex &index)
{
FlagDescription flag = index.data(FlagsModel::FlagDescriptionRole).value<FlagDescription>();
CutterCore::getInstance()->seek(flag.offset);
Core()->seek(flag.offset);
}
void FlagsWidget::on_flagspaceCombo_currentTextChanged(const QString &arg1)
@ -169,7 +169,7 @@ void FlagsWidget::on_actionRename_triggered()
r->setName(flag.name);
if (r->exec()) {
QString new_name = r->getName();
CutterCore::getInstance()->renameFlag(flag.name, new_name);
Core()->renameFlag(flag.name, new_name);
}
}
@ -204,7 +204,7 @@ void FlagsWidget::refreshFlagspaces()
ui->flagspaceCombo->clear();
ui->flagspaceCombo->addItem(tr("(all)"));
for (auto i : CutterCore::getInstance()->getAllFlagspaces()) {
for (auto i : Core()->getAllFlagspaces()) {
ui->flagspaceCombo->addItem(i.name, QVariant::fromValue(i));
}
@ -224,7 +224,7 @@ void FlagsWidget::refreshFlags()
flags_model->beginReloadFlags();
flags = CutterCore::getInstance()->getAllFlags(flagspace);
flags = Core()->getAllFlags(flagspace);
flags_model->endReloadFlags();
qhelpers::adjustColumns(ui->flagsTreeView, 2, 0);

View File

@ -169,7 +169,7 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
return static_cast<int>(Qt::AlignLeft | Qt::AlignVCenter);
case Qt::ToolTipRole: {
QList<QString> info = CutterCore::getInstance()->cmd("afi @ " + function.name).split("\n");
QList<QString> info = Core()->cmd("afi @ " + function.name).split("\n");
if (info.length() > 2) {
QString size = info[4].split(" ")[1];
QString complex = info[8].split(" ")[1];
@ -177,8 +177,8 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const
return QString("Summary:\n\n Size: " + size +
"\n Cyclomatic complexity: " + complex +
"\n Basic blocks: " + bb +
"\n\nDisasm preview:\n\n" + CutterCore::getInstance()->cmd("pdi 10 @ " + function.name) +
"\nStrings:\n\n" + CutterCore::getInstance()->cmd("pdsf @ " + function.name));
"\n\nDisasm preview:\n\n" + Core()->cmd("pdi 10 @ " + function.name) +
"\nStrings:\n\n" + Core()->cmd("pdsf @ " + function.name));
}
return QVariant();
}
@ -435,13 +435,13 @@ void FunctionsWidget::refreshTree()
{
functionModel->beginReloadFunctions();
functions = CutterCore::getInstance()->getAllFunctions();
functions = Core()->getAllFunctions();
importAddresses.clear();
foreach (ImportDescription import, CutterCore::getInstance()->getAllImports())
foreach (ImportDescription import, Core()->getAllImports())
importAddresses.insert(import.plt);
mainAdress = (ut64)CutterCore::getInstance()->cmdj("iMj").object()["vaddr"].toInt();
mainAdress = (ut64)Core()->cmdj("iMj").object()["vaddr"].toInt();
functionModel->endReloadFunctions();
@ -485,9 +485,9 @@ void FunctionsWidget::on_actionDisasAdd_comment_triggered()
// Get new function name
QString comment = c->getComment();
// Rename function in r2 core
CutterCore::getInstance()->setComment(function.offset, comment);
Core()->setComment(function.offset, comment);
// Seek to new renamed function
CutterCore::getInstance()->seek(function.offset);
Core()->seek(function.offset);
// TODO: Refresh functions tree widget
}
}
@ -509,10 +509,10 @@ void FunctionsWidget::on_actionFunctionsRename_triggered()
QString new_name = r->getName();
// Rename function in r2 core
CutterCore::getInstance()->renameFunction(function.name, new_name);
Core()->renameFunction(function.name, new_name);
// Seek to new renamed function
CutterCore::getInstance()->seek(function.offset);
Core()->seek(function.offset);
}
}

View File

@ -114,5 +114,5 @@ void ResourcesWidget::refreshResources()
void ResourcesWidget::onDoubleClicked(const QModelIndex &index)
{
ResourcesDescription res = index.data(Qt::UserRole).value<ResourcesDescription>();
CutterCore::getInstance()->seek(res.vaddr);
Core()->seek(res.vaddr);
}

View File

@ -32,18 +32,18 @@ void SdbDock::reload(QString _path)
ui->treeWidget->clear();
QList<QString> keys;
/* key-values */
keys = CutterCore::getInstance()->sdbListKeys(path);
keys = Core()->sdbListKeys(path);
foreach (QString key, keys) {
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
tempItem->setText(0, key);
tempItem->setText(1, CutterCore::getInstance()->sdbGet(path, key));
tempItem->setText(1, Core()->sdbGet(path, key));
tempItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled |
Qt::ItemIsDragEnabled | Qt::ItemIsEditable);
ui->treeWidget->insertTopLevelItem(0, tempItem);
}
qhelpers::adjustColumns(ui->treeWidget, 0);
/* namespaces */
keys = CutterCore::getInstance()->sdbList(path);
keys = Core()->sdbList(path);
keys.append("..");
foreach (QString key, keys) {
QTreeWidgetItem *tempItem = new QTreeWidgetItem();

View File

@ -29,7 +29,7 @@ void SectionsWidget::refreshSections()
tree->clear();
int row = 0;
for (auto section : CutterCore::getInstance()->getAllSections()) {
for (auto section : Core()->getAllSections()) {
fillSections(row++, section);
}

View File

@ -42,17 +42,17 @@ void SideBar::on_lockButton_clicked()
void SideBar::on_calcInput_textChanged(const QString &arg1)
{
ui->calcOutput->setText(QString::number(CutterCore::getInstance()->math(arg1)));
ui->calcOutput->setText(QString::number(Core()->math(arg1)));
}
void SideBar::on_asm2hex_clicked()
{
ui->hexInput->setPlainText(CutterCore::getInstance()->assemble(ui->asmInput->toPlainText()));
ui->hexInput->setPlainText(Core()->assemble(ui->asmInput->toPlainText()));
}
void SideBar::on_hex2asm_clicked()
{
ui->asmInput->setPlainText(CutterCore::getInstance()->disassemble(ui->hexInput->toPlainText()));
ui->asmInput->setPlainText(Core()->disassemble(ui->hexInput->toPlainText()));
}
void SideBar::on_respButton_toggled(bool checked)

View File

@ -165,13 +165,13 @@ StringsWidget::~StringsWidget() {}
void StringsWidget::on_stringsTreeView_doubleClicked(const QModelIndex &index)
{
StringDescription str = index.data(StringsModel::StringDescriptionRole).value<StringDescription>();
CutterCore::getInstance()->seek(str.vaddr);
Core()->seek(str.vaddr);
}
void StringsWidget::refreshStrings()
{
model->beginReload();
strings = CutterCore::getInstance()->getAllStrings();
strings = Core()->getAllStrings();
model->endReload();
qhelpers::adjustColumns(ui->stringsTreeView, 5, 0);

View File

@ -29,13 +29,13 @@ void SymbolsWidget::on_symbolsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item
// Get offset and name of item double clicked
SymbolDescription symbol = item->data(0, Qt::UserRole).value<SymbolDescription>();
CutterCore::getInstance()->seek(symbol.vaddr);
Core()->seek(symbol.vaddr);
}
void SymbolsWidget::fillSymbols()
{
ui->symbolsTreeWidget->clear();
for (auto symbol : CutterCore::getInstance()->getAllSymbols()) {
for (auto symbol : Core()->getAllSymbols()) {
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, RAddressString(symbol.vaddr));
item->setText(1, QString("%1 %2").arg(symbol.bind, symbol.type).trimmed());

View File

@ -129,7 +129,7 @@ TypesWidget::~TypesWidget() {}
void TypesWidget::refreshTypes()
{
types_model->beginReloadTypes();
types = CutterCore::getInstance()->getAllTypes();
types = Core()->getAllTypes();
types_model->endReloadTypes();
qhelpers::adjustColumns(ui->typesTreeView, 3, 0);
@ -144,5 +144,5 @@ void TypesWidget::on_typesTreeView_doubleClicked(const QModelIndex &index)
{
Q_UNUSED(index);
// TypeDescription exp = index.data(TypesModel::TypeDescriptionRole).value<TypeDescription>();
// CutterCore::getInstance()->seek(exp.vaddr);
// Core()->seek(exp.vaddr);
}

View File

@ -172,7 +172,7 @@ VTablesWidget::~VTablesWidget()
void VTablesWidget::refreshVTables()
{
model->beginReload();
vtables = CutterCore::getInstance()->getAllVTables();
vtables = Core()->getAllVTables();
model->endReload();
qhelpers::adjustColumns(ui->vTableTreeView, 3, 0);
@ -184,9 +184,9 @@ void VTablesWidget::on_vTableTreeView_doubleClicked(const QModelIndex &index)
{
QModelIndex parent = index.parent();
if (parent.isValid())
CutterCore::getInstance()->seek(index.data(
Core()->seek(index.data(
VTableModel::VTableDescriptionRole).value<ClassMethodDescription>().addr);
else
CutterCore::getInstance()->seek(index.data(
Core()->seek(index.data(
VTableModel::VTableDescriptionRole).value<VTableDescription>().addr);
}