Skip to content

Commit c9c477f

Browse files
committed
Fix build with rizin 0.7.0 (#26)
1 parent a5b759f commit c9c477f

File tree

1 file changed

+30
-40
lines changed

1 file changed

+30
-40
lines changed

src/rz-plugin/data.cpp

+30-40
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/**
66
* @file
7-
* @brief Information gathering from R2 and user.
7+
* @brief Information gathering from Rizin and user.
88
*/
99

1010
#include <retdec/utils/io/log.h>
@@ -20,7 +20,7 @@ using retdec::utils::io::Log;
2020

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

5151
/**
52-
* @brief Fetches path of the binary file from Radare2.
52+
* @brief Fetches path of the binary file from Rizin.
5353
*/
5454
std::string RizinDatabase::fetchFilePath() const
5555
{
@@ -157,40 +157,33 @@ Function RizinDatabase::fetchSeekedFunction() const
157157
}
158158

159159
/**
160-
* @brief Fetches functions and global variables from Radare2.
160+
* @brief Fetches functions and global variables from Rizin.
161161
*/
162-
void RizinDatabase::fetchFunctionsAndGlobals(Config &rconfig) const
162+
void RizinDatabase::fetchFunctionsAndGlobals(Config &rzconfig) const
163163
{
164164
auto list = rz_analysis_get_fcns(_rzcore.analysis);
165165
if (list != nullptr) {
166166
FunctionContainer functions;
167-
for (RzListIter *it = list->head; it; it = it->n) {
168-
auto fnc = reinterpret_cast<RzAnalysisFunction*>(it->data);
167+
for (RzListIter *it = list->head; it; it = rz_list_iter_get_next(it)) {
168+
auto fnc = reinterpret_cast<RzAnalysisFunction*>(rz_list_iter_get_data(it));
169169
if (fnc == nullptr)
170170
continue;
171171
functions.insert(convertFunctionObject(*fnc));
172172
}
173173

174-
rconfig.functions = functions;
174+
rzconfig.functions = functions;
175175
}
176-
fetchGlobals(rconfig);
176+
fetchGlobals(rzconfig);
177177
}
178178

179179
/**
180-
* @brief Fetches global variables from the Radare2.
180+
* @brief Fetches global variables from the Rizin.
181181
*
182182
* This method is intended only for internal usage. That is
183183
* why this method is private. To obtain functions and global
184184
* variables the RizinDatabase::fetchFunctionsAndGlobals
185185
* method is available.
186186
*
187-
* Reason for this is that currently the global variables are
188-
* not supported in Radare2 and fetching them requires sort
189-
* of hack by looking into all available symbols and flags.
190-
* User may spacify symbol or provide flag on a specified address
191-
* and that could be treated as presence of global variable in
192-
* some cases.
193-
*
194187
* While browsing flags and symbols this method provides correction
195188
* of fetched functions as some of them might be dynamically linked.
196189
* This is another reason why this method is private and interface
@@ -202,12 +195,15 @@ void RizinDatabase::fetchGlobals(Config &config) const
202195
if (obj == nullptr || obj->symbols == nullptr)
203196
return;
204197

205-
auto list = obj->symbols;
206-
GlobalVarContainer globals;
207198

199+
auto list = rz_analysis_var_global_get_all(_rzcore.analysis);
200+
201+
GlobalVarContainer globals;
208202
FunctionContainer functions;
209-
for (RzListIter *it = list->head; it; it = it->n) {
210-
auto sym = reinterpret_cast<RzBinSymbol*>(it->data);
203+
204+
void **it;
205+
rz_pvector_foreach(obj->symbols, it) {
206+
auto sym = reinterpret_cast<RzBinSymbol*>(*it);
211207
if (sym == nullptr)
212208
continue;
213209

@@ -236,24 +232,18 @@ void RizinDatabase::fetchGlobals(Config &config) const
236232
//TODO: do we want to include these functions?
237233
}
238234
}
239-
// Sometimes when setting flag, the type automatically is set to FUNC.
240-
if (bind == "GLOBAL" && (type == "FUNC" || type == "OBJ")) {
241-
if (config.functions.count(name) || config.functions.count("imp."+name)
242-
|| sym->vaddr == 0 || sym->vaddr == UT64_MAX) {
243-
// This is a function, not a global variable.
235+
}
236+
237+
// Searching through all globals
238+
for (RzListIter *it = list->head; it; it = rz_list_iter_get_next(it)) {
239+
auto glob = reinterpret_cast<RzAnalysisVarGlobal*>(rz_list_iter_get_data(it));
240+
if (glob == nullptr)
244241
continue;
245-
}
246-
// Flags will contain custom name set by user.
247-
RzFlagItem* flag = rz_flag_get_i(_rzcore.flags, sym->vaddr);
248-
if (flag) {
249-
name = flag->name;
250-
}
251242

252-
Object var(name, Storage::inMemory(sym->vaddr));
253-
var.setRealName(name);
243+
Object var(glob->name, Storage::inMemory(glob->addr));
244+
var.setRealName(glob->name);
254245

255246
globals.insert(var);
256-
}
257247
}
258248

259249
// If we found at least one dynamically linked function.
@@ -268,7 +258,7 @@ void RizinDatabase::fetchGlobals(Config &config) const
268258
}
269259

270260
/**
271-
* Converts function object from its representation in Radare2 into
261+
* Converts function object from its representation in Rizin into
272262
* represnetation that is used in RetDec.
273263
*/
274264
Function RizinDatabase::convertFunctionObject(RzAnalysisFunction &rzfnc) const
@@ -363,8 +353,8 @@ void RizinDatabase::fetchExtraArgsData(ObjectSequentialContainer &args, RzAnalys
363353
int nargs = rz_type_func_args_count(_rzcore.analysis->typedb, key);
364354
if (nargs) {
365355
RzList *list = rz_core_get_func_args(&_rzcore, rzfnc.name);
366-
for (RzListIter *it = list->head; it; it = it->n) {
367-
arg = reinterpret_cast<RzAnalysisFuncArg*>(it->data);
356+
for (RzListIter *it = list->head; it; it = rz_list_iter_get_next(it)) {
357+
arg = reinterpret_cast<RzAnalysisFuncArg*>(rz_list_iter_get_data(it));
368358
Object var(arg->name, Storage::undefined());
369359
var.setRealName(arg->name);
370360
var.type = Type(fu::convertTypeToLlvm(_rzcore.analysis->typedb, arg->orig_c_type));
@@ -376,7 +366,7 @@ void RizinDatabase::fetchExtraArgsData(ObjectSequentialContainer &args, RzAnalys
376366
}
377367

378368
/**
379-
* @brief Fetches the calling convention of the input function from Radare2.
369+
* @brief Fetches the calling convention of the input function from Rizin.
380370
*/
381371
void RizinDatabase::fetchFunctionCallingconvention(Function &function, RzAnalysisFunction &rzfnc) const
382372
{
@@ -391,7 +381,7 @@ void RizinDatabase::fetchFunctionCallingconvention(Function &function, RzAnalysi
391381
}
392382

393383
/**
394-
* @brief Fetches the return type of the input function from Radare2.
384+
* @brief Fetches the return type of the input function from Rizin.
395385
*/
396386
void RizinDatabase::fetchFunctionReturnType(Function &function, RzAnalysisFunction &rzfnc) const
397387
{

0 commit comments

Comments
 (0)