From 5390cff3201c26e99673efeb28334145b256de25 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sun, 9 Apr 2017 19:12:36 +0200 Subject: [PATCH] updated r2 to 5ec6cde4 (#108) * updated r2 to 5ec6cde4 (this fixes heap corruption and null pointer dereferences while starting iaito) * fix build (no need to update iaito_win32 because no changes were made to the api) --- iaito_win32 | 2 +- radare2 | 2 +- src/createnewdialog.cpp | 15 ++- src/mainwindow.cpp | 2 +- src/optionsdialog.cpp | 2 +- src/qrcore.cpp | 174 ++++++++++++++++--------- src/qrcore.h | 20 ++- src/widgets/memwidget/memorywidget.cpp | 18 ++- 8 files changed, 158 insertions(+), 77 deletions(-) diff --git a/iaito_win32 b/iaito_win32 index e603905d..48dbae99 160000 --- a/iaito_win32 +++ b/iaito_win32 @@ -1 +1 @@ -Subproject commit e603905db979bda6a95f4dd4b0b18ec2ab626f12 +Subproject commit 48dbae99de86c1b798f46c1ccdbe13312301a4ad diff --git a/radare2 b/radare2 index 4715f1e2..99c0151a 160000 --- a/radare2 +++ b/radare2 @@ -1 +1 @@ -Subproject commit 4715f1e2b9394aac832ff5f37e6a7504c59fd993 +Subproject commit 99c0151a2d9dbff70ba0a6aa46ddec2e523c8f65 diff --git a/src/createnewdialog.cpp b/src/createnewdialog.cpp index a7e4e56a..64b1cf4a 100644 --- a/src/createnewdialog.cpp +++ b/src/createnewdialog.cpp @@ -60,6 +60,7 @@ void createNewDialog::on_exampleButton_clicked() void createNewDialog::on_buttonCreate_clicked() { + RCoreLocked lcore = w->core->core(); QString type = ui->comboType->currentText(); QString str; bool created = false; @@ -69,13 +70,13 @@ void createNewDialog::on_buttonCreate_clicked() QString format = ui->comboFormat->currentText(); if (type == "Assembler") { - RAsmCode *code = r_asm_massemble (w->core->core->assembler, ui->plainTextEdit->toPlainText().toUtf8().constData()); + RAsmCode *code = r_asm_massemble (lcore->assembler, ui->plainTextEdit->toPlainText().toUtf8().constData()); if (code && code->len>0) { char file[32]; snprintf (file, sizeof(file)-1, "malloc://%d", code->len); if (w->core->loadFile(file,0,0,1,0,0,false)) { created = true; - r_core_write_at(w->core->core,0, code->buf, code->len); + r_core_write_at(lcore,0, code->buf, code->len); } else { __alert ("Failed to create file"); } @@ -89,8 +90,8 @@ void createNewDialog::on_buttonCreate_clicked() created = true; snprintf (file, sizeof(file)-1, "malloc://%d", fsize); if (w->core->loadFile(file,0,0,1,0,0,false)) { - r_core_patch (w->core->core, ui->plainTextEdit->toPlainText().toUtf8().constData()); - r_core_seek(w->core->core, 0, 1); + r_core_patch (lcore, ui->plainTextEdit->toPlainText().toUtf8().constData()); + r_core_seek(lcore, 0, 1); created = true; } else { __alert ("failed to open file"); @@ -121,13 +122,13 @@ void createNewDialog::on_buttonCreate_clicked() } } else if (type == "Text") { char file[32]; - QByteArray hexpairs = ui->plainTextEdit->toPlainText().toStdString().c_str(); + QByteArray hexpairs = ui->plainTextEdit->toPlainText().toUtf8(); int sz = strlen (hexpairs.constData()); if (sz>0) { snprintf (file, sizeof(file)-1, "malloc://%d", sz); if (w->core->loadFile(file,0,0,1,0,0,false)) { created = true; - r_core_write_at(w->core->core,0, (const ut8*)hexpairs.constData(), sz); + r_core_write_at(lcore,0, (const ut8*)hexpairs.constData(), sz); } else { __alert ("failed to open file"); } @@ -144,7 +145,7 @@ void createNewDialog::on_buttonCreate_clicked() snprintf (file, sizeof(file)-1, "malloc://%d", sz); if (w->core->loadFile(file,0,0,1,0,0,false)) { created = true; - r_core_write_at(w->core->core,0, buf, sz); + r_core_write_at(lcore,0, buf, sz); } else { __alert ("failed to open file"); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 33d44299..5b0c2ee7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -244,7 +244,7 @@ void MainWindow::start_web_server() { void MainWindow::webserverThreadFinished() { - core->core->http_up = webserverThread.isStarted() ? R_TRUE : R_FALSE; + core->core()->http_up = webserverThread.isStarted() ? R_TRUE : R_FALSE; // this is not true anymore, cause the webserver might have been stopped //if (core->core->http_up == R_FALSE) { diff --git a/src/optionsdialog.cpp b/src/optionsdialog.cpp index ad3498d9..c0957484 100644 --- a/src/optionsdialog.cpp +++ b/src/optionsdialog.cpp @@ -158,7 +158,7 @@ void OptionsDialog::on_okButton_clicked() if (!va) { va = 2; loadaddr = UT64_MAX; - r_config_set_i (this->core->core->config, "bin.laddr", loadaddr); + r_config_set_i (this->core->core()->config, "bin.laddr", loadaddr); mapaddr = 0; } } else { diff --git a/src/qrcore.cpp b/src/qrcore.cpp index 677dbfbc..7532376a 100644 --- a/src/qrcore.cpp +++ b/src/qrcore.cpp @@ -3,14 +3,47 @@ #define DB this->db +RCoreLocked::RCoreLocked(RCore *core) + : core(core) +{ + r_th_lock_enter(core->lock); +} + +RCoreLocked::RCoreLocked(RCoreLocked&& o) +{ + core = o.core; +} + +RCoreLocked::~RCoreLocked() +{ + r_th_lock_leave(core->lock); +} + +RCoreLocked::operator RCore*() const +{ + return core; +} + +RCore* RCoreLocked::operator->() const +{ + return core; +} + +RCoreLocked QRCore::core() const +{ + return RCoreLocked(this->core_); +} + +#define CORE_LOCK() RCoreLocked core_lock__(this->core_) + QRCore::QRCore(QObject *parent) : QObject(parent) { r_cons_new (); // initialize console this->projectPath = ""; - this->core = r_core_new (); - r_core_loadlibs (this->core, R_CORE_LOADLIBS_ALL, NULL); - // IMPLICIT r_bin_iobind (core->bin, core->io); + this->core_ = r_core_new (); + r_core_loadlibs (this->core_, R_CORE_LOADLIBS_ALL, NULL); + // IMPLICIT r_bin_iobind (core_->bin, core_->io); // Otherwise r2 may ask the user for input and Iaito would freeze config("scr.interactive","false"); @@ -28,8 +61,9 @@ QRCore::QRCore(QObject *parent) : } QList QRCore::getFunctionXrefs(ut64 addr) { + CORE_LOCK(); QList ret = QList(); - RList *list = r_anal_xrefs_get(core->anal, addr); + RList *list = r_anal_xrefs_get(core_->anal, addr); RAnalRef *ref; RListIter *it; QRListForeach (list, it, RAnalRef, ref) { @@ -42,9 +76,10 @@ QList QRCore::getFunctionXrefs(ut64 addr) { } QList QRCore::getFunctionRefs(ut64 addr, char type) { + CORE_LOCK(); QList ret = QList(); - //RAnalFunction *fcn = r_anal_get_fcn_at(core->anal, addr, addr); - RAnalFunction *fcn = r_anal_get_fcn_in(core->anal, addr, 0); + //RAnalFunction *fcn = r_anal_get_fcn_at(core_->anal, addr, addr); + RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0); if (!fcn) { eprintf("qcore->getFunctionRefs: No function found\n"); return ret; @@ -63,8 +98,9 @@ QList QRCore::getFunctionRefs(ut64 addr, char type) { } int QRCore::getCycloComplex(ut64 addr) { + CORE_LOCK(); QString ret = ""; - RAnalFunction *fcn = r_anal_get_fcn_in(core->anal, addr, 0); + RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0); if (fcn) { ret = cmd("afcc @ " + QString(fcn->name)); return ret.toInt(); @@ -75,9 +111,10 @@ int QRCore::getCycloComplex(ut64 addr) { } int QRCore::getFcnSize(ut64 addr) { + CORE_LOCK(); QString ret = ""; QString tmp_ret = ""; - RAnalFunction *fcn = r_anal_get_fcn_in(core->anal, addr, 0); + RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0); if (fcn) { tmp_ret = cmd("afi~size[1] " + QString(fcn->name)); ret = tmp_ret.split("\n")[0]; @@ -89,8 +126,9 @@ int QRCore::getFcnSize(ut64 addr) { } QList QRCore::sdbList(QString path) { + CORE_LOCK(); QList list = QList(); - Sdb *root = sdb_ns_path (core->sdb, path.toUtf8().constData(), 0); + Sdb *root = sdb_ns_path (core_->sdb, path.toUtf8().constData(), 0); if (root) { void *vsi; ls_iter_t *iter; @@ -103,8 +141,9 @@ QList QRCore::sdbList(QString path) { } QList QRCore::sdbListKeys(QString path) { + CORE_LOCK(); QList list = QList(); - Sdb *root = sdb_ns_path (core->sdb, path.toUtf8().constData(), 0); + Sdb *root = sdb_ns_path (core_->sdb, path.toUtf8().constData(), 0); if (root) { void *vsi; ls_iter_t *iter; @@ -118,7 +157,8 @@ QList QRCore::sdbListKeys(QString path) { } QString QRCore::sdbGet(QString path, QString key) { - Sdb *db = sdb_ns_path (core->sdb, path.toUtf8().constData(), 0); + CORE_LOCK(); + Sdb *db = sdb_ns_path (core_->sdb, path.toUtf8().constData(), 0); if (db) { const char *val = sdb_const_get(db, key.toUtf8().constData(), 0); if (val && *val) @@ -128,20 +168,22 @@ QString QRCore::sdbGet(QString path, QString key) { } bool QRCore::sdbSet(QString path, QString key, QString val) { - Sdb *db = sdb_ns_path (core->sdb, path.toUtf8().constData(), 1); + CORE_LOCK(); + Sdb *db = sdb_ns_path (core_->sdb, path.toUtf8().constData(), 1); if (!db) return false; return sdb_set (db, key.toUtf8().constData(), val.toUtf8().constData(), 0); } QRCore::~QRCore() { - r_core_free(this->core); - r_cons_free (); + r_core_free(this->core_); + r_cons_free(); } QString QRCore::cmd(const QString &str) { + CORE_LOCK(); QByteArray cmd = str.toUtf8(); //r_cons_flush(); - char *res = r_core_cmd_str (this->core, cmd.constData()); + char *res = r_core_cmd_str (this->core_, cmd.constData()); QString o = QString(res ? res : ""); //r_mem_free was added in https://github.com/radare/radare2/commit/cd28744049492dc8ac25a1f2b3ba0e42f0e9ce93 r_mem_free(res); @@ -149,18 +191,18 @@ QString QRCore::cmd(const QString &str) { } bool QRCore::loadFile(QString path, uint64_t loadaddr=0LL, uint64_t mapaddr=0LL, bool rw=false, int va=0, int bits = 0, int idx, bool loadbin) { - QNOTUSED(loadaddr); QNOTUSED(idx); + CORE_LOCK(); RCoreFile *f; if (va==0 || va == 2) - r_config_set_i (core->config, "io.va", va); - // NO ONE KNOWS WHY THIS IS FIXING A SEGFAULT. core->file should have already a proper value. Pancake dixit - //core->file = NULL; + r_config_set_i (core_->config, "io.va", va); + // NO ONE KNOWS WHY THIS IS FIXING A SEGFAULT. core_->file should have already a proper value. Pancake dixit + //core_->file = NULL; // mapaddr = 0LL; printf ("FILE OPEN (%s)\n", path.toUtf8().constData()); - f = r_core_file_open(core, path.toUtf8().constData(), rw?(R_IO_READ|R_IO_WRITE):R_IO_READ, mapaddr); + f = r_core_file_open(core_, path.toUtf8().constData(), rw?(R_IO_READ|R_IO_WRITE):R_IO_READ, mapaddr); if (!f) { eprintf ("r_core_file_open failed\n"); return false; @@ -168,8 +210,8 @@ bool QRCore::loadFile(QString path, uint64_t loadaddr=0LL, uint64_t mapaddr=0LL, if (loadbin) { if (va==1) { - if (r_core_bin_load (core, path.toUtf8().constData(), UT64_MAX)) { - RBinObject *obj = r_bin_get_object(core->bin); + if (r_core_bin_load (core_, path.toUtf8().constData(), UT64_MAX)) { + RBinObject *obj = r_bin_get_object(core_->bin); if (obj) { eprintf ("BITS %d\n", obj->info->bits); } @@ -177,8 +219,8 @@ bool QRCore::loadFile(QString path, uint64_t loadaddr=0LL, uint64_t mapaddr=0LL, eprintf ("CANNOT GET RBIN INFO\n"); } } else { - if (r_core_bin_load (core, path.toUtf8().constData(), UT64_MAX)) { - RBinObject *obj = r_bin_get_object(core->bin); + if (r_core_bin_load (core_, path.toUtf8().constData(), UT64_MAX)) { + RBinObject *obj = r_bin_get_object(core_->bin); if (obj) { eprintf ("BITS %d\n", obj->info->bits); } else { @@ -190,7 +232,7 @@ bool QRCore::loadFile(QString path, uint64_t loadaddr=0LL, uint64_t mapaddr=0LL, } } if (bits != 0) { - r_config_set_i (core->config, "asm.bits", bits); + r_config_set_i (core_->config, "asm.bits", bits); } #if HAVE_MULTIPLE_RBIN_FILES_INSIDE_SELECT_WHICH_ONE @@ -200,18 +242,19 @@ bool QRCore::loadFile(QString path, uint64_t loadaddr=0LL, uint64_t mapaddr=0LL, // load RBin information // XXX only for sub-bins r_core_bin_load (core, path.toUtf8(), loadaddr); - r_bin_select_idx (core->bin, NULL, idx); + r_bin_select_idx (core_->bin, NULL, idx); } #endif } else { // Not loading RBin info coz va = false } - r_core_hash_load(core, path.toUtf8().constData()); + r_core_hash_load(core_, path.toUtf8().constData()); fflush (stdout); return true; } void QRCore::analyze(int level) { + CORE_LOCK(); /* * Levels * Nivel 1: afr @ entry0 y main (afr@entry0;afr@main) @@ -221,13 +264,13 @@ void QRCore::analyze(int level) { */ if (level == 1) { - r_core_cmd0 (core, "afr@entry0;afr@main"); + r_core_cmd0 (core_, "afr@entry0;afr@main"); } else if (level == 2) { - r_core_cmd0 (core, "aa"); + r_core_cmd0 (core_, "aa"); } else if (level == 3) { - r_core_cmd0 (core, "aaa"); + r_core_cmd0 (core_, "aaa"); } else if (level == 4) { - r_core_cmd0 (core, "aaaa"); + r_core_cmd0 (core_, "aaaa"); } } @@ -241,7 +284,8 @@ void QRCore::setComment(QString addr, QString cmt) { } void QRCore::delComment(ut64 addr) { - r_meta_del (core->anal, 'C', addr, 1, NULL); + CORE_LOCK(); + r_meta_del (core_->anal, 'C', addr, 1, NULL); //cmd (QString("CC-@")+addr); } @@ -287,14 +331,16 @@ void QRCore::seek(QString addr) { } void QRCore::seek(ut64 addr) { - r_core_seek (this->core, addr, true); + CORE_LOCK(); + r_core_seek (this->core_, addr, true); } bool QRCore::tryFile(QString path, bool rw) { + CORE_LOCK(); RCoreFile *cf; int flags = R_IO_READ; if (rw) flags |= R_IO_WRITE; - cf = r_core_file_open (this->core, path.toUtf8().constData(), flags, 0LL); + cf = r_core_file_open (this->core_, path.toUtf8().constData(), flags, 0LL); if (!cf) { eprintf ("QRCore::tryFile: Cannot open file?\n"); return false; @@ -312,6 +358,7 @@ bool QRCore::tryFile(QString path, bool rw) { } QList QRCore::getList(const QString & type, const QString & subtype) { + CORE_LOCK(); RListIter *it; QList ret = QList(); @@ -345,8 +392,8 @@ QList QRCore::getList(const QString & type, const QString & subtype) { ret << "entry0"; } else if (subtype == "relocs") { RBinReloc *br; - if (core && core->bin && core->bin->cur && core->bin->cur->o) { - QRListForeach (core->bin->cur->o->relocs, it, RBinReloc, br) { + if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) { + QRListForeach (core_->bin->cur->o->relocs, it, RBinReloc, br) { if (br->import) { // TODO: we want the offset too! QString type = (br->additive?"ADD_":"SET_")+QString::number(br->type); @@ -360,22 +407,22 @@ QList QRCore::getList(const QString & type, const QString & subtype) { } } else if (subtype == "symbols") { RBinSymbol *bs; - if (core && core->bin && core->bin->cur && core->bin->cur->o) { - QRListForeach (core->bin->cur->o->symbols, it, RBinSymbol, bs) { + if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) { + QRListForeach (core_->bin->cur->o->symbols, it, RBinSymbol, bs) { QString type = QString(bs->bind)+" "+QString(bs->type); ret << QString ("0x%1,%2,%3").arg(QString::number(bs->vaddr,16), type, bs->name); } /* list entrypoints as symbols too */ int n = 0; RBinAddr *entry; - QRListForeach (core->bin->cur->o->entries, it, RBinAddr, entry) { + QRListForeach (core_->bin->cur->o->entries, it, RBinAddr, entry) { ret <vaddr,16),"entry","entry", QString::number(n++)); } } } else if (subtype == "strings") { RBinString *bs; - if (core && core->bin && core->bin->cur && core->bin->cur->o) { - QRListForeach (core->bin->cur->o->strings, it, RBinString, bs) { + if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) { + QRListForeach (core_->bin->cur->o->strings, it, RBinString, bs) { ret << QString ("0x%1,%2").arg(QString::number(bs->vaddr,16), bs->string); } } @@ -383,7 +430,7 @@ QList QRCore::getList(const QString & type, const QString & subtype) { } else if (type == "asm") { if (subtype == "plugins") { RAsmPlugin *ap; - QRListForeach (core->assembler->plugins, it, RAsmPlugin, ap) { + QRListForeach (core_->assembler->plugins, it, RAsmPlugin, ap) { ret << ap->name; } } else if (subtype == "cpus") { @@ -396,7 +443,7 @@ QList QRCore::getList(const QString & type, const QString & subtype) { } else if (type == "anal") { if (subtype == "plugins") { RAnalPlugin *ap; - QRListForeach (core->anal->plugins, it, RAnalPlugin, ap) { + QRListForeach (core_->anal->plugins, it, RAnalPlugin, ap) { ret << ap->name; } } else if (subtype == "functions") { @@ -430,19 +477,22 @@ QList QRCore::getList(const QString & type, const QString & subtype) { } ut64 QRCore::math(const QString &expr) { - return r_num_math (this->core?this->core->num:NULL, expr.toUtf8().constData()); + CORE_LOCK(); + return r_num_math (this->core_?this->core_->num:NULL, expr.toUtf8().constData()); } int QRCore::fcnCyclomaticComplexity(ut64 addr) { - RAnalFunction *fcn = r_anal_get_fcn_at(core->anal, addr,addr); + CORE_LOCK(); + RAnalFunction *fcn = r_anal_get_fcn_at(core_->anal, addr,addr); if (fcn) return r_anal_fcn_cc(fcn); return 0; } int QRCore::fcnBasicBlockCount(ut64 addr) { - //RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, addr, addr); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); + CORE_LOCK(); + //RAnalFunction *fcn = r_anal_get_fcn_at (core_->anal, addr, addr); + RAnalFunction *fcn = r_anal_get_fcn_in (core_->anal, addr, 0); if (fcn) { return r_list_length (fcn->bbs); } @@ -450,9 +500,10 @@ int QRCore::fcnBasicBlockCount(ut64 addr) { } int QRCore::fcnEndBbs(QString addr) { + CORE_LOCK(); bool ok; int offset = addr.toLong(&ok, 16); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, offset, 0); + RAnalFunction *fcn = r_anal_get_fcn_in (core_->anal, offset, 0); if (fcn) { QString tmp = this->cmd("afi @ " + addr + " ~end-bbs").split("\n")[0]; if (tmp.contains(":")) { @@ -469,21 +520,23 @@ QString QRCore::itoa(ut64 num, int rdx) { } QString QRCore::config(const QString &k, const QString &v) { + CORE_LOCK(); QByteArray key = k.toUtf8(); if (v!=NULL) { - r_config_set (core->config, key.constData(), v.toUtf8().constData()); + r_config_set (core_->config, key.constData(), v.toUtf8().constData()); return NULL; } - return QString(r_config_get (core->config, key.constData())); + return QString(r_config_get (core_->config, key.constData())); } int QRCore::config(const QString &k, int v) { + CORE_LOCK(); QByteArray key = k.toUtf8(); if (v!=-1) { - r_config_set_i (core->config, key.constData(), v); + r_config_set_i (core_->config, key.constData(), v); return 0; } - return r_config_get_i (core->config, key.constData()); + return r_config_get_i (core_->config, key.constData()); } void QRCore::setOptions(QString key) { @@ -516,22 +569,25 @@ void QRCore::setDefaultCPU() { } QString QRCore::assemble(const QString &code) { - RAsmCode *ac = r_asm_massemble (core->assembler, code.toUtf8().constData()); + CORE_LOCK(); + RAsmCode *ac = r_asm_massemble (core_->assembler, code.toUtf8().constData()); QString hex(ac != nullptr ? ac->buf_hex : ""); r_asm_code_free (ac); return hex; } QString QRCore::disassemble(const QString &hex) { - RAsmCode *ac = r_asm_mdisassemble_hexstr(core->assembler, hex.toUtf8().constData()); + CORE_LOCK(); + RAsmCode *ac = r_asm_mdisassemble_hexstr(core_->assembler, hex.toUtf8().constData()); QString code = QString (ac != nullptr ? ac->buf_asm : ""); r_asm_code_free (ac); return code; } RAnalFunction* QRCore::functionAt(ut64 addr) { - //return r_anal_fcn_find (core->anal, addr, addr); - return r_anal_get_fcn_in (core->anal, addr, 0); + CORE_LOCK(); + //return r_anal_fcn_find (core_->anal, addr, addr); + return r_anal_get_fcn_in (core_->anal, addr, 0); } QString QRCore::cmdFunctionAt(QString addr) { @@ -544,14 +600,16 @@ QString QRCore::cmdFunctionAt(QString addr) { int QRCore::get_size() { - RBinObject *obj = r_bin_get_object(core->bin); + CORE_LOCK(); + RBinObject *obj = r_bin_get_object(core_->bin); //return obj->size; return obj != nullptr ? obj->obj_size : 0; } ulong QRCore::get_baddr() { - ulong baddr = r_bin_get_baddr(core->bin); + CORE_LOCK(); + ulong baddr = r_bin_get_baddr(core_->bin); return baddr; } diff --git a/src/qrcore.h b/src/qrcore.h index decf4365..751fcfee 100644 --- a/src/qrcore.h +++ b/src/qrcore.h @@ -27,6 +27,20 @@ #define __alert(x) QMessageBox::question (this, "Alert", QString(x), QMessageBox::Ok) #define __question(x) (QMessageBox::Yes==QMessageBox::question (this, "Alert", QString(x), QMessageBox::Yes| QMessageBox::No)) +struct RCoreLocked +{ + explicit RCoreLocked(RCore* core); + RCoreLocked(const RCoreLocked&) = delete; + RCoreLocked& operator=(const RCoreLocked&) = delete; + RCoreLocked(RCoreLocked&&); + ~RCoreLocked(); + operator RCore*() const; + RCore* operator->() const; + +private: + RCore* core; +}; + #define QNOTUSED(x) do { (void)(x); } while ( 0 ); class QRCore : public QObject @@ -87,8 +101,10 @@ public: QList regs; void setSettings(); + RCoreLocked core() const; + /* fields */ - RCore *core; + Sdb *db; signals: @@ -98,6 +114,8 @@ private: QString default_arch; QString default_cpu; int default_bits; + + RCore *core_; }; #endif // QRCORE_H diff --git a/src/widgets/memwidget/memorywidget.cpp b/src/widgets/memwidget/memorywidget.cpp index 9b657fef..08871dca 100644 --- a/src/widgets/memwidget/memorywidget.cpp +++ b/src/widgets/memwidget/memorywidget.cpp @@ -456,9 +456,10 @@ void MemoryWidget::disasmScrolled() void MemoryWidget::refreshDisasm(const QString &offset) { + RCoreLocked lcore = this->main->core->core(); // we must store those ranges somewhere, to handle scroll - ut64 addr = this->main->core->core->offset; - int length = this->main->core->core->num->value; + ut64 addr = lcore->offset; + int length = lcore->num->value; // Prevent further scroll disconnect(this->disasTextEdit->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(disasmScrolled())); @@ -517,6 +518,7 @@ void MemoryWidget::refreshDisasm(const QString &offset) void MemoryWidget::refreshHexdump(QString where) { + RCoreLocked lcore = this->main->core->core(); // Prevent further scroll disconnect(this->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); @@ -526,7 +528,7 @@ void MemoryWidget::refreshHexdump(QString where) this->hexASCIIText->clear(); int hexdumpLength; - int cols = this->main->core->core->print->cols; + int cols = lcore->print->cols; int bsize = 128 * cols; if (hexdumpBottomOffset < bsize) { @@ -550,7 +552,7 @@ void MemoryWidget::refreshHexdump(QString where) //s = this->normalize_addr(this->main->core->cmd("s")); QList ret = this->get_hexdump(""); - hexdumpBottomOffset = this->main->core->core->offset; + hexdumpBottomOffset = lcore->offset; this->hexOffsetText->setPlainText(ret[0]); this->hexHexText->setPlainText(ret[1]); this->hexASCIIText->setPlainText(ret[2]); @@ -563,7 +565,7 @@ void MemoryWidget::refreshHexdump(QString where) s = this->normalize_addr(this->main->core->cmd("s")); ret = this->get_hexdump(""); - hexdumpBottomOffset = this->main->core->core->offset; + hexdumpBottomOffset = lcore->offset; this->hexOffsetText->append(ret[0]); this->hexHexText->append(ret[1]); this->hexASCIIText->append(ret[2]); @@ -582,11 +584,12 @@ void MemoryWidget::refreshHexdump(QString where) } QList MemoryWidget::get_hexdump(QString off = "") { + RCoreLocked lcore = this->main->core->core(); QList ret; QString hexdump; int hexdumpLength; - int cols = this->main->core->core->print->cols; + int cols = lcore->print->cols; int bsize = 128 * cols; if (hexdumpBottomOffset < bsize) { @@ -656,6 +659,7 @@ void MemoryWidget::resizeHexdump() { void MemoryWidget::hexScrolled() { + RCoreLocked lcore = this->main->core->core(); QScrollBar *sb = this->hexASCIIText->verticalScrollBar(); if ( sb->value() > sb->maximum() -10 ) { @@ -689,7 +693,7 @@ void MemoryWidget::hexScrolled() //disathis->main->add_debug_output("First Offset/VA: " + firstline); //refreshHexdump(1); - int cols = this->main->core->core->print->cols; + int cols = lcore->print->cols; // px bsize @ addr //int bsize = 128 * cols; int bsize = 800;