From 3d39cf625fdd7294a41d4867f677f6762e726446 Mon Sep 17 00:00:00 2001 From: billow Date: Sat, 14 May 2022 17:03:59 +0800 Subject: [PATCH] convert to api for `aoj` --- rizin | 2 +- src/core/Cutter.cpp | 38 +++++++++++++++++++++++++--- src/menus/DisassemblyContextMenu.cpp | 34 +++++++++++++++++-------- 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/rizin b/rizin index be48ddcd..a1c2ed18 160000 --- a/rizin +++ b/rizin @@ -1 +1 @@ -Subproject commit be48ddcd9f0c2023d0e64750426c0476a13d8589 +Subproject commit a1c2ed18d762d3641e6690e0cb6b58b45f1c3609 diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index bd801a0e..bcb9b728 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -746,12 +746,32 @@ void CutterCore::delFlag(const QString &name) QString CutterCore::getInstructionBytes(RVA addr) { - return cmdj("aoj @ " + RzAddressString(addr)).first()[RJsonKey::bytes].toString(); + auto ret = (char *)Core()->returnAtSeek( + [&]() { + CORE_LOCK(); + RzPVector *vec = rz_core_analysis_bytes(core, core->block, (int)core->blocksize, 1); + auto *ab = static_cast(rz_pvector_head(vec)); + char *str = strdup(ab->bytes); + rz_pvector_free(vec); + return str; + }, + addr); + return fromOwnedCharPtr(ret); } QString CutterCore::getInstructionOpcode(RVA addr) { - return cmdj("aoj @ " + RzAddressString(addr)).first()[RJsonKey::opcode].toString(); + auto ret = (char *)Core()->returnAtSeek( + [&]() { + CORE_LOCK(); + RzPVector *vec = rz_core_analysis_bytes(core, core->block, (int)core->blocksize, 1); + auto *ab = static_cast(rz_pvector_head(vec)); + char *str = strdup(ab->opcode); + rz_pvector_free(vec); + return str; + }, + addr); + return fromOwnedCharPtr(ret); } void CutterCore::editInstruction(RVA addr, const QString &inst) @@ -1358,7 +1378,19 @@ CutterJson CutterCore::getRegistersInfo() RVA CutterCore::getOffsetJump(RVA addr) { - return cmdj("aoj @" + QString::number(addr)).first().toRVA(); + auto rva = (RVA *)Core()->returnAtSeek( + [&]() { + CORE_LOCK(); + RzPVector *vec = rz_core_analysis_bytes(core, core->block, (int)core->blocksize, 1); + auto *ab = static_cast(rz_pvector_head(vec)); + RVA *rva = new RVA(ab->op->jump); + rz_pvector_free(vec); + return rva; + }, + addr); + RVA ret = *rva; + delete rva; + return ret; } QList CutterCore::getDecompilers() diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index f39bbd79..2f6c6d66 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -482,8 +482,15 @@ void DisassemblyContextMenu::setupRenaming() void DisassemblyContextMenu::aboutToShowSlot() { // check if set immediate base menu makes sense - CutterJson instObject = Core()->cmdj("aoj @ " + QString::number(offset)).first(); - bool immBase = instObject["val"].valid() || instObject["ptr"].valid(); + RzPVector *vec = (RzPVector *)Core()->returnAtSeek( + [&]() { + RzCoreLocked core(Core()); + return rz_core_analysis_bytes(core, core->block, (int)core->blocksize, 1); + }, + offset); + auto *ab = static_cast(rz_pvector_head(vec)); + + bool immBase = ab && ab->op && (ab->op->val || ab->op->ptr); setBaseMenu->menuAction()->setVisible(immBase); setBitsMenu->menuAction()->setVisible(true); @@ -491,17 +498,24 @@ void DisassemblyContextMenu::aboutToShowSlot() QString memBaseReg; // Base register st64 memDisp = 0; // Displacement - // Loop through both the operands of the instruction - for (const CutterJson operand : instObject["opex"]["operands"]) { - if (operand["type"].toString() == "mem" && !operand["base"].toString().contains("bp") - && operand["disp"].toSt64() > 0) { + if (ab && ab->op) { + const char *opexstr = RZ_STRBUF_SAFEGET(&ab->op->opex); + CutterJson operands = Core()->parseJson(strdup(opexstr), nullptr); - // The current operand is the one which has an immediate displacement - memBaseReg = operand["base"].toString(); - memDisp = operand["disp"].toSt64(); - break; + // Loop through both the operands of the instruction + for (const CutterJson operand : operands) { + if (operand["type"].toString() == "mem" && !operand["base"].toString().contains("bp") + && operand["disp"].toSt64() > 0) { + + // The current operand is the one which has an immediate displacement + memBaseReg = operand["base"].toString(); + memDisp = operand["disp"].toSt64(); + break; + } } } + rz_pvector_free(vec); + if (memBaseReg.isEmpty()) { // hide structure offset menu structureOffsetMenu->menuAction()->setVisible(false);