mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-02 09:46:39 +00:00
convert to api for aoj
This commit is contained in:
parent
5f376f55db
commit
3d39cf625f
2
rizin
2
rizin
@ -1 +1 @@
|
||||
Subproject commit be48ddcd9f0c2023d0e64750426c0476a13d8589
|
||||
Subproject commit a1c2ed18d762d3641e6690e0cb6b58b45f1c3609
|
@ -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<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)
|
||||
{
|
||||
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)
|
||||
@ -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<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()
|
||||
|
@ -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<RzAnalysisBytes *>(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);
|
||||
|
Loading…
Reference in New Issue
Block a user