* Fix signature of r_cons_user_fgets
- ^D is now working in radare2 core_prompt () - echo x | radare2 /bin/ls # is still broken * Random code cleanup, rapification
This commit is contained in:
parent
1838890d0f
commit
253892950d
|
@ -0,0 +1,90 @@
|
|||
TODO for the 2009-10-18 hackaton
|
||||
================================
|
||||
|
||||
Inconcrete things to do
|
||||
=======================
|
||||
|
||||
* Write Vala applications
|
||||
- Test the current .vapi files
|
||||
- Add missing methods/classes in vapi files
|
||||
- Examples can be found in libr/vapi/t
|
||||
- Propose new APIs and usage
|
||||
- Vala is a good way to express code
|
||||
|
||||
* Cleanup warnings
|
||||
- asm/p/bea? :) -- make it 32-64bit agnostic
|
||||
- Find missing function signatures in libr/include/.h
|
||||
- R_APIfy those APIs (sync with vapi)
|
||||
|
||||
|
||||
Concrete TODO points
|
||||
====================
|
||||
|
||||
* r_anal
|
||||
- Discuse and close the main design ideas for the library
|
||||
|
||||
* r_io
|
||||
- Design and implement a undo/redo subsystem that can be
|
||||
enabled and disabled. It is actually mostly done, but
|
||||
lacks coherence and can be done better.
|
||||
|
||||
- We need a way to get the underlying file which responds
|
||||
to the read call (this way we can know which library
|
||||
lives at a specified offset.
|
||||
|
||||
- Implement 'S' command in radare2 (libr/core/cmd)
|
||||
- It must use the r_io_section API
|
||||
- Implement the rest of io-related commands in r2
|
||||
- 'o' open - We need to manage more than one file
|
||||
- do e io.vaddr and io.baddr get sense in r2? (discuss)
|
||||
|
||||
- radare2 must be able to know the real/virtual offset
|
||||
- We need a function like r_io_get_real_offset();
|
||||
- We also need to know if there are overlapped sections
|
||||
and where those sections are. (like in hiew)
|
||||
|
||||
* r_bin
|
||||
- Make it IO agnostic (use r_io_bind) (HIGH PRIORITY)
|
||||
- Add mach0 file format support
|
||||
- Find why objdump can find stripped symbols with objcopy (see /TODO)
|
||||
|
||||
* radare2
|
||||
- Fix visual cursor in ANSI (raw ascii is inneficient)
|
||||
- Use r_bin with r_io to get symbols
|
||||
- The offset to read will define the module to analyze and retrieve syms
|
||||
|
||||
* r_db
|
||||
- Implement iterators r_db_next() and r_db_prev()
|
||||
- Write test programs to ensure the data is stored correctly
|
||||
|
||||
* r_search
|
||||
- The pattern finding functions are not following the design
|
||||
of the rest of the library, it needs a redesign and code cleanup
|
||||
(see bytepat.c)
|
||||
- implement radare/src/xrefs.c into r_search
|
||||
- Add support to change the case sensitive of searchs (ignore case)
|
||||
- This must be keyword-based. Not globally
|
||||
- Update vapi (r_search_regexp not implemented)
|
||||
- Enable/disable nested hits? (discuss+ implement in parent app?)
|
||||
- Just skip bytes until end of keyword
|
||||
|
||||
./libr/TODO
|
||||
./libr/line/TODO
|
||||
./libr/syscall/TODO
|
||||
./libr/search/TODO
|
||||
|
||||
|
||||
Portability
|
||||
===========
|
||||
|
||||
* Compile radare2 on many OS and platforms as possible
|
||||
- Windows? 32/64 bits (mingw32, cygwin)
|
||||
- OSX?
|
||||
- Solaris?
|
||||
|
||||
- We should take care about the library extensions (plugin loading)
|
||||
- Missing libraries (-lsocket for solaris..)
|
||||
|
||||
* r_th
|
||||
- Test the w32 port (LOW PRIORITY)
|
||||
- Do the same with r_lib (does it works on osx or w32?)
|
|
@ -19,14 +19,16 @@ static const char *radare_argv[CMDS] ={
|
|||
};
|
||||
#endif
|
||||
|
||||
char *(*r_cons_user_fgets)(char *buf, int len) = NULL;
|
||||
int (*r_cons_user_fgets)(char *buf, int len) = NULL;
|
||||
|
||||
char *dl_readline(int argc, const char **argv);
|
||||
|
||||
// XXX no control for max length here?!?!
|
||||
int r_cons_fgets(char *buf, int len, int argc, const char **argv)
|
||||
R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv)
|
||||
{
|
||||
if (r_cons_user_fgets)
|
||||
return r_cons_user_fgets(buf, 512)?strlen(buf):-1;
|
||||
return r_cons_user_fgets (buf, 512);
|
||||
|
||||
#if HAVE_DIETLINE
|
||||
/* TODO: link against dietline if possible for autocompletion */
|
||||
char *ptr;
|
||||
|
@ -39,13 +41,15 @@ int r_cons_fgets(char *buf, int len, int argc, const char **argv)
|
|||
buf[0]='\0';
|
||||
if (fgets(buf, len, r_cons_stdin_fd) == NULL)
|
||||
return -1;
|
||||
if (feof (r_cons_stdin_fd))
|
||||
return -1;
|
||||
buf[strlen(buf)-1]='\0';
|
||||
#endif
|
||||
return strlen(buf);
|
||||
}
|
||||
|
||||
|
||||
void r_cons_any_key()
|
||||
R_API void r_cons_any_key()
|
||||
{
|
||||
r_cons_strcat("\n--press any key--\n");
|
||||
r_cons_flush();
|
||||
|
@ -53,7 +57,7 @@ void r_cons_any_key()
|
|||
r_cons_strcat("\x1b[2J\x1b[0;0H");
|
||||
}
|
||||
|
||||
int r_cons_readchar()
|
||||
R_API int r_cons_readchar()
|
||||
{
|
||||
char buf[2];
|
||||
#if __WINDOWS__
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
/* this is the base fd.. more than one is supported :) */
|
||||
static int backup_fd=999;
|
||||
|
||||
int r_cons_pipe_open(const char *file, int append)
|
||||
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);
|
||||
if (fd==-1) {
|
||||
|
@ -19,7 +19,7 @@ int r_cons_pipe_open(const char *file, int append)
|
|||
return fd;
|
||||
}
|
||||
|
||||
void r_cons_pipe_close(int fd)
|
||||
R_API void r_cons_pipe_close(int fd)
|
||||
{
|
||||
if (fd == -1)
|
||||
return;
|
||||
|
@ -29,6 +29,7 @@ void r_cons_pipe_close(int fd)
|
|||
|
||||
|
||||
/* --- trash --- */
|
||||
#if 0
|
||||
|
||||
void r_cons_stdout_close(int fd)
|
||||
{
|
||||
|
@ -64,3 +65,4 @@ int r_cons_stdout_set_fd(int fd)
|
|||
return fd;
|
||||
return r_cons_stdout_fd = fd;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -84,12 +84,12 @@ static int myfgets(char *buf, int len)
|
|||
/* TODO: link against dietline if possible for autocompletion */
|
||||
char *ptr;
|
||||
buf[0]='\0';
|
||||
ptr = r_line_readline(CMDS, radare_argv);
|
||||
ptr = r_line_readline (CMDS, radare_argv);
|
||||
if (ptr == NULL)
|
||||
return -1;
|
||||
strncpy(buf, ptr, len);
|
||||
//free(ptr);
|
||||
return strlen(buf)+1;
|
||||
strncpy (buf, ptr, len);
|
||||
//free(ptr); // XXX leak
|
||||
return strlen (buf)+1;
|
||||
}
|
||||
/*-----------------------------------*/
|
||||
|
||||
|
@ -180,21 +180,21 @@ R_API struct r_core_t *r_core_free(struct r_core_t *c)
|
|||
|
||||
R_API int r_core_prompt(struct r_core_t *r)
|
||||
{
|
||||
char prompt[32];
|
||||
char line[1024];
|
||||
int ret;
|
||||
char line[1024];
|
||||
char prompt[32];
|
||||
const char *cmdprompt = r_config_get (&r->config, "cmd.prompt");
|
||||
|
||||
const char *cmdprompt = r_config_get(&r->config, "cmd.prompt");
|
||||
if (cmdprompt && cmdprompt[0])
|
||||
r_core_cmd(r, cmdprompt, 0);
|
||||
r_core_cmd (r, cmdprompt, 0);
|
||||
|
||||
sprintf(prompt, "[0x%08llx]> ", r->seek);
|
||||
sprintf (prompt, "[0x%08llx]> ", r->seek);
|
||||
r_line_prompt = prompt;
|
||||
ret = r_cons_fgets(line, sizeof(line), 0 , NULL);
|
||||
ret = r_cons_fgets (line, sizeof (line), 0, NULL);
|
||||
if (ret<0)
|
||||
return -1;
|
||||
ret = r_core_cmd(r, line, R_TRUE);
|
||||
r_cons_flush();
|
||||
ret = r_core_cmd (r, line, R_TRUE);
|
||||
r_cons_flush ();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -206,9 +206,9 @@ R_API int r_core_block_size(struct r_core_t *core, ut32 bsize)
|
|||
else if (bsize> R_CORE_BLOCKSIZE_MAX)
|
||||
bsize = R_CORE_BLOCKSIZE_MAX;
|
||||
else ret = 1;
|
||||
core->block = realloc(core->block, bsize);
|
||||
core->block = realloc (core->block, bsize);
|
||||
core->blocksize = bsize;
|
||||
r_core_block_read(core, 0);
|
||||
r_core_block_read (core, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -218,17 +218,18 @@ R_API int r_core_seek_align(struct r_core_t *core, ut64 align, int times)
|
|||
int diff = core->seek%align;
|
||||
ut64 seek = core->seek;
|
||||
|
||||
if (times == 0) diff = -diff;
|
||||
if (times == 0)
|
||||
diff = -diff;
|
||||
else if (diff) {
|
||||
if (inc>0) diff += align-diff;
|
||||
else diff = -diff;
|
||||
if (times) times -= inc;
|
||||
}
|
||||
while((times*inc)>0) {
|
||||
while ((times*inc)>0) {
|
||||
times -= inc;
|
||||
diff += align*inc;
|
||||
}
|
||||
return r_core_seek(core, seek+diff, 1);
|
||||
return r_core_seek (core, seek+diff, 1);
|
||||
}
|
||||
|
||||
R_API int r_core_seek_delta(struct r_core_t *core, st64 addr)
|
||||
|
@ -239,9 +240,8 @@ R_API int r_core_seek_delta(struct r_core_t *core, st64 addr)
|
|||
return R_TRUE;
|
||||
if (addr>0) {
|
||||
/* check end of file */
|
||||
if (0) { // tmp+addr>) {
|
||||
addr = 0;
|
||||
} else addr += tmp;
|
||||
if (0) addr = 0; // tmp+addr>) {
|
||||
else addr += tmp;
|
||||
} else {
|
||||
/* check < 0 */
|
||||
if (tmp+addr<0) {
|
||||
|
@ -249,7 +249,7 @@ R_API int r_core_seek_delta(struct r_core_t *core, st64 addr)
|
|||
} else addr += tmp;
|
||||
}
|
||||
core->seek = addr;
|
||||
ret = r_core_block_read(core, 0);
|
||||
ret = r_core_block_read (core, 0);
|
||||
if (ret == -1)
|
||||
core->seek = tmp;
|
||||
return ret;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
||||
|
||||
#include "r_core.h"
|
||||
#include "r_io.h"
|
||||
|
@ -9,8 +9,8 @@ static struct r_core_t r;
|
|||
|
||||
static int main_help(int line)
|
||||
{
|
||||
printf("Usage: radare2 [-dwnLV] [-s addr] [-b bsz] [-e k=v] [file] [...]\n");
|
||||
if (!line) printf(
|
||||
printf ("Usage: radare2 [-dwnLV] [-s addr] [-b bsz] [-e k=v] [file] [...]\n");
|
||||
if (!line) printf (
|
||||
" -d use 'file' as a program to debug\n"
|
||||
" -w open file in write mode\n"
|
||||
" -n do not run ~/.radare2rc\n"
|
||||
|
@ -28,7 +28,7 @@ static int main_help(int line)
|
|||
|
||||
static int main_version()
|
||||
{
|
||||
printf("radare2 "VERSION"\n");
|
||||
printf ("radare2 "VERSION"\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -50,10 +50,10 @@ int main(int argc, char **argv)
|
|||
while ((c = getopt (argc, argv, "wfhe:ndVs:b:Lui:l:"))!=-1) {
|
||||
switch (c) {
|
||||
case 'i':
|
||||
r_core_cmd_file(&r, optarg);
|
||||
r_core_cmd_file (&r, optarg);
|
||||
break;
|
||||
case 'l':
|
||||
r_lib_open(&r.lib, optarg);
|
||||
r_lib_open (&r.lib, optarg);
|
||||
break;
|
||||
case 'd':
|
||||
debug = 1;
|
||||
|
@ -82,13 +82,14 @@ int main(int argc, char **argv)
|
|||
seek = atoi (optarg); // XXX use r_num
|
||||
break;
|
||||
case 'L':
|
||||
r_lib_opendir(&r.lib, r_config_get(&r.config, "dir.plugins"));
|
||||
r_core_loadlibs(&r);
|
||||
r_lib_opendir (&r.lib, r_config_get (
|
||||
&r.config, "dir.plugins"));
|
||||
r_core_loadlibs (&r);
|
||||
r_lib_list (&r.lib);
|
||||
//r_io_handle_list (&r.io);
|
||||
break;
|
||||
case 'u':
|
||||
fprintf(stderr, "TODO\n");
|
||||
fprintf (stderr, "TODO\n");
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
|
@ -110,22 +111,22 @@ int main(int argc, char **argv)
|
|||
strcat (file, argv[optind]);
|
||||
strcat (file, " ");
|
||||
if (++optind != argc)
|
||||
strcat(file, " ");
|
||||
strcat (file, " ");
|
||||
}
|
||||
r_core_loadlibs(&r);
|
||||
r_core_loadlibs (&r);
|
||||
|
||||
fh = r_core_file_open (&r, file, perms);
|
||||
if (fh == NULL) {
|
||||
fprintf (stderr, "Cannot open file '%s'\n", file);
|
||||
return 1;
|
||||
}
|
||||
r_config_set(&r.config, "cfg.debug", "true");
|
||||
r_debug_use(&r.dbg, "ptrace");
|
||||
r_config_set (&r.config, "cfg.debug", "true");
|
||||
r_debug_use (&r.dbg, "ptrace");
|
||||
} else
|
||||
while (optind < argc) {
|
||||
const char *file = argv[optind++];
|
||||
// XXX dupped
|
||||
r_core_loadlibs(&r);
|
||||
r_core_loadlibs (&r);
|
||||
fh = r_core_file_open (&r, file, perms);
|
||||
if (fh == NULL) {
|
||||
fprintf (stderr, "Cannot open file '%s'\n", file);
|
||||
|
@ -167,18 +168,19 @@ int main(int argc, char **argv)
|
|||
|
||||
// Load the binary information from rabin2
|
||||
{
|
||||
char *cmd = r_str_concat(strdup(".!rabin2 -reisS "),
|
||||
r.file->filename);
|
||||
r_core_cmd(&r, cmd, 0);
|
||||
r_str_free(cmd);
|
||||
char *cmd = r_str_concat (
|
||||
strdup(".!rabin2 -reisS "), r.file->filename);
|
||||
r_core_cmd (&r, cmd, 0);
|
||||
r_str_free (cmd);
|
||||
}
|
||||
|
||||
if (run_rc)
|
||||
if (r_config_get_i (&r.config, "cfg.fortunes")) {
|
||||
r_core_cmd (&r, "fo", 0);
|
||||
r_cons_flush();
|
||||
r_cons_flush ();
|
||||
}
|
||||
|
||||
while(r_core_prompt (&r) != -1);
|
||||
while (r_core_prompt (&r) != -1);
|
||||
|
||||
return r_core_file_close (&r, fh);
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ extern int r_cons_is_html;
|
|||
extern int r_cons_noflush;
|
||||
extern char *r_cons_filterline;
|
||||
extern char *r_cons_teefile;
|
||||
extern char *(*r_cons_user_fgets)(char *buf, int len);
|
||||
extern int (*r_cons_user_fgets)(char *buf, int len);
|
||||
|
||||
#ifdef R_API
|
||||
/* constructor */
|
||||
|
|
|
@ -44,23 +44,22 @@ static int r_line_readchar()
|
|||
{
|
||||
char buf[2];
|
||||
#if __WINDOWS__
|
||||
LPDWORD out;
|
||||
BOOL ret;
|
||||
LPDWORD mode;
|
||||
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
|
||||
LPDWORD mode, out;
|
||||
HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
|
||||
|
||||
GetConsoleMode(h, &mode);
|
||||
SetConsoleMode(h, 0); // RAW
|
||||
ret = ReadConsole(h, buf,1, &out, NULL);
|
||||
GetConsoleMode (h, &mode);
|
||||
SetConsoleMode (h, 0); // RAW
|
||||
ret = ReadConsole (h, buf,1, &out, NULL);
|
||||
if (!ret) {
|
||||
// wine hack-around
|
||||
if (read(0,buf,1) != 1)
|
||||
if (read (0, buf, 1) != 1)
|
||||
return -1;
|
||||
}
|
||||
SetConsoleMode(h, mode);
|
||||
#else
|
||||
int ret = read(0,buf,1);
|
||||
if (ret <1)
|
||||
int ret = read (0, buf, 1);
|
||||
if (ret < 1)
|
||||
return -1;
|
||||
#endif
|
||||
//printf("CHAR(%d)\n", buf[0]);
|
||||
|
@ -383,21 +382,22 @@ R_API char *r_line_readline(int argc, const char **argv)
|
|||
// r_line_echo = config.verbose;
|
||||
if (r_line_disable) {
|
||||
r_line_buffer[0]='\0';
|
||||
fgets(r_line_buffer, R_LINE_BUFSIZE-1, stdin);
|
||||
if (!fgets(r_line_buffer, R_LINE_BUFSIZE-1, stdin))
|
||||
return NULL;
|
||||
r_line_buffer[strlen(r_line_buffer)] = '\0';
|
||||
return (*r_line_buffer)? r_line_buffer : r_line_nullstr;
|
||||
}
|
||||
|
||||
memset(&buf,0,sizeof buf);
|
||||
r_cons_set_raw(1);
|
||||
memset (&buf, 0, sizeof buf);
|
||||
r_cons_set_raw (1);
|
||||
|
||||
if (r_line_echo) {
|
||||
printf("%s", r_line_prompt);
|
||||
fflush(stdout);
|
||||
printf ("%s", r_line_prompt);
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
#if __UNIX__
|
||||
if (feof(stdin))
|
||||
if (feof (stdin))
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
|
@ -418,18 +418,18 @@ R_API char *r_line_readline(int argc, const char **argv)
|
|||
#endif
|
||||
|
||||
r_line_buffer[r_line_buffer_len]='\0';
|
||||
buf[0] = r_line_readchar();
|
||||
buf[0] = r_line_readchar ();
|
||||
|
||||
// printf("\x1b[K\r");
|
||||
columns = r_cons_get_real_columns()-2;
|
||||
columns = r_cons_get_real_columns ()-2;
|
||||
if (columns <1)
|
||||
columns = 40;
|
||||
if (r_line_echo)
|
||||
printf("\r%*c\r", columns, ' ');
|
||||
printf ("\r%*c\r", columns, ' ');
|
||||
|
||||
switch(buf[0]) {
|
||||
// case -1:
|
||||
// return NULL;
|
||||
switch (buf[0]) {
|
||||
//case -1: // ^D
|
||||
// return NULL;
|
||||
case 0: // control-space
|
||||
/* ignore atm */
|
||||
break;
|
||||
|
@ -609,9 +609,8 @@ R_API char *r_line_readline(int argc, const char **argv)
|
|||
}
|
||||
#endif
|
||||
default:
|
||||
if (gcomp) {
|
||||
if (gcomp)
|
||||
gcomp++;
|
||||
}
|
||||
/* XXX use ^A & ^E */
|
||||
if (r_line_buffer_idx<r_line_buffer_len) {
|
||||
for(i = ++r_line_buffer_len;i>r_line_buffer_idx;i--)
|
||||
|
@ -644,14 +643,14 @@ R_API char *r_line_readline(int argc, const char **argv)
|
|||
}
|
||||
|
||||
_end:
|
||||
r_cons_set_raw(0);
|
||||
r_cons_set_raw (0);
|
||||
if (r_line_echo) {
|
||||
printf("\r%s%s\n", r_line_prompt, r_line_buffer);
|
||||
fflush(stdout);
|
||||
printf ("\r%s%s\n", r_line_prompt, r_line_buffer);
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
if (r_line_buffer[0]=='!' && r_line_buffer[1]=='\0') {
|
||||
r_line_hist_list();
|
||||
r_line_hist_list ();
|
||||
return r_line_nullstr;
|
||||
}
|
||||
if (r_line_buffer == NULL)
|
||||
|
|
Loading…
Reference in New Issue