mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 20:36:09 +00:00
convert to api for aoj
This commit is contained in:
parent
493ff68365
commit
6e07f4d97a
@ -746,12 +746,32 @@ void CutterCore::delFlag(const QString &name)
|
|||||||
|
|
||||||
QString CutterCore::getInstructionBytes(RVA addr)
|
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<RzAnalysisBytes *>(rz_pvector_head(vec));
|
||||||
|
char *str = strdup(ab->bytes);
|
||||||
|
rz_pvector_free(vec);
|
||||||
|
return str;
|
||||||
|
},
|
||||||
|
addr);
|
||||||
|
return fromOwnedCharPtr(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CutterCore::getInstructionOpcode(RVA addr)
|
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<RzAnalysisBytes *>(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)
|
void CutterCore::editInstruction(RVA addr, const QString &inst)
|
||||||
@ -1358,7 +1378,19 @@ CutterJson CutterCore::getRegistersInfo()
|
|||||||
|
|
||||||
RVA CutterCore::getOffsetJump(RVA addr)
|
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<RzAnalysisBytes *>(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<Decompiler *> CutterCore::getDecompilers()
|
QList<Decompiler *> CutterCore::getDecompilers()
|
||||||
|
@ -482,8 +482,15 @@ void DisassemblyContextMenu::setupRenaming()
|
|||||||
void DisassemblyContextMenu::aboutToShowSlot()
|
void DisassemblyContextMenu::aboutToShowSlot()
|
||||||
{
|
{
|
||||||
// check if set immediate base menu makes sense
|
// check if set immediate base menu makes sense
|
||||||
CutterJson instObject = Core()->cmdj("aoj @ " + QString::number(offset)).first();
|
RzPVector *vec = (RzPVector *)Core()->returnAtSeek(
|
||||||
bool immBase = instObject["val"].valid() || instObject["ptr"].valid();
|
[&]() {
|
||||||
|
RzCoreLocked core(Core());
|
||||||
|
return rz_core_analysis_bytes(core, core->block, (int)core->blocksize, 1);
|
||||||
|
},
|
||||||
|
offset);
|
||||||
|
auto *ab = static_cast<RzAnalysisBytes *>(rz_pvector_head(vec));
|
||||||
|
|
||||||
|
bool immBase = ab && ab->op && (ab->op->val || ab->op->ptr);
|
||||||
setBaseMenu->menuAction()->setVisible(immBase);
|
setBaseMenu->menuAction()->setVisible(immBase);
|
||||||
setBitsMenu->menuAction()->setVisible(true);
|
setBitsMenu->menuAction()->setVisible(true);
|
||||||
|
|
||||||
@ -491,17 +498,24 @@ void DisassemblyContextMenu::aboutToShowSlot()
|
|||||||
QString memBaseReg; // Base register
|
QString memBaseReg; // Base register
|
||||||
st64 memDisp = 0; // Displacement
|
st64 memDisp = 0; // Displacement
|
||||||
|
|
||||||
// Loop through both the operands of the instruction
|
if (ab && ab->op) {
|
||||||
for (const CutterJson operand : instObject["opex"]["operands"]) {
|
const char *opexstr = RZ_STRBUF_SAFEGET(&ab->op->opex);
|
||||||
if (operand["type"].toString() == "mem" && !operand["base"].toString().contains("bp")
|
CutterJson operands = Core()->parseJson(strdup(opexstr), nullptr);
|
||||||
&& operand["disp"].toSt64() > 0) {
|
|
||||||
|
|
||||||
// The current operand is the one which has an immediate displacement
|
// Loop through both the operands of the instruction
|
||||||
memBaseReg = operand["base"].toString();
|
for (const CutterJson operand : operands) {
|
||||||
memDisp = operand["disp"].toSt64();
|
if (operand["type"].toString() == "mem" && !operand["base"].toString().contains("bp")
|
||||||
break;
|
&& 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()) {
|
if (memBaseReg.isEmpty()) {
|
||||||
// hide structure offset menu
|
// hide structure offset menu
|
||||||
structureOffsetMenu->menuAction()->setVisible(false);
|
structureOffsetMenu->menuAction()->setVisible(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user