* Add RIOMap in r_core_file_open

- RCore.file_open() now accepts one more arg for offset
  - Fix RIO api issues related to RIOMap and opening multiple files
  - Fix infinite loop and simplify design
  - Added test case to ensure it does not breaks
* Fix build of r_lang in OSX (thanks @capri_x)
* Remove debugging printfs
* io.ffio is now true by default
This commit is contained in:
pancake 2011-02-12 01:52:41 +01:00
parent 68e88b956c
commit f950dcb33c
19 changed files with 146 additions and 165 deletions

8
TODO
View File

@ -3,6 +3,14 @@
| < V . | . V . < _/ .-' _/| () |
|__\__|_|__|___/__|__|_\__\___/ |____(_)____/
BINARY INFORMATION
==================
dwarf, pdb, def, lib
load symbols from .lib or .def (find signatures)
.def -> .idt
.lib -> ar2idt
UNDER DEVELOPMENT
=================
* r2-swig : Distribute generated .i files and cxx files.. so build is faster

View File

@ -162,20 +162,19 @@ int main(int argc, char **argv) {
strcat (file, " ");
}
fh = r_core_file_open (&r, file, perms);
fh = r_core_file_open (&r, file, perms, 0LL);
// TODO: move into if (debug) ..
r_debug_use (r.dbg, "native");
} else {
if (optind<argc) {
while (optind < argc)
fh = r_core_file_open (&r, argv[optind++], perms);
fh = r_core_file_open (&r, argv[optind++], perms, 0);
} else {
const char *prj = r_config_get (r.config, "file.project");
if (prj && *prj) {
char *file = r_core_project_info (&r, prj);
if (file) {
fh = r_core_file_open (&r, file, perms);
} else eprintf ("No file\n");
if (file) fh = r_core_file_open (&r, file, perms, 0);
else eprintf ("No file\n");
}
}
}

View File

@ -51,7 +51,7 @@ R_API char *r_anal_cc_to_string (RAnal *anal, RAnalCC* cc) {
const char *a0 = r_reg_get_name (anal->reg, R_REG_NAME_A0); // A0 or RET ??
item = r_reg_get (anal->reg, a0, R_REG_TYPE_GPR);
if (!item) {
eprintf ("cannot get reg a0\n");
//eprintf ("cannot get reg a0\n");
return R_FALSE;
}
eax = (int)r_reg_get_value (anal->reg, item);

View File

@ -1537,7 +1537,7 @@ static int cmd_cmp(void *data, const char *input) {
}
core2->io->va = core->io->va;
core2->anal->split = core->anal->split;
if (!r_core_file_open (core2, file2, 0)) {
if (!r_core_file_open (core2, file2, 0, 0LL)) {
eprintf ("Cannot open diff file '%s'\n", file2);
r_core_free (core2);
return R_FALSE;
@ -3158,20 +3158,18 @@ static int cmd_open(void *data, const char *input) {
case ' ':
ptr = strchr (input+1, ' ');
if (ptr) *ptr = '\0';
file = r_core_file_open (core, input+1, R_IO_READ);
addr = ptr?r_num_math (core->num, ptr+1):0LL;
file = r_core_file_open (core, input+1, R_IO_READ, addr);
if (file) {
if (ptr) {
addr = r_num_math (core->num, ptr+1);
size = r_io_size (core->io);
file->map = r_io_map_add (core->io, file->fd->fd, R_IO_READ, 0, addr, size);
eprintf ("Map '%s' in 0x%08"PFMT64x" with size 0x%"PFMT64x"\n",
input+1, addr, file->size);
}
//eprintf ("Map '%s' in 0x%08"PFMT64x" with size 0x%"PFMT64x"\n",
// input+1, addr, file->size);
} else eprintf ("Cannot open file '%s'\n", input+1);
r_core_block_read (core, 0);
break;
case '-':
if (!r_core_file_close_fd (core, atoi (input+1)))
eprintf ("Unable to find filedescriptor %d\n", atoi (input+1));
r_core_block_read (core, 0);
break;
case '?':
default:

View File

@ -376,7 +376,7 @@ R_API int r_core_config_init(RCore *core) {
r_config_set_i_cb (cfg, "search.align", 0, &config_searchalign_callback);
r_config_set (cfg, "search.asmstr", "true");
r_config_set_cb (cfg, "scr.html", "false", &config_scrhtml_callback);
r_config_set_cb (cfg, "io.ffio", "false", &config_ioffio_callback);
r_config_set_cb (cfg, "io.ffio", "true", &config_ioffio_callback);
r_config_set_cb (cfg, "io.va", "true", &config_iova_callback);
r_config_set_cb (cfg, "io.cache", "false", &config_iocache_callback);
r_config_set (cfg, "file.path", "");

View File

@ -30,7 +30,6 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) {
core->block, core->blocksize);
break;
}
/* return value */
switch (str[1]) {
case '{':
@ -477,19 +476,25 @@ reaccept:
eprintf ("open (%d): ", cmd);
r_socket_read_block (c, &cmd, 1); // len
pipefd = -1;
ptr = malloc (cmd);
//XXX cmd is ut8..so <256 if (cmd<RMT_MAX) {
ptr = malloc(cmd);
if (ptr == NULL) {
eprintf ("Cannot malloc in rmt-open len = %d\n", cmd);
} else {
r_socket_read_block (c, ptr, cmd); //filename
ptr[cmd] = 0;
r_core_file_open (core, (const char *)ptr, R_IO_READ); // XXX: mode write?
if (ptr == NULL) {
eprintf ("Cannot malloc in rmt-open len = %d\n", cmd);
} else {
RCoreFile *file;
r_socket_read_block (c, ptr, cmd); //filename
ptr[cmd] = 0;
file = r_core_file_open (core, (const char *)ptr, R_IO_READ, 0); // XXX: write mode?
if (file) {
file->map = r_io_map_add (core->io, file->fd->fd, R_IO_READ, 0, 0, file->size);
pipefd = core->file->fd->fd;
eprintf("(flags: %hhd) len: %hhd filename: '%s'\n",
eprintf ("(flags: %hhd) len: %hhd filename: '%s'\n",
flg, cmd, ptr); //config.file);
} else {
pipefd = -1;
eprintf ("Cannot open file (%s)\n", ptr);
}
//}
}
buf[0] = RMT_OPEN | RMT_REPLY;
r_mem_copyendian (buf+1, (ut8 *)&pipefd, 4, !endian);
r_socket_write (c, buf, 5);

View File

@ -160,6 +160,9 @@ R_API int r_core_bin_load(RCore *r, const char *file) {
// z -> Strings
r_flag_space_set (r->flags, "strings");
if ((list = r_bin_get_strings (r->bin)) != NULL) {
if (r_list_length (list) > 1024) {
eprintf ("rabin2: too many strings. not importing string info\n");
} else
r_list_foreach (list, iter, string) {
/* Jump the withespaces before the string */
for (i=0;*(string->string+i)==' ';i++);
@ -218,7 +221,7 @@ R_API int r_core_bin_load(RCore *r, const char *file) {
return R_TRUE;
}
R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int mode) {
R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int mode, ut64 loadaddr) {
RCoreFile *fh;
const char *cp;
char *p;
@ -250,6 +253,7 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int mode) {
if (cp && *cp)
r_core_cmd (r, cp, 0);
r_config_set (r->config, "file.path", file);
fh->map = r_io_map_add (r->io, fh->fd->fd, mode, 0, loadaddr, fh->size);
return fh;
}

View File

@ -109,8 +109,10 @@ R_API int r_core_write_at(RCore *core, ut64 addr, const ut8 *buf, int size) {
}
R_API int r_core_block_read(RCore *core, int next) {
if (core->file == NULL)
if (core->file == NULL) {
memset (core->block, 0xff, core->blocksize);
return -1;
}
r_io_set_fd (core->io, core->file->fd);
r_io_seek (core->io, core->offset+((next)?core->blocksize:0), R_IO_SEEK_SET);
return r_io_read (core->io, core->block, core->blocksize);

View File

@ -132,7 +132,7 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch);
R_API int r_core_search_cb(RCore *core, ut64 from, ut64 to, RCoreSearchCallback cb);
R_API int r_core_serve(RCore *core, RIODesc *fd);
R_API void r_core_file_free(RCoreFile *cf);
R_API struct r_core_file_t *r_core_file_open(struct r_core_t *r, const char *file, int mode);
R_API struct r_core_file_t *r_core_file_open(struct r_core_t *r, const char *file, int mode, ut64 loadaddr);
R_API struct r_core_file_t *r_core_file_get_fd(struct r_core_t *core, int fd);
R_API int r_core_file_close(struct r_core_t *r, RCoreFile *fh);
R_API int r_core_file_close_fd(struct r_core_t *core, int fd);

View File

@ -37,7 +37,6 @@ typedef struct r_io_map_t {
ut64 delta;
ut64 from;
ut64 to;
struct list_head list;
} RIOMap;
typedef struct r_io_desc_t {
@ -220,9 +219,8 @@ R_API void r_io_map_init(RIO *io);
R_API RIOMap *r_io_map_add(RIO *io, int fd, int flags, ut64 delta, ut64 offset, ut64 size);
R_API int r_io_map_del(RIO *io, int fd);
R_API int r_io_map(RIO *io, const char *file, ut64 offset);
R_API int r_io_map_read_at(RIO *io, ut64 off, ut8 *buf, int len);
R_API int r_io_map_select(RIO *io, ut64 off);
//R_API int r_io_map_read_rest(RIO *io, ut64 off, ut8 *buf, ut64 len);
R_API int r_io_map_write_at(RIO *io, ut64 off, const ut8 *buf, int len);
R_API RIOMap *r_io_map_resolve(RIO *io, int fd);
/* io/section.c */

View File

@ -35,8 +35,7 @@ R_API RBuffer *r_io_read_buf(struct r_io_t *io, ut64 addr, int len) {
RBuffer *b = R_NEW (RBuffer);
b->buf = malloc (len);
len = r_io_read_at (io, addr, b->buf, len);
if (len<0) len = 0;
b->length = len;
b->length = (len<0)?0:len;
return b;
}
@ -144,14 +143,14 @@ R_API int r_io_set_fdn(RIO *io, int fd) {
return R_FALSE;
}
R_API int r_io_read(struct r_io_t *io, ut8 *buf, int len) {
R_API int r_io_read(RIO *io, ut8 *buf, int len) {
ut64 off;
int ret;
if (io==NULL || io->fd == NULL)
return -1;
/* check section permissions */
if (io->enforce_rwx && !(r_io_section_get_rwx (io, io->off) & R_IO_READ))
return -1;
#if 0
if (io->cached) {
ret = r_io_cache_read (io, io->off, buf, len);
@ -166,14 +165,8 @@ R_API int r_io_read(struct r_io_t *io, ut8 *buf, int len) {
return len;
}
#endif
ret = r_io_map_read_at (io, io->off, buf, len);
// partial reads
if (ret != len) {
if (ret != -1) {
len -= ret;
buf += len;
}
off = io->off;
if (r_io_map_select (io, io->off)) {
if (io->plugin && io->plugin->read) {
if (io->plugin->read != NULL)
ret = io->plugin->read (io, io->fd, buf, len);
@ -182,7 +175,8 @@ R_API int r_io_read(struct r_io_t *io, ut8 *buf, int len) {
if (ret>0 && ret<len)
memset (buf+ret, 0xff, len-ret);
}
r_io_cache_read (io, io->off, buf, len);
// this must be before?? r_io_cache_read (io, io->off, buf, len);
r_io_seek (io, off, R_IO_SEEK_SET);
return ret;
}
@ -256,7 +250,7 @@ R_API int r_io_write(struct r_io_t *io, const ut8 *buf, int len) {
buf = data;
}
if (!r_io_map_write_at (io, io->off, buf, len)) {
if (r_io_map_select (io, io->off)) {
if (io->plugin) {
if (io->plugin->write)
ret = io->plugin->write (io, io->fd, buf, len);
@ -279,7 +273,7 @@ R_API int r_io_write_at(struct r_io_t *io, ut64 addr, const ut8 *buf, int len) {
R_API ut64 r_io_seek(struct r_io_t *io, ut64 offset, int whence) {
int posix_whence = SEEK_SET;
ut64 ret = -1;
switch(whence) {
switch (whence) {
case R_IO_SEEK_SET:
posix_whence = SEEK_SET;
ret=offset;
@ -287,7 +281,7 @@ R_API ut64 r_io_seek(struct r_io_t *io, ut64 offset, int whence) {
case R_IO_SEEK_CUR:
// offset += io->off;
posix_whence = SEEK_CUR;
ret=offset+io->off;
ret = offset+io->off;
break;
case R_IO_SEEK_END:
//offset = UT64_MAX; // XXX: depending on io bits?

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2008-2010 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2008-2011 pancake<nopcode.org> */
#include <stdio.h>
#include <string.h>
@ -10,7 +10,7 @@ R_API void r_io_map_init(struct r_io_t *io) {
io->maps = r_list_new ();
}
R_API struct r_io_map_t *r_io_map_resolve(struct r_io_t *io, int fd) {
R_API RIOMap *r_io_map_resolve(struct r_io_t *io, int fd) {
RIOMap *map;
RListIter *iter;
r_list_foreach (io->maps, iter, map) {
@ -35,51 +35,31 @@ R_API int r_io_map_del(struct r_io_t *io, int fd) {
R_API RIOMap *r_io_map_add(struct r_io_t *io, int fd, int flags, ut64 delta, ut64 offset, ut64 size) {
RIOMap *im = R_NEW (RIOMap);
if (im) {
im->fd = fd;
im->flags = flags;
im->delta = delta;
im->from = offset;
im->to = offset + size;
r_list_append (io->maps, im);
}
if (!im) return NULL;
im->fd = fd;
im->flags = flags;
im->delta = delta;
im->from = offset;
im->to = offset + size;
r_list_append (io->maps, im);
return im;
}
R_API int r_io_map_read_at(RIO *io, ut64 off, ut8 *buf, int len) {
R_API int r_io_map_select(RIO *io, ut64 off) {
RIOMap *im;
RListIter *iter;
r_list_foreach (io->maps, iter, im) { // _prev?
if (im && off >= im->from && off < im->to) {
r_io_set_fdn (io, im->fd);
// XXX: Detect loop
if (im->from == 0) // wtf
return -1;
return r_io_read_at (io, off-im->from + im->delta, buf, len);
r_io_seek (io, off-im->from+im->delta, R_IO_SEEK_SET);
return R_TRUE;
}
}
return -1;
return R_FALSE;
}
R_API int r_io_map_write_at(struct r_io_t *io, ut64 off, const ut8 *buf, int len) {
RIOMap *im;
RListIter *iter;
r_list_foreach (io->maps, iter, im) {
if (im && off >= im->from && off < im->to) {
if (im->flags & R_IO_WRITE) {
r_io_set_fdn (io, im->fd);
return r_io_write_at (io, off-im->from + im->delta, buf, len);
} else return -1;
}
}
return 0;
}
// DEPRECATE ??? DEPREACATE
#if 0
int r_io_map_read_rest(struct r_io_t *io, ut64 off, ut8 *buf, ut64 len)
{
int r_io_map_read_rest(struct r_io_t *io, ut64 off, ut8 *buf, ut64 len) {
struct list_head *pos;
list_for_each_prev(pos, &io->maps) {
struct r_io_map_t *im = list_entry(pos, struct r_io_map_t, list);

2
libr/io/t/test/Makefile Normal file
View File

@ -0,0 +1,2 @@
all:
r2 -e io.ffio=1 -v a <script

1
libr/io/t/test/a Normal file
View File

@ -0,0 +1 @@
hello

1
libr/io/t/test/b Normal file
View File

@ -0,0 +1 @@
world

8
libr/io/t/test/script Normal file
View File

@ -0,0 +1,8 @@
o
x@0xbf9298d40000001c
x@0
x@0x1000
o b 0x1000
o
x@0
x@0x1000

View File

@ -1,5 +1,5 @@
NAME=r_lang
OBJ=lang.o
DEPS=r_util
DEPS=r_util r_lib
include ../rules.mk

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2010 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2007-2011 pancake<nopcode.org> */
#include "r_cons.h"
#include "r_util.h"
@ -31,23 +31,19 @@ static void print_mem_help(RPrint *p) {
/* TODO: needs refactoring */
R_API void r_print_format(struct r_print_t *p, ut64 seek, const ut8* buf, int len, const char *fmt) {
unsigned char buffer[256];
int endian = 0;
int i,j,idx;
int times, otimes;
char tmp, last = 0;
char *args, *bracket;
int nargs = 0;
int nargs, i, j, idx, times, otimes, endian;
char *args, *bracket, tmp, last = 0;
const char *arg = fmt;
const char *argend = arg+strlen(fmt);
ut64 addr = 0;
char namefmt[8];
i = j = 0;
nargs = endian = i = j = 0;
while (*arg && *arg==' ') arg = arg +1;
while (*arg && *arg==' ') arg++;
/* get times */
otimes = times = atoi(arg);
otimes = times = atoi (arg);
if (times > 0)
while ((*arg>='0'&&*arg<='9')) arg = arg +1;
while ((*arg>='0'&&*arg<='9')) arg++;
bracket = strchr (arg,'{');
if (bracket) {
char *end = strchr (arg,'}');
@ -148,36 +144,34 @@ R_API void r_print_format(struct r_print_t *p, ut64 seek, const ut8* buf, int le
#endif
case 'e': {
double doub;
memcpy(&doub, buf+i, sizeof(double));
p->printf("%e = ", doub);
p->printf("(double)");
memcpy (&doub, buf+i, sizeof (double));
p->printf ("%e = ", doub);
p->printf ("(double)");
i+=8;
}
break;
case 'q':
p->printf("0x%08x = ", seek+i);
p->printf("(qword)");
p->printf ("0x%08x = ", seek+i);
p->printf ("(qword)");
i+=8;
break;
case 'b':
p->printf("0x%08x = ", seek+i);
p->printf("%d ; 0x%02x ; '%c' ",
p->printf ("0x%08x = ", seek+i);
p->printf ("%d ; 0x%02x ; '%c' ",
buf[i], buf[i], IS_PRINTABLE(buf[i])?buf[i]:0);
i++;
break;
case 'B':
memset(buffer, '\0', 255);
if (p->read_at)
p->read_at((ut64)addr, buffer, 248, p->user);
else {
printf("(cannot read memory)\n");
if (!p->read_at) {
printf ("(cannot read memory)\n");
break;
}
p->printf("0x%08x = ", seek+i);
for(j=0;j<10;j++) p->printf("%02x ", buf[j]);
} else p->read_at ((ut64)addr, buffer, 248, p->user);
p->printf ("0x%08x = ", seek+i);
for (j=0;j<10;j++) p->printf ("%02x ", buf[j]);
p->printf(" ... (");
for(j=0;j<10;j++)
if (IS_PRINTABLE(buf[j]))
for (j=0;j<10;j++)
if (IS_PRINTABLE (buf[j]))
p->printf("%c", buf[j]);
p->printf(")");
i+=4;
@ -195,59 +189,59 @@ R_API void r_print_format(struct r_print_t *p, ut64 seek, const ut8* buf, int le
case 'X': {
ut32 addr32 = (ut32)addr;
//char buf[128];
p->printf("0x%08x = ", seek+i);
p->printf("0x%08"PFMT64x" ", addr32);
p->printf ("0x%08x = ", seek+i);
p->printf ("0x%08"PFMT64x" ", addr32);
//if (string_flag_offset(buf, (ut64)addr32, -1))
// p->printf("; %s", buf);
i+=4;
} break;
case 'w':
case '1': // word (16 bits)
p->printf("0x%08x = ", seek+i);
p->printf ("0x%08x = ", seek+i);
if (endian)
addr = (*(buf+i))<<8 | (*(buf+i+1));
else addr = (*(buf+i+1))<<8 | (*(buf+i));
p->printf("0x%04x ", addr);
p->printf ("0x%04x ", addr);
break;
case 'z': // zero terminated string
p->printf("0x%08x = ", seek+i);
for(;buf[i]&&i<len;i++) {
if (IS_PRINTABLE(buf[i]))
p->printf("%c", buf[i]);
else p->printf(".");
p->printf ("0x%08x = ", seek+i);
for (;buf[i]&&i<len; i++) {
if (IS_PRINTABLE (buf[i]))
p->printf ("%c", buf[i]);
else p->printf (".");
}
break;
case 'Z': // zero terminated wide string
p->printf("0x%08x = ", seek+i);
for(;buf[i]&&i<len;i+=2) {
if (IS_PRINTABLE(buf[i]))
p->printf("%c", buf[i]);
else p->printf(".");
p->printf ("0x%08x = ", seek+i);
for (;buf[i]&&i<len; i+=2) {
if (IS_PRINTABLE (buf[i]))
p->printf ("%c", buf[i]);
else p->printf (".");
}
p->printf(" ");
p->printf (" ");
break;
case 's':
p->printf("0x%08x = ", seek+i);
memset(buffer, '\0', 255);
p->printf ("0x%08x = ", seek+i);
memset (buffer, '\0', 255);
if (p->read_at)
p->read_at((ut64)addr, buffer, 248, p->user);
p->read_at ((ut64)addr, buffer, 248, p->user);
else {
printf("(cannot read memory)\n");
printf ("(cannot read memory)\n");
break;
}
p->printf("0x%08x -> 0x%08x ", seek+i, addr);
p->printf("%s ", buffer);
p->printf ("0x%08x -> 0x%08x ", seek+i, addr);
p->printf ("%s ", buffer);
i+=4;
break;
default:
/* ignore unknown chars */
break;
}
p->printf("\n");
p->printf ("\n");
last = tmp;
}
if (otimes>1)
p->printf("}\n");
p->printf ("}\n");
arg = orig;
idx = 0;
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2010 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2007-2011 pancake<nopcode.org> */
#include "r_cons.h"
#include "r_print.h"
@ -42,7 +42,7 @@ R_API RPrint *r_print_free(RPrint *p) {
R_API void r_print_set_cursor(RPrint *p, int enable, int ocursor, int cursor) {
p->cur_enabled = enable;
p->ocur = ocursor;
if (cursor<0) cursor=0;
if (cursor<0) cursor = 0;
p->cur = cursor;
}
@ -52,7 +52,7 @@ R_API void r_print_cursor(RPrint *p, int cur, int set) {
if (p->ocur != -1) {
int from = p->ocur;
int to = p->cur;
r_num_minmax_swap_i(&from, &to);
r_num_minmax_swap_i (&from, &to);
if (cur>=from&&cur<=to)
r_cons_invert (set, p->flags&R_PRINT_FLAGS_COLOR);
} else
@ -68,7 +68,7 @@ R_API void r_print_addr(RPrint *p, ut64 addr) {
p->printf("%s0x%08"PFMT64x""Color_RESET"%c ",
r_cons_singleton ()->palette[PAL_ADDRESS], addr, ch);
#endif
p->printf("0x%08"PFMT64x"%c ", addr, ch);
p->printf ("0x%08"PFMT64x"%c ", addr, ch);
} else r_cons_printf ("0x%08"PFMT64x"%c ", addr, ch);
}
@ -87,10 +87,10 @@ R_API char *r_print_hexpair(RPrint *p, const char *str, int n) {
cur = ocur;
ocur++;
#if CURDBG
sprintf(dst, "(%d/%d/%d/%d)", p->cur_enabled, cur, ocur, n);
d = dst+ strlen(dst);
sprintf(dst, "(%d/%d/%d/%d)", p->cur_enabled, cur, ocur, n);
d = dst+ strlen(dst);
#else
d = dst;
d = dst;
#endif
// XXX: overflow here
#define memcat(x,y) { memcpy(x,y,strlen(y));x+=strlen(y); }
@ -102,15 +102,10 @@ d = dst;
if (i>=cur-n && i<ocur-n)
memcat (d, "\x1b[7m");
}
if (s[0]=='0' && s[1]=='0') {
memcat (d, "\x1b[31m");
} else
if (s[0]=='f' && s[1]=='f') {
memcat (d, "\x1b[32m");
} else
if (s[0]=='7' && s[1]=='f') {
memcat (d, "\x1b[33m");
} else {
if (s[0]=='0' && s[1]=='0') { memcat (d, "\x1b[32m"); }
else if (s[0]=='7' && s[1]=='f') { memcat (d, "\x1b[33m"); }
else if (s[0]=='f' && s[1]=='f') { memcat (d, "\x1b[31m"); }
else {
sscanf (s, "%02x", &ch);
if (IS_PRINTABLE (ch))
memcat (d, "\x1b[35m");
@ -129,10 +124,10 @@ R_API void r_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch) {
//if (p->flags & R_PRINT_FLAGS_CURSOR && idx == p->cur) {
if (p->flags & R_PRINT_FLAGS_COLOR) {
char *pre = NULL;
switch(ch) {
case 0x00: pre = "\x1b[31m"; break;
case 0xFF: pre = "\x1b[32m"; break;
switch (ch) {
case 0x00: pre = "\x1b[32m"; break;
case 0x7F: pre = "\x1b[33m"; break;
case 0xFF: pre = "\x1b[31m"; break;
default:
if (IS_PRINTABLE (ch))
pre = "\x1b[35m";
@ -255,7 +250,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
R_API void r_print_bytes(RPrint *p, const ut8* buf, int len, const char *fmt) {
int i;
for (i=0;i<len;i++)
for (i=0; i<len; i++)
p->printf (fmt, buf[i]);
p->printf ("\n");
}
@ -325,17 +320,14 @@ void lsb_stego_process (FILE *fd, int length, bool forward, bool downward, int o
char dbyte; /* Destination byte (decrypted msg) */
for ( byte = offset ; byte < length ; )
{
for ( byte = offset ; byte < length ; ) {
dbyte = 0;
for (bit = 0; bit <= 7; bit++, byte++)
{
for (bit = 0; bit <= 7; bit++, byte++) {
/* Set position at the beginning or eof */
if (forward)
fseek(fd, byte, SEEK_SET);
else
fseek(fd, -(byte+1), SEEK_END);
else fseek(fd, -(byte+1), SEEK_END);
/* Read one byte */
fread(&sbyte, sizeof(sbyte), 1, fd);
@ -344,14 +336,9 @@ void lsb_stego_process (FILE *fd, int length, bool forward, bool downward, int o
lsb = sbyte & 1;
/* Add lsb to decrypted message */
if (downward)
dbyte = dbyte | lsb << (7-bit) ;
else
dbyte = dbyte | lsb << bit ;
dbyte = dbyte | lsb << ((downward)?(7-bit):bit);
}
printf ("%c", dbyte);
}
}
#endif