Merge and fix jvoisin #235 #236

This commit is contained in:
pancake 2013-10-04 13:57:49 +02:00
parent a1cddb68cf
commit 653881eb3a
11 changed files with 84 additions and 77 deletions

View File

@ -4,13 +4,6 @@
|__\__|_|__|___/__|__|_\__\___\ |____(_)____/
Broken stuff to fixe before release
===================================
- java
- dalvik
- dwarf
- rar asm/dis
0.9.6
=====
* use __unused if available

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2013 - pancake */
/* radare2 - LGPL - Copyright 2013 - pancake */
#include <getopt.c>
#include <r_core.h>
@ -14,8 +14,9 @@ int main() {
#include "index.h"
static int usage (int v) {
printf ("Usage: r2agent [-dh] [-p port]\n"
" -d run in daemon mode (background\n"
printf ("Usage: r2agent [-adhs] [-p port]\n"
" -a listen for everyone (localhost by default)\n"
" -d run in daemon mode (background)\n"
" -h show this help message\n"
" -s run in sandbox mode\n"
" -p 8392 specify listening port (defaults to 8080)\n");
@ -28,11 +29,15 @@ int main(int argc, char **argv) {
int c, timeout = 3;
int dodaemon = 0;
int dosandbox = 0;
int listenlocal = 1;
const char *port = "8080";
// TODO: add flag to specify if listen in local or 0.0.0.0
while ((c = getopt (argc, argv, "hp:ds")) != -1) {
switch (c) {
while ((c = getopt (argc, argv, "ahp:ds")) != -1) {
switch (c) {
case 'a':
listenlocal = 0;
break;
case 's':
dosandbox = 1;
break;
@ -46,6 +51,8 @@ int main(int argc, char **argv) {
break;
}
}
if (optind != argc)
return usage (1);
if (dodaemon) {
int pid = fork ();
if (pid >0) {
@ -54,12 +61,14 @@ int main(int argc, char **argv) {
}
}
s = r_socket_new (R_FALSE);
s->local = 1; // by default
s->local = listenlocal;
if (!r_socket_listen (s, port, NULL)) {
eprintf ("Cannot listen on http.port\n");
eprintf ("Cannot listen on %d\n", s->port);
r_socket_free (s);
return 1;
}
eprintf ("http://localhost:%d/\n", s->port);
r_sandbox_enable (dosandbox);
while (!r_cons_singleton ()->breaked) {
char *result_heap = NULL;

View File

@ -480,7 +480,7 @@ int main(int argc, char **argv) {
if (seek) {
r_core_seek (&r, seek, 1);
} else {
if (r_flag_get (r.flags, "entry0"))
if (!debug && r_flag_get (r.flags, "entry0"))
r_core_cmd0 (&r, "s entry0");
}

View File

@ -499,61 +499,61 @@ R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf) {
continue;
} else if (*ptr_start == '.') { /* pseudo */
ptr = ptr_start;
if (!memcmp (ptr, ".intel_syntax", 13))
if (!strncmp (ptr, ".intel_syntax", 13))
a->syntax = R_ASM_SYNTAX_INTEL;
else if (!memcmp (ptr, ".att_syntax", 10))
else if (!strncmp (ptr, ".att_syntax", 10))
a->syntax = R_ASM_SYNTAX_ATT;
else if (!memcmp (ptr, ".string ", 8)) {
else if (!strncmp (ptr, ".string ", 8)) {
r_str_chop (ptr+8);
ret = r_asm_pseudo_string (&op, ptr+8, 1);
} else if (!memcmp (ptr, ".ascii ", 7)) {
} else if (!strncmp (ptr, ".ascii ", 7)) {
ret = r_asm_pseudo_string (&op, ptr+7, 0);
} else if (!memcmp (ptr, ".align", 7)) {
} else if (!strncmp (ptr, ".align", 7)) {
ret = r_asm_pseudo_align (&op, ptr+7);
} else if (!memcmp (ptr, ".arm", 4)) {
} else if (!strncmp (ptr, ".arm", 4)) {
r_asm_use (a, "arm");
r_asm_set_bits (a, 32);
ret = 0;
} else if (!memcmp (ptr, ".thumb", 6)) {
} else if (!strncmp (ptr, ".thumb", 6)) {
r_asm_use (a, "arm");
r_asm_set_bits (a, 16);
ret = 0;
} else if (!memcmp (ptr, ".arch ", 6))
} else if (!strncmp (ptr, ".arch ", 6))
ret = r_asm_pseudo_arch (a, ptr+6);
else if (!memcmp (ptr, ".bits ", 6))
else if (!strncmp (ptr, ".bits ", 6))
ret = r_asm_pseudo_bits (a, ptr+6);
else if (!memcmp (ptr, ".fill ", 6))
else if (!strncmp (ptr, ".fill ", 6))
ret = r_asm_pseudo_fill (&op, ptr+6);
else if (!memcmp (ptr, ".hex ", 5))
else if (!strncmp (ptr, ".hex ", 5))
ret = r_asm_pseudo_hex (&op, ptr+5);
else if ((!memcmp (ptr, ".int16 ", 7)) || !memcmp (ptr, ".short ", 7))
else if ((!strncmp (ptr, ".int16 ", 7)) || !strncmp (ptr, ".short ", 7))
ret = r_asm_pseudo_int16 (a, &op, ptr+7);
else if (!memcmp (ptr, ".int32 ", 7))
else if (!strncmp (ptr, ".int32 ", 7))
ret = r_asm_pseudo_int32 (a, &op, ptr+7);
else if (!memcmp (ptr, ".int64 ", 7))
else if (!strncmp (ptr, ".int64 ", 7))
ret = r_asm_pseudo_int64 (a, &op, ptr+7);
else if (!memcmp (ptr, ".size", 5))
else if (!strncmp (ptr, ".size", 5))
ret = R_TRUE; // do nothing, ignored
else if (!memcmp (ptr, ".section", 8))
else if (!strncmp (ptr, ".section", 8))
ret = R_TRUE; // do nothing, ignored
else if ((!memcmp (ptr, ".byte ", 6)) || (!memcmp (ptr, ".int8 ", 6)))
else if ((!strncmp (ptr, ".byte ", 6)) || (!strncmp (ptr, ".int8 ", 6)))
ret = r_asm_pseudo_byte (&op, ptr+6);
else if (!memcmp (ptr, ".glob", 5)) { // .global .globl
else if (!strncmp (ptr, ".glob", 5)) { // .global .globl
// eprintf (".global directive not yet implemented\n");
ret = 0;
continue;
} else if (!memcmp (ptr, ".equ ", 5)) {
} else if (!strncmp (ptr, ".equ ", 5)) {
ptr2 = strchr (ptr+5, ',');
if (ptr2) {
*ptr2 = '\0';
r_asm_code_set_equ (acode, ptr+5, ptr2+1);
} else eprintf ("TODO: undef equ\n");
} else if (!memcmp (ptr, ".org ", 5)) {
} else if (!strncmp (ptr, ".org ", 5)) {
ret = r_asm_pseudo_org (a, ptr+5);
off = a->pc;
} else if (!memcmp (ptr, ".text", 5)) {
} else if (!strncmp (ptr, ".text", 5)) {
acode->code_offset = a->pc;
} else if (!memcmp (ptr, ".data", 5)) {
} else if (!strncmp (ptr, ".data", 5)) {
acode->data_offset = a->pc;
} else {
eprintf ("Unknown directive (%s)\n", ptr);

View File

@ -55,7 +55,8 @@ R_API void r_core_print_cmp(RCore *core, ut64 from, ut64 to) {
memset (b, 0xff, core->blocksize);
delta = addr - from;
r_core_read_at (core, to+delta, b, core->blocksize);
r_print_hexdiff (core->print, core->offset, core->block, to+delta, b, core->blocksize, col);
r_print_hexdiff (core->print, core->offset, core->block,
to+delta, b, core->blocksize, col);
free (b);
}
@ -69,7 +70,8 @@ static int pdi(RCore *core, int l, int len, int ilen) {
if (l==0) l = len;
for (i=j=0; j<len && j<l && i<ilen; i+=ret, j++) {
r_asm_set_pc (core->assembler, core->offset+i);
ret = r_asm_disassemble (core->assembler, &asmop, buf+i, core->blocksize-i);
ret = r_asm_disassemble (core->assembler, &asmop, buf+i,
core->blocksize-i);
if (show_offset)
r_cons_printf ("0x%08"PFMT64x" ", core->offset+i);
if (ret<1) {
@ -412,18 +414,25 @@ static int cmd_print(void *data, const char *input) {
case 'a':
{
RAsmOp asmop;
int j, ret, err = 0;
const ut8 *buf = core->block;
if (l==0) l = len;
for (i=j=0; i<core->blocksize && j<len && j<l; i++,j++ ) {
int ret, err = 0;
ut8 *buf = core->block;
if (l<1) l = len;
if (l>=core->blocksize) {
buf = malloc (l+1);
r_core_read_at (core, core->offset, buf, l);
}
for (i=0; i<l; i++ ) {
ret = r_asm_disassemble (core->assembler, &asmop,
buf+i, core->blocksize-i);
buf+i, l-i);
if (ret<1) {
ret = err = 1;
r_cons_printf ("???\n");
//r_cons_printf ("???\n");
r_cons_printf ("0x%08"PFMT64x" ???\n", core->offset+i);
} else r_cons_printf ("0x%08"PFMT64x" %16s %s\n",
core->offset+i, asmop.buf_hex, asmop.buf_asm);
}
if (buf != core->block)
free (buf);
return R_TRUE;
}
break;

View File

@ -921,8 +921,8 @@ static void r_core_visual_refresh (RCore *core) {
if (vcmd && *vcmd) {
r_core_cmd (core, vcmd, 0);
} else {
if (zoom) r_core_cmd (core, "pz", 0);
else r_core_cmd (core, printfmt[PIDX], 0);
if (zoom) r_core_cmd0 (core, "pz");
else r_core_cmd0 (core, printfmt[PIDX]);
}
blocksize = core->num->value? core->num->value : core->blocksize;

View File

@ -21,6 +21,7 @@ typedef struct r_socket_t {
int fd;
int is_ssl;
int local; // TODO: merge ssl with local -> flags/options
int port;
struct sockaddr_in sa;
#if HAVE_LIB_SSL
SSL_CTX *ctx;
@ -43,6 +44,7 @@ R_API int r_socket_connect (RSocket *s, const char *host, const char *port, int
#define r_socket_connect_unix(a,b) r_socket_connect(a,b,NULL,R_SOCKET_PROTO_UNIX)
R_API int r_socket_unix_listen (RSocket *s, const char *file);
#endif
R_API int r_socket_port_by_name(const char *name);
R_API int r_socket_close (RSocket *s);
R_API int r_socket_free (RSocket *s);
R_API int r_socket_listen (RSocket *s, const char *port, const char *certfile);

View File

@ -67,7 +67,7 @@
#define B0100 4
#define B0011 3
#define B0010 2
#undef _
#undef _(a,b,c,d)
#define _(a,b,c,d) ((a<<12)|(b<<8)|(c<<4)|(d))
#endif

View File

@ -347,7 +347,7 @@ R_API const char *r_str_casestr(const char *a, const char *b);
R_API const char *r_str_lastbut (const char *s, char ch, const char *but);
R_API int r_str_split(char *str, char ch);
R_API char* r_str_replace(char *str, const char *key, const char *val, int g);
R_API void r_str_cpy(char *dst, const char *src);
#define r_str_cpy(x,y) memmove(x,y,strlen(y)+1);
R_API int r_str_bits (char *strout, const ut8 *buf, int len, const char *bitz);
R_API int r_str_rwx(const char *str);
R_API int r_str_replace_char (char *s, int a, int b);

View File

@ -25,7 +25,6 @@ R_API RSocket *r_socket_new (int is_ssl) { return NULL; }
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
//#include <sys/fcntl.h>
#endif
#ifdef __WINDOWS__
@ -97,6 +96,7 @@ R_API int r_socket_unix_listen (RSocket *s, const char *file) {
R_API RSocket *r_socket_new (int is_ssl) {
RSocket *s = R_NEW (RSocket);
s->is_ssl = is_ssl;
s->port = 0;
#if __UNIX_
signal (SIGPIPE, SIG_IGN);
#endif
@ -139,7 +139,9 @@ R_API int r_socket_connect (RSocket *s, const char *host, const char *port, int
}
sa.sin_addr = *((struct in_addr *)he->h_addr);
sa.sin_port = htons (atoi (port));
s->port = r_socket_port_by_name (port);
sa.sin_port = htons (s->port);
#warning TODO: implement connect timeout on w32
if (connect (s->fd, (const struct sockaddr*)&sa, sizeof (struct sockaddr))) {
close (s->fd);
@ -147,7 +149,7 @@ R_API int r_socket_connect (RSocket *s, const char *host, const char *port, int
}
return R_TRUE;
#elif __UNIX__
if (proto==0) proto= R_SOCKET_PROTO_TCP;
if (!proto) proto = R_SOCKET_PROTO_TCP;
int gai, ret;
struct addrinfo hints, *res, *rp;
signal (SIGPIPE, SIG_IGN);
@ -274,6 +276,13 @@ R_API int r_socket_free (RSocket *s) {
return res;
}
R_API int r_socket_port_by_name(const char *name) {
struct servent *p = getservbyname (name, "tcp");
if (p && p->s_port)
return ntohs (p->s_port);
return atoi (name);
}
R_API int r_socket_listen (RSocket *s, const char *port, const char *certfile) {
int optval = 1;
struct linger linger = { 0 };
@ -291,7 +300,10 @@ R_API int r_socket_listen (RSocket *s, const char *port, const char *certfile) {
memset (&s->sa, 0, sizeof (s->sa));
s->sa.sin_family = AF_INET;
s->sa.sin_addr.s_addr = htonl (s->local? INADDR_LOOPBACK: INADDR_ANY);
s->sa.sin_port = htons (atoi (port)); // WTF we should honor etc/services
s->port = r_socket_port_by_name (port);
if (s->port <1)
return R_FALSE;
s->sa.sin_port = htons (s->port); // TODO honor etc/services
if (bind (s->fd, (struct sockaddr *)&s->sa, sizeof(s->sa)) < 0) {
close (s->fd);

View File

@ -205,25 +205,16 @@ fail:
}
R_API ut64 r_str_hash64(const char *s) {
int len = strlen (s);
ut64 h = 5381;
if (len<1) len = strlen (s)+1; // XXX slow
while (len--) {
h += (h<<5);
h ^= *s++;
}
ut64 len, h = 5381;
if (!s)
return 0;
for (len=strlen (s); len>0; len--)
h = (h^(h<<5)) ^ *s++;
return h;
}
R_API ut32 r_str_hash (const char *s) {
int len = strlen (s);
ut32 h = 5381;
if (len<1) len = strlen (s)+1; // XXX slow
while (len--) {
h += (h<<5);
h ^= *s++;
}
return h;
return (ut32) r_str_hash64 (s);
}
R_API int r_str_delta(char *p, char a, char b) {
@ -454,15 +445,6 @@ R_API char *r_str_trim(char *str) {
return str;
}
/* strcpy() copies more than one byte at once which might cause problems when
* copying into the same buffer. TODO: memmove()? */
R_API void r_str_cpy(char *dst, const char *src) {
int i;
for (i=0; src[i]; i++)
dst[i] = src[i];
dst[i] = 0;
}
R_API void r_str_ncpy(char *dst, const char *src, int n) {
int i;
for (i=0; src[i] && n>0; i++, n--)