SDB usage cleanup within rz_bin
This commit is contained in:
parent
a73b845304
commit
0dcdc842a2
14 changed files with 145 additions and 162 deletions
|
|
@ -188,24 +188,25 @@ static void get_strings_range(RzBinFile *bf, RzList *list, size_t min, ut64 from
|
|||
string_scan_range(list, bf, min, from, to, type);
|
||||
}
|
||||
|
||||
RZ_IPI RzBinFile *rz_bin_file_new(RzBin *bin, const char *file, ut64 file_sz, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr) {
|
||||
RZ_IPI RzBinFile *rz_bin_file_new(RzBin *bin, const char *file, ut64 file_sz, int fd, const char *xtrname, bool steal_ptr) {
|
||||
ut32 bf_id;
|
||||
if (!rz_id_pool_grab_id(bin->ids->pool, &bf_id)) {
|
||||
return NULL;
|
||||
}
|
||||
RzBinFile *bf = RZ_NEW0(RzBinFile);
|
||||
if (bf) {
|
||||
bf->id = bf_id;
|
||||
bf->rbin = bin;
|
||||
bf->file = file ? strdup(file) : NULL;
|
||||
bf->fd = fd;
|
||||
bf->curxtr = xtrname ? rz_bin_get_xtrplugin_by_name(bin, xtrname) : NULL;
|
||||
bf->sdb = sdb;
|
||||
bf->size = file_sz;
|
||||
bf->xtr_data = rz_list_newf((RzListFree)rz_bin_xtrdata_free);
|
||||
bf->xtr_obj = NULL;
|
||||
bf->sdb = sdb_new0();
|
||||
if (!bf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bf->id = bf_id;
|
||||
bf->rbin = bin;
|
||||
bf->file = RZ_STR_DUP(file);
|
||||
bf->fd = fd;
|
||||
bf->curxtr = xtrname ? rz_bin_get_xtrplugin_by_name(bin, xtrname) : NULL;
|
||||
bf->size = file_sz;
|
||||
bf->xtr_data = rz_list_newf((RzListFree)rz_bin_xtrdata_free);
|
||||
bf->xtr_obj = NULL;
|
||||
bf->sdb = sdb_new0();
|
||||
return bf;
|
||||
}
|
||||
|
||||
|
|
@ -231,6 +232,7 @@ RZ_IPI void rz_bin_file_free(void /*RzBinFile*/ *_bf) {
|
|||
free(bf->file);
|
||||
rz_bin_object_free(bf->o);
|
||||
rz_list_free(bf->xtr_data);
|
||||
sdb_free(bf->sdb);
|
||||
if (bf->id != -1) {
|
||||
// TODO: use rz_storage api
|
||||
rz_id_pool_kick_id(bf->rbin->ids->pool, bf->id);
|
||||
|
|
@ -306,21 +308,23 @@ static bool xtr_metadata_match(RzBinXtrData *xtr_data, const char *arch, int bit
|
|||
RZ_IPI RzBinFile *rz_bin_file_new_from_buffer(RzBin *bin, const char *file, RzBuffer *buf, RzBinObjectLoadOptions *opts, int fd, const char *pluginname) {
|
||||
rz_return_val_if_fail(bin && file && buf, NULL);
|
||||
|
||||
RzBinFile *bf = rz_bin_file_new(bin, file, rz_buf_size(buf), fd, pluginname, NULL, false);
|
||||
if (bf) {
|
||||
RzListIter *item = rz_list_append(bin->binfiles, bf);
|
||||
bf->buf = rz_buf_ref(buf);
|
||||
RzBinPlugin *plugin = get_plugin_from_buffer(bin, pluginname, bf->buf);
|
||||
RzBinObject *o = rz_bin_object_new(bf, plugin, opts, 0, rz_buf_size(bf->buf));
|
||||
if (!o) {
|
||||
rz_list_delete(bin->binfiles, item);
|
||||
return NULL;
|
||||
}
|
||||
// size is set here because the reported size of the object depends on
|
||||
// if loaded from xtr plugin or partially read
|
||||
if (!o->size) {
|
||||
o->size = rz_buf_size(buf);
|
||||
}
|
||||
RzBinFile *bf = rz_bin_file_new(bin, file, rz_buf_size(buf), fd, pluginname, false);
|
||||
if (!bf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RzListIter *item = rz_list_append(bin->binfiles, bf);
|
||||
bf->buf = rz_buf_ref(buf);
|
||||
RzBinPlugin *plugin = get_plugin_from_buffer(bin, pluginname, bf->buf);
|
||||
RzBinObject *o = rz_bin_object_new(bf, plugin, opts, 0, rz_buf_size(bf->buf));
|
||||
if (!o) {
|
||||
rz_list_delete(bin->binfiles, item);
|
||||
return NULL;
|
||||
}
|
||||
// size is set here because the reported size of the object depends on
|
||||
// if loaded from xtr plugin or partially read
|
||||
if (!o->size) {
|
||||
o->size = rz_buf_size(buf);
|
||||
}
|
||||
return bf;
|
||||
}
|
||||
|
|
@ -466,7 +470,7 @@ RZ_IPI RzBinFile *rz_bin_file_xtr_load_buffer(RzBin *bin, RzBinXtrPlugin *xtr, c
|
|||
|
||||
RzBinFile *bf = rz_bin_file_find_by_name(bin, filename);
|
||||
if (!bf) {
|
||||
bf = rz_bin_file_new(bin, filename, rz_buf_size(buf), fd, xtr->name, bin->sdb, false);
|
||||
bf = rz_bin_file_new(bin, filename, rz_buf_size(buf), fd, xtr->name, false);
|
||||
if (!bf) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,9 +146,12 @@ RZ_API RzBinReloc *rz_bin_reloc_storage_get_reloc_to(RzBinRelocStorage *storage,
|
|||
return r->target_vaddr == vaddr ? r : NULL;
|
||||
}
|
||||
|
||||
static void object_delete_items(RzBinObject *o) {
|
||||
ut32 i = 0;
|
||||
rz_return_if_fail(o);
|
||||
RZ_IPI void rz_bin_object_free(RzBinObject *o) {
|
||||
if (!o) {
|
||||
return;
|
||||
}
|
||||
free(o->regstate);
|
||||
rz_bin_info_free(o->info);
|
||||
ht_up_free(o->addrzklassmethod);
|
||||
rz_list_free(o->entries);
|
||||
rz_list_free(o->maps);
|
||||
|
|
@ -166,21 +169,11 @@ static void object_delete_items(RzBinObject *o) {
|
|||
ht_pp_free(o->classes_ht);
|
||||
ht_pp_free(o->methods_ht);
|
||||
rz_bin_source_line_info_free(o->lines);
|
||||
sdb_free(o->kv);
|
||||
rz_list_free(o->mem);
|
||||
for (i = 0; i < RZ_BIN_SPECIAL_SYMBOL_LAST; i++) {
|
||||
for (ut32 i = 0; i < RZ_BIN_SPECIAL_SYMBOL_LAST; i++) {
|
||||
free(o->binsym[i]);
|
||||
}
|
||||
}
|
||||
|
||||
RZ_IPI void rz_bin_object_free(void /*RzBinObject*/ *o_) {
|
||||
RzBinObject *o = o_;
|
||||
if (o) {
|
||||
free(o->regstate);
|
||||
rz_bin_info_free(o->info);
|
||||
object_delete_items(o);
|
||||
free(o);
|
||||
}
|
||||
free(o);
|
||||
}
|
||||
|
||||
static char *swiftField(const char *dn, const char *cn) {
|
||||
|
|
@ -247,7 +240,6 @@ static RzList *classes_from_symbols(RzBinFile *bf) {
|
|||
RZ_IPI RzBinObject *rz_bin_object_new(RzBinFile *bf, RzBinPlugin *plugin, RzBinObjectLoadOptions *opts, ut64 offset, ut64 sz) {
|
||||
rz_return_val_if_fail(bf && plugin, NULL);
|
||||
ut64 bytes_sz = rz_buf_size(bf->buf);
|
||||
Sdb *sdb = bf->sdb;
|
||||
RzBinObject *o = RZ_NEW0(RzBinObject);
|
||||
if (!o) {
|
||||
return NULL;
|
||||
|
|
@ -261,7 +253,6 @@ RZ_IPI RzBinObject *rz_bin_object_new(RzBinFile *bf, RzBinPlugin *plugin, RzBinO
|
|||
o->boffset = offset;
|
||||
o->strings_db = ht_up_new0();
|
||||
o->regstate = NULL;
|
||||
o->kv = sdb_new0(); // XXX bf->sdb bf->o->sdb
|
||||
o->classes = rz_list_newf((RzListFree)rz_bin_class_free);
|
||||
o->classes_ht = ht_pp_new0();
|
||||
o->methods_ht = ht_pp_new0();
|
||||
|
|
@ -269,18 +260,16 @@ RZ_IPI RzBinObject *rz_bin_object_new(RzBinFile *bf, RzBinPlugin *plugin, RzBinO
|
|||
o->plugin = plugin;
|
||||
|
||||
if (plugin && plugin->load_buffer) {
|
||||
if (!plugin->load_buffer(bf, o, bf->buf, sdb)) {
|
||||
if (!plugin->load_buffer(bf, o, bf->buf, bf->sdb)) {
|
||||
if (bf->rbin->verbose) {
|
||||
RZ_LOG_ERROR("rz_bin_object_new: load_buffer failed for %s plugin\n", plugin->name);
|
||||
}
|
||||
sdb_free(o->kv);
|
||||
free(o);
|
||||
rz_bin_object_free(o);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
RZ_LOG_WARN("Plugin %s should implement load_buffer method.\n", plugin->name);
|
||||
sdb_free(o->kv);
|
||||
free(o);
|
||||
rz_bin_object_free(o);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -292,28 +281,19 @@ RZ_IPI RzBinObject *rz_bin_object_new(RzBinFile *bf, RzBinPlugin *plugin, RzBinO
|
|||
rz_bin_set_baddr(bf->rbin, o->opts.baseaddr);
|
||||
rz_bin_object_set_items(bf, o);
|
||||
|
||||
bf->sdb_info = o->kv;
|
||||
sdb = bf->rbin->sdb;
|
||||
if (sdb) {
|
||||
Sdb *bdb = bf->sdb; // sdb_new0 ();
|
||||
sdb_ns_set(bdb, "info", o->kv);
|
||||
o->kv = bdb;
|
||||
// bf->sdb = o->kv;
|
||||
// bf->sdb_info = o->kv;
|
||||
// sdb_ns_set (bf->sdb, "info", o->kv);
|
||||
// sdb_ns (sdb, sdb_fmt ("fd.%d", bf->fd), 1);
|
||||
sdb_set(bf->sdb, "archs", "0:0:x86:32", 0); // x86??
|
||||
/* NOTE */
|
||||
/* Those refs++ are necessary because sdb_ns() doesnt rerefs all
|
||||
* sub-namespaces */
|
||||
/* And if any namespace is referenced backwards it gets
|
||||
* double-freed */
|
||||
// bf->sdb_info = sdb_ns (bf->sdb, "info", 1);
|
||||
sdb_ns_set(sdb, "cur", bdb); // bf->sdb);
|
||||
const char *fdns = sdb_fmt("fd.%d", bf->fd);
|
||||
sdb_ns_set(sdb, fdns, bdb); // bf->sdb);
|
||||
bf->sdb->refs++;
|
||||
if (!bf->rbin->sdb) {
|
||||
return o;
|
||||
}
|
||||
|
||||
sdb_ns_set(bf->sdb, "info", o->kv);
|
||||
sdb_ns_set(bf->rbin->sdb, "cur", bf->sdb);
|
||||
char *fdns = rz_str_newf("fd.%d", bf->fd);
|
||||
if (fdns) {
|
||||
sdb_ns_set(bf->rbin->sdb, fdns, bf->sdb);
|
||||
free(fdns);
|
||||
}
|
||||
bf->sdb->refs++;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -657,12 +657,16 @@ bool rz_bin_ne_buf_init(RzBuffer *buf, rz_bin_ne_obj_t *bin) {
|
|||
}
|
||||
|
||||
void rz_bin_ne_free(rz_bin_ne_obj_t *bin) {
|
||||
if (!bin) {
|
||||
return;
|
||||
}
|
||||
// rz_list_free (bin->imports); // double free
|
||||
rz_list_free(bin->resources);
|
||||
free(bin->entry_table);
|
||||
free(bin->ne_header);
|
||||
free(bin->resident_name_table);
|
||||
free(bin->segment_entries);
|
||||
free(bin);
|
||||
}
|
||||
|
||||
rz_bin_ne_obj_t *rz_bin_ne_new_buf(RzBuffer *buf, bool verbose) {
|
||||
|
|
@ -671,7 +675,7 @@ rz_bin_ne_obj_t *rz_bin_ne_new_buf(RzBuffer *buf, bool verbose) {
|
|||
return NULL;
|
||||
}
|
||||
if (!rz_bin_ne_buf_init(buf, bin)) {
|
||||
free(bin);
|
||||
rz_bin_ne_free(bin);
|
||||
return NULL;
|
||||
}
|
||||
return bin;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include <rz_util.h>
|
||||
#include <rz_types.h>
|
||||
|
||||
RZ_IPI RzBinFile *rz_bin_file_new(RzBin *bin, const char *file, ut64 file_sz, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr);
|
||||
RZ_IPI RzBinFile *rz_bin_file_new(RzBin *bin, const char *file, ut64 file_sz, int fd, const char *xtrname, bool steal_ptr);
|
||||
RZ_IPI RzBinObject *rz_bin_file_object_find_by_id(RzBinFile *binfile, ut32 binobj_id);
|
||||
RZ_IPI RzBinFile *rz_bin_file_find_by_object_id(RzBin *bin, ut32 binobj_id);
|
||||
RZ_IPI RzBinFile *rz_bin_file_find_by_id(RzBin *bin, ut32 binfile_id);
|
||||
|
|
@ -23,7 +23,7 @@ RZ_IPI RzBinPlugin *rz_bin_get_binplugin_by_filename(RzBin *bin);
|
|||
|
||||
RZ_IPI void rz_bin_section_free(RzBinSection *bs);
|
||||
|
||||
RZ_IPI void rz_bin_object_free(void /*RzBinObject*/ *o_);
|
||||
RZ_IPI void rz_bin_object_free(RzBinObject *o);
|
||||
RZ_IPI ut64 rz_bin_object_get_baddr(RzBinObject *o);
|
||||
RZ_IPI void rz_bin_object_filter_strings(RzBinObject *bo);
|
||||
RZ_IPI RzBinObject *rz_bin_object_new(RzBinFile *binfile, RzBinPlugin *plugin, RzBinObjectLoadOptions *opts, ut64 offset, ut64 sz);
|
||||
|
|
|
|||
|
|
@ -113,7 +113,6 @@ RZ_API void rz_core_bin_export_info(RzCore *core, int mode) {
|
|||
return;
|
||||
}
|
||||
Sdb *db = sdb_ns(bf->sdb, "info", 0);
|
||||
;
|
||||
if (!db) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -3003,7 +3002,6 @@ RZ_API bool rz_core_bin_info_print(RzCore *core, RzBinFile *bf, RzCmdStateOutput
|
|||
PJ *pj = state->d.pj;
|
||||
RzTable *t = state->d.t;
|
||||
int i, j, u, v, uv;
|
||||
Sdb *sdb_info = sdb_ns(obj->kv, "info", false);
|
||||
|
||||
switch (state->mode) {
|
||||
case RZ_OUTPUT_MODE_QUIET:
|
||||
|
|
@ -3105,7 +3103,7 @@ RZ_API bool rz_core_bin_info_print(RzCore *core, RzBinFile *bf, RzCmdStateOutput
|
|||
pj_ki(pj, "pcalign", uv);
|
||||
}
|
||||
|
||||
tmp_buf = sdb_get(sdb_info, "elf.relro", 0);
|
||||
tmp_buf = sdb_get(obj->kv, "elf.relro", 0);
|
||||
if (tmp_buf) {
|
||||
pj_ks(pj, "relro", tmp_buf);
|
||||
free(tmp_buf);
|
||||
|
|
@ -3213,7 +3211,7 @@ RZ_API bool rz_core_bin_info_print(RzCore *core, RzBinFile *bf, RzCmdStateOutput
|
|||
rz_table_add_rowf(t, "sd", "pcalign", uv);
|
||||
}
|
||||
|
||||
tmp_buf = sdb_get(sdb_info, "elf.relro", 0);
|
||||
tmp_buf = sdb_get(obj->kv, "elf.relro", 0);
|
||||
if (tmp_buf) {
|
||||
rz_table_add_rowf(t, "ss", "relro", tmp_buf);
|
||||
free(tmp_buf);
|
||||
|
|
@ -4204,16 +4202,16 @@ static void bin_pe_versioninfo(RzCore *r, PJ *pj, int mode) {
|
|||
}
|
||||
|
||||
static void bin_elf_versioninfo_versym(RzCore *r, PJ *pj, int mode) {
|
||||
if (IS_MODE_JSON(mode)) {
|
||||
pj_o(pj);
|
||||
pj_ka(pj, "versym");
|
||||
}
|
||||
|
||||
Sdb *sdb = sdb_ns_path(r->sdb, "bin/cur/info/versioninfo/versym", 0);
|
||||
if (!sdb) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (IS_MODE_JSON(mode)) {
|
||||
pj_o(pj);
|
||||
pj_ka(pj, "versym");
|
||||
}
|
||||
|
||||
const ut64 addr = sdb_num_get(sdb, "addr", 0);
|
||||
const ut64 offset = sdb_num_get(sdb, "offset", 0);
|
||||
const ut64 num_entries = sdb_num_get(sdb, "num_entries", 0);
|
||||
|
|
@ -4257,16 +4255,16 @@ static void bin_elf_versioninfo_versym(RzCore *r, PJ *pj, int mode) {
|
|||
}
|
||||
|
||||
static void bin_elf_versioninfo_verneed(RzCore *r, PJ *pj, int mode) {
|
||||
if (IS_MODE_JSON(mode)) {
|
||||
pj_end(pj);
|
||||
pj_ka(pj, "verneed");
|
||||
}
|
||||
|
||||
Sdb *sdb = sdb_ns_path(r->sdb, "bin/cur/info/versioninfo/verneed", 0);
|
||||
if (!sdb) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (IS_MODE_JSON(mode)) {
|
||||
pj_end(pj);
|
||||
pj_ka(pj, "verneed");
|
||||
}
|
||||
|
||||
const ut64 address = sdb_num_get(sdb, "addr", 0);
|
||||
const ut64 offset = sdb_num_get(sdb, "offset", 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -637,7 +637,7 @@ RZ_IPI void rz_core_kuery_print(RzCore *core, const char *k) {
|
|||
}
|
||||
|
||||
RZ_IPI int rz_cmd_kuery(void *data, const char *input) {
|
||||
char buf[1024], *out;
|
||||
char buf[1024], *out, *tofree;
|
||||
RzCore *core = (RzCore *)data;
|
||||
const char *sp, *p = "[sdb]> ";
|
||||
Sdb *s = core->sdb;
|
||||
|
|
@ -646,9 +646,8 @@ RZ_IPI int rz_cmd_kuery(void *data, const char *input) {
|
|||
char *temp_pos = NULL, *temp_cmd = NULL;
|
||||
|
||||
switch (input[0]) {
|
||||
|
||||
case 'j':
|
||||
out = sdb_querys(s, NULL, 0, "analysis/**");
|
||||
tofree = out = sdb_querys(s, NULL, 0, "analysis/**");
|
||||
if (!out) {
|
||||
rz_cons_println("No Output from sdb");
|
||||
break;
|
||||
|
|
@ -687,6 +686,7 @@ RZ_IPI int rz_cmd_kuery(void *data, const char *input) {
|
|||
}
|
||||
temp_cmd = rz_str_ndup(temp, temp_pos - temp);
|
||||
pj_s(pj, temp_cmd);
|
||||
free(temp_cmd);
|
||||
temp = temp_pos + 1;
|
||||
}
|
||||
out = cur_pos + 1;
|
||||
|
|
@ -700,6 +700,7 @@ RZ_IPI int rz_cmd_kuery(void *data, const char *input) {
|
|||
RZ_FREE(next_cmd);
|
||||
free(next_cmd);
|
||||
free(cur_cmd);
|
||||
free(tofree);
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
|
|
|
|||
|
|
@ -2657,68 +2657,59 @@ RZ_API void rz_core_fini(RzCore *c) {
|
|||
rz_core_task_break_all(&c->tasks);
|
||||
rz_core_task_join(&c->tasks, NULL, -1);
|
||||
rz_core_wait(c);
|
||||
/* TODO: it leaks badly */
|
||||
// update_sdb (c);
|
||||
// avoid double free
|
||||
rz_list_free(c->ropchain);
|
||||
rz_event_free(c->ev);
|
||||
free(c->cmdlog);
|
||||
free(c->lastsearch);
|
||||
RZ_FREE_CUSTOM(c->ropchain, rz_list_free);
|
||||
RZ_FREE_CUSTOM(c->ev, rz_event_free);
|
||||
RZ_FREE(c->cmdlog);
|
||||
RZ_FREE(c->lastsearch);
|
||||
RZ_FREE(c->cons->pager);
|
||||
free(c->cmdqueue);
|
||||
free(c->lastcmd);
|
||||
free(c->stkcmd);
|
||||
rz_list_free(c->visual.tabs);
|
||||
free(c->block);
|
||||
rz_core_autocomplete_free(c->autocomplete);
|
||||
RZ_FREE(c->cmdqueue);
|
||||
RZ_FREE(c->lastcmd);
|
||||
RZ_FREE(c->stkcmd);
|
||||
RZ_FREE_CUSTOM(c->visual.tabs, rz_list_free);
|
||||
RZ_FREE(c->block);
|
||||
RZ_FREE_CUSTOM(c->autocomplete, rz_core_autocomplete_free);
|
||||
|
||||
rz_list_free(c->gadgets);
|
||||
rz_num_free(c->num);
|
||||
// TODO: sync or not? sdb_sync (c->sdb);
|
||||
// TODO: sync all dbs?
|
||||
// rz_core_file_free (c->file);
|
||||
// c->file = NULL;
|
||||
RZ_FREE_CUSTOM(c->gadgets, rz_list_free);
|
||||
RZ_FREE_CUSTOM(c->num, rz_num_free);
|
||||
RZ_FREE(c->table_query);
|
||||
rz_io_free(c->io);
|
||||
rz_list_free(c->files);
|
||||
rz_list_free(c->watchers);
|
||||
rz_list_free(c->scriptstack);
|
||||
RZ_FREE_CUSTOM(c->io, rz_io_free);
|
||||
RZ_FREE_CUSTOM(c->files, rz_list_free);
|
||||
RZ_FREE_CUSTOM(c->watchers, rz_list_free);
|
||||
RZ_FREE_CUSTOM(c->scriptstack, rz_list_free);
|
||||
rz_core_task_scheduler_fini(&c->tasks);
|
||||
c->rcmd = rz_cmd_free(c->rcmd);
|
||||
rz_list_free(c->cmd_descriptors);
|
||||
c->analysis = rz_analysis_free(c->analysis);
|
||||
rz_asm_free(c->rasm);
|
||||
c->rasm = NULL;
|
||||
c->print = rz_print_free(c->print);
|
||||
c->bin = (rz_bin_free(c->bin), NULL);
|
||||
c->lang = (rz_lang_free(c->lang), NULL);
|
||||
c->dbg = (rz_debug_free(c->dbg), NULL);
|
||||
rz_config_free(c->config);
|
||||
RZ_FREE_CUSTOM(c->rcmd, rz_cmd_free);
|
||||
RZ_FREE_CUSTOM(c->cmd_descriptors, rz_list_free);
|
||||
RZ_FREE_CUSTOM(c->analysis, rz_analysis_free);
|
||||
RZ_FREE_CUSTOM(c->rasm, rz_asm_free);
|
||||
RZ_FREE_CUSTOM(c->print, rz_print_free);
|
||||
RZ_FREE_CUSTOM(c->bin, rz_bin_free);
|
||||
RZ_FREE_CUSTOM(c->lang, rz_lang_free);
|
||||
RZ_FREE_CUSTOM(c->dbg, rz_debug_free);
|
||||
RZ_FREE_CUSTOM(c->config, rz_config_free);
|
||||
/* after rz_config_free, the value of I.teefile is trashed */
|
||||
/* rconfig doesnt knows how to deinitialize vars, so we
|
||||
should probably need to add a rz_config_free_payload callback */
|
||||
rz_cons_free();
|
||||
rz_cons_singleton()->teefile = NULL; // HACK
|
||||
rz_search_free(c->search);
|
||||
rz_flag_free(c->flags);
|
||||
rz_egg_free(c->egg);
|
||||
rz_lib_free(c->lib);
|
||||
rz_buf_free(c->yank_buf);
|
||||
rz_agraph_free(c->graph);
|
||||
free(c->asmqjmps);
|
||||
sdb_free(c->sdb);
|
||||
rz_parse_free(c->parser);
|
||||
free(c->times);
|
||||
RZ_FREE_CUSTOM(c->search, rz_search_free);
|
||||
RZ_FREE_CUSTOM(c->flags, rz_flag_free);
|
||||
RZ_FREE_CUSTOM(c->egg, rz_egg_free);
|
||||
RZ_FREE_CUSTOM(c->lib, rz_lib_free);
|
||||
RZ_FREE_CUSTOM(c->yank_buf, rz_buf_free);
|
||||
RZ_FREE_CUSTOM(c->graph, rz_agraph_free);
|
||||
RZ_FREE(c->asmqjmps);
|
||||
RZ_FREE_CUSTOM(c->sdb, sdb_free);
|
||||
RZ_FREE_CUSTOM(c->parser, rz_parse_free);
|
||||
RZ_FREE(c->times);
|
||||
rz_core_seek_free(c);
|
||||
free(c->rtr_host);
|
||||
RZ_FREE(c->rtr_host);
|
||||
RZ_FREE(c->curtheme);
|
||||
}
|
||||
|
||||
RZ_API void rz_core_free(RzCore *c) {
|
||||
if (c) {
|
||||
rz_core_fini(c);
|
||||
free(c);
|
||||
}
|
||||
rz_core_fini(c);
|
||||
free(c);
|
||||
}
|
||||
|
||||
RZ_API void rz_core_prompt_loop(RzCore *r) {
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ typedef struct rz_bin_object_t {
|
|||
RzBinAddr *binsym[RZ_BIN_SPECIAL_SYMBOL_LAST];
|
||||
struct rz_bin_plugin_t *plugin;
|
||||
RzBinLanguage lang;
|
||||
RZ_DEPRECATE Sdb *kv; ///< deprecated, put info in C structures instead of this
|
||||
RZ_DEPRECATE RZ_BORROW Sdb *kv; ///< deprecated, put info in C structures instead of this (holds a copy of another pointer.)
|
||||
HtUP *addrzklassmethod;
|
||||
void *bin_obj; // internal pointer used by formats
|
||||
} RzBinObject;
|
||||
|
|
@ -328,7 +328,6 @@ struct rz_bin_file_t {
|
|||
// struct rz_bin_plugin_t *curplugin; // use o->plugin
|
||||
RzList *xtr_data;
|
||||
RZ_DEPRECATE Sdb *sdb; ///< deprecated, put info in C structures instead of this
|
||||
RZ_DEPRECATE Sdb *sdb_info; ///< deprecated, put info in C structures instead of this
|
||||
struct rz_bin_t *rbin;
|
||||
}; // RzBinFile
|
||||
|
||||
|
|
|
|||
|
|
@ -357,6 +357,12 @@ static inline void *rz_new_copy(int size, void *data) {
|
|||
x = NULL; \
|
||||
}
|
||||
|
||||
#define RZ_FREE_CUSTOM(x, y) \
|
||||
{ \
|
||||
y(x); \
|
||||
x = NULL; \
|
||||
}
|
||||
|
||||
#if __WINDOWS__
|
||||
#define PFMT64x "I64x"
|
||||
#define PFMT64d "I64d"
|
||||
|
|
|
|||
|
|
@ -1546,7 +1546,7 @@ RZ_API int rz_type_format_struct_size(const RzTypeDB *typedb, const char *f, int
|
|||
if (fmt[0] == '{') {
|
||||
char *end = strchr(fmt + 1, '}');
|
||||
if (!end) {
|
||||
eprintf("No end curly bracket.\n");
|
||||
RZ_LOG_ERROR("No end curly bracket.\n");
|
||||
free(o);
|
||||
free(args);
|
||||
return -1;
|
||||
|
|
@ -1568,7 +1568,7 @@ RZ_API int rz_type_format_struct_size(const RzTypeDB *typedb, const char *f, int
|
|||
if (fmt[i] == '[') {
|
||||
char *end = strchr(fmt + i, ']');
|
||||
if (!end) {
|
||||
eprintf("No end bracket.\n");
|
||||
RZ_LOG_ERROR("No end bracket.\n");
|
||||
continue;
|
||||
}
|
||||
*end = '\0';
|
||||
|
|
@ -1627,7 +1627,7 @@ RZ_API int rz_type_format_struct_size(const RzTypeDB *typedb, const char *f, int
|
|||
case 'E':
|
||||
if (tabsize_set) {
|
||||
if (tabsize < 1 || tabsize > 8) {
|
||||
eprintf("Unknown enum format size: %d\n", tabsize);
|
||||
RZ_LOG_ERROR("Unknown enum format size: %d\n", tabsize);
|
||||
break;
|
||||
}
|
||||
size += tabsize;
|
||||
|
|
@ -1641,7 +1641,7 @@ RZ_API int rz_type_format_struct_size(const RzTypeDB *typedb, const char *f, int
|
|||
char *endname = NULL, *structname = NULL;
|
||||
char tmp = 0;
|
||||
if (words < idx) {
|
||||
eprintf("Index out of bounds\n");
|
||||
RZ_LOG_ERROR("Index out of bounds\n");
|
||||
} else {
|
||||
wordAtIndex = rz_str_word_get0(args, idx);
|
||||
}
|
||||
|
|
@ -1677,14 +1677,14 @@ RZ_API int rz_type_format_struct_size(const RzTypeDB *typedb, const char *f, int
|
|||
}
|
||||
}
|
||||
if (!format) {
|
||||
eprintf("Cannot find format for struct `%s'\n", structname + 1);
|
||||
RZ_LOG_ERROR("Cannot find format for struct `%s'\n", structname + 1);
|
||||
free(structname);
|
||||
free(o);
|
||||
return 0;
|
||||
}
|
||||
int newsize = rz_type_format_struct_size(typedb, format, mode, n + 1);
|
||||
if (newsize < 1) {
|
||||
eprintf("Cannot find size for `%s'\n", format);
|
||||
RZ_LOG_ERROR("Cannot find size for `%s'\n", format);
|
||||
free(structname);
|
||||
free(o);
|
||||
return 0;
|
||||
|
|
@ -1740,7 +1740,7 @@ RZ_API int rz_type_format_struct_size(const RzTypeDB *typedb, const char *f, int
|
|||
} else if (fmt[i + 1] == '8') {
|
||||
size += tabsize * 8;
|
||||
} else {
|
||||
eprintf("Invalid n format in (%s)\n", fmt);
|
||||
RZ_LOG_ERROR("Invalid '%c' format in (%s)\n", fmt[i + 1], fmt);
|
||||
free(o);
|
||||
free(args);
|
||||
return -2;
|
||||
|
|
|
|||
|
|
@ -4515,7 +4515,7 @@ RUN
|
|||
|
||||
NAME=ik-relro
|
||||
FILE=bins/elf/analysis/x86-helloworld-gcc
|
||||
CMDS=ik info/elf.relro
|
||||
CMDS=ik elf.relro
|
||||
EXPECT=<<EOF
|
||||
no
|
||||
EOF
|
||||
|
|
@ -4525,7 +4525,7 @@ NAME=ibk use after free
|
|||
FILE=bins/elf/analysis/x86-helloworld-gcc
|
||||
CMDS=<<EOF
|
||||
obR
|
||||
ik info/*~?elf.relro
|
||||
ik *~?elf.relro
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
1
|
||||
|
|
@ -5069,7 +5069,7 @@ RUN
|
|||
|
||||
NAME=ik-macho
|
||||
FILE=bins/mach0/fatmach0-3true
|
||||
CMDS=ik info/mach0.entry.vaddr~?0x100000ef8
|
||||
CMDS=ik mach0.entry.vaddr~?0x100000ef8
|
||||
EXPECT=<<EOF
|
||||
1
|
||||
EOF
|
||||
|
|
@ -5077,7 +5077,7 @@ RUN
|
|||
|
||||
NAME=ikv
|
||||
FILE=bins/mach0/fatmach0-3true
|
||||
CMDS=ikv info/mach0.entry.vaddr
|
||||
CMDS=ikv mach0.entry.vaddr
|
||||
EXPECT=<<EOF
|
||||
0x100000ef8
|
||||
EOF
|
||||
|
|
@ -5085,7 +5085,7 @@ RUN
|
|||
|
||||
NAME=ik.
|
||||
FILE=bins/mach0/fatmach0-3true
|
||||
CMDS=ik. info/mach0.entry.vaddr
|
||||
CMDS=ik. mach0.entry.vaddr
|
||||
EXPECT=<<EOF
|
||||
0x100000ef8
|
||||
EOF
|
||||
|
|
|
|||
|
|
@ -67,20 +67,20 @@ RUN
|
|||
|
||||
NAME=ELF: corkami elf-relro - relro enabled
|
||||
FILE=bins/elf/analysis/elf-relro
|
||||
CMDS=ik ***~relro
|
||||
CMDS=ik ~relro
|
||||
EXPECT=<<EOF
|
||||
info/elf.relro=partial
|
||||
elf.relro=partial
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=ELF: imports partial
|
||||
FILE=bins/elf/vim
|
||||
CMDS=<<EOF
|
||||
ik ***~relro
|
||||
ik ~relro
|
||||
ii
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
info/elf.relro=full
|
||||
elf.relro=full
|
||||
nth vaddr bind type lib name
|
||||
-------------------------------------------------------------
|
||||
2 0x00051f60 GLOBAL FUNC __ctype_toupper_loc
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
NAME=PE: corkami elf-xnorelro - relro disabled
|
||||
FILE=bins/elf/analysis/elf-xnorelro
|
||||
CMDS=ik info/*~relro
|
||||
CMDS=ik ~relro
|
||||
EXPECT=<<EOF
|
||||
elf.relro=no
|
||||
EOF
|
||||
|
|
|
|||
|
|
@ -263,12 +263,12 @@ RUN
|
|||
|
||||
NAME=osx mach0 ik
|
||||
FILE=bins/mach0/ls-osx-x86_64
|
||||
CMDS=ik ***~uuid
|
||||
CMDS=ik~uuid
|
||||
EXPECT=<<EOF
|
||||
info/mach0_uuid_command.format=[4]Ed[16]b (mach0_load_command_type)cmd cmdsize uuid
|
||||
info/mach0_cmd_8.format=mach0_uuid_command
|
||||
info/uuid.0=ff4d6c2e1dc0369d98d0d3040a8049e8
|
||||
info/mach0_cmd_8.cmd=uuid
|
||||
mach0_cmd_8.cmd=uuid
|
||||
mach0_cmd_8.format=mach0_uuid_command
|
||||
mach0_uuid_command.format=[4]Ed[16]b (mach0_load_command_type)cmd cmdsize uuid
|
||||
uuid.0=ff4d6c2e1dc0369d98d0d3040a8049e8
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue