4
4
5
5
/* *
6
6
* @file
7
- * @brief Information gathering from R2 and user.
7
+ * @brief Information gathering from Rizin and user.
8
8
*/
9
9
10
10
#include < retdec/utils/io/log.h>
@@ -20,7 +20,7 @@ using retdec::utils::io::Log;
20
20
21
21
/* *
22
22
* 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.
24
24
*/
25
25
std::map<const std::string, const CallingConventionID> RizinDatabase::_rzrdcc = {
26
26
{" arm32" , CallingConventionID::CC_ARM},
@@ -49,7 +49,7 @@ RizinDatabase::RizinDatabase(RzCore &core):
49
49
}
50
50
51
51
/* *
52
- * @brief Fetches path of the binary file from Radare2 .
52
+ * @brief Fetches path of the binary file from Rizin .
53
53
*/
54
54
std::string RizinDatabase::fetchFilePath () const
55
55
{
@@ -157,40 +157,33 @@ Function RizinDatabase::fetchSeekedFunction() const
157
157
}
158
158
159
159
/* *
160
- * @brief Fetches functions and global variables from Radare2 .
160
+ * @brief Fetches functions and global variables from Rizin .
161
161
*/
162
- void RizinDatabase::fetchFunctionsAndGlobals (Config &rconfig ) const
162
+ void RizinDatabase::fetchFunctionsAndGlobals (Config &rzconfig ) const
163
163
{
164
164
auto list = rz_analysis_get_fcns (_rzcore.analysis );
165
165
if (list != nullptr ) {
166
166
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) );
169
169
if (fnc == nullptr )
170
170
continue ;
171
171
functions.insert (convertFunctionObject (*fnc));
172
172
}
173
173
174
- rconfig .functions = functions;
174
+ rzconfig .functions = functions;
175
175
}
176
- fetchGlobals (rconfig );
176
+ fetchGlobals (rzconfig );
177
177
}
178
178
179
179
/* *
180
- * @brief Fetches global variables from the Radare2 .
180
+ * @brief Fetches global variables from the Rizin .
181
181
*
182
182
* This method is intended only for internal usage. That is
183
183
* why this method is private. To obtain functions and global
184
184
* variables the RizinDatabase::fetchFunctionsAndGlobals
185
185
* method is available.
186
186
*
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
- *
194
187
* While browsing flags and symbols this method provides correction
195
188
* of fetched functions as some of them might be dynamically linked.
196
189
* This is another reason why this method is private and interface
@@ -202,12 +195,15 @@ void RizinDatabase::fetchGlobals(Config &config) const
202
195
if (obj == nullptr || obj->symbols == nullptr )
203
196
return ;
204
197
205
- auto list = obj->symbols ;
206
- GlobalVarContainer globals;
207
198
199
+ auto list = rz_analysis_var_global_get_all (_rzcore.analysis );
200
+
201
+ GlobalVarContainer globals;
208
202
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);
211
207
if (sym == nullptr )
212
208
continue ;
213
209
@@ -236,24 +232,18 @@ void RizinDatabase::fetchGlobals(Config &config) const
236
232
// TODO: do we want to include these functions?
237
233
}
238
234
}
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 )
244
241
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
- }
251
242
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 );
254
245
255
246
globals.insert (var);
256
- }
257
247
}
258
248
259
249
// If we found at least one dynamically linked function.
@@ -268,7 +258,7 @@ void RizinDatabase::fetchGlobals(Config &config) const
268
258
}
269
259
270
260
/* *
271
- * Converts function object from its representation in Radare2 into
261
+ * Converts function object from its representation in Rizin into
272
262
* represnetation that is used in RetDec.
273
263
*/
274
264
Function RizinDatabase::convertFunctionObject (RzAnalysisFunction &rzfnc) const
@@ -363,8 +353,8 @@ void RizinDatabase::fetchExtraArgsData(ObjectSequentialContainer &args, RzAnalys
363
353
int nargs = rz_type_func_args_count (_rzcore.analysis ->typedb , key);
364
354
if (nargs) {
365
355
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) );
368
358
Object var (arg->name , Storage::undefined ());
369
359
var.setRealName (arg->name );
370
360
var.type = Type (fu::convertTypeToLlvm (_rzcore.analysis ->typedb , arg->orig_c_type ));
@@ -376,7 +366,7 @@ void RizinDatabase::fetchExtraArgsData(ObjectSequentialContainer &args, RzAnalys
376
366
}
377
367
378
368
/* *
379
- * @brief Fetches the calling convention of the input function from Radare2 .
369
+ * @brief Fetches the calling convention of the input function from Rizin .
380
370
*/
381
371
void RizinDatabase::fetchFunctionCallingconvention (Function &function, RzAnalysisFunction &rzfnc) const
382
372
{
@@ -391,7 +381,7 @@ void RizinDatabase::fetchFunctionCallingconvention(Function &function, RzAnalysi
391
381
}
392
382
393
383
/* *
394
- * @brief Fetches the return type of the input function from Radare2 .
384
+ * @brief Fetches the return type of the input function from Rizin .
395
385
*/
396
386
void RizinDatabase::fetchFunctionReturnType (Function &function, RzAnalysisFunction &rzfnc) const
397
387
{
0 commit comments