mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-26 17:15:38 +00:00
* Fix api for config_set_cb
- Now every callback gets a *user pointer - Define full api in r_config.h with R_API - Added scr.color in radare2 - Added po, pu, pU and pS print modes in r2 * Add r_print_unset_flags helper * Fix urlencoding print mode * Add test program for r_print_format * Fix build O:)
This commit is contained in:
parent
1e6806aa84
commit
d292b4fb6d
2
TODO
2
TODO
@ -1,3 +1,5 @@
|
|||||||
|
* Fix hexdump ascii column colors
|
||||||
|
* Add test for config.c with _set_cb
|
||||||
* Rename __UNIX__ as __POSIX__
|
* Rename __UNIX__ as __POSIX__
|
||||||
* Strip non input symbols in plugins (speed up loading)
|
* Strip non input symbols in plugins (speed up loading)
|
||||||
* Specify binmask in hexpairs
|
* Specify binmask in hexpairs
|
||||||
|
@ -85,7 +85,7 @@ u64 r_config_get_i(struct r_config_t *cfg, const char *name)
|
|||||||
return (u64)0LL;
|
return (u64)0LL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct r_config_node_t *r_config_set_cb(struct r_config_t *cfg, const char *name, const char *value, int (*callback)(void *data))
|
struct r_config_node_t *r_config_set_cb(struct r_config_t *cfg, const char *name, const char *value, int (*callback)(void *user, void *data))
|
||||||
{
|
{
|
||||||
struct r_config_node_t *node;
|
struct r_config_node_t *node;
|
||||||
node = r_config_set(cfg, name, value);
|
node = r_config_set(cfg, name, value);
|
||||||
@ -140,7 +140,7 @@ struct r_config_node_t *r_config_set(struct r_config_t *cfg, const char *name, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node && node->callback)
|
if (node && node->callback)
|
||||||
node->callback(node);
|
node->callback(cfg->user, node);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ struct r_config_node_t *r_config_set_i(struct r_config_t *cfg, const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node && node->callback)
|
if (node && node->callback)
|
||||||
node->callback(node);
|
node->callback(cfg->user, node);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -249,20 +249,21 @@ void r_config_lock(struct r_config_t *cfg, int l)
|
|||||||
cfg->lock = l;
|
cfg->lock = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
int r_config_init(struct r_config_t *cfg)
|
int r_config_init(struct r_config_t *cfg, void *user)
|
||||||
{
|
{
|
||||||
|
cfg->user = user;
|
||||||
cfg->n_nodes = 0;
|
cfg->n_nodes = 0;
|
||||||
cfg->lock = 0;
|
cfg->lock = 0;
|
||||||
cfg->printf = &printf;
|
cfg->printf = printf;
|
||||||
INIT_LIST_HEAD(&(cfg->nodes));
|
INIT_LIST_HEAD(&(cfg->nodes));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct r_config_t *r_config_new()
|
struct r_config_t *r_config_new(void *user)
|
||||||
{
|
{
|
||||||
struct r_config_t *cfg = (struct r_config_t *)
|
struct r_config_t *cfg = (struct r_config_t *)
|
||||||
malloc(sizeof(struct r_config_t));
|
malloc(sizeof(struct r_config_t));
|
||||||
r_config_init(cfg);
|
r_config_init(cfg, user);
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ int main()
|
|||||||
struct r_config_t *cfg;
|
struct r_config_t *cfg;
|
||||||
|
|
||||||
/* initialize config table */
|
/* initialize config table */
|
||||||
cfg = r_config_new();
|
cfg = r_config_new(NULL);
|
||||||
r_config_set(cfg, "foo", "bar");
|
r_config_set(cfg, "foo", "bar");
|
||||||
r_config_set_i(cfg, "bar", 33);
|
r_config_set_i(cfg, "bar", 33);
|
||||||
r_config_lock(cfg, 1);
|
r_config_lock(cfg, 1);
|
||||||
|
@ -282,8 +282,8 @@ static int cmd_print(void *data, const char *input)
|
|||||||
struct r_core_t *core = (struct r_core_t *)data;
|
struct r_core_t *core = (struct r_core_t *)data;
|
||||||
int l, len = core->blocksize;
|
int l, len = core->blocksize;
|
||||||
u32 tbs = core->blocksize;
|
u32 tbs = core->blocksize;
|
||||||
int show_offset = r_config_get(&core->config, "asm.offset");
|
int show_offset = r_config_get_i(&core->config, "asm.offset");
|
||||||
int show_bytes = r_config_get(&core->config, "asm.bytes");
|
int show_bytes = r_config_get_i(&core->config, "asm.bytes");
|
||||||
|
|
||||||
if (input[0] && input[1]) {
|
if (input[0] && input[1]) {
|
||||||
l = (int) r_num_get(&core->num, input+2);
|
l = (int) r_num_get(&core->num, input+2);
|
||||||
@ -318,7 +318,16 @@ static int cmd_print(void *data, const char *input)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
r_print_string(&core->print, core->seek, core->block, len); //, 78, 1);
|
r_print_string(&core->print, core->seek, core->block, len, 0, 1, 0); //, 78, 1);
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
r_print_string(&core->print, core->seek, core->block, len, 1, 1, 0); //, 78, 1);
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
r_print_string(&core->print, core->seek, core->block, len, 0, 1, 1); //, 78, 1);
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
r_print_string(&core->print, core->seek, core->block, len, 1, 1, 1); //, 78, 1);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
r_print_code(&core->print, core->seek, core->block, len); //, 78, 1);
|
r_print_code(&core->print, core->seek, core->block, len); //, 78, 1);
|
||||||
@ -326,8 +335,11 @@ static int cmd_print(void *data, const char *input)
|
|||||||
case 'r':
|
case 'r':
|
||||||
r_print_raw(&core->print, core->block, len);
|
r_print_raw(&core->print, core->block, len);
|
||||||
break;
|
break;
|
||||||
|
case 'o':
|
||||||
|
r_print_hexdump(&core->print, core->seek, core->block, len, 8, 1); //, 78, !(input[1]=='-'));
|
||||||
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
r_print_hexdump(&core->print, core->seek, core->block, len, 1); //, 78, !(input[1]=='-'));
|
r_print_hexdump(&core->print, core->seek, core->block, len, 16, 1); //, 78, !(input[1]=='-'));
|
||||||
break;
|
break;
|
||||||
case '8':
|
case '8':
|
||||||
r_print_bytes(&core->print, core->block, len, "%02x");
|
r_print_bytes(&core->print, core->block, len, "%02x");
|
||||||
@ -336,10 +348,14 @@ static int cmd_print(void *data, const char *input)
|
|||||||
fprintf(stderr, "Usage: p[8] [len]\n"
|
fprintf(stderr, "Usage: p[8] [len]\n"
|
||||||
" p8 [len] 8bit hexpair list of bytes\n"
|
" p8 [len] 8bit hexpair list of bytes\n"
|
||||||
" px [len] hexdump of N bytes\n"
|
" px [len] hexdump of N bytes\n"
|
||||||
|
" po [len] octal dump of N bytes\n"
|
||||||
" pc [len] output C format\n"
|
" pc [len] output C format\n"
|
||||||
" ps [len] print string\n"
|
" ps [len] print string\n"
|
||||||
|
" pS [len] print wide string\n"
|
||||||
" pd [len] disassemble N bytes\n"
|
" pd [len] disassemble N bytes\n"
|
||||||
" pr [len] print N raw bytes\n");
|
" pr [len] print N raw bytes\n"
|
||||||
|
" pu [len] print N url encoded bytes\n"
|
||||||
|
" pU [len] print N wide url encoded bytes\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (tbs != core->blocksize)
|
if (tbs != core->blocksize)
|
||||||
@ -387,7 +403,7 @@ static int cmd_flag(void *data, const char *input)
|
|||||||
case 's':
|
case 's':
|
||||||
if (input[1]==' ')
|
if (input[1]==' ')
|
||||||
r_flag_space_set(&core->flags, input+2);
|
r_flag_space_set(&core->flags, input+2);
|
||||||
else r_flag_space_list(&core->flags, 0);
|
else r_flag_space_list(&core->flags);
|
||||||
break;
|
break;
|
||||||
case '*':
|
case '*':
|
||||||
r_flag_list(&core->flags, 1);
|
r_flag_list(&core->flags, 1);
|
||||||
@ -729,7 +745,7 @@ static int cmd_eval(void *data, const char *input)
|
|||||||
r_config_list(&core->config, NULL, 0);
|
r_config_list(&core->config, NULL, 0);
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
r_config_init(&core->config);
|
r_config_init(&core->config, core);
|
||||||
break;
|
break;
|
||||||
case '*':
|
case '*':
|
||||||
r_config_list(&core->config, NULL, 1);
|
r_config_list(&core->config, NULL, 1);
|
||||||
|
@ -2,12 +2,25 @@
|
|||||||
|
|
||||||
#include <r_core.h>
|
#include <r_core.h>
|
||||||
|
|
||||||
|
void config_color_callback(void *user, void *data)
|
||||||
|
{
|
||||||
|
struct r_core_t *core = (struct r_core_t *) user;
|
||||||
|
struct r_config_node_t *node =
|
||||||
|
(struct r_config_node_t *) data;
|
||||||
|
|
||||||
|
if (node->i_value) {
|
||||||
|
core->print.flags|=R_PRINT_FLAGS_COLOR;
|
||||||
|
} else {
|
||||||
|
// XXX ??? sure
|
||||||
|
if (core->print.flags&R_PRINT_FLAGS_COLOR)
|
||||||
|
core->print.flags^=R_PRINT_FLAGS_COLOR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int r_core_config_init(struct r_core_t *core)
|
int r_core_config_init(struct r_core_t *core)
|
||||||
{
|
{
|
||||||
struct r_config_t *cfg = &core->config;
|
struct r_config_t *cfg = &core->config;
|
||||||
r_config_init(cfg);
|
r_config_init(cfg, (void *)core);
|
||||||
//r_config_callback_int("");
|
|
||||||
|
|
||||||
r_config_set(cfg, "asm.arch", "x86");
|
r_config_set(cfg, "asm.arch", "x86");
|
||||||
r_config_set_i(cfg, "asm.bits", 32);
|
r_config_set_i(cfg, "asm.bits", 32);
|
||||||
r_config_set(cfg, "asm.syntax", "x86");
|
r_config_set(cfg, "asm.syntax", "x86");
|
||||||
@ -17,6 +30,9 @@ int r_core_config_init(struct r_core_t *core)
|
|||||||
r_config_set(cfg, "asm.os", "linux");
|
r_config_set(cfg, "asm.os", "linux");
|
||||||
r_config_set(cfg, "cmd.prompt", "");
|
r_config_set(cfg, "cmd.prompt", "");
|
||||||
r_config_set(cfg, "cmd.vprompt", "");
|
r_config_set(cfg, "cmd.vprompt", "");
|
||||||
|
r_config_set_cb(cfg, "scr.color",
|
||||||
|
(core->print.flags&R_PRINT_FLAGS_COLOR)?"true":"false",
|
||||||
|
&config_color_callback);
|
||||||
#if 0
|
#if 0
|
||||||
node = config_set("asm.profile", "default");
|
node = config_set("asm.profile", "default");
|
||||||
// node->callback = &config_asm_profile;
|
// node->callback = &config_asm_profile;
|
||||||
@ -300,8 +316,6 @@ int r_core_config_init(struct r_core_t *core)
|
|||||||
config_set_scr_pal("7f","magenta")
|
config_set_scr_pal("7f","magenta")
|
||||||
|
|
||||||
config_set("scr.seek", "eip");
|
config_set("scr.seek", "eip");
|
||||||
node = config_set("scr.color", (config.color)?"true":"false");
|
|
||||||
node->callback = &config_color_callback;
|
|
||||||
config_set("scr.grephigh", "");
|
config_set("scr.grephigh", "");
|
||||||
node = config_set("scr.tee", "");
|
node = config_set("scr.tee", "");
|
||||||
node->callback = &config_teefile_callback;
|
node->callback = &config_teefile_callback;
|
||||||
|
@ -21,7 +21,7 @@ struct r_config_node_t {
|
|||||||
u64 *cb_ptr_q;
|
u64 *cb_ptr_q;
|
||||||
int *cb_ptr_i;
|
int *cb_ptr_i;
|
||||||
char **cb_ptr_s;
|
char **cb_ptr_s;
|
||||||
int (*callback)(void *data);
|
int (*callback)(void *user, void *data);
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -29,18 +29,20 @@ struct r_config_t {
|
|||||||
int lock;
|
int lock;
|
||||||
int last_notfound;
|
int last_notfound;
|
||||||
int n_nodes;
|
int n_nodes;
|
||||||
|
void *user;
|
||||||
void (*printf)(const char *str, ...);
|
void (*printf)(const char *str, ...);
|
||||||
struct list_head nodes;
|
struct list_head nodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define O struct r_config_t *obj
|
#define O struct r_config_t *obj
|
||||||
|
|
||||||
struct r_config_t *r_config_new();
|
struct r_config_t *r_config_new(void *user);
|
||||||
int r_config_free(struct r_config_t *cfg);
|
int r_config_free(struct r_config_t *cfg);
|
||||||
int r_config_init(O);
|
int r_config_init(struct r_config_t *core, void *user);
|
||||||
void r_config_lock(O, int l);
|
void r_config_lock(O, int l);
|
||||||
int r_config_eval(O, const char *str);
|
int r_config_eval(O, const char *str);
|
||||||
struct r_config_node_t *r_config_set_i(O, const char *name, const u64 i);
|
struct r_config_node_t *r_config_set_i(O, const char *name, const u64 i);
|
||||||
|
struct r_config_node_t *r_config_set_cb(struct r_config_t *cfg, const char *name, const char *value, int (*callback)(void *user, void *data));
|
||||||
int r_config_rm(O, const char *name);
|
int r_config_rm(O, const char *name);
|
||||||
struct r_config_node_t *r_config_set(O, const char *name, const char *value);
|
struct r_config_node_t *r_config_set(O, const char *name, const char *value);
|
||||||
u64 r_config_get_i(O, const char *name);
|
u64 r_config_get_i(O, const char *name);
|
||||||
|
@ -39,6 +39,6 @@ int r_flag_name_filter(char *name);
|
|||||||
/* spaces */
|
/* spaces */
|
||||||
const const char *r_flag_space_get(struct r_flag_t *f, int idx);
|
const const char *r_flag_space_get(struct r_flag_t *f, int idx);
|
||||||
void r_flag_space_set(struct r_flag_t *f, const char *name);
|
void r_flag_space_set(struct r_flag_t *f, const char *name);
|
||||||
void flag_space_list(struct r_flag_t *f);
|
void r_flag_space_list(struct r_flag_t *f);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,6 +18,7 @@ struct r_print_t {
|
|||||||
int interrupt;
|
int interrupt;
|
||||||
int bigendian;
|
int bigendian;
|
||||||
int width;
|
int width;
|
||||||
|
int limit;
|
||||||
int cur_enabled;
|
int cur_enabled;
|
||||||
int cur;
|
int cur;
|
||||||
int ocur;
|
int ocur;
|
||||||
@ -26,17 +27,23 @@ struct r_print_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
R_API struct r_print_t *r_print_new();
|
R_API struct r_print_t *r_print_new();
|
||||||
|
R_API int r_print_init(struct r_print_t *p);
|
||||||
R_API struct r_print_t *r_print_free(struct r_print_t *p);
|
R_API struct r_print_t *r_print_free(struct r_print_t *p);
|
||||||
R_API void r_print_set_flags(struct r_print_t *p, int _flags);
|
R_API void r_print_set_flags(struct r_print_t *p, int _flags);
|
||||||
|
void r_print_unset_flags(struct r_print_t *p, int flags);
|
||||||
R_API void r_print_set_width(struct r_print_t *p, int width);
|
R_API void r_print_set_width(struct r_print_t *p, int width);
|
||||||
R_API void r_print_addr(struct r_print_t *p, u64 addr);
|
R_API void r_print_addr(struct r_print_t *p, u64 addr);
|
||||||
R_API void r_print_hexdump(struct r_print_t *p, u64 addr, u8 *buf, int len, int step);
|
R_API void r_print_hexdump(struct r_print_t *p, u64 addr, u8 *buf, int len, int base, int step);
|
||||||
|
R_API void r_print_hexpairs(struct r_print_t *p, u64 addr, u8 *buf, int len);
|
||||||
R_API void r_print_bytes(struct r_print_t *p, const u8* buf, int len, const char *fmt);
|
R_API void r_print_bytes(struct r_print_t *p, const u8* buf, int len, const char *fmt);
|
||||||
|
R_API void r_print_byte(struct r_print_t *p, const char *fmt, int idx, u8 ch);
|
||||||
|
R_API void r_print_c(struct r_print_t *p, const char *str, int len);
|
||||||
R_API void r_print_raw(struct r_print_t *p, const u8* buf, int len);
|
R_API void r_print_raw(struct r_print_t *p, const u8* buf, int len);
|
||||||
R_API void r_print_cursor(struct r_print_t *p, int cur, int set);
|
R_API void r_print_cursor(struct r_print_t *p, int cur, int set);
|
||||||
R_API void r_print_set_cursor(struct r_print_t *p, int curset, int ocursor, int cursor);
|
R_API void r_print_set_cursor(struct r_print_t *p, int curset, int ocursor, int cursor);
|
||||||
R_API void r_print_code(struct r_print_t *p, u64 addr, u8 *buf, int len);
|
R_API void r_print_code(struct r_print_t *p, u64 addr, u8 *buf, int len);
|
||||||
R_API void r_print_format(struct r_print_t *p, u64 seek, const u8* buf, int len, const char *fmt);
|
R_API void r_print_format(struct r_print_t *p, u64 seek, const u8* buf, int len, const char *fmt);
|
||||||
R_API int r_print_string(struct r_print_t *p, const u8 *str, int len, int wide, int zeroend, int urlencode);
|
// XXX . change wide, zeroend, urlencode for option flags
|
||||||
|
R_API int r_print_string(struct r_print_t *p, u64 seek, const u8 *str, int len, int wide, int zeroend, int urlencode);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "r_print.h"
|
#include "r_print.h"
|
||||||
#include "r_util.h"
|
#include "r_util.h"
|
||||||
|
|
||||||
int r_print_init(struct r_print_t *p)
|
R_API int r_print_init(struct r_print_t *p)
|
||||||
{
|
{
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return R_FALSE;
|
return R_FALSE;
|
||||||
@ -41,6 +41,11 @@ void r_print_set_flags(struct r_print_t *p, int _flags)
|
|||||||
p->flags = _flags;
|
p->flags = _flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void r_print_unset_flags(struct r_print_t *p, int flags)
|
||||||
|
{
|
||||||
|
p->flags = p->flags & (p->flags^flags);
|
||||||
|
}
|
||||||
|
|
||||||
struct r_print_t *r_print_free(struct r_print_t *p)
|
struct r_print_t *r_print_free(struct r_print_t *p)
|
||||||
{
|
{
|
||||||
free(p);
|
free(p);
|
||||||
@ -126,9 +131,12 @@ void r_print_code(struct r_print_t *p, u64 addr, u8 *buf, int len)
|
|||||||
p->printf("};\n");
|
p->printf("};\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
R_API int r_print_string(struct r_print_t *p, const u8 *buf, int len, int wide, int zeroend, int urlencode)
|
R_API int r_print_string(struct r_print_t *p, u64 seek, const u8 *buf, int len, int wide, int zeroend, int urlencode)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
//if (p->flags & R_PRINT_FLAGS_OFFSET)
|
||||||
|
// r_print_addr(p, seek);
|
||||||
p->interrupt = 0;
|
p->interrupt = 0;
|
||||||
for(i=0;!p->interrupt&&i<len;i++) {
|
for(i=0;!p->interrupt&&i<len;i++) {
|
||||||
if (zeroend && buf[i]=='\0')
|
if (zeroend && buf[i]=='\0')
|
||||||
@ -136,7 +144,7 @@ R_API int r_print_string(struct r_print_t *p, const u8 *buf, int len, int wide,
|
|||||||
r_print_cursor(p, i, 1);
|
r_print_cursor(p, i, 1);
|
||||||
if (urlencode) {
|
if (urlencode) {
|
||||||
// TODO: some ascii can be bypassed here
|
// TODO: some ascii can be bypassed here
|
||||||
p->printf("%02x", buf[i]);
|
p->printf("%%%02x", buf[i]);
|
||||||
} else {
|
} else {
|
||||||
if (IS_PRINTABLE(buf[i]))
|
if (IS_PRINTABLE(buf[i]))
|
||||||
p->printf("%c", buf[i]);
|
p->printf("%c", buf[i]);
|
||||||
@ -159,11 +167,17 @@ R_API void r_print_hexpairs(struct r_print_t *p, u64 addr, u8 *buf, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX: step is borken
|
// XXX: step is borken
|
||||||
R_API void r_print_hexdump(struct r_print_t *p, u64 addr, u8 *buf, int len, int step)
|
R_API void r_print_hexdump(struct r_print_t *p, u64 addr, u8 *buf, int len, int base, int step)
|
||||||
{
|
{
|
||||||
int i,j,k,inc;
|
int i,j,k,inc;
|
||||||
const char *fmt;
|
const char *fmt = "%02x";
|
||||||
|
const char *pre = "";
|
||||||
|
switch(base) {
|
||||||
|
case 8: fmt = "%03x"; pre = " "; break;
|
||||||
|
case 10: fmt = "%03d"; pre = " "; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Use base to change %03o and so on
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
// TODO: use defaults r_print_t (static one)
|
// TODO: use defaults r_print_t (static one)
|
||||||
fprintf(stderr, "TODO: r_print_hexdump does not supports NULL as arg0\n");
|
fprintf(stderr, "TODO: r_print_hexdump does not supports NULL as arg0\n");
|
||||||
@ -180,6 +194,7 @@ R_API void r_print_hexdump(struct r_print_t *p, u64 addr, u8 *buf, int len, int
|
|||||||
p->printf(" offset ");
|
p->printf(" offset ");
|
||||||
k = 0; // TODO: ??? SURE??? config.seek & 0xF;
|
k = 0; // TODO: ??? SURE??? config.seek & 0xF;
|
||||||
for (i=0; i<inc; i++) {
|
for (i=0; i<inc; i++) {
|
||||||
|
p->printf(pre);
|
||||||
p->printf(" %c", hex[(i+k)%16]);
|
p->printf(" %c", hex[(i+k)%16]);
|
||||||
if (i&1) p->printf(" ");
|
if (i&1) p->printf(" ");
|
||||||
}
|
}
|
||||||
@ -206,10 +221,9 @@ R_API void r_print_hexdump(struct r_print_t *p, u64 addr, u8 *buf, int len, int
|
|||||||
if (j >= len)
|
if (j >= len)
|
||||||
p->printf(" ");
|
p->printf(" ");
|
||||||
else {
|
else {
|
||||||
r_print_cursor(p, j, 1);
|
r_print_byte(p, "%c", j,
|
||||||
p->printf("%c", (IS_PRINTABLE(buf[j]))?
|
(IS_PRINTABLE(buf[j]))?
|
||||||
buf[j] : '.');
|
buf[j] : '.');
|
||||||
r_print_cursor(p, j, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p->printf("\n");
|
p->printf("\n");
|
||||||
|
18
libr/print/t/fmt.c
Normal file
18
libr/print/t/fmt.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include "r_cons.h"
|
||||||
|
#include "r_print.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
struct r_print_t *p;
|
||||||
|
const u8 buf[] = "1234578901234567890";
|
||||||
|
|
||||||
|
p = r_print_new();
|
||||||
|
p->printf = r_cons_printf;
|
||||||
|
r_cons_init();
|
||||||
|
r_print_format(p, 0LL, buf, 10, "xxd foo bar cow");
|
||||||
|
r_print_format(p, 0LL, buf, 10, "xxd");
|
||||||
|
r_cons_flush();
|
||||||
|
r_print_free(p);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user