mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-29 16:10:52 +00:00
Merged
This commit is contained in:
commit
f96c6b51b2
@ -126,7 +126,7 @@ R_API char *r_anal_strmask (RAnal *anal, const char *data) {
|
||||
int oplen, len, idx = 0;
|
||||
|
||||
ret = strdup (data);
|
||||
buf = malloc (strlen (data));
|
||||
buf = malloc (1+strlen (data));
|
||||
op = r_anal_op_new ();
|
||||
if (op == NULL || ret == NULL || buf == NULL) {
|
||||
free (op);
|
||||
|
@ -29,9 +29,9 @@ R_API int r_anal_diff_fingerprint_bb(RAnal *anal, RAnalBlock *bb) {
|
||||
if (anal && anal->cur && anal->cur->fingerprint_bb)
|
||||
return (anal->cur->fingerprint_bb (anal, bb));
|
||||
|
||||
if (!(bb->fingerprint = malloc (bb->size)))
|
||||
if (!(bb->fingerprint = malloc (1+bb->size)))
|
||||
return R_FALSE;
|
||||
if (!(buf = malloc (bb->size))) {
|
||||
if (!(buf = malloc (1+bb->size))) {
|
||||
free (bb->fingerprint);
|
||||
return 0;
|
||||
}
|
||||
|
@ -254,10 +254,12 @@ struct r_range_t *r_meta_ranges(RMeta *m)
|
||||
|
||||
static void printmetaitem(RMeta *m, RMetaItem *d) {
|
||||
char *str = r_str_unscape (d->str);
|
||||
if (str) {
|
||||
m->printf ("%s %d \"%s\" @ 0x%08"PFMT64x"\n",
|
||||
r_meta_type_to_string (d->type),
|
||||
(int)(d->to-d->from), str, d->from);
|
||||
free (str);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Deprecate
|
||||
|
@ -455,10 +455,8 @@ static int read_bin(struct state *s, struct directive *d) {
|
||||
}
|
||||
|
||||
static struct directive *next_inst(struct state *s) {
|
||||
struct directive *d;
|
||||
int rd;
|
||||
|
||||
d = malloc (sizeof (*d));
|
||||
struct directive *d = malloc (sizeof (*d));
|
||||
if (!d) {
|
||||
perror ("malloc()");
|
||||
return NULL;
|
||||
|
@ -298,13 +298,12 @@ int java_classdump(const char *file, int verbose) {
|
||||
|
||||
cf.cp_count--;
|
||||
V printf("ConstantPoolCount %d\n", cf.cp_count);
|
||||
cp_items = malloc(sizeof(struct cp_item)*(cf.cp_count+1));
|
||||
cp_items = malloc (sizeof (struct cp_item)*(cf.cp_count+1));
|
||||
for(i=0;i<cf.cp_count;i++) {
|
||||
struct constant_t *c;
|
||||
fread(buf, 1, 1, fd);
|
||||
|
||||
fread (buf, 1, 1, fd);
|
||||
c = NULL;
|
||||
for(j=0;constants[j].name;j++) {
|
||||
for (j=0; constants[j].name; j++) {
|
||||
if (constants[j].tag == buf[0]) {
|
||||
c = &constants[j];
|
||||
break;
|
||||
|
@ -231,14 +231,14 @@ R_API RAsmCode* r_asm_mdisassemble(RAsm *a, ut8 *buf, ut64 len) {
|
||||
|
||||
if (!(acode = r_asm_code_new()))
|
||||
return NULL;
|
||||
if (!(acode->buf = malloc (len)))
|
||||
if (!(acode->buf = malloc (1+len)))
|
||||
return r_asm_code_free (acode);
|
||||
memcpy (acode->buf, buf, len);
|
||||
if (!(acode->buf_hex = malloc(2*len+1)))
|
||||
if (!(acode->buf_hex = malloc (2*len+1)))
|
||||
return r_asm_code_free(acode);
|
||||
r_hex_bin2str(buf, len, acode->buf_hex);
|
||||
if (!(acode->buf_asm = malloc(2)))
|
||||
return r_asm_code_free(acode);
|
||||
if (!(acode->buf_asm = malloc (2)))
|
||||
return r_asm_code_free (acode);
|
||||
|
||||
for (idx = ret = slen = 0, acode->buf_asm[0] = '\0'; idx < len; idx+=ret) {
|
||||
r_asm_set_pc(a, a->pc + ret);
|
||||
@ -262,7 +262,7 @@ R_API RAsmCode* r_asm_mdisassemble_hexstr(RAsm *a, const char *hexstr) {
|
||||
ut8 *buf;
|
||||
int len;
|
||||
|
||||
if (!(buf = malloc (strlen (hexstr))))
|
||||
if (!(buf = malloc (1+strlen (hexstr))))
|
||||
return NULL;
|
||||
len = r_hex_str2bin (hexstr, buf);
|
||||
ret = r_asm_mdisassemble (a, buf, len);
|
||||
|
@ -44,7 +44,7 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
if (buf_global == NULL || format == NULL)
|
||||
return R_FALSE;
|
||||
va_start (ap, format);
|
||||
tmp = malloc (strlen(format)+strlen(buf_global)+2);
|
||||
tmp = malloc (strlen (format)+strlen (buf_global)+2);
|
||||
if (tmp == NULL)
|
||||
return R_FALSE;
|
||||
sprintf (tmp, "%s%s", buf_global, format);
|
||||
|
@ -13,7 +13,7 @@ char* r_bin_dex_get_version(struct r_bin_dex_obj_t* bin) {
|
||||
struct r_bin_dex_obj_t* r_bin_dex_new_buf(struct r_buf_t *buf) {
|
||||
struct r_bin_dex_obj_t *bin;
|
||||
|
||||
if (!(bin = malloc(sizeof(struct r_bin_dex_obj_t))))
|
||||
if (!(bin = malloc (sizeof (struct r_bin_dex_obj_t))))
|
||||
return NULL;
|
||||
memset (bin, 0, sizeof (struct r_bin_dex_obj_t));
|
||||
bin->b = buf;
|
||||
|
@ -458,7 +458,7 @@ char *Elf_(r_bin_elf_get_rpath)(struct Elf_(r_bin_elf_obj_t) *bin) {
|
||||
return NULL;
|
||||
for (i = 0; i < bin->ehdr.e_phnum; i++)
|
||||
if (bin->phdr[i].p_type == PT_DYNAMIC) {
|
||||
if (!(dyn = malloc (bin->phdr[i].p_filesz))) {
|
||||
if (!(dyn = malloc (1+bin->phdr[i].p_filesz))) {
|
||||
perror ("malloc (dyn)");
|
||||
return NULL;
|
||||
}
|
||||
@ -552,6 +552,8 @@ struct r_bin_elf_reloc_t* Elf_(r_bin_elf_get_relocs)(struct Elf_(r_bin_elf_obj_t
|
||||
else if (!strcmp (&bin->strtab[bin->shdr[i].sh_name], ".rela.plt"))
|
||||
tsize = sizeof (Elf_(Rela));
|
||||
else continue;
|
||||
if (tsize <1)
|
||||
return ret; // -1 ?
|
||||
if ((rel = (Elf_(Rel) *)malloc ((int)(bin->shdr[i].sh_size / tsize) * sizeof (Elf_(Rel)))) == NULL) {
|
||||
perror ("malloc (rel)");
|
||||
return NULL;
|
||||
|
@ -55,9 +55,9 @@ ut64 Elf_(r_bin_elf_resize_section)(struct Elf_(r_bin_elf_obj_t) *bin, const cha
|
||||
for (i = 0, shdrp = shdr; i < ehdr->e_shnum; i++, shdrp++) {
|
||||
if (!strcmp(&strtab[shdrp->sh_name], ".rel.plt")) {
|
||||
Elf_(Rel) *rel, *relp;
|
||||
rel = (Elf_(Rel) *)malloc(shdrp->sh_size);
|
||||
rel = (Elf_(Rel) *)malloc (1+shdrp->sh_size);
|
||||
if (rel == NULL) {
|
||||
perror("malloc");
|
||||
perror ("malloc");
|
||||
return 0;
|
||||
}
|
||||
if (r_buf_read_at(bin->b, shdrp->sh_offset, (ut8*)rel, shdrp->sh_size) == -1)
|
||||
@ -78,7 +78,7 @@ ut64 Elf_(r_bin_elf_resize_section)(struct Elf_(r_bin_elf_obj_t) *bin, const cha
|
||||
break;
|
||||
} else if (!strcmp(&strtab[shdrp->sh_name], ".rela.plt")) {
|
||||
Elf_(Rela) *rel, *relp;
|
||||
rel = (Elf_(Rela) *)malloc(shdrp->sh_size);
|
||||
rel = (Elf_(Rela) *)malloc (1+shdrp->sh_size);
|
||||
if (rel == NULL) {
|
||||
perror("malloc");
|
||||
return 0;
|
||||
@ -153,7 +153,7 @@ ut64 Elf_(r_bin_elf_resize_section)(struct Elf_(r_bin_elf_obj_t) *bin, const cha
|
||||
/* XXX Check when delta is negative */
|
||||
rest_size = bin->size - (rsz_offset + rsz_osize);
|
||||
|
||||
buf = (ut8 *)malloc (bin->size);
|
||||
buf = (ut8 *)malloc (1+bin->size);
|
||||
r_buf_read_at (bin->b, 0, (ut8*)buf, bin->size);
|
||||
r_buf_set_bytes (bin->b, (ut8*)buf, (int)(rsz_offset+rsz_size+rest_size));
|
||||
|
||||
@ -176,7 +176,7 @@ int Elf_(r_bin_elf_del_rpath)(struct Elf_(r_bin_elf_obj_t) *bin) {
|
||||
|
||||
for (i = 0; i < bin->ehdr.e_phnum; i++)
|
||||
if (bin->phdr[i].p_type == PT_DYNAMIC) {
|
||||
if (!(dyn = malloc (bin->phdr[i].p_filesz))) {
|
||||
if (!(dyn = malloc (1+bin->phdr[i].p_filesz))) {
|
||||
perror ("malloc (dyn)");
|
||||
return R_FALSE;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ static int attributes_walk(struct r_bin_java_obj_t *bin, struct r_bin_java_attr_
|
||||
IFDBG printf(" code Attributes_count: %d\n", sz4);
|
||||
|
||||
if (sz4>0) {
|
||||
attr->attributes = malloc(sz4 * sizeof(struct r_bin_java_attr_t));
|
||||
attr->attributes = malloc(1+sz4 * sizeof(struct r_bin_java_attr_t));
|
||||
attributes_walk(bin, attr->attributes, sz4, fields);
|
||||
}
|
||||
} else
|
||||
@ -177,7 +177,7 @@ static int javasm_init(struct r_bin_java_obj_t *bin) {
|
||||
bin->cf.cp_count--;
|
||||
|
||||
IFDBG printf("ConstantPoolCount %d\n", bin->cf.cp_count);
|
||||
bin->cp_items = malloc(sizeof(struct r_bin_java_cp_item_t)*(bin->cf.cp_count+1));
|
||||
bin->cp_items = malloc (sizeof (struct r_bin_java_cp_item_t)*(bin->cf.cp_count+1));
|
||||
for(i=0;i<bin->cf.cp_count;i++) {
|
||||
struct constant_t *c;
|
||||
|
||||
@ -274,7 +274,7 @@ static int javasm_init(struct r_bin_java_obj_t *bin) {
|
||||
bin->fields_count = sz;
|
||||
IFDBG printf("Fields count: %d\n", sz);
|
||||
if (sz>0) {
|
||||
bin->fields = malloc(sz * sizeof(struct r_bin_java_fm_t));
|
||||
bin->fields = malloc (1+sz * sizeof(struct r_bin_java_fm_t));
|
||||
for (i=0;i<sz;i++) {
|
||||
r_buf_read_at(bin->b, R_BUF_CUR, (ut8*)buf, 8);
|
||||
bin->fields[i].flags = R_BIN_JAVA_USHORT(buf, 0);
|
||||
@ -289,7 +289,7 @@ static int javasm_init(struct r_bin_java_obj_t *bin) {
|
||||
bin->fields[i].attr_count = sz2;
|
||||
IFDBG printf(" field Attributes Count: %d\n", sz2);
|
||||
if (sz2 > 0) {
|
||||
bin->fields[i].attributes = malloc(sz2 * sizeof(struct r_bin_java_attr_t));
|
||||
bin->fields[i].attributes = malloc(1+sz2 * sizeof(struct r_bin_java_attr_t));
|
||||
for(j=0;j<sz2;j++)
|
||||
attributes_walk(bin, &bin->fields[i].attributes[j], sz2, 1);
|
||||
}
|
||||
@ -324,7 +324,7 @@ static int javasm_init(struct r_bin_java_obj_t *bin) {
|
||||
bin->methods[i].attr_count = sz2;
|
||||
IFDBG printf(" method Attributes Count: %d\n", sz2);
|
||||
if (sz2 > 0) {
|
||||
bin->methods[i].attributes = malloc(sz2 * sizeof(struct r_bin_java_attr_t));
|
||||
bin->methods[i].attributes = malloc(1+sz2 * sizeof(struct r_bin_java_attr_t));
|
||||
for(j=0;j<sz2;j++) {
|
||||
if (!attributes_walk (bin, &bin->methods[i].attributes[j], sz2, 0))
|
||||
return R_FALSE;
|
||||
@ -356,7 +356,7 @@ struct r_bin_java_sym_t* r_bin_java_get_symbols(struct r_bin_java_obj_t* bin) {
|
||||
struct r_bin_java_sym_t *symbols;
|
||||
int i, j, ctr = 0;
|
||||
|
||||
if ((symbols = malloc((bin->methods_count + 1) * sizeof(struct r_bin_java_sym_t))) == NULL)
|
||||
if ((symbols = malloc ((bin->methods_count + 1) * sizeof(struct r_bin_java_sym_t))) == NULL)
|
||||
return NULL;
|
||||
for (i=0; i < bin->methods_count; i++) {
|
||||
memcpy(symbols[ctr].name, bin->methods[i].name, R_BIN_JAVA_MAXSTR);
|
||||
|
@ -34,7 +34,7 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj
|
||||
if (bin->nlibs < 0 || idx < 0 || idx > bin->nlibs)
|
||||
return NULL;
|
||||
*nlib = bin->nlibs;
|
||||
if (!(ret = malloc (sizeof(struct r_bin_dyldcache_lib_t)))) {
|
||||
if (!(ret = malloc (sizeof (struct r_bin_dyldcache_lib_t)))) {
|
||||
perror ("malloc (ret)");
|
||||
return NULL;
|
||||
}
|
||||
@ -153,7 +153,7 @@ void* r_bin_dyldcache_free(struct r_bin_dyldcache_obj_t* bin) {
|
||||
struct r_bin_dyldcache_obj_t* r_bin_dyldcache_new(const char* file) {
|
||||
struct r_bin_dyldcache_obj_t *bin;
|
||||
ut8 *buf;
|
||||
if (!(bin = malloc(sizeof(struct r_bin_dyldcache_obj_t))))
|
||||
if (!(bin = malloc (sizeof (struct r_bin_dyldcache_obj_t))))
|
||||
return NULL;
|
||||
memset (bin, 0, sizeof (struct r_bin_dyldcache_obj_t));
|
||||
bin->file = file;
|
||||
|
@ -16,6 +16,8 @@ static int r_bin_fatmach0_init(struct r_bin_fatmach0_obj_t* bin) {
|
||||
bin->nfat_arch = bin->hdr.nfat_arch;
|
||||
if (bin->hdr.magic != FAT_MAGIC || bin->nfat_arch == 0)
|
||||
return R_FALSE;
|
||||
if (bin->nfat_arch<1)
|
||||
return R_FALSE;
|
||||
if (!(bin->archs = malloc (bin->nfat_arch * sizeof (struct fat_arch)))) {
|
||||
perror ("malloc (fat_arch)");
|
||||
return R_FALSE;
|
||||
@ -35,7 +37,7 @@ struct r_bin_fatmach0_arch_t *r_bin_fatmach0_extract(struct r_bin_fatmach0_obj_t
|
||||
if (bin->hdr.nfat_arch < 0 || idx < 0 || idx > bin->hdr.nfat_arch)
|
||||
return NULL;
|
||||
*narch = bin->hdr.nfat_arch;
|
||||
if (!(ret = malloc (sizeof(struct r_bin_fatmach0_arch_t)))) {
|
||||
if (!(ret = malloc (sizeof (struct r_bin_fatmach0_arch_t)))) {
|
||||
perror ("malloc (ret)");
|
||||
return NULL;
|
||||
}
|
||||
@ -44,7 +46,7 @@ struct r_bin_fatmach0_arch_t *r_bin_fatmach0_extract(struct r_bin_fatmach0_obj_t
|
||||
free (ret);
|
||||
return NULL;
|
||||
}
|
||||
if (!(buf = malloc (bin->archs[idx].size))) {
|
||||
if (!(buf = malloc (1+bin->archs[idx].size))) {
|
||||
perror ("malloc (buf)");
|
||||
free (ret);
|
||||
return NULL;
|
||||
@ -86,11 +88,11 @@ struct r_bin_fatmach0_obj_t* r_bin_fatmach0_new(const char* file) {
|
||||
struct r_bin_fatmach0_obj_t *bin;
|
||||
ut8 *buf;
|
||||
|
||||
if (!(bin = malloc(sizeof(struct r_bin_fatmach0_obj_t))))
|
||||
if (!(bin = malloc (sizeof (struct r_bin_fatmach0_obj_t))))
|
||||
return NULL;
|
||||
memset (bin, 0, sizeof (struct r_bin_fatmach0_obj_t));
|
||||
bin->file = file;
|
||||
if (!(buf = (ut8*)r_file_slurp(file, &bin->size)))
|
||||
if (!(buf = (ut8*)r_file_slurp (file, &bin->size)))
|
||||
return r_bin_fatmach0_free(bin);
|
||||
bin->b = r_buf_new();
|
||||
if (!r_buf_set_bytes(bin->b, buf, bin->size))
|
||||
|
@ -101,17 +101,17 @@ static int MACH0_(r_bin_mach0_parse_symtab)(struct MACH0_(r_bin_mach0_obj_t)* bi
|
||||
}
|
||||
if (st.strsize > 0 && st.strsize < bin->size && st.nsyms > 0) {
|
||||
bin->nsymtab = st.nsyms;
|
||||
if (!(bin->symstr = malloc(st.strsize))) {
|
||||
if (!(bin->symstr = malloc (st.strsize))) {
|
||||
perror("malloc (symstr)");
|
||||
return R_FALSE;
|
||||
}
|
||||
bin->symstrlen = st.strsize;
|
||||
if (r_buf_read_at(bin->b, st.stroff, (ut8*)bin->symstr, st.strsize) == -1) {
|
||||
if (r_buf_read_at (bin->b, st.stroff, (ut8*)bin->symstr, st.strsize) == -1) {
|
||||
eprintf("Error: read (symstr)\n");
|
||||
R_FREE (bin->symstr);
|
||||
return R_FALSE;
|
||||
}
|
||||
if (!(bin->symtab = malloc(bin->nsymtab * sizeof(struct MACH0_(nlist))))) {
|
||||
if (!(bin->symtab = malloc (bin->nsymtab * sizeof (struct MACH0_(nlist))))) {
|
||||
perror("malloc (symtab)");
|
||||
return R_FALSE;
|
||||
}
|
||||
@ -140,7 +140,7 @@ static int MACH0_(r_bin_mach0_parse_dysymtab)(struct MACH0_(r_bin_mach0_obj_t)*
|
||||
}
|
||||
bin->ntoc = bin->dysymtab.ntoc;
|
||||
if (bin->ntoc > 0) {
|
||||
if (!(bin->toc = malloc(bin->ntoc * sizeof(struct dylib_table_of_contents)))) {
|
||||
if (!(bin->toc = malloc (bin->ntoc * sizeof(struct dylib_table_of_contents)))) {
|
||||
perror("malloc (toc)");
|
||||
return R_FALSE;
|
||||
}
|
||||
@ -153,7 +153,7 @@ static int MACH0_(r_bin_mach0_parse_dysymtab)(struct MACH0_(r_bin_mach0_obj_t)*
|
||||
}
|
||||
bin->nmodtab = bin->dysymtab.nmodtab;
|
||||
if (bin->nmodtab > 0) {
|
||||
if (!(bin->modtab = malloc(bin->nmodtab * sizeof(struct MACH0_(dylib_module))))) {
|
||||
if (!(bin->modtab = malloc (bin->nmodtab * sizeof(struct MACH0_(dylib_module))))) {
|
||||
perror("malloc (modtab)");
|
||||
return R_FALSE;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ R_API RCmd *r_cmd_new () {
|
||||
INIT_LIST_HEAD (&cmd->lcmds);
|
||||
for (i=0;i<255;i++)
|
||||
cmd->cmds[i] = NULL;
|
||||
cmd->nullcallback =
|
||||
cmd->data = NULL;
|
||||
}
|
||||
r_cmd_plugin_init (cmd);
|
||||
|
@ -1,5 +1,6 @@
|
||||
NAME=r_cons
|
||||
OBJ=cons.o pipe.o output.o grep.o input.o color.o
|
||||
OBJ=cons.o pipe.o output.o grep.o input.o
|
||||
#color.o
|
||||
DEPS=r_util
|
||||
#r_line ??
|
||||
#LINK=../line/*.o ../util/*.a
|
||||
|
@ -1,5 +1,7 @@
|
||||
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
||||
|
||||
// XXX: deprecate this stuff
|
||||
|
||||
#include <r_cons.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -40,16 +42,6 @@ static const char *r_cons_color_names[CONS_COLORS_SIZE+1] = {
|
||||
"bgreen", "byellow", "bturqoise", "reset", "bgblack", "bgred", NULL
|
||||
};
|
||||
|
||||
R_API void r_cons_invert(int set, int color) {
|
||||
if (color) {
|
||||
if (set) r_cons_strcat("\x1b[7m");
|
||||
else r_cons_strcat("\x1b[27m");
|
||||
} else {
|
||||
if (set) r_cons_strcat("[");
|
||||
else r_cons_strcat("]");
|
||||
}
|
||||
}
|
||||
|
||||
static const char *r_cons_colors[CONS_COLORS_SIZE+1] = {
|
||||
Color_BLACK, // 0
|
||||
Color_GRAY, // 1
|
||||
|
@ -344,3 +344,13 @@ R_API void r_cons_set_raw(int is_raw) {
|
||||
#endif
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
R_API void r_cons_invert(int set, int color) {
|
||||
if (color) {
|
||||
if (set) r_cons_strcat("\x1b[7m");
|
||||
else r_cons_strcat("\x1b[27m");
|
||||
} else {
|
||||
if (set) r_cons_strcat("[");
|
||||
else r_cons_strcat("]");
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> nibble<develsec.org> */
|
||||
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> nibble<develsec.org> */
|
||||
|
||||
#include <r_cons.h>
|
||||
#include <r_util.h>
|
||||
@ -116,7 +116,7 @@ R_API int r_cons_grepbuf(char *buf, int len) {
|
||||
free (tbuf);
|
||||
free (tline);
|
||||
if (cons->grep.counter) {
|
||||
sprintf (cons->buffer, "%d\n", cons->lines);
|
||||
snprintf (cons->buffer, cons->buffer_len, "%d\n", cons->lines);
|
||||
cons->buffer_len = strlen (cons->buffer);;
|
||||
}
|
||||
return cons->lines;
|
||||
@ -127,7 +127,7 @@ R_API int r_cons_grep_line(char *buf, int len) {
|
||||
const char delims[6][2] = { "|", "/", "\\", ",", ";", "\t" };
|
||||
char *in, *out, *tok = NULL;
|
||||
int hit = cons->grep.neg;
|
||||
int i, j;
|
||||
int i, j, outlen = 0;
|
||||
|
||||
in = calloc (1, len+1);
|
||||
out = calloc (1, len+2);
|
||||
@ -148,22 +148,30 @@ R_API int r_cons_grep_line(char *buf, int len) {
|
||||
if (in[i] == delims[j][0])
|
||||
in[i] = ' ';
|
||||
for (i=0; i <= cons->grep.tokento; i++) {
|
||||
if (i==0) tok = (char *)strtok (in, " ");
|
||||
else tok = (char *)strtok (NULL, " ");
|
||||
if (tok == NULL) {
|
||||
tok = (char *) strtok (i?NULL:in, " ");
|
||||
if (tok) {
|
||||
if (i >= cons->grep.tokenfrom) {
|
||||
int toklen = strlen (tok);
|
||||
memcpy (out+outlen, tok, toklen);
|
||||
memcpy (out+outlen+toklen, " ", 2);
|
||||
outlen += toklen+1;
|
||||
}
|
||||
} else {
|
||||
if (strlen (out) == 0) {
|
||||
free (in);
|
||||
free (out);
|
||||
return -1;
|
||||
} else break;
|
||||
}
|
||||
if (i >= cons->grep.tokenfrom) {
|
||||
strcat (out, tok);
|
||||
strcat (out, " ");
|
||||
}
|
||||
outlen = outlen>0? outlen - 1: 0;
|
||||
if (outlen>len) { // should never happen
|
||||
eprintf ("r_cons_grep_line: wtf, how you reach this?\n");
|
||||
return -1;
|
||||
}
|
||||
len = strlen (out) - 1;
|
||||
memcpy (buf, out, len);
|
||||
len = outlen;
|
||||
|
||||
}
|
||||
} else len = 0;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
|
||||
|
||||
#include <r_cons.h>
|
||||
#include <string.h>
|
||||
|
@ -1,20 +1,24 @@
|
||||
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
|
||||
|
||||
#include <r_cons.h>
|
||||
#include <unistd.h>
|
||||
|
||||
//TODO: cons_pipe should be using a stack pipe_push, pipe_pop
|
||||
/* this is the base fd.. more than one is supported :) */
|
||||
static int backup_fd=999;
|
||||
static int backup_fd = 10;
|
||||
|
||||
R_API int r_cons_pipe_open(const char *file, int append) {
|
||||
int fd = open(file, O_RDWR | O_CREAT | (append?O_APPEND:O_TRUNC), 0644);
|
||||
int fd = open (file, O_RDWR | O_CREAT | (append?O_APPEND:O_TRUNC), 0644);
|
||||
if (fd==-1) {
|
||||
eprintf ("Cannot open file '%s'\n", file);
|
||||
return -1;
|
||||
} else eprintf ("%s created\n", file);
|
||||
dup2 (1, backup_fd+fd);
|
||||
close(1);
|
||||
backup_fd = getdtablesize () - (fd-2);
|
||||
if (dup2 (1, backup_fd) == -1) {
|
||||
eprintf ("Cannot dup stdout to %d\n", backup_fd);
|
||||
return -1;
|
||||
}
|
||||
close (1);
|
||||
dup2 (fd, 1);
|
||||
return fd;
|
||||
}
|
||||
@ -22,47 +26,6 @@ R_API int r_cons_pipe_open(const char *file, int append) {
|
||||
R_API void r_cons_pipe_close(int fd) {
|
||||
if (fd == -1)
|
||||
return;
|
||||
close(fd);
|
||||
dup2(backup_fd+fd, 1);
|
||||
close (fd);
|
||||
dup2 (backup_fd, 1);
|
||||
}
|
||||
|
||||
|
||||
/* --- trash --- */
|
||||
#if 0
|
||||
|
||||
void r_cons_stdout_close(int fd)
|
||||
{
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
dup2(fd, 1);
|
||||
}
|
||||
|
||||
void r_cons_stdout_close_file() {
|
||||
RCons *cons = r_cons_instance ();
|
||||
close(cons->fdout);
|
||||
dup2(cons->fdout, 1);
|
||||
}
|
||||
|
||||
void r_cons_stdout_open(const char *file, int append)
|
||||
{
|
||||
int fd;
|
||||
RCons *cons = r_cons_instance ();
|
||||
if (r_cons_instance.fdout != 1) // XXX nested stdout dupping not supported
|
||||
return;
|
||||
|
||||
fd = open(file, O_RDWR | O_CREAT | (append?O_APPEND:O_TRUNC), 0644);
|
||||
if (fd==-1)
|
||||
return;
|
||||
r_cons_instance.fdout = fd;
|
||||
dup2(1, r_cons_instance.fdout);
|
||||
//close(1);
|
||||
dup2(fd, 1);
|
||||
}
|
||||
|
||||
int r_cons_stdout_set_fd(int fd)
|
||||
{
|
||||
if (r_cons_instance.fdout == 0)
|
||||
return fd;
|
||||
return r_cons_instance.fdout = fd;
|
||||
}
|
||||
#endif
|
||||
|
@ -29,7 +29,7 @@ R_API RDebug *r_debug_new(int hard) {
|
||||
RDebug *dbg = R_NEW (RDebug);
|
||||
if (dbg) {
|
||||
// R_SYS_ARCH
|
||||
dbg->arch = R_SYS_ARCH; // 0 is native by default
|
||||
dbg->arch = r_sys_arch_id (R_SYS_ARCH); // 0 is native by default
|
||||
dbg->bits = R_SYS_BITS;
|
||||
dbg->anal = NULL;
|
||||
dbg->pid = -1;
|
||||
@ -84,12 +84,13 @@ R_API int r_debug_attach(RDebug *dbg, int pid) {
|
||||
R_API int r_debug_set_arch(RDebug *dbg, int arch, int bits) {
|
||||
if (dbg && dbg->h) {
|
||||
if (arch & dbg->h->arch) {
|
||||
eprintf ("arch supported by debug backend (%x)\n", arch);
|
||||
//eprintf ("arch supported by debug backend (%x)\n", arch);
|
||||
dbg->arch = arch;
|
||||
return R_TRUE;
|
||||
}
|
||||
}
|
||||
eprintf ("arch not supported by debug backend (%s)\n", dbg->h->name);
|
||||
eprintf ("arch (%s) not supported by debug backend (%s)\n",
|
||||
r_sys_arch_str (arch), dbg->h->name);
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,6 @@ static int debug_os_read_at(int pid, void *buf, int sz, ut64 addr) {
|
||||
for (x=0; x<words; x++) {
|
||||
((long *)buf)[x] = debug_read_raw (pid,
|
||||
(void *)(&((long*)(long)addr)[x]));
|
||||
if (((long *)buf)[x] == -1) // && errno)
|
||||
return s;
|
||||
s += sizeof (s);
|
||||
}
|
||||
if (last) {
|
||||
|
@ -30,8 +30,10 @@ lang_python.${EXT_SO}:
|
||||
else
|
||||
PYCFLAGS=`python-config --cflags 2>/dev/null | sed -e 's/-arch [^\s]*//g' | sed s,-Wstrict-prototypes,,g`
|
||||
PYCFLAGS+=`python2-config --cflags 2>/dev/null | sed -e 's/-arch [^\s]*//g' | sed s,-Wstrict-prototypes,,g`
|
||||
PYCFLAGS+=`python2.5-config --cflags 2>/dev/null | sed -e 's/-arch [^\s]*//g' | sed s,-Wstrict-prototypes,,g`
|
||||
PYLDFLAGS=`python-config --cflags 2>/dev/null | sed -e 's/-arch [^\s]*//g' | sed s,-Wstrict-prototypes,,g`
|
||||
PYLDFLAGS+=`python2-config --cflags 2>/dev/null | sed -e 's/-arch [^\s]*//g' | sed s,-Wstrict-prototypes,,g`
|
||||
PYLDFLAGS+=`python2.5-config --cflags 2>/dev/null | sed -e 's/-arch [^\s]*//g' | sed s,-Wstrict-prototypes,,g`
|
||||
|
||||
lang_python.${EXT_SO}:
|
||||
${CC} ${CFLAGS} ${PYCFLAGS} ${PYLDFLAGS} \
|
||||
|
@ -39,8 +39,8 @@ R_API int r_hex_bin2str(const ut8 *in, int len, char *out) {
|
||||
int i;
|
||||
char tmp[5];
|
||||
out[0]='\0';
|
||||
for (i=0;i<len;i++) {
|
||||
sprintf (tmp, "%02x", in[i]);
|
||||
for (i=0; i<len; i++) {
|
||||
snprintf (tmp, sizeof (tmp), "%02x", in[i]);
|
||||
strcat (out, tmp);
|
||||
}
|
||||
return len;
|
||||
@ -50,8 +50,8 @@ R_API char *r_hex_bin2strdup(const ut8 *in, int len) {
|
||||
int i;
|
||||
char tmp[5], *out = malloc ((len+1)*2);
|
||||
out[0]='\0';
|
||||
for (i=0;i<len;i++) {
|
||||
sprintf (tmp, "%02x", in[i]);
|
||||
for (i=0; i<len; i++) {
|
||||
snprintf (tmp, sizeof (tmp), "%02x", in[i]);
|
||||
strcat (out, tmp);
|
||||
}
|
||||
return out;
|
||||
|
@ -582,7 +582,9 @@ R_API int r_str_escape(char *buf) {
|
||||
R_API char *r_str_unscape(char *buf) {
|
||||
char *ptr, *ret;
|
||||
int len = strlen (buf);
|
||||
ptr = ret = malloc (len*2);
|
||||
ptr = ret = malloc (1+len*2);
|
||||
if (ptr == NULL)
|
||||
return NULL;
|
||||
for (;*buf;buf++,ptr++) {
|
||||
if (*buf=='\n') {
|
||||
*ptr = '\\';
|
||||
@ -594,7 +596,7 @@ R_API char *r_str_unscape(char *buf) {
|
||||
ptr++;
|
||||
*ptr = 't';
|
||||
} else
|
||||
if (IS_PRINTABLE(*buf)) {
|
||||
if (IS_PRINTABLE (*buf)) {
|
||||
*ptr = *buf;
|
||||
} else break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user