mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-26 07:44:29 +00:00
* Add 'tcc' lang plugin
* Implement lua lang plugin * Rename 'CD' command to 'CL' (code lines takes more sense)
This commit is contained in:
parent
12af51655b
commit
0caaaaf82b
18
libr/TODO
18
libr/TODO
@ -6,6 +6,24 @@
|
||||
|
||||
----------------------------------------[ todo
|
||||
|
||||
r_cache
|
||||
- register a hashtable of {int,char*}
|
||||
r_cache_validate(&cache, 0x800000, 0x8004000);
|
||||
char *str = r_cache_get(&cache, 0x8048000);
|
||||
if (str) { printf("%s\n", str); }
|
||||
... construct line ...
|
||||
r_cache_set(&cache, seek, constructedstring);
|
||||
- used by the disassebmler to not construct lines all the time
|
||||
|
||||
r_flagtree
|
||||
- r_flags should have a tree construction to access to them faster
|
||||
- btree? following pointers like bigger,smaller
|
||||
{ struct r_flag_t *bigger, *smaller; }
|
||||
- hooks r_flag_add to recalculate in r_flag_optimize(), bigger/smaller pointers
|
||||
- hooks r_flag_del to recalculate too.
|
||||
- the r_flag_get by string should have another construction with btree
|
||||
for the string of the name
|
||||
|
||||
|| search ||
|
||||
------------
|
||||
- implement r_search_xrefs
|
||||
|
@ -917,7 +917,7 @@ static int cmd_meta(void *data, const char *input)
|
||||
case '\0':
|
||||
/* meta help */
|
||||
break;
|
||||
case 'D': // debug information of current offset
|
||||
case 'L': // debug information of current offset
|
||||
ret = r_bininfo_get_line(
|
||||
&core->bininfo, core->seek, file, 1023, &line);
|
||||
if (ret)
|
||||
@ -931,9 +931,9 @@ static int cmd_meta(void *data, const char *input)
|
||||
case '?':
|
||||
eprintf(
|
||||
"Usage: C[CDF?] [arg]\n"
|
||||
" CD show debug information (bininfo)\n"
|
||||
" CF register function size here\n"
|
||||
" CC add comment\n");
|
||||
" CL [addr] ; show 'code line' information (bininfo)\n"
|
||||
" CF [size] [addr] ; register function size here (TODO)\n"
|
||||
" CC [string] ; add comment (TODO)\n");
|
||||
}
|
||||
return R_TRUE;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
CFLAGS=-I../../include -Wall
|
||||
BINDEPS=
|
||||
|
||||
all: lua.so dummy.so ruby.so python.so perl.so
|
||||
all: lua.so dummy.so ruby.so python.so perl.so tcc.so
|
||||
@true
|
||||
|
||||
python.so:
|
||||
@ -15,6 +15,9 @@ python.so:
|
||||
-I/usr/include/python2.6/ -lpython2.6 ; \
|
||||
fi
|
||||
|
||||
tcc.so: tcc.o
|
||||
-${CC} ${CFLAGS} -fPIC -shared -o tcc.so tcc.c -Wl,-R.. -ldl -ltcc
|
||||
|
||||
lua.so: lua.o
|
||||
-${CC} ${CFLAGS} -fPIC -shared -o lua.so lua.c -Wl,-R..
|
||||
@#strip -s lua.so
|
||||
|
@ -1,11 +1,97 @@
|
||||
/* lua extension for libr (radare2) */
|
||||
|
||||
#include "r_lib.h"
|
||||
#include "r_core.h"
|
||||
#include "r_lang.h"
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
// XXX
|
||||
#define LIBDIR "/usr/lib"
|
||||
|
||||
static lua_State *L;
|
||||
|
||||
struct r_core_t *core = NULL;
|
||||
|
||||
static int r_lang_lua_report (lua_State *L, int status) {
|
||||
const char *msg;
|
||||
if (status) {
|
||||
msg = lua_tostring(L, -1);
|
||||
if (msg == NULL) msg = "(error with no message)";
|
||||
fprintf(stderr, "status=%d, %s\n", status, msg);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static int r_lua_file(void *user, const char *file)
|
||||
{
|
||||
int status = luaL_loadfile(L, file);
|
||||
if (status)
|
||||
return r_lang_lua_report(L,status);
|
||||
status = lua_pcall(L,0,0,0);
|
||||
if (status)
|
||||
return r_lang_lua_report(L,status);
|
||||
return 0;
|
||||
}
|
||||
static int lua_cmd_str (lua_State *L) {
|
||||
char *str;
|
||||
const char *s = lua_tostring(L, 1); /* get argument */
|
||||
str = r_core_cmd_str(core, s);
|
||||
lua_pushstring(L, str); /* push result */
|
||||
free(str);
|
||||
return 1; /* number of results */
|
||||
}
|
||||
|
||||
static int lua_cmd (lua_State *L) {
|
||||
const char *s = lua_tostring(L, 1); /* get argument */
|
||||
|
||||
lua_pushnumber(L, r_core_cmd(core, s, 0)); /* push result */
|
||||
return 1; /* number of results */
|
||||
}
|
||||
|
||||
static int init(void *user)
|
||||
{
|
||||
L = (lua_State*)lua_open();
|
||||
if (L==NULL) {
|
||||
printf("Exit\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_gc(L, LUA_GCSTOP, 0);
|
||||
luaL_openlibs(L);
|
||||
luaopen_base(L);
|
||||
luaopen_string(L);
|
||||
//luaopen_io(L); // PANIC!!
|
||||
lua_gc(L, LUA_GCRESTART, 0);
|
||||
|
||||
lua_register(L, "cmd_str", &lua_cmd_str);
|
||||
lua_pushcfunction(L, lua_cmd_str);
|
||||
lua_setglobal(L,"cmd_str");
|
||||
|
||||
// DEPRECATED: cmd = radare_cmd_str
|
||||
lua_register(L, "cmd", &lua_cmd);
|
||||
lua_pushcfunction(L,lua_cmd);
|
||||
lua_setglobal(L,"cmd");
|
||||
|
||||
//-- load template
|
||||
printf("Loading radare api... %s\n",
|
||||
r_lua_file(NULL, LIBDIR"/radare/radare.lua")?
|
||||
"error ( "LIBDIR"/radare/radare.lua )":"ok");
|
||||
fflush(stdout);
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int lua_run(void *user, const char *code, int len)
|
||||
{
|
||||
printf("Evaluating '%s'\n", code);
|
||||
core = user; // XXX buggy?
|
||||
luaL_loadbuffer(L, code, len, ""); // \n included
|
||||
if ( lua_pcall(L,0,0,0) != 0 )
|
||||
printf("Oops\n");
|
||||
clearerr(stdin);
|
||||
//lua_close(L); // TODO
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
@ -13,8 +99,9 @@ static struct r_lang_handle_t r_lang_plugin_lua = {
|
||||
.name = "lua",
|
||||
.desc = "LUA language extension",
|
||||
.help = NULL,
|
||||
.run = &lua_run,
|
||||
.run_file = NULL,
|
||||
.run = lua_run,
|
||||
.init = init,
|
||||
.run_file = r_lua_file,
|
||||
.set_argv = NULL,
|
||||
};
|
||||
|
||||
|
29
libr/lang/p/tcc.c
Normal file
29
libr/lang/p/tcc.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* tcc extension for libr (radare2) */
|
||||
|
||||
#include "r_lib.h"
|
||||
#include "r_lang.h"
|
||||
#include <libtcc.h>
|
||||
|
||||
/* TODO: store the state globally or so.. */
|
||||
static int r_lang_tcc_run(void *user, const char *code, int len)
|
||||
{
|
||||
TCCState *ts = tcc_new ();
|
||||
tcc_compile_string (ts, code);
|
||||
tcc_run (ts, 0, 0);//argc, argv);
|
||||
tcc_delete (ts);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static struct r_lang_handle_t r_lang_plugin_tcc = {
|
||||
.name = "c99",
|
||||
.desc = "C99 language extension (using libtcc)",
|
||||
.help = NULL,
|
||||
.run = &r_lang_tcc_run,
|
||||
.run_file = NULL,
|
||||
.set_argv = NULL,
|
||||
};
|
||||
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_LANG,
|
||||
.data = &r_lang_plugin_tcc,
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user