Some random cleanups in RUtil (#16457)
This commit is contained in:
parent
6d633a96a9
commit
ab05f06287
17 changed files with 129 additions and 201 deletions
|
|
@ -60,7 +60,7 @@ R_API RGraphNode *r_graph_nth_neighbour(const RGraph *g, const RGraphNode *n, in
|
|||
R_API const RList *r_graph_innodes(const RGraph *g, const RGraphNode *n);
|
||||
R_API const RList *r_graph_all_neighbours(const RGraph *g, const RGraphNode *n);
|
||||
R_API const RList *r_graph_get_nodes(const RGraph *g);
|
||||
R_API int r_graph_adjacent(const RGraph *g, const RGraphNode *from, const RGraphNode *to);
|
||||
R_API bool r_graph_adjacent(const RGraph *g, const RGraphNode *from, const RGraphNode *to);
|
||||
R_API void r_graph_dfs_node(RGraph *g, RGraphNode *n, RGraphVisitor *vis);
|
||||
R_API void r_graph_dfs_node_reverse(RGraph *g, RGraphNode *n, RGraphVisitor *vis);
|
||||
R_API void r_graph_dfs(RGraph *g, RGraphVisitor *vis);
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
R_API int r_name_check(const char *name);
|
||||
R_API int r_name_filter(char *name, int len);
|
||||
R_API bool r_name_check(const char *name);
|
||||
R_API bool r_name_filter(char *name, int len);
|
||||
R_API char *r_name_filter2(const char *name);
|
||||
R_API int r_name_validate_char(const char ch);
|
||||
R_API bool r_name_validate_char(const char ch);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ R_API RStack *r_stack_new(ut32 n);
|
|||
R_API void r_stack_free(RStack *s);
|
||||
R_API bool r_stack_is_empty(RStack *s);
|
||||
R_API RStack *r_stack_newf(ut32 n, RStackFree f);
|
||||
R_API int r_stack_push(RStack *s, void *el);
|
||||
R_API bool r_stack_push(RStack *s, void *el);
|
||||
R_API void *r_stack_pop(RStack *s);
|
||||
R_API unsigned int r_stack_size(RStack *s);
|
||||
R_API size_t r_stack_size(RStack *s);
|
||||
R_API void *r_stack_peek(RStack *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -620,7 +620,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) {
|
|||
len = r_num_math (NULL, opt.arg);
|
||||
break;
|
||||
case 'L':
|
||||
rasm2_list (as, argv[opt.ind]);
|
||||
rasm2_list (as, opt.argv[opt.ind]);
|
||||
ret = 1;
|
||||
goto beach;
|
||||
case '@':
|
||||
|
|
@ -714,7 +714,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) {
|
|||
r_anal_set_big_endian (as->anal, canbebig);
|
||||
}
|
||||
if (whatsop) {
|
||||
const char *s = r_asm_describe (as->a, argv[opt.ind]);
|
||||
const char *s = r_asm_describe (as->a, opt.argv[opt.ind]);
|
||||
ret = 1;
|
||||
if (s) {
|
||||
printf ("%s\n", s);
|
||||
|
|
@ -803,8 +803,8 @@ R_API int r_main_rasm2(int argc, const char *argv[]) {
|
|||
ret = 1;
|
||||
}
|
||||
}
|
||||
} else if (argv[opt.ind]) {
|
||||
if (!strcmp (argv[opt.ind], "-")) {
|
||||
} else if (opt.argv[opt.ind]) {
|
||||
if (!strcmp (opt.argv[opt.ind], "-")) {
|
||||
int length;
|
||||
do {
|
||||
char buf[1024]; // TODO: use(implement) r_stdin_line() or so
|
||||
|
|
@ -848,7 +848,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) {
|
|||
goto beach;
|
||||
}
|
||||
if (dis) {
|
||||
char *usrstr = strdup (argv[opt.ind]);
|
||||
char *usrstr = strdup (opt.argv[opt.ind]);
|
||||
len = strlen (usrstr);
|
||||
if (skip && len > skip) {
|
||||
skip *= 2;
|
||||
|
|
@ -871,9 +871,9 @@ R_API int r_main_rasm2(int argc, const char *argv[]) {
|
|||
as->a->bits, ascii, bin, dis - 1);
|
||||
free (usrstr);
|
||||
} else if (analinfo) {
|
||||
ret = show_analinfo (as, (const char *)argv[opt.ind], offset);
|
||||
ret = show_analinfo (as, (const char *)opt.argv[opt.ind], offset);
|
||||
} else {
|
||||
ret = print_assembly_output (as, argv[opt.ind], offset, len, as->a->bits,
|
||||
ret = print_assembly_output (as, opt.argv[opt.ind], offset, len, as->a->bits,
|
||||
bin, use_spp, rad, hexwords, arch);
|
||||
}
|
||||
if (!ret) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
/* radare - LGPL - Copyright 2011-2012 - pancake */
|
||||
/* radare - LGPL - Copyright 2017-2020 - pancake, crowell */
|
||||
|
||||
#include <r_util.h>
|
||||
|
||||
#define BITMAP_TEST 0
|
||||
|
|
@ -53,49 +54,3 @@ R_API int r_bitmap_test(RBitmap *b, size_t bit) {
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if BITMAP_TEST
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_VALUE (2343 + 1)
|
||||
static const uint32_t test_values[] = { 1,2,3,4,8,34,543,2343 };
|
||||
#define test_values_len (sizeof(test_values)/sizeof(uint32_t))
|
||||
|
||||
static void set_values(Bitmap *bitmap, const uint32_t *values, int len) {
|
||||
int i;
|
||||
for(i=0; i < len; i++) {
|
||||
r_bitmap_set (bitmap, values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void unset_values(Bitmap *bitmap, const uint32_t *values, int len) {
|
||||
int i;
|
||||
for(i=0; i < len; i++) {
|
||||
r_bitmap_unset(bitmap, values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void check_values(Bitmap *bitmap, const uint32_t *values, int len, bool is_set) {
|
||||
int i;
|
||||
for(i = 0; i < len; i++) {
|
||||
if (r_bitmap_test(bitmap, values[i]) != is_set) {
|
||||
eprintf ("Value not set\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Bitmap *bitmap = bitmap_new(MAX_VALUE);
|
||||
|
||||
set_values(bitmap, test_values, test_values_len);
|
||||
|
||||
check_values(bitmap, test_values, test_values_len, true);
|
||||
|
||||
unset_values(bitmap, test_values, test_values_len);
|
||||
|
||||
check_values(bitmap, test_values, test_values_len, false);
|
||||
bitmap_free(bitmap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ R_API void **r_flist_new(int n) {
|
|||
return NULL;
|
||||
}
|
||||
*it = it;
|
||||
memset (++it, 0, (n+1) * sizeof (void*));
|
||||
memset (++it, 0, (n + 1) * sizeof (void*));
|
||||
return it;
|
||||
}
|
||||
|
||||
|
|
@ -69,8 +69,9 @@ R_API void r_flist_delete(void **it, int idx) {
|
|||
|
||||
R_API void r_flist_free(void **it) {
|
||||
void *pos;
|
||||
r_flist_foreach (it, pos)
|
||||
r_flist_foreach (it, pos) {
|
||||
free (pos);
|
||||
}
|
||||
r_flist_rewind (it);
|
||||
free (--it);
|
||||
}
|
||||
|
|
@ -78,7 +79,8 @@ R_API void r_flist_free(void **it) {
|
|||
R_API int r_flist_length (void **it) {
|
||||
void *pos;
|
||||
int len = 0;
|
||||
r_flist_foreach (it, pos)
|
||||
r_flist_foreach (it, pos) {
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ static void dfs_node (RGraph *g, RGraphNode *n, RGraphVisitor *vis, int color[],
|
|||
r_stack_free (s);
|
||||
}
|
||||
|
||||
R_API RGraph *r_graph_new () {
|
||||
R_API RGraph *r_graph_new() {
|
||||
RGraph *t = R_NEW0 (RGraph);
|
||||
if (!t) {
|
||||
return NULL;
|
||||
|
|
@ -119,12 +119,12 @@ R_API RGraph *r_graph_new () {
|
|||
return t;
|
||||
}
|
||||
|
||||
R_API void r_graph_free (RGraph* t) {
|
||||
R_API void r_graph_free(RGraph* t) {
|
||||
r_list_free (t->nodes);
|
||||
free (t);
|
||||
}
|
||||
|
||||
R_API RGraphNode *r_graph_get_node (const RGraph *t, unsigned int idx) {
|
||||
R_API RGraphNode *r_graph_get_node(const RGraph *t, unsigned int idx) {
|
||||
RListIter *it = r_list_find (t->nodes, (void *)(size_t)idx, (RListComparator)node_cmp);
|
||||
if (!it) {
|
||||
return NULL;
|
||||
|
|
@ -132,7 +132,7 @@ R_API RGraphNode *r_graph_get_node (const RGraph *t, unsigned int idx) {
|
|||
return (RGraphNode *)it->data;
|
||||
}
|
||||
|
||||
R_API RListIter *r_graph_node_iter (const RGraph *t, unsigned int idx) {
|
||||
R_API RListIter *r_graph_node_iter(const RGraph *t, unsigned int idx) {
|
||||
return r_list_find (t->nodes, (void *)(size_t)idx, (RListComparator)node_cmp);
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +148,7 @@ R_API void r_graph_reset (RGraph *t) {
|
|||
t->last_index = 0;
|
||||
}
|
||||
|
||||
R_API RGraphNode *r_graph_add_node (RGraph *t, void *data) {
|
||||
R_API RGraphNode *r_graph_add_node(RGraph *t, void *data) {
|
||||
if (!t) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ R_API void r_graph_del_node(RGraph *t, RGraphNode *n) {
|
|||
t->n_nodes--;
|
||||
}
|
||||
|
||||
R_API void r_graph_add_edge (RGraph *t, RGraphNode *from, RGraphNode *to) {
|
||||
R_API void r_graph_add_edge(RGraph *t, RGraphNode *from, RGraphNode *to) {
|
||||
r_graph_add_edge_at (t, from, to, -1);
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +201,7 @@ R_API void r_graph_add_edge_at (RGraph *t, RGraphNode *from, RGraphNode *to, int
|
|||
}
|
||||
|
||||
// splits the "split_me", so that new node has it's outnodes
|
||||
R_API RGraphNode *r_graph_node_split_forward (RGraph *g, RGraphNode *split_me, void *data) {
|
||||
R_API RGraphNode *r_graph_node_split_forward(RGraph *g, RGraphNode *split_me, void *data) {
|
||||
RGraphNode *front = r_graph_add_node(g, data);
|
||||
RList *tmp = front->out_nodes;
|
||||
front->out_nodes = split_me->out_nodes;
|
||||
|
|
@ -220,7 +220,7 @@ R_API RGraphNode *r_graph_node_split_forward (RGraph *g, RGraphNode *split_me, v
|
|||
}
|
||||
|
||||
|
||||
R_API void r_graph_del_edge (RGraph *t, RGraphNode *from, RGraphNode *to) {
|
||||
R_API void r_graph_del_edge(RGraph *t, RGraphNode *from, RGraphNode *to) {
|
||||
if (!from || !to || !r_graph_adjacent (t, from, to)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -233,39 +233,39 @@ R_API void r_graph_del_edge (RGraph *t, RGraphNode *from, RGraphNode *to) {
|
|||
|
||||
// XXX remove comments and static inline all this crap
|
||||
/* returns the list of nodes reachable from `n` */
|
||||
R_API const RList *r_graph_get_neighbours (const RGraph *g, const RGraphNode *n) {
|
||||
R_API const RList *r_graph_get_neighbours(const RGraph *g, const RGraphNode *n) {
|
||||
return n? n->out_nodes: NULL;
|
||||
}
|
||||
|
||||
/* returns the n-th nodes reachable from the give node `n`.
|
||||
* This, of course, depends on the order of the nodes. */
|
||||
R_API RGraphNode *r_graph_nth_neighbour (const RGraph *g, const RGraphNode *n, int nth) {
|
||||
R_API RGraphNode *r_graph_nth_neighbour(const RGraph *g, const RGraphNode *n, int nth) {
|
||||
return n? (RGraphNode *)r_list_get_n (n->out_nodes, nth): NULL;
|
||||
}
|
||||
|
||||
/* returns the list of nodes that can reach `n` */
|
||||
R_API const RList *r_graph_innodes (const RGraph *g, const RGraphNode *n) {
|
||||
R_API const RList *r_graph_innodes(const RGraph *g, const RGraphNode *n) {
|
||||
return n? n->in_nodes: NULL;
|
||||
}
|
||||
|
||||
/* returns the list of nodes reachable from `n` and that can reach `n`. */
|
||||
R_API const RList *r_graph_all_neighbours (const RGraph *g, const RGraphNode *n) {
|
||||
R_API const RList *r_graph_all_neighbours(const RGraph *g, const RGraphNode *n) {
|
||||
return n? n->all_neighbours: NULL;
|
||||
}
|
||||
|
||||
R_API const RList *r_graph_get_nodes (const RGraph *g) {
|
||||
R_API const RList *r_graph_get_nodes(const RGraph *g) {
|
||||
return g? g->nodes: NULL;
|
||||
}
|
||||
|
||||
/* true if there is an edge from the node `from` to the node `to` */
|
||||
R_API int r_graph_adjacent (const RGraph *g, const RGraphNode *from, const RGraphNode *to) {
|
||||
R_API bool r_graph_adjacent(const RGraph *g, const RGraphNode *from, const RGraphNode *to) {
|
||||
if (!g || !from) {
|
||||
return false;
|
||||
}
|
||||
return r_list_contains (from->out_nodes, to) ? true : false;
|
||||
return r_list_contains (from->out_nodes, to);
|
||||
}
|
||||
|
||||
R_API void r_graph_dfs_node (RGraph *g, RGraphNode *n, RGraphVisitor *vis) {
|
||||
R_API void r_graph_dfs_node(RGraph *g, RGraphNode *n, RGraphVisitor *vis) {
|
||||
if (!g || !n || !vis) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -276,7 +276,7 @@ R_API void r_graph_dfs_node (RGraph *g, RGraphNode *n, RGraphVisitor *vis) {
|
|||
}
|
||||
}
|
||||
|
||||
R_API void r_graph_dfs_node_reverse (RGraph *g, RGraphNode *n, RGraphVisitor *vis) {
|
||||
R_API void r_graph_dfs_node_reverse(RGraph *g, RGraphNode *n, RGraphVisitor *vis) {
|
||||
if (!g || !n || !vis) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -287,7 +287,7 @@ R_API void r_graph_dfs_node_reverse (RGraph *g, RGraphNode *n, RGraphVisitor *vi
|
|||
}
|
||||
}
|
||||
|
||||
R_API void r_graph_dfs (RGraph *g, RGraphVisitor *vis) {
|
||||
R_API void r_graph_dfs(RGraph *g, RGraphVisitor *vis) {
|
||||
r_return_if_fail (g && vis);
|
||||
RGraphNode *n;
|
||||
RListIter *it;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2007-2013 - pancake */
|
||||
/* radare - LGPL - Copyright 2007-2018 - pancake, ret2libc */
|
||||
|
||||
#define LOG_CONFIGSTR_SIZE 512
|
||||
#define LOG_OUTPUTBUF_SIZE 512
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
/* radare - LGPL - Copyright 2007-2016 - pancake */
|
||||
/* radare - LGPL - Copyright 2007-2020 - pancake */
|
||||
|
||||
#include <r_util.h>
|
||||
#include <stdlib.h>
|
||||
#if __UNIX__
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
|
@ -38,22 +37,21 @@ R_API void r_mem_copyloop(ut8 *dest, const ut8 *orig, int dsize, int osize) {
|
|||
}
|
||||
|
||||
R_API int r_mem_cmp_mask(const ut8 *dest, const ut8 *orig, const ut8 *mask, int len) {
|
||||
int i, ret = -1;
|
||||
ut8 *mdest, *morig;
|
||||
mdest = malloc (len);
|
||||
ut8 *mdest = malloc (len);
|
||||
if (!mdest) {
|
||||
return ret;
|
||||
return -1;
|
||||
}
|
||||
morig = malloc (len);
|
||||
ut8 *morig = malloc (len);
|
||||
if (!morig) {
|
||||
free (mdest);
|
||||
return ret;
|
||||
return -1;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < len; i++) {
|
||||
mdest[i] = dest[i] & mask[i];
|
||||
morig[i] = orig[i] & mask[i];
|
||||
}
|
||||
ret = memcmp (mdest, morig, len);
|
||||
int ret = memcmp (mdest, morig, len);
|
||||
free (mdest);
|
||||
free (morig);
|
||||
return ret;
|
||||
|
|
@ -79,18 +77,18 @@ R_API void r_mem_copybits(ut8 *dst, const ut8 *src, int bits) {
|
|||
}
|
||||
}
|
||||
|
||||
static char readbit(const ut8 *src, int bitoffset) {
|
||||
static inline char readbit(const ut8 *src, int bitoffset) {
|
||||
const int wholeBytes = bitoffset / 8;
|
||||
const int remainingBits = bitoffset % 8;
|
||||
// return (src[wholeBytes] >> remainingBits) & 1;
|
||||
return (src[wholeBytes] & 1<< remainingBits);
|
||||
}
|
||||
|
||||
static void writebit (ut8 *dst, int i, bool c) {
|
||||
int byte = i / 8;
|
||||
int bit = (i % 8);
|
||||
// eprintf ("Write %d %d = %d\n", byte, bit, c);
|
||||
dst += byte;
|
||||
static inline void writebit (ut8 *dst, int i, bool c) {
|
||||
const int byte = i / 8;
|
||||
const int bit = (i % 8);
|
||||
// eprintf ("Write %d %d = %d\n", byte, bit, c);
|
||||
dst += byte;
|
||||
if (c) {
|
||||
//dst[byte] |= (1 << bit);
|
||||
R_BIT_SET (dst , bit);
|
||||
|
|
@ -100,7 +98,6 @@ dst += byte;
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: this method is ugly as shit.
|
||||
R_API void r_mem_copybits_delta(ut8 *dst, int doff, const ut8 *src, int soff, int bits) {
|
||||
int i;
|
||||
if (doff < 0 || soff < 0 || !dst || !src) {
|
||||
|
|
@ -108,7 +105,6 @@ R_API void r_mem_copybits_delta(ut8 *dst, int doff, const ut8 *src, int soff, in
|
|||
}
|
||||
for (i = 0; i < bits; i++) {
|
||||
bool c = readbit (src, i + soff);
|
||||
// eprintf ("%d %d\n", i, c);
|
||||
writebit (dst, i + doff, c);
|
||||
}
|
||||
}
|
||||
|
|
@ -282,10 +278,9 @@ R_API int r_mem_protect(void *ptr, int size, const char *prot) {
|
|||
|
||||
R_API void *r_mem_dup(const void *s, int l) {
|
||||
void *d = malloc (l);
|
||||
if (!d) {
|
||||
return NULL;
|
||||
if (d) {
|
||||
memcpy (d, s, l);
|
||||
}
|
||||
memcpy (d, s, l);
|
||||
return d;
|
||||
}
|
||||
|
||||
|
|
@ -361,7 +356,6 @@ R_API void *r_mem_mmap_resize(RMmap *m, ut64 newsize) {
|
|||
if (!r_sys_truncate (m->filename, newsize)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m->len = newsize;
|
||||
r_file_mmap_arch (m, m->filename, m->fd);
|
||||
return m->buf;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <r_util.h>
|
||||
|
||||
R_API int r_name_validate_char(const char ch) {
|
||||
R_API bool r_name_validate_char(const char ch) {
|
||||
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (IS_DIGIT(ch))) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ R_API int r_name_validate_char(const char ch) {
|
|||
return false;
|
||||
}
|
||||
|
||||
R_API int r_name_check(const char *name) {
|
||||
R_API bool r_name_check(const char *name) {
|
||||
/* Cannot start by number */
|
||||
if (!name || !*name || IS_DIGIT (*name)) {
|
||||
return false;
|
||||
|
|
@ -34,11 +34,10 @@ static inline bool is_special_char (char *name) {
|
|||
return (n == 'b' || n == 'f' || n == 'n' || n == 'r' || n == 't' || n == 'v' || n == 'a');
|
||||
}
|
||||
|
||||
R_API int r_name_filter(char *name, int maxlen) {
|
||||
int i;
|
||||
size_t len;
|
||||
R_API bool r_name_filter(char *name, int maxlen) {
|
||||
size_t i, len;
|
||||
if (!name) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (maxlen < 0) {
|
||||
maxlen = strlen (name);
|
||||
|
|
@ -87,7 +86,7 @@ R_API int r_name_filter(char *name, int maxlen) {
|
|||
}
|
||||
|
||||
R_API char *r_name_filter2(const char *name) {
|
||||
int i;
|
||||
size_t i;
|
||||
while (!IS_PRINTABLE (*name)) {
|
||||
name++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,9 @@
|
|||
/* radare - LGPL - Copyright 2007-2019 - pancake */
|
||||
/* radare - LGPL - Copyright 2007-2020 - pancake */
|
||||
|
||||
#include "r_anal.h"
|
||||
#include "r_cons.h"
|
||||
#include "r_util.h"
|
||||
#include "r_util/r_print.h"
|
||||
#include "r_core.h"
|
||||
#include <r_core.h>
|
||||
|
||||
#define DFLT_ROWS 16
|
||||
|
||||
#define IS_ALPHA(C) (((C) >= 'a' && (C) <= 'z') || ((C) >= 'A' && (C) <= 'Z'))
|
||||
|
||||
static const char hex[16] = "0123456789ABCDEF";
|
||||
|
||||
static int nullprinter(const char *a, ...) {
|
||||
|
|
@ -70,7 +64,7 @@ R_API void r_print_portionbar(RPrint *p, const ut64 *portions, int n_portions) {
|
|||
p->cb_printf ("]\n");
|
||||
}
|
||||
|
||||
R_API void r_print_columns (RPrint *p, const ut8 *buf, int len, int height) {
|
||||
R_API void r_print_columns(RPrint *p, const ut8 *buf, int len, int height) {
|
||||
int i, j, cols = 78;
|
||||
int rows = height > 0 ? height : 10;
|
||||
// int realrows = rows * 2;
|
||||
|
|
@ -105,7 +99,7 @@ R_API void r_print_columns (RPrint *p, const ut8 *buf, int len, int height) {
|
|||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i<rows; i++) {
|
||||
for (i = 0; i < rows; i++) {
|
||||
int threshold = i * (0xff / rows);
|
||||
for (j = 0; j < cols; j++) {
|
||||
int realJ = j * len / cols;
|
||||
|
|
@ -239,16 +233,14 @@ static int r_print_stereogram_private(const char *bump, int w, int h, char *out,
|
|||
}
|
||||
|
||||
R_API char* r_print_stereogram(const char *bump, int w, int h) {
|
||||
ut64 size;
|
||||
char *out;
|
||||
if (w < 1 || h < 1) {
|
||||
return NULL;
|
||||
}
|
||||
size = w * (ut64) h * 2;
|
||||
ut64 size = w * (ut64) h * 2;
|
||||
if (size > UT32_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
out = calloc (1, size * 2);
|
||||
char *out = calloc (1, size * 2);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1393,11 +1385,10 @@ static const char* getchardiff(RPrint *p, char *fmt, ut8 a, ut8 b) {
|
|||
|
||||
static ut8* M(const ut8 *b, int len) {
|
||||
ut8 *r = malloc (len + 16);
|
||||
if (!r) {
|
||||
return NULL;
|
||||
if (r) {
|
||||
memset (r, 0xff, len + 16);
|
||||
memcpy (r, b, len);
|
||||
}
|
||||
memset (r, 0xff, len + 16);
|
||||
memcpy (r, b, len);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
@ -1708,7 +1699,6 @@ R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step
|
|||
const char *v_line = useUtf8 ? RUNE_LINE_VERT : "|";
|
||||
int i = 0, j;
|
||||
|
||||
|
||||
#define INC 5
|
||||
#if TOPLINE
|
||||
if (arr[0] > 1) {
|
||||
|
|
@ -1962,7 +1952,7 @@ static bool issymbol(char c) {
|
|||
static bool check_arg_name (RPrint *print, char *p, ut64 func_addr) {
|
||||
if (func_addr && print->exists_var) {
|
||||
int z;
|
||||
for (z = 0; p[z] && (IS_ALPHA (p[z]) || IS_DIGIT (p[z]) || p[z] == '_'); z++) {
|
||||
for (z = 0; p[z] && (isalpha (p[z]) || isdigit (p[z]) || p[z] == '_'); z++) {
|
||||
;
|
||||
}
|
||||
char tmp = p[z];
|
||||
|
|
|
|||
|
|
@ -255,15 +255,15 @@ R_API bool r_rbtree_aug_insert(RBNode **root, void *data, RBNode *node, RBCompar
|
|||
|
||||
// returns true if the sum has been updated, false if node has not been found
|
||||
R_API bool r_rbtree_aug_update_sum(RBNode *root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum) {
|
||||
int dep = 0;
|
||||
size_t dep = 0;
|
||||
RBNode *path[R_RBTREE_MAX_HEIGHT];
|
||||
RBNode *cur = root;
|
||||
for (;;) {
|
||||
if (dep >= R_RBTREE_MAX_HEIGHT) {
|
||||
eprintf ("Too deep tree\n");
|
||||
if (!cur) {
|
||||
return false;
|
||||
}
|
||||
if (!cur) {
|
||||
if (dep >= R_RBTREE_MAX_HEIGHT) {
|
||||
eprintf ("Too deep tree\n");
|
||||
return false;
|
||||
}
|
||||
path[dep] = cur;
|
||||
|
|
@ -271,13 +271,8 @@ R_API bool r_rbtree_aug_update_sum(RBNode *root, void *data, RBNode *node, RBCom
|
|||
if (cur == node) {
|
||||
break;
|
||||
}
|
||||
|
||||
int d = cmp (data, cur, cmp_user);
|
||||
if (d < 0) {
|
||||
cur = cur->child[0];
|
||||
} else {
|
||||
cur = cur->child[1];
|
||||
}
|
||||
cur = cur->child[(d < 0)? 0: 1];
|
||||
}
|
||||
|
||||
for (; dep > 0; dep--) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
/* radare - LGPL - Copyright 2012-2013 - pancake */
|
||||
#include <r_util.h>
|
||||
|
||||
// TODO: work in progress
|
||||
|
||||
#if 0
|
||||
for(i=0; i<len; i++) {
|
||||
packing_7bit_character(config.block+i, buffer);
|
||||
|
|
@ -10,53 +8,50 @@ for(i=0; i<len; i++) {
|
|||
}
|
||||
#endif
|
||||
|
||||
R_API int r_print_pack7bit (const char *src, char *dest) {
|
||||
int len, i, j = 0, shift = 0;
|
||||
ut8 ch1, ch2;
|
||||
char tmp[2];
|
||||
R_API int r_print_pack7bit(const char *src, char *dest) {
|
||||
int i, j = 0, shift = 0;
|
||||
ut8 ch1, ch2;
|
||||
char tmp[2];
|
||||
|
||||
*dest = '\0';
|
||||
len = strlen (src);
|
||||
*dest = '\0';
|
||||
int len = strlen (src);
|
||||
|
||||
for (i=0; i<len; i++ ) {
|
||||
ch1 = src[i] & 0x7F;
|
||||
ch1 = ch1 >> shift;
|
||||
ch2 = src[(i+1)] & 0x7F;
|
||||
ch2 = ch2 << (7-shift);
|
||||
for (i = 0; i < len; i++) {
|
||||
ch1 = src[i] & 0x7F;
|
||||
ch1 = ch1 >> shift;
|
||||
ch2 = src[(i + 1)] & 0x7F;
|
||||
ch2 = ch2 << (7 - shift);
|
||||
ch1 = ch1 | ch2;
|
||||
|
||||
ch1 = ch1 | ch2;
|
||||
|
||||
j = strlen(dest);
|
||||
sprintf (tmp, "%x", (ch1 >> 4));
|
||||
dest[j++] = tmp[0];
|
||||
sprintf (tmp, "%x", (ch1 & 0x0F));
|
||||
dest[j++] = tmp[0];
|
||||
dest[j++] = '\0';
|
||||
if (7 == ++shift) {
|
||||
shift = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
j = strlen(dest);
|
||||
sprintf (tmp, "%x", (ch1 >> 4));
|
||||
dest[j++] = tmp[0];
|
||||
sprintf (tmp, "%x", (ch1 & 0x0F));
|
||||
dest[j++] = tmp[0];
|
||||
dest[j++] = '\0';
|
||||
if (7 == ++shift) {
|
||||
shift = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
R_API int r_print_unpack7bit (const char *src, char *dest) {
|
||||
int i, j, shift = 0, len = strlen (src);
|
||||
ut8 ch1, ch2 = '\0';
|
||||
char buf[8];
|
||||
R_API int r_print_unpack7bit(const char *src, char *dest) {
|
||||
int i, j, shift = 0, len = strlen (src);
|
||||
ut8 ch1, ch2 = '\0';
|
||||
char buf[8];
|
||||
|
||||
*dest = '\0';
|
||||
*dest = '\0';
|
||||
|
||||
for (i=0; i<len; i+=2) {
|
||||
sprintf (buf, "%c%c", src[i], src[i+1]);
|
||||
ch1 = strtol (buf, NULL, 16);
|
||||
|
||||
j = strlen(dest);
|
||||
dest[j++] = ((ch1 & (0x7F >> shift)) << shift) | ch2;
|
||||
dest[j++] = '\0';
|
||||
ch2 = ch1 >> (7-shift);
|
||||
|
||||
shift++;
|
||||
}
|
||||
return 0;
|
||||
for (i = 0; i < len; i += 2) {
|
||||
sprintf (buf, "%c%c", src[i], src[i + 1]);
|
||||
ch1 = strtol (buf, NULL, 16);
|
||||
j = strlen(dest);
|
||||
dest[j++] = ((ch1 & (0x7F >> shift)) << shift) | ch2;
|
||||
dest[j++] = '\0';
|
||||
ch2 = ch1 >> (7 - shift);
|
||||
shift++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
/* radare - LGPL - Copyright 2017-2020 - polsha3 */
|
||||
|
||||
#include <r_util.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ R_API void r_spaces_free(RSpaces *sp) {
|
|||
free (sp);
|
||||
}
|
||||
|
||||
static void space_free(RSpace *s) {
|
||||
static inline void space_free(RSpace *s) {
|
||||
if (s) {
|
||||
free (s->name);
|
||||
free (s);
|
||||
|
|
@ -122,7 +122,7 @@ R_API RSpace *r_spaces_set(RSpaces *sp, const char *name) {
|
|||
return sp->current;
|
||||
}
|
||||
|
||||
static bool spaces_unset_single(RSpaces *sp, const char *name) {
|
||||
static inline bool spaces_unset_single(RSpaces *sp, const char *name) {
|
||||
RSpace *space = r_spaces_get (sp, name);
|
||||
if (!space) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2007-2015 - ret2libc */
|
||||
/* radare - LGPL - Copyright 2007-2020 - ret2libc */
|
||||
|
||||
#include <r_util.h>
|
||||
|
||||
|
|
@ -38,14 +38,15 @@ R_API void r_stack_free(RStack *s) {
|
|||
}
|
||||
}
|
||||
|
||||
R_API int r_stack_push(RStack *s, void *el) {
|
||||
R_API bool r_stack_push(RStack *s, void *el) {
|
||||
if (s->top == s->n_elems - 1) {
|
||||
/* reallocate the stack */
|
||||
s->n_elems *= 2;
|
||||
s->elems = realloc (s->elems, s->n_elems * sizeof (void *));
|
||||
if (!s->elems) {
|
||||
void **elems = realloc (s->elems, s->n_elems * sizeof (void *));
|
||||
if (!elems) {
|
||||
return false;
|
||||
}
|
||||
s->elems = elems;
|
||||
}
|
||||
|
||||
s->top++;
|
||||
|
|
@ -53,14 +54,12 @@ R_API int r_stack_push(RStack *s, void *el) {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
//the caller should be take care of the object returned
|
||||
R_API void *r_stack_pop(RStack *s) {
|
||||
void *res;
|
||||
if (s->top == -1) {
|
||||
return NULL;
|
||||
}
|
||||
res = s->elems[s->top];
|
||||
void *res = s->elems[s->top];
|
||||
s->top--;
|
||||
return res;
|
||||
}
|
||||
|
|
@ -69,15 +68,10 @@ R_API bool r_stack_is_empty(RStack *s) {
|
|||
return s->top == -1;
|
||||
}
|
||||
|
||||
R_API unsigned int r_stack_size(RStack *s) {
|
||||
return (unsigned int)(s->top + 1);
|
||||
R_API size_t r_stack_size(RStack *s) {
|
||||
return (size_t)(s->top + 1);
|
||||
}
|
||||
|
||||
R_API void *r_stack_peek(RStack *s) {
|
||||
void *res;
|
||||
if (!r_stack_is_empty (s)) {
|
||||
res = s->elems[s->top];
|
||||
return res;
|
||||
}
|
||||
return NULL;
|
||||
return r_stack_is_empty (s)? NULL: s->elems[s->top];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
/* radare - LGPL - Copyright 2017-2020 - maskray, thestr4ng3r */
|
||||
|
||||
#include "r_vector.h"
|
||||
|
||||
// Optimize memory usage on glibc
|
||||
|
|
|
|||
Loading…
Reference in a new issue