* Fix warnings in asmserv on windows

* Some alloca->malloc fixes for w32
* More error checking in r_sys_rmkdir
  - Uses the new r_sys_mkdir_failed() api
  - works on windows and posix
* Disable asm.dwarf when the plugin fails to init
  - Displays a warning message
* Added 'e scr.cols=16'
  - Determines the width of the hexdump (px, x)
  - Used also by Visual mode hjkl dimensions
This commit is contained in:
pancake 2010-10-17 23:03:54 +02:00
parent 7fe2f823e7
commit 9f7040dbf8
13 changed files with 110 additions and 84 deletions

72
TODO
View File

@ -6,30 +6,26 @@
<{include libr/TODO}>
Windows
=======
r2 -d <pid>
> dh native
> dp=824
> ...
TODO 0.6
========
pancake
* remove \r in asmserv.c and look for others
* cursor mode in visual breaks flags too (r2 -d ls ; Vcjjj)
* fix colorize of selected bytes
* fix eflags string and str_bits
* fix arm assembler issue reported via twitter (umf :/)
nibble
* I think i broke r_sys_rmkdir.. can u chk? ktxby!
* r_bin - Better way to fix got_offset issue?
* in Visual Debugger mode cursor mode also scrolls O_o
* Switch to 'arm' code analysis module :?
* mach0 armthumb bin detect
Questions
=========
* Support more than 16 columns 'px'
* fix colorize of selected bytes
* Switch to 'arm' code analysis module
* Add "pm ?" for bit print like in pb?
* Only use uppercase KMG for Kilo,Mega,Giga in r_num?
- 'g' is for double
* Add support for float/double in r_num :?
* in Visual Debugger mode cursor mode also scrolls O_o
* Only use uppercase KMG for Kilo,Mega,Giga in r_num? - 'g' is for double
* distribute 'spp' with 'rarc2' ? imho no
* rarc2 allows to compile invalid code like calling puts() out of context
0.6 RELEASE
===========
* Create radare2-testsuite project
- tests for ired, rax2, radare2, rabin2 ...
TODO nibble
-----------
@ -37,9 +33,6 @@ TODO nibble
- use r_anal_value everywhere
- x86im
- make x86_x86im the default backend for x86 analysis
- implement analysis for more instructions
* r_bin
- Better way to fix got_offset issue?
* diff code analysis
- diff two programs
1st level:
@ -67,9 +60,9 @@ TODO edu
TODO pancake
------------
* Fix eflags string and str_bits
* rarc2 allows to compile invalid code like calling puts() out of context
* Implement DRX support
* Implement RAnalCall (analyze function arguments, return values, propagate types..)
* Implement RAnalCall (analyze function arguments, return values, propagate types..)
- define number of arguments for given function
- warn if signature and analysis differs in number of args or so..
- when calling a function
@ -78,13 +71,6 @@ TODO pancake
- function signature comparsion if they dont match
r_anal_fcn_cmp (anal, f1, f2);
unassigned TODO pointz
----------------------
* Implement minimalist 'ar' and add support for .a archive libs? (not necessary in this life)
* Realign flags when using project in debug mode
* FileDescriptors: dd -- copy from !fd in r1
* Initial analysis looking for xrefs to strings and so? ax? ./a@@entry0 - Launched at startup
Bindings
========
* generate accessors from valaswig
@ -100,12 +86,12 @@ Refactoring
- r_vm must use mmu cache when emulating code
- use the one from r_io? and deprecate vm->mmu_cache?
* Review the r_flags api
* add pipe_to_buffer..not only file descriptors
* Add pipe_to_buffer..not only file descriptors
* r_config set_int and so..simplify
- find/use more common cases for char* or &int maps
- automatic callbacks for most common usecases
* What do we have to do with r_th, r_vm ?
* Merge r_vm into r_anal ?
* Merge r_vm into r_parse ?
* Merge r_socket inside r_util ?
* Add SSL support to r_socket ?
* Discuss missing r_core_sysenv_update in core/file.c:33
@ -115,7 +101,6 @@ Refactoring
* Move 'r_syscall_t' stuff into r_debug (sync r_core)
* Implement r_bind api to link multiple pointers
core->asm = r_bind_set (core->asm->bind, r_asm_new ());
* what do we have to do with r_th, r_parse and r_vm ?
* Find a better name for r_buf_fread (really?)
* Review r_io and r_reg API
* semi-ok state (R_TRUFAE), implement r_errno and r_errstr in r_util?
@ -124,9 +109,12 @@ Refactoring
0.7
===
* r2 -d <pid> > dh native > dp=824 > ... -- not really :) for 0.6
* Create radare2-testsuite project
- tests for ired, rax2, radare2, rabin2 ...
* Record trace of register status for each function when running
- r_reg_arena_copy();
* Add lua and dalvik disassembler
* Add lua and dalvik disassembler (volunteers?)
* Reimplement or fix the delta diffing in C
- first we need to do it for ired..
* Trace contents of buffers: filter search results..? cc 8080 @@ hit* .. check for values that has changed.
@ -140,15 +128,17 @@ Refactoring
- Add support for STATIC_PLUGINS in r_lang
- dlerror(/usr/lib/radare2/lang_perl.so): libperl.so: cannot open shared object file: No such file or directory
This issue is fixed by setting LD_LIBRARY_PATH...looks like dlopen ignores rpath
Build system:
-------------
* Store version information in libraries ? debian claims for it
* install.sh (to track installed files ..)
* acr -ldl check must be fixed for kfreebsd
Future
======
* Implement minimalist 'ar' and add support for .a archive libs? (not necessary in this life)
* Realign flags when using project in debug mode
* FileDescriptors: dd -- copy from !fd in r1
* Initial analysis looking for xrefs to strings and so? ax? ./a@@entry0 - Launched at startup
* Store version information in libraries ? debian claims for it
* install.sh (to track installed files ..)
* acr -ldl check must be fixed for kfreebsd
* Add support for float/double in r_num :?
* radare2 -e dbg.engine=vm -d ls
- load the program using r_bin in virtual space
- initialize vm and set regs

View File

@ -769,12 +769,21 @@ int Printfloat10(char *s,long double ext) {
k=sprintf(s,"-0.0"); // Negative floating 0.0
else if (ext==0.0)
k=sprintf(s,"0.0"); // Print 0 with decimal point
#if __WINDOWS__
else if ((ext>=-1.e10 && ext<-1.0) || (ext>1.0 && ext<=1.e10))
k=sprintf(s,"%#.20lg",ext);
else if ((ext>=-1.0 && ext<=-1.e-5) || (ext>=1.e-5 && ext<=1.0))
k=sprintf(s,"%#.19lf",ext);
else
k=sprintf(s,"%#.19le",ext);
#else
else if ((ext>=-1.e10 && ext<-1.0) || (ext>1.0 && ext<=1.e10))
k=sprintf(s,"%#.20Lg",ext);
else if ((ext>=-1.0 && ext<=-1.e-5) || (ext>=1.e-5 && ext<=1.0))
k=sprintf(s,"%#.19Lf",ext);
else
k=sprintf(s,"%#.19Le",ext);
#endif
return k;
};

View File

@ -40,14 +40,17 @@ static void print_address(bfd_vma address, struct disassemble_info *info) {
static int buf_fprintf(void *stream, const char *format, ...) {
va_list ap;
char *tmp;
if (buf_global == NULL)
return 0;
va_start(ap, format);
tmp = alloca (strlen (format)+strlen (buf_global)+2);
if (buf_global == NULL || format == NULL)
return R_FALSE;
va_start (ap, format);
tmp = malloc (strlen (format)+strlen (buf_global)+2);
if (tmp == NULL)
return R_FALSE;
sprintf (tmp, "%s%s", buf_global, format);
vsprintf (buf_global, tmp, ap);
va_end (ap);
return 0;
free (tmp);
return R_TRUE;
}
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut64 len) {

View File

@ -43,14 +43,17 @@ static void print_address(bfd_vma address, struct disassemble_info *info) {
static int buf_fprintf(void *stream, const char *format, ...) {
va_list ap;
char *tmp;
if (buf_global == NULL)
return 0;
if (buf_global == NULL || format == NULL)
return R_FALSE;
va_start (ap, format);
tmp = alloca (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);
vsprintf (buf_global, tmp, ap);
va_end (ap);
return 0;
free (tmp);
return R_TRUE;
}
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut64 len) {
@ -75,7 +78,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut6
disasm_obj.fprintf_func = &buf_fprintf;
disasm_obj.stream = stdout;
aop->buf_asm[0]='\0';
aop->buf_asm[0] = '\0';
if (a->big_endian)
aop->inst_len = print_insn_big_mips ((bfd_vma)Offset, &disasm_obj);
else aop->inst_len = print_insn_little_mips ((bfd_vma)Offset, &disasm_obj);

View File

@ -276,9 +276,9 @@ static int MACH0_(r_bin_mach0_init_items)(struct MACH0_(r_bin_mach0_obj_t)* bin)
int i, len;
for (i = 0, off = sizeof (struct MACH0_(mach_header)); i < bin->hdr.ncmds; i++, off += lc.cmdsize) {
len = r_buf_fread_at(bin->b, off, (ut8*)&lc, bin->endian?"2I":"2i", 1);
len = r_buf_fread_at (bin->b, off, (ut8*)&lc, bin->endian?"2I":"2i", 1);
if (len == -1) {
eprintf ("Error: read (lc) at 0x%08llx\n", off);
eprintf ("Error: read (lc) at 0x%08"PFMT64x"\n", off);
return R_FALSE;
}
switch (lc.cmd) {

View File

@ -348,14 +348,20 @@ static void r_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len,
char *sl = r_bin_meta_get_source_line (core->bin, at);
int len = strlen (opstr);
if (len<30) len = 30-len;
if (sl && (!osl || (osl && strcmp (sl, osl)))) {
while (len--)
r_cons_strcat (" ");
if (show_color)
r_cons_printf (Color_TURQOISE" ; %s"Color_RESET, sl);
else r_cons_printf (" ; %s\n", sl);
free (osl);
osl = sl;
if (sl) {
if ((!osl || (osl && strcmp (sl, osl)))) {
while (len--)
r_cons_strcat (" ");
if (show_color)
r_cons_printf (Color_TURQOISE" ; %s"Color_RESET, sl);
else r_cons_printf (" ; %s\n", sl);
free (osl);
osl = sl;
}
} else {
eprintf ("Warning: Forced asm.dwarf=false because of error\n");
show_dwarf = R_FALSE;
r_config_set (core->config, "asm.dwarf", "false");
}
}
if (middle != 0) {

View File

@ -2,6 +2,12 @@
#include <r_core.h>
static int config_scrcols_callback(void *user, void *data) {
int c = R_MIN (128, R_MAX (((RConfigNode*)data)->i_value, 0));
((RCore *)user)->print->cols = c & ~1;
return R_TRUE;
}
static int config_scrhtml_callback(void *user, void *data) {
RConfigNode *node = (RConfigNode *) data;
r_cons_singleton()->is_html = node->i_value;
@ -333,6 +339,7 @@ R_API int r_core_config_init(RCore *core) {
(core->print->flags&R_PRINT_FLAGS_COLOR)?"true":"false",
&config_color_callback);
r_config_set (cfg, "scr.seek", "");
r_config_set_i_cb (cfg, "scr.cols", 16, &config_scrcols_callback);
r_config_set_i (cfg, "search.from", 0);
r_config_set_i (cfg, "search.to", 0);
r_config_set_i (cfg, "search.distance", 0); // TODO: use i_cb here and remove code in cmd.c

View File

@ -705,6 +705,7 @@ R_API void r_core_visual_define (RCore *core) {
/* TODO: use r_cmd here in core->vcmd..optimize over 255 table */
R_API int r_core_visual_cmd(RCore *core, int ch) {
char buf[1024];
int cols = core->print->cols;
ch = r_cons_arrow_to_hjkl (ch);
// do we need hotkeys for data references? not only calls?
@ -785,7 +786,7 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
case 'J':
if (curset) {
if (ocursor==-1) ocursor = cursor;
cursor += 16;
cursor += cols;
} else r_core_cmd (core, "s++", 0);
break;
case 'g':
@ -799,7 +800,7 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
case 'K':
if (curset) {
if (ocursor==-1) ocursor=cursor;
cursor -= 16;
cursor -= cols;
} else r_core_cmd (core, "s--", 0);
break;
case 'L':
@ -831,19 +832,15 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
break;
case 'j':
if (curset) {
cursor+=16;
ocursor=-1;
} else {
if (printidx==1)
r_core_cmd (core, "s+ 8", 0);
else r_core_cmd (core, "s+ 16", 0);
}
cursor += cols;
ocursor = -1;
} else r_core_seek (core, core->offset + (printidx==1?8:16), 0);
break;
case 'k':
if (curset) {
cursor-=16;
ocursor=-1;
} else r_core_cmd (core, (printidx==1)?"s- 8":"s- 16", 0);
cursor -= cols;
ocursor = -1;
} else r_core_seek (core, core->offset - (printidx==1?8:16), 0);
break;
case 's':
r_core_cmd (core, "ds", 0);
@ -900,10 +897,10 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
} else r_core_block_size (core, core->blocksize+1);
break;
case '/':
r_core_block_size (core, core->blocksize-16);
r_core_block_size (core, core->blocksize-cols);
break;
case '*':
r_core_block_size (core, core->blocksize+16);
r_core_block_size (core, core->blocksize+cols);
break;
case '>':
r_core_seek_align (core, core->blocksize, 1);

View File

@ -21,6 +21,7 @@ typedef struct r_print_t {
int limit;
int cur_enabled;
int cur;
int cols;
int ocur;
int flags;
int addrmod;

View File

@ -267,9 +267,11 @@ R_API char *r_file_slurp_line(const char *file, int line, int context);
R_API ut64 r_sys_now();
R_API void r_sys_perror(const char *fun);
#if __WINDOWS__
#define r_sys_mkdir(x) (mkdir(x)!=-1)
#define r_sys_mkdir(x) (CreateDirectory(x,NULL)!=0)
#define r_sys_mkdir_failed() (GetLastError () != ERROR_ALREADY_EXISTS)
#else
#define r_sys_mkdir(x) (mkdir(x,0755)!=-1)
#define r_sys_mkdir_failed() (errno != EEXIST)
#endif
R_API int r_sys_rmkdir(const char *dir);
R_API int r_sys_sleep(int secs);

View File

@ -42,10 +42,10 @@ R_API int r_print_date_unix(struct r_print_t *p, const ut8 *buf, int len) {
if (time) {
ret = strftime (datestr, 256, p->datefmt, time);
if (ret) {
p->printf("%s\n", datestr);
p->printf ("%s\n", datestr);
ret = sizeof(time_t);
}
} else r_cons_printf("Invalid time\n");
} else p->printf ("Invalid time\n");
}
}
return ret;

View File

@ -196,7 +196,7 @@ R_API void r_print_hexpairs(RPrint *p, ut64 addr, ut8 *buf, int len) {
// XXX: step is borken
R_API void r_print_hexdump(RPrint *p, ut64 addr, ut8 *buf, int len, int base, int step) {
int i,j,k,inc;
int i, j, k, inc;
const char *fmt = "%02x";
const char *pre = "";
@ -215,6 +215,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, ut8 *buf, int len, int base, in
inc = 2 + (int)((p->width-14)/4);
if (inc%2) inc++;
inc = 16;
inc = p->cols;
if (p->flags & R_PRINT_FLAGS_HEADER) {
// only for color..too many options .. brbr

View File

@ -4,14 +4,16 @@
#include <r_util.h>
#if __UNIX__
#include <sys/wait.h>
#include <sys/stat.h>
#include <errno.h>
#include <signal.h>
#include <execinfo.h>
#elif __WINDOWS__
#include <io.h>
#endif
#include <sys/types.h>
/* TODO: import stuff fron bininfo/p/bininfo_addr2line */
/* TODO: import stuff fron bininfo/p/bininfo_addr2line */
/* TODO: check endianness issues here */
R_API ut64 r_sys_now(void) {
ut64 ret;
@ -243,17 +245,22 @@ R_API char *r_sys_cmd_str(const char *cmd, const char *input, int *len) {
R_API int r_sys_rmkdir(const char *dir) {
int ret = R_TRUE;
char *path = strdup (dir), *ptr = path;
// XXX: Wrong for w32 (/)
// XXX: Wrong for w32 (/).. and no errno ?
while ((ptr = strchr (ptr, '/'))) {
*ptr = 0;
if (!r_sys_mkdir (path)) {
free (path);
return R_FALSE;
if (r_sys_mkdir_failed ()) {
eprintf ("r_sys_rmkdir: fail %s\n", dir);
free (path);
return R_FALSE;
}
}
*ptr = '/';
ptr = ptr+1;
ptr++;
}
ret = r_sys_mkdir (path);
if (r_sys_mkdir_failed ())
ret = R_TRUE;
free (path);
return ret;
}