diff --git a/rizin b/rizin index 0fc9c968..b79201b4 160000 --- a/rizin +++ b/rizin @@ -1 +1 @@ -Subproject commit 0fc9c9682e8a74245e4f24b84508f2bb6b185328 +Subproject commit b79201b49a0d687c854b6e2f0c88fc8a7f2afa61 diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index a8a8c038..1cd9ad50 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -377,6 +377,37 @@ QString CutterCore::cmd(const char *str) return o; } +QString CutterCore::getFunctionExecOut(const std::function &fcn, const RVA addr) +{ + CORE_LOCK(); + + RVA offset = core->offset; + seekSilent(addr); + QString o = {}; + rz_cons_push(); + bool is_pipe = core->is_pipe; + core->is_pipe = true; + + if (!fcn(core)) { + core->is_pipe = is_pipe; + rz_cons_pop(); + goto clean_return; + } + + core->is_pipe = is_pipe; + rz_cons_filter(); + o = rz_cons_get_buffer(); + + rz_cons_pop(); + rz_cons_echo(NULL); + +clean_return: + if (offset != core->offset) { + seekSilent(offset); + } + return o; +} + bool CutterCore::isRedirectableDebugee() { if (!currentlyDebugging || currentlyAttachedToPID != -1) { @@ -1055,24 +1086,23 @@ RVA CutterCore::prevOpAddr(RVA startAddr, int count) RVA CutterCore::nextOpAddr(RVA startAddr, int count) { CORE_LOCK(); - - CutterJson array = - Core()->cmdj("pdj " + QString::number(count + 1) + " @ " + QString::number(startAddr)); - if (!array.size()) { - return startAddr + 1; + auto vec = reinterpret_cast(returnAtSeek( + [&]() { + return rz_core_analysis_bytes(core, core->block, (int)core->blocksize, count + 1); + }, + startAddr)); + RVA addr = startAddr + 1; + if (!vec) { + return addr; } - - CutterJson instValue = array.last(); - if (instValue.type() != RZ_JSON_OBJECT) { - return startAddr + 1; + auto ab = reinterpret_cast(rz_pvector_tail(vec)); + if (!(ab && ab->op)) { + rz_pvector_free(vec); + return addr; } - - RVA offset = instValue[RJsonKey::offset].toRVA(); - if (offset == RVA_INVALID) { - return startAddr + 1; - } - - return offset; + addr = ab->op->addr; + rz_pvector_free(vec); + return addr; } RVA CutterCore::getOffset() @@ -4176,18 +4206,35 @@ void CutterCore::loadPDB(const QString &file) QList CutterCore::disassembleLines(RVA offset, int lines) { - CutterJson array = cmdj(QString("pdJ ") + QString::number(lines) + QString(" @ ") - + QString::number(offset)); - QList r; - - for (CutterJson object : array) { - DisassemblyLine line; - line.offset = object[RJsonKey::offset].toRVA(); - line.text = ansiEscapeToHtml(object[RJsonKey::text].toString()); - line.arrow = object[RJsonKey::arrow].toRVA(); - r << line; + CORE_LOCK(); + RzPVector *vec = rz_pvector_new(reinterpret_cast(rz_analysis_disasm_text_free)); + if (!vec) { + return {}; } + RzCoreDisasmOptions options = {}; + options.cbytes = 1; + options.vec = vec; + applyAtSeek( + [&]() { + if (rz_cons_singleton()->is_html) { + rz_cons_singleton()->is_html = false; + rz_cons_singleton()->was_html = true; + } + rz_core_print_disasm(core, offset, core->block, core->blocksize, lines, NULL, + &options); + }, + offset); + + QList r; + for (const auto &t : CutterPVector(vec)) { + DisassemblyLine line; + line.offset = t->offset; + line.text = ansiEscapeToHtml(t->text); + line.arrow = t->arrow; + r << line; + } + rz_pvector_free(vec); return r; } @@ -4354,7 +4401,7 @@ QString CutterCore::ansiEscapeToHtml(const QString &text) int len; char *html = rz_cons_html_filter(text.toUtf8().constData(), &len); if (!html) { - return QString(); + return {}; } QString r = QString::fromUtf8(html, len); rz_mem_free(html); diff --git a/src/core/Cutter.h b/src/core/Cutter.h index bdddd342..e544f3a5 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -81,6 +81,10 @@ public: RVA getOffset() const { return core_->offset; } /* Core functions (commands) */ + /* Almost the same as core_cmd_raw, + * only executes std::function instead of char* */ + QString getFunctionExecOut(const std::function &fcn, + const RVA addr = RVA_INVALID); static QString sanitizeStringForCommand(QString s); /** * @brief send a command to Rizin diff --git a/src/dialogs/XrefsDialog.cpp b/src/dialogs/XrefsDialog.cpp index 0a721e71..c7803562 100644 --- a/src/dialogs/XrefsDialog.cpp +++ b/src/dialogs/XrefsDialog.cpp @@ -131,8 +131,18 @@ void XrefsDialog::updatePreview(RVA addr) tempConfig.set("asm.lines", false); tempConfig.set("asm.bytes", false); - // Use cmd because cmRaw cannot handle the output properly. Why? - QString disas = Core()->cmd("pd--20 @ " + QString::number(addr)); + QString disas = Core()->getFunctionExecOut( + [](RzCore *core) { + ut64 offset = core->offset; + if (!rz_core_prevop_addr(core, core->offset, 20, &offset)) { + offset = rz_core_prevop_addr_force(core, core->offset, 20); + } + rz_core_seek(core, offset, true); + rz_core_print_disasm(core, core->offset, core->block, (int)core->blocksize, 40, + NULL, NULL); + return true; + }, + addr); ui->previewTextEdit->document()->setHtml(disas); // Does it make any sense? diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index f3f2dcfb..f08b8c5e 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -726,19 +726,23 @@ void DisassemblyContextMenu::on_actionNopInstruction_triggered() void DisassemblyContextMenu::showReverseJmpQuery() { - QString type; - - CutterJson array = Core()->cmdj("pdj 1 @ " + RzAddressString(offset)); - if (!array.size()) { + actionJmpReverse.setVisible(false); + RzCoreLocked core(Core()); + auto vec = reinterpret_cast(Core()->returnAtSeek( + [&]() { return rz_core_analysis_bytes(core, core->block, (int)core->blocksize, 1); }, + offset)); + if (!vec) { return; } - - type = array.first()["type"].toString(); - if (type == "cjmp") { - actionJmpReverse.setVisible(true); - } else { - actionJmpReverse.setVisible(false); + auto ab = reinterpret_cast(rz_pvector_head(vec)); + if (!(ab && ab->op)) { + rz_pvector_free(vec); + return; } + if (ab->op->type == RZ_ANALYSIS_OP_TYPE_CJMP) { + actionJmpReverse.setVisible(true); + } + rz_pvector_free(vec); } void DisassemblyContextMenu::on_actionJmpReverse_triggered()