Rizin
unix-like reverse engineering framework and cli tools
bfile.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009-2019 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2009-2019 nibble <nibble.ds@gmail.com>
3 // SPDX-FileCopyrightText: 2009-2019 dso <dso@rice.edu>
4 // SPDX-License-Identifier: LGPL-3.0-only
5 
6 #include <rz_bin.h>
7 #include <rz_hash.h>
8 #include <rz_util/rz_log.h>
9 #include "i/private.h"
10 
11 static RzBinClass *__getClass(RzBinFile *bf, const char *name) {
12  rz_return_val_if_fail(bf && bf->o && bf->o->classes_ht && name, NULL);
13  return ht_pp_find(bf->o->classes_ht, name, NULL);
14 }
15 
16 static RzBinSymbol *__getMethod(RzBinFile *bf, const char *klass, const char *method) {
17  rz_return_val_if_fail(bf && bf->o && bf->o->methods_ht && klass && method, NULL);
18  const char *name = sdb_fmt("%s::%s", klass, method);
19  return ht_pp_find(bf->o->methods_ht, name, NULL);
20 }
21 
22 RZ_IPI RzBinFile *rz_bin_file_new(RzBin *bin, const char *file, ut64 file_sz, int fd, const char *xtrname, bool steal_ptr) {
23  ut32 bf_id;
24  if (!rz_id_pool_grab_id(bin->ids->pool, &bf_id)) {
25  return NULL;
26  }
28  if (!bf) {
29  return NULL;
30  }
31 
32  bf->id = bf_id;
33  bf->rbin = bin;
34  bf->file = RZ_STR_DUP(file);
35  bf->fd = fd;
36  bf->curxtr = xtrname ? rz_bin_get_xtrplugin_by_name(bin, xtrname) : NULL;
37  bf->size = file_sz;
39  bf->xtr_obj = NULL;
40  bf->sdb = sdb_new0();
41  return bf;
42 }
43 
44 RZ_IPI void rz_bin_file_free(void /*RzBinFile*/ *_bf) {
45  if (!_bf) {
46  return;
47  }
48  RzBinFile *bf = _bf;
49  if (bf->rbin->cur == bf) {
50  bf->rbin->cur = NULL;
51  }
52  RzBinPlugin *plugin = rz_bin_file_cur_plugin(bf);
53  // Binary format objects are connected to the
54  // RzBinObject, so the plugin must destroy the
55  // format data first
56  if (plugin && plugin->destroy) {
57  plugin->destroy(bf);
58  }
59  rz_buf_free(bf->buf);
60  if (bf->curxtr && bf->curxtr->destroy && bf->xtr_obj) {
61  bf->curxtr->free_xtr((void *)(bf->xtr_obj));
62  }
63  free(bf->file);
64  rz_bin_object_free(bf->o);
66  sdb_free(bf->sdb);
67  if (bf->id != -1) {
68  // TODO: use rz_storage api
69  rz_id_pool_kick_id(bf->rbin->ids->pool, bf->id);
70  }
71  free(bf);
72 }
73 
74 static RzBinPlugin *get_plugin_from_buffer(RzBin *bin, const char *pluginname, RzBuffer *buf) {
75  RzBinPlugin *plugin = bin->force ? rz_bin_get_binplugin_by_name(bin, bin->force) : NULL;
76  if (plugin) {
77  return plugin;
78  }
79  plugin = pluginname ? rz_bin_get_binplugin_by_name(bin, pluginname) : NULL;
80  if (plugin) {
81  return plugin;
82  }
84  if (plugin) {
85  return plugin;
86  }
88  if (plugin) {
89  return plugin;
90  }
91  return rz_bin_get_binplugin_by_name(bin, "any");
92 }
93 
95  rz_return_val_if_fail(bin && bf && data, false);
96 
97  ut64 offset = data->offset;
98  ut64 sz = data->size;
99 
100  RzBinPlugin *plugin = get_plugin_from_buffer(bin, NULL, data->buf);
101  bf->buf = rz_buf_ref(data->buf);
102 
103  RzBinObject *o = rz_bin_object_new(bf, plugin, opts, offset, sz);
104  if (!o) {
105  return false;
106  }
107  // size is set here because the reported size of the object depends on
108  // if loaded from xtr plugin or partially read
109  if (!o->size) {
110  o->size = sz;
111  }
112  bf->narch = data->file_count;
113  if (!o->info) {
114  o->info = RZ_NEW0(RzBinInfo);
115  }
116  free(o->info->file);
117  free(o->info->arch);
118  free(o->info->machine);
119  free(o->info->type);
120  o->info->file = strdup(bf->file);
121  o->info->arch = strdup(data->metadata->arch);
122  o->info->machine = strdup(data->metadata->machine);
123  o->info->type = strdup(data->metadata->type);
124  o->info->bits = data->metadata->bits;
125  o->info->has_crypto = bf->o->info->has_crypto;
126  data->loaded = true;
127  return true;
128 }
129 
130 static bool xtr_metadata_match(RzBinXtrData *xtr_data, const char *arch, int bits) {
131  if (!xtr_data->metadata || !xtr_data->metadata->arch) {
132  return false;
133  }
134  const char *iter_arch = xtr_data->metadata->arch;
135  int iter_bits = xtr_data->metadata->bits;
136  return bits == iter_bits && !strcmp(iter_arch, arch) && !xtr_data->loaded;
137 }
138 
139 RZ_IPI RzBinFile *rz_bin_file_new_from_buffer(RzBin *bin, const char *file, RzBuffer *buf, RzBinObjectLoadOptions *opts, int fd, const char *pluginname) {
141 
142  RzBinFile *bf = rz_bin_file_new(bin, file, rz_buf_size(buf), fd, pluginname, false);
143  if (!bf) {
144  return NULL;
145  }
146 
147  RzListIter *item = rz_list_append(bin->binfiles, bf);
148  bf->buf = rz_buf_ref(buf);
149  RzBinPlugin *plugin = get_plugin_from_buffer(bin, pluginname, bf->buf);
150  RzBinObject *o = rz_bin_object_new(bf, plugin, opts, 0, rz_buf_size(bf->buf));
151  if (!o) {
152  rz_list_delete(bin->binfiles, item);
153  return NULL;
154  }
155  // size is set here because the reported size of the object depends on
156  // if loaded from xtr plugin or partially read
157  if (!o->size) {
158  o->size = rz_buf_size(buf);
159  }
160  return bf;
161 }
162 
164  RzListIter *iter;
165  RzBinFile *binfile = NULL;
166  RzBinXtrData *xtr_data;
167 
169 
170  rz_list_foreach (bin->binfiles, iter, binfile) {
171  RzListIter *iter_xtr;
172  if (!binfile->xtr_data) {
173  continue;
174  }
175  // look for sub-bins in Xtr Data and Load if we need to
176  rz_list_foreach (binfile->xtr_data, iter_xtr, xtr_data) {
177  if (xtr_metadata_match(xtr_data, arch, bits)) {
178  if (!rz_bin_file_object_new_from_xtr_data(bin, binfile, &xtr_data->obj_opts, xtr_data)) {
179  return NULL;
180  }
181  return binfile;
182  }
183  }
184  }
185  return binfile;
186 }
187 
189  RzBinFile *bf;
190  RzListIter *iter;
191  rz_list_foreach (bin->binfiles, iter, bf) {
192  if (bf->id == bf_id) {
193  return bf;
194  }
195  }
196  return NULL;
197 }
198 
201  ut64 counter = rz_list_length(bin->binfiles);
202  RzListIter *it;
203  RzBinFile *bf;
204  rz_list_foreach (bin->binfiles, it, bf) {
205  RzEventBinFileDel ev = { bf };
207  }
208  rz_list_purge(bin->binfiles);
209  bin->cur = NULL;
210  return counter;
211 }
212 
214  rz_return_val_if_fail(bin && bf, false);
215  RzListIter *it = rz_list_find_ptr(bin->binfiles, bf);
216  rz_return_val_if_fail(it, false); // calling del on a bf not in the bin is a programming error
217  if (bin->cur == bf) {
218  bin->cur = NULL;
219  }
220  RzEventBinFileDel ev = { bf };
222  rz_list_delete(bin->binfiles, it);
223  return true;
224 }
225 
228  RzListIter *iter;
229  RzBinFile *bf;
230 
231  rz_list_foreach (bin->binfiles, iter, bf) {
232  if (bf->fd == bin_fd) {
233  return bf;
234  }
235  }
236  return NULL;
237 }
238 
240  RzListIter *iter;
241  RzBinFile *bf;
242 
244 
245  rz_list_foreach (bin->binfiles, iter, bf) {
246  if (bf->file && !strcmp(bf->file, name)) {
247  return bf;
248  }
249  }
250  return NULL;
251 }
252 
254  RzBinFile *bf = rz_bin_file_find_by_id(bin, bin_id);
255  return bf ? rz_bin_file_set_cur_binfile(bin, bf) : false;
256 }
257 
259  RzBinFile *bf = rz_bin_file_find_by_fd(bin, bin_fd);
260  return bf ? rz_bin_file_set_cur_binfile(bin, bf) : false;
261 }
262 
264  rz_return_val_if_fail(bin && bf, false);
265  bin->file = bf->file;
266  bin->cur = bf;
267  bin->narch = bf->narch;
268  if (obj) {
269  bf->o = obj;
270  } else {
271  obj = bf->o;
272  }
273  RzBinPlugin *plugin = rz_bin_file_cur_plugin(bf);
274  if (bin->minstrlen < 1) {
275  bin->minstrlen = plugin ? plugin->minstrlen : bin->minstrlen;
276  }
277  if (obj) {
278  if (!obj->info) {
279  return false;
280  }
281  if (!obj->info->lang) {
282  obj->info->lang = rz_bin_language_to_string(obj->lang);
283  }
284  }
285  return true;
286 }
287 
289  rz_return_val_if_fail(bin && bf, false);
290  return rz_bin_file_set_obj(bin, bf, bf->o);
291 }
292 
294  rz_return_val_if_fail(bin && name, false);
296  return rz_bin_file_set_cur_binfile(bin, bf);
297 }
298 
300  rz_return_val_if_fail(bin && xtr && buf, NULL);
301 
303  if (!bf) {
304  bf = rz_bin_file_new(bin, filename, rz_buf_size(buf), fd, xtr->name, false);
305  if (!bf) {
306  return NULL;
307  }
308  rz_list_append(bin->binfiles, bf);
309  if (!bin->cur) {
310  bin->cur = bf;
311  }
312  }
313  rz_list_free(bf->xtr_data);
314  bf->xtr_data = NULL;
315  if (xtr->extractall_from_buffer) {
316  bf->xtr_data = xtr->extractall_from_buffer(bin, buf);
317  } else if (xtr->extractall_from_bytes) {
318  ut64 sz = 0;
319  const ut8 *bytes = rz_buf_data(buf, &sz);
320  RZ_LOG_INFO("TODO: Implement extractall_from_buffer in '%s' xtr.bin plugin\n", xtr->name);
321  bf->xtr_data = xtr->extractall_from_bytes(bin, bytes, sz);
322  }
323  if (bf->xtr_data) {
324  RzListIter *iter;
325  RzBinXtrData *x;
326  // populate xtr_data with baddr and laddr that will be used later on
327  // rz_bin_file_object_new_from_xtr_data
328  rz_list_foreach (bf->xtr_data, iter, x) {
329  x->obj_opts = *obj_opts;
330  }
331  }
332  bf->loadaddr = obj_opts->loadaddr;
333  return bf;
334 }
335 
336 // XXX deprecate this function imho.. wee can just access bf->buf directly
337 RZ_IPI bool rz_bin_file_set_bytes(RzBinFile *bf, const ut8 *bytes, ut64 sz, bool steal_ptr) {
338  rz_return_val_if_fail(bf && bytes, false);
339  rz_buf_free(bf->buf);
340  if (steal_ptr) {
341  bf->buf = rz_buf_new_with_pointers(bytes, sz, true);
342  } else {
343  bf->buf = rz_buf_new_with_bytes(bytes, sz);
344  }
345  return bf->buf != NULL;
346 }
347 
349  return (bf && bf->o) ? bf->o->plugin : NULL;
350 }
351 
353  if (bf && bf->o) {
354  return bf->o->opts.baseaddr;
355  }
356  return UT64_MAX;
357 }
358 
360  rz_return_val_if_fail(bin, false);
361  RzBinFile *bf = rz_id_storage_take(bin->ids, bd);
362  if (bf) {
363  // file_free removes the fd already.. maybe its unnecessary
364  rz_id_storage_delete(bin->ids, bd);
365  rz_bin_file_free(bf);
366  return true;
367  }
368  return false;
369 }
370 
371 static inline bool add_file_hash(RzHashCfg *md, const char *name, RzList *list) {
372  char hash[128];
373  const ut8 *digest = NULL;
374  RzHashSize digest_size = 0;
375 
376  digest = rz_hash_cfg_get_result(md, name, &digest_size);
377  if (!digest) {
378  return false;
379  }
380 
381  if (!strcmp(name, "entropy")) {
382  double entropy = rz_read_be_double(digest);
383  rz_strf(hash, "%f", entropy);
384  } else {
385  rz_hex_bin2str(digest, digest_size, hash);
386  }
387 
389  if (!fh) {
390  RZ_LOG_ERROR("Cannot allocate RzBinFileHash\n");
391  return false;
392  }
393 
394  fh->type = strdup(name);
395  fh->hex = strdup(hash);
396  rz_list_push(list, fh);
397  return true;
398 }
399 
400 static ut64 buf_compute_hashes(const ut8 *buf, ut64 size, void *user) {
401  if (!rz_hash_cfg_update((RzHashCfg *)user, buf, size)) {
402  return 0;
403  }
404  return size;
405 }
406 
412  rz_return_val_if_fail(bin && bf && bf->o, NULL);
413  RzBinObject *o = bf->o;
414  RzList *file_hashes = NULL;
415  RzHashCfg *md = NULL;
416  RzBuffer *buf = rz_buf_new_with_io_fd(&bin->iob, bf->fd);
417  const ut64 buf_size = rz_buf_size(buf);
418  if (!buf_size) {
419  rz_buf_free(buf);
420  return NULL;
421  }
422  if (buf_size > limit) {
423  if (bin->verbose) {
424  RZ_LOG_WARN("rz_bin_file_hash: file exceeds bin.hashlimit\n");
425  }
426  return NULL;
427  }
429  if (!file_hashes) {
430  RZ_LOG_ERROR("Cannot allocate file hash list\n");
431  goto rz_bin_file_compute_hashes_bad;
432  }
433 
434  md = rz_hash_cfg_new(bin->hash);
435  if (!md) {
436  goto rz_bin_file_compute_hashes_bad;
437  }
438 
439  if (!rz_hash_cfg_configure(md, "md5") ||
440  !rz_hash_cfg_configure(md, "sha1") ||
441  !rz_hash_cfg_configure(md, "sha256") ||
442  !rz_hash_cfg_configure(md, "crc32") ||
443  !rz_hash_cfg_configure(md, "entropy")) {
444  goto rz_bin_file_compute_hashes_bad;
445  }
446  if (!rz_hash_cfg_init(md)) {
447  goto rz_bin_file_compute_hashes_bad;
448  }
449 
451  goto rz_bin_file_compute_hashes_bad;
452  }
453 
454  if (!rz_hash_cfg_final(md)) {
455  goto rz_bin_file_compute_hashes_bad;
456  }
457 
458  if (!add_file_hash(md, "md5", file_hashes) ||
459  !add_file_hash(md, "sha1", file_hashes) ||
460  !add_file_hash(md, "sha256", file_hashes) ||
461  !add_file_hash(md, "crc32", file_hashes) ||
462  !add_file_hash(md, "entropy", file_hashes)) {
463  goto rz_bin_file_compute_hashes_bad;
464  }
465 
466  if (o->plugin && o->plugin->hashes) {
467  RzList *plugin_hashes = o->plugin->hashes(bf);
468  rz_list_join(file_hashes, plugin_hashes);
469  rz_list_free(plugin_hashes);
470  }
471 
472  // TODO: add here more rows
473  rz_buf_free(buf);
475  return file_hashes;
476 
477 rz_bin_file_compute_hashes_bad:
478  rz_buf_free(buf);
480  rz_list_free(file_hashes);
481  return NULL;
482 }
483 
488 RZ_API RZ_OWN RzList /*<RzBinFileHash *>*/ *rz_bin_file_set_hashes(RzBin *bin, RZ_OWN RzList /*<RzBinFileHash *>*/ *new_hashes) {
489  rz_return_val_if_fail(bin && bin->cur && bin->cur->o && bin->cur->o->info, NULL);
490  RzBinFile *bf = bin->cur;
491  RzBinInfo *info = bf->o->info;
492 
493  RzList *prev_hashes = info->file_hashes;
494  info->file_hashes = new_hashes;
495 
496  return prev_hashes;
497 }
498 
499 RZ_IPI RzBinClass *rz_bin_class_new(const char *name, const char *super, int view) {
502  if (c) {
503  c->name = strdup(name);
504  c->super = super ? strdup(super) : NULL;
505  c->methods = rz_list_new();
506  c->fields = rz_list_new();
507  c->visibility = view;
508  }
509  return c;
510 }
511 
513  if (k && k->name) {
514  free(k->name);
515  free(k->super);
516  rz_list_free(k->methods);
517  rz_list_free(k->fields);
518  free(k->visibility_str);
519  free(k);
520  }
521 }
522 
523 RZ_API RzBinClass *rz_bin_file_add_class(RzBinFile *bf, const char *name, const char *super, int view) {
524  rz_return_val_if_fail(name && bf && bf->o, NULL);
525  RzBinClass *c = __getClass(bf, name);
526  if (c) {
527  if (super) {
528  free(c->super);
529  c->super = strdup(super);
530  }
531  return c;
532  }
533  c = rz_bin_class_new(name, super, view);
534  if (c) {
535  // XXX. no need for a list, the ht is iterable too
536  c->index = rz_list_length(bf->o->classes);
537  rz_list_append(bf->o->classes, c);
538  ht_pp_insert(bf->o->classes_ht, name, c);
539  }
540  return c;
541 }
542 
543 RZ_API RzBinSymbol *rz_bin_file_add_method(RzBinFile *bf, const char *klass, const char *method, int nargs) {
545 
546  RzBinClass *c = rz_bin_file_add_class(bf, klass, NULL, 0);
547  if (!c) {
548  RZ_LOG_ERROR("Cannot allocate RzBinClass for '%s'\n", klass);
549  return NULL;
550  }
551  RzBinSymbol *sym = __getMethod(bf, klass, method);
552  if (!sym) {
553  sym = RZ_NEW0(RzBinSymbol);
554  if (sym) {
555  sym->name = strdup(method);
556  rz_list_append(c->methods, sym);
557  const char *name = sdb_fmt("%s::%s", klass, method);
558  ht_pp_insert(bf->o->methods_ht, name, sym);
559  }
560  }
561  return sym;
562 }
563 
565  rz_return_val_if_fail(bf && bf->o && bf->o->plugin, NULL);
566  if (bf->o->plugin->trycatch) {
567  return bf->o->plugin->trycatch(bf);
568  }
569  return NULL;
570 }
571 
572 RZ_API RzList /*<RzBinSymbol *>*/ *rz_bin_file_get_symbols(RzBinFile *bf) {
574  RzBinObject *o = bf->o;
575  return o ? (RzList *)rz_bin_object_get_symbols(o) : NULL;
576 }
#define RZ_IPI
Definition: analysis_wasm.c:11
static ut8 bytes[32]
Definition: asm_arc.c:23
RZ_API bool rz_bin_file_set_cur_binfile(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:288
RZ_API RZ_OWN RzList * rz_bin_file_set_hashes(RzBin *bin, RZ_OWN RzList *new_hashes)
Set file_hashes on current RzBinInfo.
Definition: bfile.c:488
RZ_API ut64 rz_bin_file_delete_all(RzBin *bin)
Definition: bfile.c:199
RZ_API RzBinSymbol * rz_bin_file_add_method(RzBinFile *bf, const char *klass, const char *method, int nargs)
Definition: bfile.c:543
RZ_IPI RzBinFile * rz_bin_file_new_from_buffer(RzBin *bin, const char *file, RzBuffer *buf, RzBinObjectLoadOptions *opts, int fd, const char *pluginname)
Definition: bfile.c:139
RZ_API RzBinClass * rz_bin_file_add_class(RzBinFile *bf, const char *name, const char *super, int view)
Definition: bfile.c:523
RZ_API RzBinFile * rz_bin_file_find_by_name(RzBin *bin, const char *name)
Definition: bfile.c:239
RZ_IPI bool rz_bin_file_set_obj(RzBin *bin, RzBinFile *bf, RzBinObject *obj)
Definition: bfile.c:263
RZ_API RzBinFile * rz_bin_file_find_by_id(RzBin *bin, ut32 bf_id)
Definition: bfile.c:188
RZ_API bool rz_bin_file_set_cur_by_fd(RzBin *bin, ut32 bin_fd)
Definition: bfile.c:258
RZ_IPI bool rz_bin_file_set_bytes(RzBinFile *bf, const ut8 *bytes, ut64 sz, bool steal_ptr)
Definition: bfile.c:337
static RzBinClass * __getClass(RzBinFile *bf, const char *name)
Definition: bfile.c:11
static RzBinSymbol * __getMethod(RzBinFile *bf, const char *klass, const char *method)
Definition: bfile.c:16
RZ_IPI void rz_bin_class_free(RzBinClass *k)
Definition: bfile.c:512
RZ_API RzList * rz_bin_file_get_symbols(RzBinFile *bf)
Definition: bfile.c:572
RZ_API RzBinFile * rz_bin_file_find_by_fd(RzBin *bin, ut32 bin_fd)
Definition: bfile.c:226
RZ_API bool rz_bin_file_delete(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:213
RZ_IPI RzBinClass * rz_bin_class_new(const char *name, const char *super, int view)
Definition: bfile.c:499
RZ_API RzBinFile * rz_bin_file_find_by_arch_bits(RzBin *bin, const char *arch, int bits)
Definition: bfile.c:163
static ut64 buf_compute_hashes(const ut8 *buf, ut64 size, void *user)
Definition: bfile.c:400
static RzBinPlugin * get_plugin_from_buffer(RzBin *bin, const char *pluginname, RzBuffer *buf)
Definition: bfile.c:74
RZ_IPI RzBinFile * rz_bin_file_new(RzBin *bin, const char *file, ut64 file_sz, int fd, const char *xtrname, bool steal_ptr)
Definition: bfile.c:22
RZ_API bool rz_bin_file_close(RzBin *bin, int bd)
Definition: bfile.c:359
RZ_API RZ_OWN RzList * rz_bin_file_compute_hashes(RzBin *bin, RzBinFile *bf, ut64 limit)
Definition: bfile.c:411
RZ_API bool rz_bin_file_set_cur_by_id(RzBin *bin, ut32 bin_id)
Definition: bfile.c:253
RZ_API RzBinPlugin * rz_bin_file_cur_plugin(RzBinFile *bf)
Definition: bfile.c:348
static bool add_file_hash(RzHashCfg *md, const char *name, RzList *list)
Definition: bfile.c:371
static bool xtr_metadata_match(RzBinXtrData *xtr_data, const char *arch, int bits)
Definition: bfile.c:130
RZ_IPI void rz_bin_file_free(void *_bf)
Definition: bfile.c:44
RZ_API bool rz_bin_file_object_new_from_xtr_data(RzBin *bin, RzBinFile *bf, RzBinObjectLoadOptions *opts, RzBinXtrData *data)
Definition: bfile.c:94
RZ_IPI RzBinFile * rz_bin_file_xtr_load_buffer(RzBin *bin, RzBinXtrPlugin *xtr, const char *filename, RzBuffer *buf, RzBinObjectLoadOptions *obj_opts, int idx, int fd)
Definition: bfile.c:299
RZ_API bool rz_bin_file_set_cur_by_name(RzBin *bin, const char *name)
Definition: bfile.c:293
RZ_API ut64 rz_bin_file_get_baddr(RzBinFile *bf)
Definition: bfile.c:352
RZ_API RzList * rz_bin_file_get_trycatch(RZ_NONNULL RzBinFile *bf)
Definition: bfile.c:564
RZ_API void rz_bin_xtrdata_free(void *data_)
Definition: bin.c:61
RZ_API void rz_bin_file_hash_free(RzBinFileHash *fhash)
Definition: bin.c:89
RZ_API RzBinPlugin * rz_bin_get_binplugin_by_buffer(RzBin *bin, RzBuffer *buf)
Definition: bin.c:349
RZ_IPI RzBinPlugin * rz_bin_get_binplugin_by_name(RzBin *bin, const char *name)
Definition: bin.c:335
RZ_IPI RzBinPlugin * rz_bin_get_binplugin_by_filename(RzBin *bin)
Definition: bin.c:365
RZ_IPI RzBinXtrPlugin * rz_bin_get_xtrplugin_by_name(RzBin *bin, const char *name)
Definition: bin.c:383
RZ_API const char * rz_bin_language_to_string(RzBinLanguage language)
returns the language name based on the given language identifier
Definition: bin_language.c:229
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
int bits(struct state *s, int need)
Definition: blast.c:72
RZ_IPI void rz_bin_object_free(RzBinObject *o)
Definition: bobj.c:188
RZ_IPI RzBinObject * rz_bin_object_new(RzBinFile *bf, RzBinPlugin *plugin, RzBinObjectLoadOptions *opts, ut64 offset, ut64 sz)
Definition: bobj.c:278
RZ_API const RzList * rz_bin_object_get_symbols(RZ_NONNULL RzBinObject *obj)
Get list of RzBinSymbol representing the symbols in the binary object.
Definition: bobj.c:817
FILE * fh
Definition: cabinfo.c:52
#define RZ_API
#define NULL
Definition: cris-opc.c:27
cs_arch arch
Definition: cstool.c:13
static int buf_size
Definition: debug_qnx.c:35
uint32_t ut32
const char * k
Definition: dsignal.c:11
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
RZ_API RZ_BORROW const ut8 * rz_hash_cfg_get_result(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name, RZ_NONNULL ut32 *size)
Returns the digest value of the requested algorithm name.
Definition: hash.c:445
RZ_API RZ_OWN RzHashCfg * rz_hash_cfg_new(RZ_NONNULL RzHash *rh)
Definition: hash.c:134
RZ_API void rz_hash_cfg_free(RZ_NONNULL RzHashCfg *md)
Definition: hash.c:186
RZ_API bool rz_hash_cfg_configure(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name)
Allocates and configures the plugin message digest context.
Definition: hash.c:199
RZ_API bool rz_hash_cfg_init(RZ_NONNULL RzHashCfg *md)
Resets/initialize the message digest contextes.
Definition: hash.c:298
RZ_API bool rz_hash_cfg_update(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const ut8 *data, ut64 size)
Inserts data into each the message digest contextes.
Definition: hash.c:337
RZ_API bool rz_hash_cfg_final(RZ_NONNULL RzHashCfg *md)
Generates the final value of the message digest contextes.
Definition: hash.c:359
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
const char * filename
Definition: ioapi.h:137
voidpf uLong offset
Definition: ioapi.h:144
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_find_ptr(RZ_NONNULL const RzList *list, RZ_NONNULL const void *ptr)
Returns the RzListIter of the given pointer, if found.
Definition: list.c:600
RZ_API void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
Definition: list.c:162
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API bool rz_list_join(RZ_NONNULL RzList *list1, RZ_NONNULL RzList *list2)
Joins 2 list into one (list2 pointer needs to be freed by the user)
Definition: list.c:209
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition: list.c:120
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static uint32_t const uint8_t uint32_t uint32_t limit
Definition: memcmplen.h:45
int x
Definition: mipsasm.c:20
int idx
Definition: setup.py:197
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RzBuffer * rz_buf_ref(RzBuffer *b)
Increment the reference count of the buffer.
Definition: buf.c:668
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_io_fd(RZ_NONNULL void *iob, int fd)
Creates a new buffer wrapping a file descriptor accessed through RzIOBind.
Definition: buf.c:490
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal)
Creates a new buffer with a bytes array.
Definition: buf.c:552
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
Definition: buf.c:465
RZ_API ut64 rz_buf_fwd_scan(RZ_NONNULL RzBuffer *b, ut64 start, ut64 amount, RZ_NONNULL RzBufferFwdScan fwd_scan, RZ_NULLABLE void *user)
Scans buffer linearly in chunks calling fwd_scan for each chunk.
Definition: buf.c:1303
RZ_DEPRECATE RZ_API RZ_BORROW ut8 * rz_buf_data(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut64 *size)
Return a borrowed array of bytes representing the buffer data.
Definition: buf.c:1287
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
static double rz_read_be_double(const void *src)
Definition: rz_endian.h:157
RZ_API void rz_event_send(RzEvent *ev, int type, void *data)
Definition: event.c:115
@ RZ_EVENT_BIN_FILE_DEL
Definition: rz_event.h:45
ut32 RzHashSize
Definition: rz_hash.h:24
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
RZ_API bool rz_id_pool_grab_id(RzIDPool *pool, ut32 *grabber)
Definition: idpool.c:34
RZ_API void * rz_id_storage_take(RzIDStorage *storage, ut32 id)
Definition: idpool.c:248
RZ_API void rz_id_storage_delete(RzIDStorage *storage, ut32 id)
Definition: idpool.c:221
RZ_API bool rz_id_pool_kick_id(RzIDPool *pool, ut32 kick)
Definition: idpool.c:53
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_STR_DUP(x)
Definition: rz_str.h:69
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_NONNULL
Definition: rz_types.h:64
#define UT64_MAX
Definition: rz_types_base.h:86
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
#define c(i)
Definition: sha256.c:43
Definition: malloc.c:26
Definition: gzappend.c:170
Definition: z80asm.h:102
ut64 loadaddr
starting physical address to read from the target file
Definition: rz_bin.h:249
ut64 baseaddr
where the linker maps the binary in memory
Definition: rz_bin.h:248
XX curplugin == o->plugin.
Definition: rz_bin.h:298
ut64 loadaddr
Definition: rz_bin.h:307
RzBinObject * o
Definition: rz_bin.h:305
RZ_DEPRECATE Sdb * sdb
deprecated, put info in C structures instead of this
Definition: rz_bin.h:315
struct rz_bin_t * rbin
Definition: rz_bin.h:316
int fd
when used in combination with RzIO, this refers to the io fd.
Definition: rz_bin.h:300
struct rz_bin_xtr_plugin_t * curxtr
Definition: rz_bin.h:312
char * file
Definition: rz_bin.h:299
RzBuffer * buf
Definition: rz_bin.h:303
RzList * xtr_data
Definition: rz_bin.h:314
void * xtr_obj
Definition: rz_bin.h:306
char * type
Definition: rz_bin.h:211
int has_crypto
Definition: rz_bin.h:233
RzList * file_hashes
Definition: rz_bin.h:226
char * machine
Definition: rz_bin.h:216
const char * lang
Definition: rz_bin.h:224
char * file
Definition: rz_bin.h:210
char * arch
Definition: rz_bin.h:214
RzList * classes
Definition: rz_bin.h:281
RzBinObjectLoadOptions opts
Definition: rz_bin.h:260
RzBinLanguage lang
Definition: rz_bin.h:290
struct rz_bin_plugin_t * plugin
Definition: rz_bin.h:289
RzBinInfo * info
Definition: rz_bin.h:287
HtPP * methods_ht
Definition: rz_bin.h:283
HtPP * classes_ht
Definition: rz_bin.h:282
RzList *(* hashes)(RzBinFile *bf)
Definition: rz_bin.h:540
void(* destroy)(RzBinFile *bf)
Definition: rz_bin.h:517
char * name
Definition: rz_bin.h:675
RZ_DEPRECATE RzBinFile * cur
never use this in new code! Get a file from the binfiles list or track it yourself.
Definition: rz_bin.h:330
RzIDStorage * ids
Definition: rz_bin.h:341
RzBinObjectLoadOptions obj_opts
Definition: rz_bin.h:383
RzBuffer * buf
Definition: rz_bin.h:380
RzBinXtrMetadata * metadata
Definition: rz_bin.h:386
void(* free_xtr)(void *xtr_obj)
Definition: rz_bin.h:410
void(* destroy)(RzBin *bin)
Definition: rz_bin.h:409
RzList *(* extractall_from_bytes)(RzBin *bin, const ut8 *buf, ut64 size)
Definition: rz_bin.h:402
RzList *(* extractall_from_buffer)(RzBin *bin, RzBuffer *buf)
Definition: rz_bin.h:403
RzIDPool * pool
Definition: rz_idpool.h:28
int64_t counter
Definition: main.c:4
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
Definition: z80_tab.h:997