* Check for libtcc in acr to build or not r_lang_plugin_tcc

* R_APIze r_config
  - Added r_config_swap
  - Fix a bug in r_config_set for bool types
* Some more rules in doc/syntax
* Some integration from r_core to r_meta
  - CC command is now working to add and remove comments
  - Make 'C' show help and 'C*' list metadata
  - CF is semi working
* Show comments in disassembly 'asm.comments'
* Added 'e!' command to toggle a eval variable value
  - e!asm.bytes    ; for example
* Drop arrow-debugging in r_core_visual
  - Added key ';' to add comments
  - Do not 's eip' on debug
* Fix build of flags test program (thanks graz!)
* Added r_str_chop_ro (read-only string chopping)
This commit is contained in:
pancake 2009-04-06 22:53:25 +00:00
parent fd06adb922
commit 4494eac83f
15 changed files with 164 additions and 59 deletions

View File

@ -11,5 +11,7 @@ RUNTIME_DEBUG=1
# TODO: add flag to choose ostype
OSTYPE?=@USEROSTYPE@
HAVE_LIB_TCC=@HAVE_LIB_TCC@
#-include ../config.mk
#-include ../../config.mk

5
configure vendored
View File

@ -247,7 +247,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 LDFLAGS HAVE_LANG_C HAVE_LIB_EWF HAVE_EWF USERCC USEROSTYPE WANT_VALA HAVE_VALAC VALAC HAVE_VALA_1_0_VERSION_0_5_0"
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 LDFLAGS HAVE_LANG_C HAVE_LIB_EWF HAVE_EWF HAVE_LIB_TCC USERCC USEROSTYPE WANT_VALA HAVE_VALAC VALAC HAVE_VALA_1_0_VERSION_0_5_0"
create_environ
@ -295,6 +295,7 @@ else
check_library HAVE_LIB_EWF ewf 0
if [ "$HAVE_EWF" = "1" ]; then
export HAVE_LIB_EWF="0"; fi
check_library HAVE_LIB_TCC tcc 0
printf "checking for valac... "
if [ -x "${VALAC}" ]; then
FIND=${VALAC}
@ -370,7 +371,7 @@ done
do_remove
echo
echo "Final report:"
for A in PREFIX HAVE_LIB_EWF HAVE_VALAC USERCC USEROSTYPE ; do # REPORT
for A in PREFIX HAVE_LIB_EWF HAVE_LIB_TCC HAVE_VALAC USERCC USEROSTYPE ; do # REPORT
eval VAL="\$${A}"
[ -z "${VAL}" ] && VAL="(null)"
echo " - ${A} = ${VAL}"

View File

@ -8,6 +8,8 @@ CHKLIB ewf
ARG_WITHOUT HAVE_EWF ewf disable EWF dependency ;
IF HAVE_EWF { HAVE_LIB_EWF = 0 ; }
CHKLIB tcc
(( rules for the compiler ))
ARG_WITH USERCC=gcc compiler Define compiler to use (see mk/) ;
ARG_WITH USEROSTYPE=gnulinux ostype Choose OS type ( gnulinux windows osx ) ;
@ -27,6 +29,6 @@ IF WANT_VALA {
HAVE_VALAC = 0 ;
}
REPORT PREFIX HAVE_LIB_EWF HAVE_VALAC USERCC USEROSTYPE ;
REPORT PREFIX HAVE_LIB_EWF HAVE_LIB_TCC HAVE_VALAC USERCC USEROSTYPE ;
SUBDIRS ./config-user.mk ;

View File

@ -28,6 +28,12 @@ coding style guidelines ;) Here'r some rules:
* Use 'R_API' define to mark exportable methods
* Try not using oneline comments '//'. Use /* */ instead
* To comment out some code use #if 0 (...) #endif
* Do not write ultra-large functions, split them into multiple or simplify
the algorithm, only external-copy-pasted-not-going-to-be-maintained code
can be accepted in this way (gnu code, external disassemblers, etc..)
VIM syntax configuration:
-------------------------

View File

@ -3,7 +3,7 @@
#include "r_config.h"
#include "r_util.h" // r_str_hash, r_str_chop, ...
struct r_config_node_t* r_config_node_new(const char *name, const char *value)
R_API struct r_config_node_t* r_config_node_new(const char *name, const char *value)
{
struct r_config_node_t *node =
(struct r_config_node_t *)
@ -18,13 +18,13 @@ struct r_config_node_t* r_config_node_new(const char *name, const char *value)
return node;
}
void r_config_list(struct r_config_t *cfg, const char *str, int rad)
R_API void r_config_list(struct r_config_t *cfg, const char *str, int rad)
{
struct list_head *i;
int len = 0;
if (!strnull(str)) {
str = r_str_chop(str);
str = r_str_chop_ro(str);
len = strlen(str);
}
@ -42,7 +42,7 @@ void r_config_list(struct r_config_t *cfg, const char *str, int rad)
}
}
struct r_config_node_t *r_config_node_get(struct r_config_t *cfg, const char *name)
R_API struct r_config_node_t *r_config_node_get(struct r_config_t *cfg, const char *name)
{
struct list_head *i;
int hash;
@ -57,7 +57,7 @@ struct r_config_node_t *r_config_node_get(struct r_config_t *cfg, const char *na
return NULL;
}
const char *r_config_get(struct r_config_t *cfg, const char *name)
R_API const char *r_config_get(struct r_config_t *cfg, const char *name)
{
struct r_config_node_t *node =
r_config_node_get(cfg, name);
@ -66,14 +66,26 @@ const char *r_config_get(struct r_config_t *cfg, const char *name)
if (node->flags & CN_BOOL)
return (const char *)
(((!strcmp("true", node->value))
|| (!strcmp("1", node->value)))?(const char *)1:NULL);
|| (!strcmp("1", node->value)))?
(const char *)1:NULL);
return node->value;
}
cfg->last_notfound = 1;
return NULL;
}
u64 r_config_get_i(struct r_config_t *cfg, const char *name)
R_API int r_config_swap(struct r_config_t *cfg, const char *name)
{
struct r_config_node_t *node =
r_config_node_get(cfg, name);
if (node && node->flags & CN_BOOL) {
r_config_set_i(cfg, name, !node->i_value);
return R_TRUE;
}
return R_FALSE;
}
R_API u64 r_config_get_i(struct r_config_t *cfg, const char *name)
{
struct r_config_node_t *node =
r_config_node_get(cfg, name);
@ -85,7 +97,7 @@ u64 r_config_get_i(struct r_config_t *cfg, const char *name)
return (u64)0LL;
}
struct r_config_node_t *r_config_set_cb(struct r_config_t *cfg, const char *name, const char *value, int (*callback)(void *user, void *data))
R_API struct r_config_node_t *r_config_set_cb(struct r_config_t *cfg, const char *name, const char *value, int (*callback)(void *user, void *data))
{
struct r_config_node_t *node;
node = r_config_set(cfg, name, value);
@ -95,7 +107,7 @@ struct r_config_node_t *r_config_set_cb(struct r_config_t *cfg, const char *name
return node;
}
struct r_config_node_t *r_config_set(struct r_config_t *cfg, const char *name, const char *value)
R_API struct r_config_node_t *r_config_set(struct r_config_t *cfg, const char *name, const char *value)
{
struct r_config_node_t *node;
@ -146,7 +158,7 @@ struct r_config_node_t *r_config_set(struct r_config_t *cfg, const char *name, c
return node;
}
int r_config_rm(struct r_config_t *cfg, const char *name)
R_API int r_config_rm(struct r_config_t *cfg, const char *name)
{
struct r_config_node_t *node =
r_config_node_get(cfg, name);
@ -158,7 +170,7 @@ int r_config_rm(struct r_config_t *cfg, const char *name)
return 0;
}
struct r_config_node_t *r_config_set_i(struct r_config_t *cfg, const char *name, const u64 i)
R_API struct r_config_node_t *r_config_set_i(struct r_config_t *cfg, const char *name, const u64 i)
{
char buf[128];
struct r_config_node_t *node =
@ -174,13 +186,13 @@ struct r_config_node_t *r_config_set_i(struct r_config_t *cfg, const char *name,
sprintf(buf, "%lld", i); //0x%08lx", i);
node->value = strdup(buf);
}
node->flags = CN_RW | CN_INT;
//node->flags = CN_RW | CN_INT;
node->i_value = i;
} else {
if (cfg->lock) {
eprintf("(locked: no new keys can be created)");
} else {
sprintf(buf, "%d", (unsigned int)i);//OFF_FMTd, (u64) i);
sprintf(buf, "0x%08llx", i);
node = r_config_node_new(name, buf);
node->flags = CN_RW | CN_OFFT;
node->i_value = i;
@ -195,7 +207,7 @@ struct r_config_node_t *r_config_set_i(struct r_config_t *cfg, const char *name,
return node;
}
int r_config_eval(struct r_config_t *cfg, const char *str)
R_API int r_config_eval(struct r_config_t *cfg, const char *str)
{
char *ptr,*a,*b;
char *name;
@ -246,12 +258,12 @@ int r_config_eval(struct r_config_t *cfg, const char *str)
return 1;
}
void r_config_lock(struct r_config_t *cfg, int l)
R_API void r_config_lock(struct r_config_t *cfg, int l)
{
cfg->lock = l;
}
int r_config_init(struct r_config_t *cfg, void *user)
R_API int r_config_init(struct r_config_t *cfg, void *user)
{
cfg->user = user;
cfg->n_nodes = 0;
@ -261,7 +273,7 @@ int r_config_init(struct r_config_t *cfg, void *user)
return 0;
}
struct r_config_t *r_config_new(void *user)
R_API struct r_config_t *r_config_new(void *user)
{
struct r_config_t *cfg = (struct r_config_t *)
malloc(sizeof(struct r_config_t));
@ -269,14 +281,14 @@ struct r_config_t *r_config_new(void *user)
return cfg;
}
int r_config_free(struct r_config_t *cfg)
R_API int r_config_free(struct r_config_t *cfg)
{
// TODO: Free node list
free(cfg);
return 0;
}
void r_config_visual_hit_i(struct r_config_t *cfg, const char *name, int delta)
R_API void r_config_visual_hit_i(struct r_config_t *cfg, const char *name, int delta)
{
struct r_config_node_t *node =
r_config_node_get(cfg, name);

View File

@ -486,9 +486,11 @@ void r_cons_set_raw(int b)
//int r_cons_0x1b_to_hjkl(int ch)
int r_cons_get_arrow(int ch)
{
#if 0
printf("ARROW(0x%x)\n", ch);
fflush(stdout);
r_sys_sleep(3);
#endif
if (ch==0x1b) {
ch = r_cons_readchar();
if (ch==0x5b) {

View File

@ -345,6 +345,7 @@ static int cmd_print(void *data, const char *input)
int show_bytes = r_config_get_i(&core->config, "asm.bytes");
int show_lines = r_config_get_i(&core->config, "asm.reflines");
int linesout = r_config_get_i(&core->config, "asm.reflinesout");
int show_comments = r_config_get_i(&core->config, "asm.comments");
int linesopts = 0;
int pseudo = r_config_get_i(&core->config, "asm.pseudo");
@ -369,6 +370,7 @@ static int cmd_print(void *data, const char *input)
u8 *buf = core->block;
char str[128];
char line[128];
char *comment;
struct r_asm_aop_t asmop;
struct r_anal_aop_t analop;
struct r_anal_refline_t *reflines;
@ -380,6 +382,14 @@ static int cmd_print(void *data, const char *input)
for(idx=ret=0; idx < len; idx+=ret) {
r_asm_set_pc(&core->assembler, core->assembler.pc + ret);
r_anal_set_pc(&core->anal, core->anal.pc + ret);
// ONLY SHOW IF ASM.COMMENTS IS TRUE
if (show_comments) {
comment = r_meta_get_string(&core->meta, R_META_COMMENT, core->anal.pc+ret);
if (comment) {
r_cons_strcat(comment);
free(comment);
}
}
r_anal_reflines_str(&core->anal, reflines, line, linesopts);
ret = r_asm_disassemble(&core->assembler, &asmop, buf+idx, len-idx);
if (ret <1) {
@ -851,6 +861,11 @@ static int cmd_eval(void *data, const char *input)
case '\0':
r_config_list(&core->config, NULL, 0);
break;
case '!':
input = r_str_chop_ro(input+1);
if (!r_config_swap(&core->config, input))
eprintf("r_config: '%s' is not a boolean variable.\n", input);
break;
case '-':
r_core_config_init(core);
eprintf("BUG: 'e-' command locks the eval hashtable. patches are welcome :)\n");
@ -864,6 +879,7 @@ static int cmd_eval(void *data, const char *input)
" e ; list config vars\n"
" e- ; reset config vars\n"
" e* ; dump config vars in r commands\n"
" e!a ; invert the boolean value of 'a' var\n"
" e a ; get value of var 'a'\n"
" e a=b ; set var 'a' the 'b' value\n");
//r_cmd_help(&core->cmd, "e");
@ -969,8 +985,8 @@ static int cmd_meta(void *data, const char *input)
char file[1024];
//struct r_core_t *core = (struct r_core_t *)data;
switch(input[0]) {
case '\0':
/* meta help */
case '*':
r_meta_list(&core->meta, R_META_ANY);
break;
case 'L': // debug information of current offset
ret = r_bininfo_get_line(
@ -979,16 +995,46 @@ static int cmd_meta(void *data, const char *input)
r_cons_printf("file %s\nline %d\n", file, line);
break;
case 'C': /* add comment */
// r_meta_add(&core->meta);
// TODO: do we need to get the size? or the offset?
// TODO: is this an exception compared to other C? commands?
if (input[1]==' ') input = input+1;
if (input[1]=='-') {
r_meta_del(&core->meta, R_META_COMMENT, core->seek, 1, input+2);
} else r_meta_add(&core->meta, R_META_COMMENT, core->seek, 1, input+1);
break;
case 'S':
case 's':
case 'm': /* struct */
case 'x': /* code xref */
case 'X': /* data xref */
case 'F': /* add function */
{
u64 addr = core->seek;
char fun_name[128];
int size = atoi(input);
int type = R_META_FUNCTION;
char *t, *p = strchr(input+1, ' ');
if (p) {
t = strdup(p+1);
printf("T=(%s)\n", t);
p = strchr(t, ' ');
if (p) {
*p='\0';
strncpy(fun_name, p+1, sizeof(fun_name));
} else sprintf(fun_name, "sub_%08llx", addr);
addr = r_num_math(&core->num, t);
free(t);
}
r_meta_add(&core->meta, type, addr, size, fun_name);
}
break;
case '\0':
case '?':
eprintf(
"Usage: C[CDF?] [arg]\n"
" CL [addr] ; show 'code line' information (bininfo)\n"
" CF [size] [addr] ; register function size here (TODO)\n"
" CC [string] ; add comment (TODO)\n");
" CL [addr] ; show 'code line' information (bininfo)\n"
" CF [size] [name] [addr] [name] ; register function size here (TODO)\n"
" CC [string] ; add comment (TODO)\n");
}
return R_TRUE;
}

View File

@ -44,6 +44,7 @@ R_API int r_core_config_init(struct r_core_t *core)
{
struct r_config_t *cfg = &core->config;
r_config_init(cfg, (void *)core);
cfg->printf = r_cons_printf;
r_config_set_cb(cfg, "asm.arch", "x86",
&config_asm_arch_callback);
@ -63,6 +64,7 @@ R_API int r_core_config_init(struct r_core_t *core)
r_config_set(cfg, "asm.reflinesout", "false");
r_config_set(cfg, "asm.reflinesstyle", "false");
r_config_set(cfg, "asm.reflineswide", "true");
r_config_set(cfg, "asm.comments", "true");
r_config_set(cfg, "cmd.prompt", "");
r_config_set(cfg, "cmd.vprompt", "");
r_config_set(cfg, "cmd.hit", "");

View File

@ -548,7 +548,7 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch)
case 's':
r_core_cmd(core, "ds", 0);
r_core_cmd(core, ".dr", 0);
r_core_cmd(core, "s eip", 0);
//r_core_cmd(core, "s eip", 0);
break;
case 'p':
printidx++;
@ -584,17 +584,29 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch)
r_cons_fgets(buf, 1023, 0, NULL);
r_core_cmd(core, buf, 0);
break;
case ';':
r_cons_printf("Enter a comment: (prefix it with '-' to remove)\n");
r_cons_flush();
r_cons_set_raw(0);
strcpy(buf, "CC ");
if (r_cons_fgets(buf+3, 1000, 0, NULL) <0)
buf[0]='\0';
if (buf[0])
r_core_cmd(core, buf, 1);
r_cons_set_raw(1);
break;
case '?':
r_cons_clear00();
r_cons_printf(
"\nVisual mode help:\n\n"
" >||< - seek aligned to block size\n"
" hjkl - move around\n"
" HJKL - move around faster\n"
" P||p - rotate print modes\n"
" /*+- - change block size\n"
" :cmd - run radare command\n"
" q - back to radare shell\n");
" >||< - seek aligned to block size\n"
" hjkl - move around\n"
" HJKL - move around faster\n"
" P||p - rotate print modes\n"
" /*+- - change block size\n"
" :cmd - run radare command\n"
" ;[-]cmt - add/remove comment\n"
" q - back to radare shell\n");
r_cons_flush();
r_cons_any_key();
break;

View File

@ -1,7 +1,7 @@
all: test
test:
${CC} -g -I ../../include test.c ../*.o -lr_util -L../util -o test
${CC} -g -I ../../include test.c ../*.o -lr_util -L../../util -o test
clean:
rm -f test

View File

@ -36,19 +36,20 @@ struct r_config_t {
#define O struct r_config_t *obj
struct r_config_t *r_config_new(void *user);
int r_config_free(struct r_config_t *cfg);
int r_config_init(struct r_config_t *core, void *user);
void r_config_lock(O, int l);
int r_config_eval(O, const char *str);
struct r_config_node_t *r_config_set_i(O, const char *name, const u64 i);
struct r_config_node_t *r_config_set_cb(struct r_config_t *cfg, const char *name, const char *value, int (*callback)(void *user, void *data));
int r_config_rm(O, const char *name);
struct r_config_node_t *r_config_set(O, const char *name, const char *value);
u64 r_config_get_i(O, const char *name);
const char *r_config_get(O, const char *name);
void r_config_list(O, const char *str, int rad);
struct r_config_node_t *r_config_node_get(O, const char *name);
struct r_config_node_t *r_config_node_new(const char *name, const char *value);
R_API struct r_config_t *r_config_new(void *user);
R_API int r_config_free(struct r_config_t *cfg);
R_API int r_config_init(struct r_config_t *core, void *user);
R_API void r_config_lock(O, int l);
R_API int r_config_eval(O, const char *str);
R_API struct r_config_node_t *r_config_set_i(O, const char *name, const u64 i);
R_API struct r_config_node_t *r_config_set_cb(struct r_config_t *cfg, const char *name, const char *value, int (*callback)(void *user, void *data));
R_API int r_config_rm(O, const char *name);
R_API struct r_config_node_t *r_config_set(O, const char *name, const char *value);
R_API u64 r_config_get_i(O, const char *name);
R_API const char *r_config_get(O, const char *name);
R_API void r_config_list(O, const char *str, int rad);
R_API struct r_config_node_t *r_config_node_get(O, const char *name);
R_API struct r_config_node_t *r_config_node_new(const char *name, const char *value);
R_API int r_config_swap(struct r_config_t *cfg, const char *name);
#endif

View File

@ -12,6 +12,15 @@ struct r_meta_count_t {
/* TODO: ... */
};
#if 0
TODO:
We need a way to determine sections for other architectures, so we will
be able to read a mixed x86/ppc mach0 binary in a shot.
We also need a way to determine if the folder is opened or closed (bool)
We also need to specify which type of data is the contents of a data block
(hexdump, structure, ...) select print format command
#endif
/* old data_t */
struct r_meta_item_t {
u64 from;

View File

@ -69,6 +69,7 @@ int r_str_word_set0(char *str);
const char *r_str_word_get0(const char *str, int idx);
char *r_str_chop(char *str);
R_API const char *r_str_chop_ro(const char *str);
int r_str_hash(const char *str);
char *r_str_clean(char *str);
int r_str_nstr(char *from, char *to, int size);

View File

@ -17,8 +17,10 @@ lang_python.so:
-I/usr/include/python2.6/ -lpython2.6 ; \
fi
ifeq ($(HAVE_LIB_TCC),1)
lang_tcc.so: tcc.o
-${CC} ${CFLAGS} -fPIC -shared -o lang_tcc.so tcc.c -Wl,-R.. -ldl -ltcc
endif
lang_lua.so: lua.o
-${CC} ${CFLAGS} -fPIC -shared -o lang_lua.so lua.c -Wl,-R..

View File

@ -33,7 +33,7 @@ char *r_str_home(const char *str)
return dst;
}
int r_str_hash(const char *str)
R_API int r_str_hash(const char *str)
{
int i = 1;
int a = 0x31;
@ -46,7 +46,7 @@ int r_str_hash(const char *str)
return h&0x7ffffff;
}
int r_str_delta(char *p, char a, char b)
R_API int r_str_delta(char *p, char a, char b)
{
char *_a = strchr(p, a);
char *_b = strchr(p, b);
@ -54,7 +54,7 @@ int r_str_delta(char *p, char a, char b)
return (_a-_b);
}
int r_str_word_set0(char *str)
R_API int r_str_word_set0(char *str)
{
int i;
char *p;
@ -64,7 +64,7 @@ int r_str_word_set0(char *str)
return i;
}
const char *r_str_word_get0(const char *str, int idx)
R_API const char *r_str_word_get0(const char *str, int idx)
{
int i;
const char *ptr = str;
@ -75,7 +75,7 @@ const char *r_str_word_get0(const char *str, int idx)
return ptr;
}
int r_str_word_count(const char *string)
R_API int r_str_word_count(const char *string)
{
char *text = (char *)string;
char *tmp = (char *)string;
@ -94,8 +94,7 @@ int r_str_word_count(const char *string)
return word-1;
}
char *r_str_ichr(char *str, char chr)
R_API char *r_str_ichr(char *str, char chr)
{
while(*str==chr) {
str = str+1;
@ -103,7 +102,7 @@ char *r_str_ichr(char *str, char chr)
return str;
}
char *r_str_lchr(char *str, char chr)
R_API char *r_str_lchr(char *str, char chr)
{
int len = strlen(str)+1;
for(;len>=0;len--)
@ -132,6 +131,14 @@ R_API int r_str_nstr(char *from, char *to, int size)
return (size!=i);
}
R_API const char *r_str_chop_ro(const char *str)
{
if (str)
while(str[0]&&iswhitechar(str[0]))
str = str + 1;
return str;
}
R_API char *r_str_chop(char *str)
{
int len;