* Add ^ and $ in cons grep expressions

* Minor work on source CL commands, needs review
This commit is contained in:
pancake 2012-06-21 10:12:02 +02:00
parent 3877483e88
commit 690445700a
8 changed files with 97 additions and 56 deletions

9
configure vendored
View File

@ -1,5 +1,5 @@
#!/bin/sh
# This script was automatically generated by ACR v0.9
# This script was automatically generated by ACR v0.9.1
# @author: pancake <youterm.com>
# @url: http://www.nopcode.org
# @repo: hg clone http://hg.youterm.com/acr
@ -101,7 +101,8 @@ done
: ${INSTALL_DIR:=${INSTALL} -d}
: ${INSTALL_DATA:=${INSTALL} -m 644}
: ${INSTALL_SCRIPT:=${INSTALL} -m 755}
: ${INSTALL_PROGRAM:=${INSTALL} -m 755 -s}
: ${INSTALL_PROGRAM:=${INSTALL} -m 755}
: ${INSTALL_PROGRAM_STRIP:=${INSTALL} -m 755 -s}
: ${INSTALL_MAN:=${INSTALL} -m 444}
: ${INSTALL_LIB:=${INSTALL} -c}
PKGNAME='radare2' ; VERSION='0.9.1hg' ; CONTACT_MAIL="pancake@nopcode.org" ; CONTACT_NAME="pancake" ; CONTACT="pancake <pancake@nopcode.org>" ;
@ -187,7 +188,7 @@ take_environ() {
}
show_version() {
echo "radare2-0.9.1hg configuration script done with acr v0.9.
echo "radare2-0.9.1hg configuration script done with acr v0.9.1.
The 'Free Software Foundation' message is only for autodetection.
Originally written by pancake <youterm.com>."
exit 0
@ -287,7 +288,7 @@ parse_options $1
shift
done
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU PKGNAME VPATH VERSION CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C DEBUGGER HAVE_LIB_DL DL_LIBS LIL_ENDIAN BIG_ENDIAN BYTEORDER HAVE_LIB_MAGIC USE_MAGIC USE_LIB_MAGIC LIBMAGIC HAVE_LIB_EWF EWF_CFLAGS EWF_LDFLAGS HAVE_PKGCFG_LIBEWF HAVE_EWF HAVE_LIB_GMP HAVE_GMP HAVE_LIB_SSL SSL_CFLAGS SSL_LDFLAGS HAVE_PKGCFG_OPENSSL HAVE_OPENSSL HAVE_LILEND HAVE_BIGEND HAVE_LIB_LUA5_1 HAVE_LIB_TCC USERCC USEROSTYPE WITHPIC WITHNONPIC LIBVERSION"
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU PKGNAME VPATH VERSION CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C DEBUGGER HAVE_LIB_DL DL_LIBS LIL_ENDIAN BIG_ENDIAN BYTEORDER HAVE_LIB_MAGIC USE_MAGIC USE_LIB_MAGIC LIBMAGIC HAVE_LIB_EWF EWF_CFLAGS EWF_LDFLAGS HAVE_PKGCFG_LIBEWF HAVE_EWF HAVE_LIB_GMP HAVE_GMP HAVE_LIB_SSL SSL_CFLAGS SSL_LDFLAGS HAVE_PKGCFG_OPENSSL HAVE_OPENSSL HAVE_LILEND HAVE_BIGEND HAVE_LIB_LUA5_1 HAVE_LIB_TCC USERCC USEROSTYPE WITHPIC WITHNONPIC LIBVERSION"
create_environ

View File

@ -24,7 +24,8 @@ static int MACH0_(r_bin_mach0_addr_to_offset)(struct MACH0_(r_bin_mach0_obj_t)*
}
static int MACH0_(r_bin_mach0_init_hdr)(struct MACH0_(r_bin_mach0_obj_t)* bin) {
int magic, len;
ut32 magic;
int len;
if (r_buf_read_at (bin->b, 0, (ut8*)&magic, 4) == -1) {
eprintf ("Error: read (magic)\n");

View File

@ -158,7 +158,7 @@ static RBinInfo* info(RBinArch *arch) {
free (str);
}
strncpy (ret->rclass, "mach0", R_BIN_SIZEOF_STRINGS);
/* TODO get os*/
/* TODO get os */
strncpy (ret->os, "darwin", R_BIN_SIZEOF_STRINGS);
strncpy (ret->subsystem, "darwin", R_BIN_SIZEOF_STRINGS);
if ((str = MACH0_(r_bin_mach0_get_cputype) (arch->bin_obj))) {
@ -183,10 +183,11 @@ static RBinInfo* info(RBinArch *arch) {
#if !R_BIN_MACH064
static int check(RBinArch *arch) {
if (arch && arch->buf && arch->buf->buf)
if (!memcmp (arch->buf->buf, "\xce\xfa\xed\xfe", 4) ||
!memcmp (arch->buf->buf, "\xfe\xed\xfa\xce", 4))
return R_TRUE;
if (arch && arch->buf && arch->buf->buf) {
if (!memcmp (arch->buf->buf, "\xce\xfa\xed\xfe", 4) ||
!memcmp (arch->buf->buf, "\xfe\xed\xfa\xce", 4))
return R_TRUE;
}
return R_FALSE;
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> nibble<develsec.org> */
/* radare - LGPL - Copyright 2009-2012 pancake<nopcode.org> nibble<develsec.org> */
#include <r_cons.h>
#include <r_util.h>
@ -9,6 +9,9 @@ R_API void r_cons_grep(const char *str) {
char *ptr, *optr, *ptr2, *ptr3;
cons = r_cons_singleton ();
cons->grep.str = NULL;
cons->grep.neg = 0;
cons->grep.begin = 0;
cons->grep.end = 0;
cons->grep.nstrings = 0;
cons->grep.tokenfrom = 0;
cons->grep.tokento = ST32_MAX;
@ -18,6 +21,10 @@ R_API void r_cons_grep(const char *str) {
if (str == NULL || !*str)
return;
if (*str == '^') { // neg
cons->grep.begin = 1;
str++;
}
if (*str == '!') { // neg
cons->grep.neg = 1;
str++;
@ -28,6 +35,13 @@ R_API void r_cons_grep(const char *str) {
}
strncpy (buf, str, sizeof (buf)-1);
{
int len = strlen (buf)-1;
if (len>1 && buf[len]=='$' && buf[len-1]!='\\') {
cons->grep.end = 1;
buf[len] = 0;
}
}
ptr = buf;
ptr3 = strchr (ptr, '['); // column number
if (ptr3) {
@ -131,11 +145,17 @@ R_API int r_cons_grep_line(char *buf, int len) {
memcpy (in, buf, len);
if (cons->grep.nstrings>0) {
for (i=0; i<cons->grep.nstrings; i++)
if (strstr (in, cons->grep.strings[i])) {
hit = !cons->grep.neg;
break;
}
for (i=0; i<cons->grep.nstrings; i++) {
char *p = strstr (in, cons->grep.strings[i]);
if (!p) continue;
if (cons->grep.begin)
hit = (p == in)? 1: 0;
else hit = !cons->grep.neg;
// XXX: this can be optimized
if (cons->grep.end && (strlen (cons->grep.strings[i]) != strlen (p)))
hit = 0;
break;
}
} else hit = 1;
if (hit) {

View File

@ -1,4 +1,3 @@
/* radare - LGPL - Copyright 2009-2012 // pancake<nopcode.org> */
static int cmd_info(void *data, const char *input) {
@ -46,13 +45,13 @@ static int cmd_info(void *data, const char *input) {
r_cons_printf (
"Usage: i[aeiIsSz]* ; get info from opened file\n"
"NOTE: Append a '*' to get the output in radare commands\n"
" ia ; show all info (imports, exports, sections..)\n"
" ii ; imports\n"
" iI ; binary info\n"
" ie ; entrypoint\n"
" is ; symbols\n"
" iS ; sections\n"
" iz ; strings\n");
" ia ; show all info (imports, exports, sections..)\n"
" ii ; imports\n"
" iI ; binary info\n"
" ie ; entrypoint\n"
" is ; symbols\n"
" iS ; sections\n"
" iz ; strings\n");
break;
case '*':
break;

View File

@ -47,42 +47,59 @@ static int cmd_meta(void *data, const char *input) {
}
break;
case 'l':
{
int num;
char *f, *p, *line, buf[4096];
f = strdup (input +2);
p = strchr (f, ':');
if (p) {
*p=0;
num = atoi (p+1);
line = r_file_slurp_line (input+2, num, 0);
if (!line) {
const char *dirsrc = r_config_get (core->config, "dir.source");
if (dirsrc && *dirsrc) {
f = r_str_concat (strdup (dirsrc), f);
line = r_file_slurp_line (f, num, 0);
}
if (!line) {
eprintf ("Cannot slurp file\n");
return R_FALSE;
}
}
p = strchr (p+1, ' ');
if (p) {
snprintf (buf, sizeof (buf), "CC %s:%d %s @ %s",
f, num, line, p+1);
// XXX: this should be moved to CL?
if (input[2]=='a') {
ut64 offset;
input++;
if (input[1]=='?') {
eprintf ("Usage: cla [addr]\n");
} else {
snprintf (buf, sizeof (buf), "\"CC %s:%d %s\"",
f, num, line);
char *sl;
if (input[1]==' ')
offset = r_num_math (core->num, input+2);
else offset = core->offset;
sl = r_bin_meta_get_source_line (core->bin, offset);
if (sl) {
r_cons_printf ("%s\n", sl);
free (sl);
}
}
} else {
int num;
char *f, *p, *line, buf[4096];
f = strdup (input +2);
p = strchr (f, ':');
if (p) {
*p=0;
num = atoi (p+1);
line = r_file_slurp_line (input+2, num, 0);
if (!line) {
const char *dirsrc = r_config_get (core->config, "dir.source");
if (dirsrc && *dirsrc) {
f = r_str_concat (strdup (dirsrc), f);
line = r_file_slurp_line (f, num, 0);
}
if (!line) {
eprintf ("Cannot slurp file\n");
return R_FALSE;
}
}
p = strchr (p+1, ' ');
if (p) {
snprintf (buf, sizeof (buf), "CC %s:%d %s @ %s",
f, num, line, p+1);
} else {
snprintf (buf, sizeof (buf), "\"CC %s:%d %s\"",
f, num, line);
}
r_core_cmd0 (core, buf);
free (line);
free (f);
}
r_core_cmd0 (core, buf);
free (line);
free (f);
}
}
break;
case 'L': // debug information of current offset
ret = r_bin_meta_get_line (core->bin, core->offset, file, 1023, &line);
ret = r_bin_meta_get_line (core->bin, core->offset, file, sizeof (file)-1, &line);
if (ret) {
r_cons_printf ("file %s\nline %d\n", file, line);
ret = (line<5)? 5-line: 5;

View File

@ -40,6 +40,8 @@ typedef struct r_cons_grep_t {
int tokenfrom;
int tokento;
int neg;
int begin;
int end;
} RConsGrep;
typedef void (*RConsEvent)(void *);

View File

@ -205,7 +205,7 @@ void ascii85_decode(FILE *fp, int delims, int ignore_garbage) {
int main(int argc, char *argv[]) {
extern char *optarg;
extern int optind, optopt, opterr;
int opt, long_optind, decode = 0, ignore_garbage = 0, delims = 1, wrap = 76, y_abbr = 0;
int opt, long_optind, decode = 0, ignore_garbage = 0, delims = 0, wrap = 76, y_abbr = 0;
FILE *fp = stdin;
char *opts = "dinw:yh";
struct option long_opts[] = {