Random code cleanup in RCore

This commit is contained in:
pancake 2021-10-28 12:19:02 +02:00 committed by GitHub
parent ce75aeb287
commit c90696c089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 51 deletions

View File

@ -372,7 +372,9 @@ static void _print_strings(RCore *r, RList *list, PJ *pj, int mode, int va) {
int minstr = r_config_get_i (r->config, "bin.minstr");
int maxstr = r_config_get_i (r->config, "bin.maxstr");
RTable *table = r_core_table (r, "strings");
r_return_if_fail (table);
if (!table) {
return;
}
RBin *bin = r->bin;
RBinObject *obj = r_bin_cur_object (bin);
RListIter *iter;
@ -4074,7 +4076,7 @@ static void bin_no_resources(RCore *r, PJ *pj, int mode) {
}
}
static int bin_resources(RCore *r, PJ *pj, int mode) {
static bool bin_resources(RCore *r, PJ *pj, int mode) {
const RBinInfo *info = r_bin_get_info (r->bin);
if (!info || !info->rclass) {
if (IS_MODE_JSON (mode)) {
@ -4091,7 +4093,7 @@ static int bin_resources(RCore *r, PJ *pj, int mode) {
return true;
}
static int bin_versioninfo(RCore *r, PJ *pj, int mode) {
static bool bin_versioninfo(RCore *r, PJ *pj, int mode) {
const RBinInfo *info = r_bin_get_info (r->bin);
if (!info || !info->rclass) {
if (IS_MODE_JSON (mode)) {
@ -4117,7 +4119,7 @@ static int bin_versioninfo(RCore *r, PJ *pj, int mode) {
return true;
}
static int bin_signature(RCore *r, PJ *pj, int mode) {
static bool bin_signature(RCore *r, PJ *pj, int mode) {
RBinFile *cur = r_bin_cur (r->bin);
RBinPlugin *plg = r_bin_file_cur_plugin (cur);
if (plg && plg->signature) {
@ -4141,7 +4143,7 @@ static int bin_signature(RCore *r, PJ *pj, int mode) {
return false;
}
static int bin_header(RCore *r, int mode) {
static bool bin_header(RCore *r, int mode) {
RBinFile *cur = r_bin_cur (r->bin);
RBinPlugin *plg = r_bin_file_cur_plugin (cur);
if (plg && plg->header) {
@ -4151,8 +4153,8 @@ static int bin_header(RCore *r, int mode) {
return false;
}
R_API int r_core_bin_info(RCore *core, int action, PJ *pj, int mode, int va, RCoreBinFilter *filter, const char *chksum) {
int ret = true;
R_API bool r_core_bin_info(RCore *core, int action, PJ *pj, int mode, int va, RCoreBinFilter *filter, const char *chksum) {
bool ret = true;
const char *name = NULL;
ut64 at = UT64_MAX, loadaddr = r_bin_get_laddr (core->bin);
if (filter && filter->offset) {
@ -4261,7 +4263,7 @@ R_API int r_core_bin_info(RCore *core, int action, PJ *pj, int mode, int va, RCo
return ret;
}
R_API int r_core_bin_set_arch_bits(RCore *r, const char *name, const char * arch, ut16 bits) {
R_API bool r_core_bin_set_arch_bits(RCore *r, const char *name, const char * arch, ut16 bits) {
int fd = r_io_fd_get_current (r->io);
RIODesc *desc = r_io_desc_get (r->io, fd);
RBinFile *curfile, *binfile = NULL;
@ -4292,7 +4294,7 @@ R_API int r_core_bin_set_arch_bits(RCore *r, const char *name, const char * arch
return true;
}
R_API int r_core_bin_update_arch_bits(RCore *r) {
R_API bool r_core_bin_update_arch_bits(RCore *r) {
RBinFile *binfile = NULL;
const char *name = NULL, *arch = NULL;
ut16 bits = 0;
@ -4489,3 +4491,18 @@ padding:
out:
return r_strbuf_drain (buf);
}
R_API int r_core_bin_rebase(RCore *core, ut64 baddr) {
if (!core || !core->bin || !core->bin->cur) {
return 0;
}
if (baddr == UT64_MAX) {
return 0;
}
RBinFile *bf = core->bin->cur;
bf->o->baddr = baddr;
bf->o->loadaddr = baddr;
r_bin_object_set_items (bf, bf->o);
return 1;
}

View File

@ -485,16 +485,14 @@ static bool try_loadlib(RCore *core, const char *lib, ut64 addr) {
R_API bool r_core_file_loadlib(RCore *core, const char *lib, ut64 libaddr) {
const char *dirlibs = r_config_get (core->config, "dir.libs");
bool free_libdir = true;
#ifdef __WINDOWS__
char *libdir = r_str_r2_prefix (R2_LIBDIR);
if (!libdir) {
libdir = strdup (R2_LIBDIR);
}
#else
char *libdir = strdup (R2_LIBDIR);
#endif
if (!libdir) {
libdir = R2_LIBDIR;
free_libdir = false;
}
if (!dirlibs || !*dirlibs) {
dirlibs = "." R_SYS_DIR;
}
@ -533,28 +531,11 @@ R_API bool r_core_file_loadlib(RCore *core, const char *lib, ut64 libaddr) {
libpath++;
}
}
if (free_libdir) {
free (libdir);
}
free (libdir);
return ret;
}
R_API int r_core_bin_rebase(RCore *core, ut64 baddr) {
if (!core || !core->bin || !core->bin->cur) {
return 0;
}
if (baddr == UT64_MAX) {
return 0;
}
RBinFile *bf = core->bin->cur;
bf->o->baddr = baddr;
bf->o->loadaddr = baddr;
r_bin_object_set_items (bf, bf->o);
return 1;
}
static void load_scripts_for(RCore *core, const char *name) {
// TODO:
char *file;
RListIter *iter;
char *hdir = r_str_newf (R_JOIN_2_PATHS (R2_HOME_BINRC, "bin-%s"), name);

View File

@ -552,7 +552,7 @@ static const RList *symbols_of(RCore *core, int id0) {
RBinFile *bf = r_bin_file_find_by_id (core->bin, id0);
RBinFile *old_bf = core->bin->cur;
r_bin_file_set_cur_binfile (core->bin, bf);
const RList *list = bf? r_bin_get_symbols (core->bin): r_list_newf (NULL);
const RList *list = bf? r_bin_get_symbols (core->bin): NULL;
r_bin_file_set_cur_binfile (core->bin, old_bf);
return list;
}
@ -682,8 +682,6 @@ static void _core_cmp_info_symbols(RCore *core, int id0, int id1) {
r_cons_printf ("+%s\n", s->name);
}
}
// r_list_free (s0);
// r_list_free (s1);
}
static void _core_cmp_info(RCore *core, const char *input) {

View File

@ -1828,6 +1828,10 @@ static bool find_autocomplete(RCore *core, RLineCompletion *completion, RLineBuf
}
R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completion, RLineBuffer *buf, RLinePromptType prompt_type) {
if (!core) {
autocomplete_default (core, completion, buf);
return;
}
if (r_config_get_b (core->config, "scr.prompt.tabhelp")) {
if (buf->data[0] && buf->data[strlen (buf->data) - 1] != ' ' && !strchr (buf->data, ' ')) {
r_line_completion_clear (completion);
@ -1837,10 +1841,6 @@ R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completi
return;
}
}
if (!core) {
autocomplete_default (core, completion, buf);
return;
}
r_line_completion_clear (completion);
char *pipe = strchr (buf->data, '>');
char *ptr = strchr (buf->data, '@');

View File

@ -1129,6 +1129,7 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) {
char *input = strdup (ds->opstr? ds->opstr: ds->str);
r_parse_filter (core->parser, ds->vat, core->flags, ds->hint, input, // asm_str,
ds->str, sizeof (ds->str), core->print->big_endian);
free (input);
//ds->opstr = strdup (ds->str);
} else {
if (ds->opstr) {
@ -6493,6 +6494,10 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo
RDisasmState *ds = ds_init (core);
if (l > core->blocksize || addr != core->offset) {
buf = malloc (l + 1);
if (!buf) {
ds_free (ds);
return 0;
}
r_io_read_at (core->io, addr, buf, l);
}
PJ *pj = NULL;

View File

@ -2,11 +2,10 @@
#include <r_core.h>
R_API int r_core_patch_line(RCore *core, char *str) {
char *p, *q;
p = strchr (str + 1, ' ');
R_API bool r_core_patch_line(RCore *core, char *str) {
char *q, *p = strchr (str + 1, ' ');
if (!p) {
return 0;
return false;
}
*p = 0;
for (++p; *p == ' '; p++) {
@ -44,20 +43,20 @@ R_API int r_core_patch_line(RCore *core, char *str) {
r_core_cmdf (core, "wx %s", p);
break;
}
return 1;
return true;
}
static int __core_patch_bracket(RCore *core, const char *str, ut64 *noff) {
static bool __core_patch_bracket(RCore *core, const char *str, ut64 *noff) {
char tmp[128];
char *s, *p, *q, *off;
RBuffer *b = r_buf_new ();
if (!b) {
return 0;
return false;
}
p = off = strdup (str);
if (!p) {
r_buf_free (b);
return 0;
return false;
}
for (;*p;) {
if (*p == '\n') {
@ -103,7 +102,7 @@ static int __core_patch_bracket(RCore *core, const char *str, ut64 *noff) {
r_core_write_at (core, *noff, tmpbuf, tmpsz);
*noff += r_buf_size (b);
free (off);
return 1;
return true;
}
R_API int r_core_patch(RCore *core, const char *patch) {

View File

@ -762,9 +762,9 @@ typedef struct r_core_bin_filter_t {
const char *name;
} RCoreBinFilter;
R_API int r_core_bin_info (RCore *core, int action, PJ *pj, int mode, int va, RCoreBinFilter *filter, const char *chksum);
R_API int r_core_bin_set_arch_bits (RCore *r, const char *name, const char * arch, ut16 bits);
R_API int r_core_bin_update_arch_bits (RCore *r);
R_API bool r_core_bin_info(RCore *core, int action, PJ *pj, int mode, int va, RCoreBinFilter *filter, const char *chksum);
R_API bool r_core_bin_set_arch_bits(RCore *r, const char *name, const char * arch, ut16 bits);
R_API bool r_core_bin_update_arch_bits(RCore *r);
R_API char *r_core_bin_method_flags_str(ut64 flags, int mode);
R_API bool r_core_pdb_info(RCore *core, const char *file, PJ *pj, int mode);