mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-22 04:46:11 +00:00
Rewrite getVariables with API
This also avoids annoying "ERROR: No function found in ..." beging printed by afvj when right-clicking anywhere outside a function. The heuristics in functionIn() also have been adjusted to prefer the function that has its entrypoint at the given addr, if there is any.
This commit is contained in:
parent
0dc4e94647
commit
d65ad504ca
@ -1221,10 +1221,13 @@ QString CutterCore::disassembleSingleInstruction(RVA addr)
|
|||||||
RzAnalysisFunction *CutterCore::functionIn(ut64 addr)
|
RzAnalysisFunction *CutterCore::functionIn(ut64 addr)
|
||||||
{
|
{
|
||||||
CORE_LOCK();
|
CORE_LOCK();
|
||||||
|
RzAnalysisFunction *fcn = rz_analysis_get_function_at(core->analysis, addr);
|
||||||
|
if (fcn) {
|
||||||
|
return fcn;
|
||||||
|
}
|
||||||
RzList *fcns = rz_analysis_get_functions_in(core->analysis, addr);
|
RzList *fcns = rz_analysis_get_functions_in(core->analysis, addr);
|
||||||
RzAnalysisFunction *fcn = !rz_list_empty(fcns)
|
fcn = !rz_list_empty(fcns) ? reinterpret_cast<RzAnalysisFunction *>(rz_list_first(fcns))
|
||||||
? reinterpret_cast<RzAnalysisFunction *>(rz_list_first(fcns))
|
: nullptr;
|
||||||
: nullptr;
|
|
||||||
rz_list_free(fcns);
|
rz_list_free(fcns);
|
||||||
return fcn;
|
return fcn;
|
||||||
}
|
}
|
||||||
@ -1750,22 +1753,37 @@ CutterJson CutterCore::getRegisterValues()
|
|||||||
QList<VariableDescription> CutterCore::getVariables(RVA at)
|
QList<VariableDescription> CutterCore::getVariables(RVA at)
|
||||||
{
|
{
|
||||||
QList<VariableDescription> ret;
|
QList<VariableDescription> ret;
|
||||||
CutterJson varsObject = cmdj(QString("afvj @ %1").arg(at));
|
CORE_LOCK();
|
||||||
|
RzAnalysisFunction *fcn = functionIn(at);
|
||||||
auto addVars = [&](VariableDescription::RefType refType, const CutterJson &array) {
|
if (!fcn) {
|
||||||
for (CutterJson varObject : array) {
|
return ret;
|
||||||
VariableDescription desc;
|
}
|
||||||
desc.refType = refType;
|
for (auto var : CutterPVector<RzAnalysisVar>(&fcn->vars)) {
|
||||||
desc.name = varObject["name"].toString();
|
VariableDescription desc;
|
||||||
desc.type = varObject["type"].toString();
|
switch (var->kind) {
|
||||||
ret << desc;
|
case RZ_ANALYSIS_VAR_KIND_BPV:
|
||||||
|
desc.refType = VariableDescription::RefType::BP;
|
||||||
|
break;
|
||||||
|
case RZ_ANALYSIS_VAR_KIND_SPV:
|
||||||
|
desc.refType = VariableDescription::RefType::SP;
|
||||||
|
break;
|
||||||
|
case RZ_ANALYSIS_VAR_KIND_REG:
|
||||||
|
default:
|
||||||
|
desc.refType = VariableDescription::RefType::Reg;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
if (!var->name || !var->type) {
|
||||||
|
continue;
|
||||||
addVars(VariableDescription::RefType::SP, varsObject["sp"]);
|
}
|
||||||
addVars(VariableDescription::RefType::BP, varsObject["bp"]);
|
desc.name = QString::fromUtf8(var->name);
|
||||||
addVars(VariableDescription::RefType::Reg, varsObject["reg"]);
|
char *tn = rz_type_as_string(core->analysis->typedb, var->type);
|
||||||
|
if (!tn) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
desc.type = QString::fromUtf8(tn);
|
||||||
|
rz_mem_free(tn);
|
||||||
|
ret.push_back(desc);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user