Skip to content

Commit

Permalink
Fix build with rizin 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka committed Feb 24, 2024
1 parent a5b759f commit a6c33e0
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/rz-plugin/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using retdec::utils::io::Log;

/**
* Translation map between tokens representing calling convention type returned
* by Radare2 and CallingConventionID that is recognized by RetDec.
* by Rizin and CallingConventionID that is recognized by RetDec.
*/
std::map<const std::string, const CallingConventionID> RizinDatabase::_rzrdcc = {
{"arm32", CallingConventionID::CC_ARM},
Expand Down Expand Up @@ -49,7 +49,7 @@ RizinDatabase::RizinDatabase(RzCore &core):
}

/**
* @brief Fetches path of the binary file from Radare2.
* @brief Fetches path of the binary file from Rizin.
*/
std::string RizinDatabase::fetchFilePath() const
{
Expand Down Expand Up @@ -157,40 +157,42 @@ Function RizinDatabase::fetchSeekedFunction() const
}

/**
* @brief Fetches functions and global variables from Radare2.
* @brief Fetches functions and global variables from Rizin.
*/
void RizinDatabase::fetchFunctionsAndGlobals(Config &rconfig) const
void RizinDatabase::fetchFunctionsAndGlobals(Config &rzconfig) const
{
auto list = rz_analysis_get_fcns(_rzcore.analysis);
if (list != nullptr) {
FunctionContainer functions;
for (RzListIter *it = list->head; it; it = it->n) {
auto fnc = reinterpret_cast<RzAnalysisFunction*>(it->data);
for (RzListIter *it = list->head; it; it = rz_list_iter_get_next(it)) {
auto fnc = reinterpret_cast<RzAnalysisFunction*>(rz_list_iter_get_data(it));
if (fnc == nullptr)
continue;
functions.insert(convertFunctionObject(*fnc));
}

rconfig.functions = functions;
rzconfig.functions = functions;
}
fetchGlobals(rconfig);
fetchGlobals(rzconfig);
}

/**
* @brief Fetches global variables from the Radare2.
* @brief Fetches global variables from the Rizin.
*
* This method is intended only for internal usage. That is
* why this method is private. To obtain functions and global
* variables the RizinDatabase::fetchFunctionsAndGlobals
* method is available.
*
* Reason for this is that currently the global variables are
* not supported in Radare2 and fetching them requires sort
* not supported in Rizin and fetching them requires sort
* of hack by looking into all available symbols and flags.
* User may spacify symbol or provide flag on a specified address
* and that could be treated as presence of global variable in
* some cases.
*
* TODO: Just use the proper rz_analysis_global_*() API
*
* While browsing flags and symbols this method provides correction
* of fetched functions as some of them might be dynamically linked.
* This is another reason why this method is private and interface
Expand All @@ -206,8 +208,8 @@ void RizinDatabase::fetchGlobals(Config &config) const
GlobalVarContainer globals;

FunctionContainer functions;
for (RzListIter *it = list->head; it; it = it->n) {
auto sym = reinterpret_cast<RzBinSymbol*>(it->data);
for (RzListIter *it = list->head; it; it = rz_list_iter_get_next(it)) {
auto sym = reinterpret_cast<RzBinSymbol*>(rz_list_iter_get_data(it));
if (sym == nullptr)
continue;

Expand Down Expand Up @@ -268,7 +270,7 @@ void RizinDatabase::fetchGlobals(Config &config) const
}

/**
* Converts function object from its representation in Radare2 into
* Converts function object from its representation in Rizin into
* represnetation that is used in RetDec.
*/
Function RizinDatabase::convertFunctionObject(RzAnalysisFunction &rzfnc) const
Expand Down Expand Up @@ -363,8 +365,8 @@ void RizinDatabase::fetchExtraArgsData(ObjectSequentialContainer &args, RzAnalys
int nargs = rz_type_func_args_count(_rzcore.analysis->typedb, key);
if (nargs) {
RzList *list = rz_core_get_func_args(&_rzcore, rzfnc.name);
for (RzListIter *it = list->head; it; it = it->n) {
arg = reinterpret_cast<RzAnalysisFuncArg*>(it->data);
for (RzListIter *it = list->head; it; it = rz_list_iter_get_next(it)) {
arg = reinterpret_cast<RzAnalysisFuncArg*>(rz_list_iter_get_data(it));
Object var(arg->name, Storage::undefined());
var.setRealName(arg->name);
var.type = Type(fu::convertTypeToLlvm(_rzcore.analysis->typedb, arg->orig_c_type));
Expand All @@ -376,7 +378,7 @@ void RizinDatabase::fetchExtraArgsData(ObjectSequentialContainer &args, RzAnalys
}

/**
* @brief Fetches the calling convention of the input function from Radare2.
* @brief Fetches the calling convention of the input function from Rizin.
*/
void RizinDatabase::fetchFunctionCallingconvention(Function &function, RzAnalysisFunction &rzfnc) const
{
Expand All @@ -391,7 +393,7 @@ void RizinDatabase::fetchFunctionCallingconvention(Function &function, RzAnalysi
}

/**
* @brief Fetches the return type of the input function from Radare2.
* @brief Fetches the return type of the input function from Rizin.
*/
void RizinDatabase::fetchFunctionReturnType(Function &function, RzAnalysisFunction &rzfnc) const
{
Expand Down

0 comments on commit a6c33e0

Please sign in to comment.