* Commit initial vala plugin in swig/vapi/t/plugin.vala

- Many fixes in r_core, r_lib, r_cmd and r_anal
  - Needs patched vala head with #618933
    https://bugzilla.gnome.org/show_bug.cgi?id=618933
* Fix RCmd plugin handlers user data pointer
This commit is contained in:
pancake 2010-05-18 00:20:24 +02:00
parent 8ff37cd30b
commit 1ea43bbc10
13 changed files with 131 additions and 11 deletions

8
TODO
View file

@ -3,6 +3,8 @@
| < V . T . V < _/ .--'_/ | () |
|_|\__|_|__|___/|_|_|_|\__\___/ |_____(_)____/
* r_cmd.vapi not done?!?
----------------------------------------[ todo
33 decompilation -- we need better code analysis, but basic decompilation will be in 0.5
29 bindiffing (graph) -- nibble is working on this too, pancake has some binary diffing in C
@ -30,9 +32,15 @@
<{include libr/TODO}>
** See libr/*/TODO FMI
* Added 'prj.name', 'prj.desc' and 'prj.md5'
* Add description to project e file.desc ?
* Merge r_socket inside r_util ?
* Add SSL support to r_socket ?
* Move disasm loop into r_print (r_print should depend on r_asm)
* references: data (read, write), code (call, jmp)
* visual byte cursor in disassembly
* stack analysis

View file

@ -68,7 +68,7 @@ R_API int r_cmd_call(struct r_cmd_t *cmd, const char *input) {
iter = r_list_iterator (cmd->plist);
while (r_list_iter_next (iter)) {
cp = (RCmdHandle*) r_list_iter_get (iter);
if (cp->call (NULL, input))
if (cp->call (cmd->data, input))
return R_TRUE;
}

View file

@ -17,6 +17,11 @@ static int r_core_project_init() {
if (str && (ret = r_sys_mkdir (str))) {
str = r_str_home (".radare2/rdb");
ret = r_sys_mkdir (str);
if (!ret) {
free (str);
str = r_str_home (".radare2/plugins");
ret = r_sys_mkdir (str);
}
}
free (str);
return ret;

View file

@ -38,6 +38,7 @@ typedef struct r_cmd_macro_t {
struct list_head macros;
} RCmdMacro;
typedef int (*RCmdCallback)(void *user, const char *cmd);
typedef struct r_cmd_item_t {
char cmd[64];
@ -64,7 +65,7 @@ typedef struct r_cmd_t {
typedef struct r_cmd_handle_t {
char *name;
int (*call)(void *user, const char *cmd);
RCmdCallback call;
} RCmdHandle;
#ifdef R_API

View file

@ -57,7 +57,7 @@ typedef struct r_core_t {
struct r_num_t num;
struct r_lib_t lib;
struct r_cmd_t cmd;
struct r_anal_t anal;
RAnal anal;
RSyscall syscall;
RAsm assembler;
struct r_parse_t parser;

View file

@ -1,4 +1,4 @@
LIBS=r_util.so r_bp.so r_asm.so r_diff.so r_core.so r_bin.so r_cons.so r_anal.so
LIBS=r_util.so r_bp.so r_asm.so r_diff.so r_core.so r_bin.so r_cons.so r_anal.so r_cmd.so
LIBS+=r_debug.so r_config.so r_io.so r_syscall.so r_search.so r_lib.so libr.so r_flags.so
.SUFFIXES: .so

View file

@ -1,14 +1,15 @@
/* radare - LGPL - Copyright 2010 pancake<@nopcode.org> */
namespace Radare {
[Compact]
[CCode (cheader_filename="r_anal.h", cprefix="r_anal_", lowercase_c_prefix="r_anal_", free_function="r_anal_free")]
public class Radare.RAnal {
[CCode (cheader_filename="r_anal.h", cprefix="r_anal_", lowercase_c_prefix="r_anal_", free_function="r_anal_free", cname="RAnal")]
public class RAnal {
public int bits;
public bool big_endian;
public void *user;
RList <BasicBlock> bbs;
RList <Function> fcns;
RList <VariableType> vartypes;
public RList <BasicBlock> bbs;
public RList <Function> fcns;
public RList <VariableType> vartypes;
public RAnal ();
//public weak RAnal init ();
@ -45,7 +46,7 @@ public class Radare.RAnal {
}
[Compact]
[CCode (cprefix="r_anal_fcn_t")]
[CCode (cprefix="r_anal_fcn_t", cname="RAnalFcn")]
public class Function {
public string name;
public uint64 addr;
@ -89,3 +90,4 @@ public class Radare.RAnal {
int index;
}
}
}

39
swig/vapi/r_cmd.vapi Normal file
View file

@ -0,0 +1,39 @@
/* radare - LGPL - Copyright 2010 pancake<nopcode.org> */
namespace Radare {
// HACK
[Compact]
[CCode (cheader_filename="r_lib.h", cprefix="r_lib_struct_", cname="struct r_lib_struct_t", free_function="", destroy_function="")]
public struct RCmdStruct {
public RLibType type;
public RCmdHandle data;
}
[Compact]
[CCode (cheader_filename="r_cmd.h", cprefix="r_cmd_", cname="struct r_cmd_macro_t", free_function="")]
public class RCmdMacroItem {
int counter;
// TODO much moar
}
[CCode (has_target=false, cname="RCmdCallback")]
public delegate bool RCmdCallback (void *user, string cmd);
[CCode (cheader_filename="r_cmd.h", cname="RCmdHandle", free_function="", destroy_function="")]
public struct RCmdHandle {
string name;
RCmdCallback call;
}
[Compact]
[CCode (cheader_filename="r_cmd.h", cprefix="r_cmd_", cname="struct r_cmd_t", free_function="r_cmd_free")]
public class RCmd {
public RCmd ();
public void set_data (void *data);
public bool @add (string cmd, string desc, RCmdCallback cb);
public bool add_long (string cmd, string scmd, string desc);
public bool del (string cmd);
public bool call (string cmd);
public bool call_long (string cmd);
}
}

View file

@ -1,4 +1,5 @@
r_cons
r_anal
r_line
r_io
r_bp

View file

@ -8,6 +8,7 @@ public class Radare.RCore {
/* lifecycle */
public RCore();
public RCons cons;
public RAnal anal;
public static unowned RCore cast(uint64 ptr);
public bool loadlibs();

View file

@ -31,4 +31,29 @@ namespace Radare {
// destructor
}
}
[Compact]
[CCode (cheader_filename="r_lib.h", cprefix="r_lib_struct_", cname="struct r_lib_struct_t", free_function="r_lib_free")]
public struct RLibStruct {
public RLibType foo;
public void *data;
}
[CCode (cprefix="R_LIB_TYPE_", cname="int")]
public enum RLibType {
IO,
DBG,
LANG,
ASM,
ANAL,
PARSE,
BIN,
BININFO,
BP,
SYSCALL,
FASTCALL,
CRYPTO,
CMD,
LAST
}
}

View file

@ -1,6 +1,9 @@
all: bin lang core regs hash sc socket asm search db io array list
all: plugin.so bin lang core regs hash sc socket asm search db io array list
@true
plugin.so:
valac --library=plugin -o plugin.so --Xcc=-shared --Xcc=-fPIC --vapidir=.. --pkg r_cmd --pkg r_lib --pkg r_core plugin.vala
#bin:
# valac --vapidir=.. bin.vala --pkg r_bin --pkg r_util

35
swig/vapi/t/plugin.vala Normal file
View file

@ -0,0 +1,35 @@
/* vala r2 plugin */
using Radare;
[CCode (has_target = false)]
private bool mycall(void *user, string cmd) {
if (cmd.has_prefix (":bc")) {
if (cmd.len () == 3) {
print ( "BinCrowd radare2 plugin help:\n"+
":bc pull retrieve signatures from server\n"+
":bc push upload signatures to server\n"+
"See: http://bincrowd.zynamics.com/\n");
} else {
RCore* core = (RCore*)user;
string p = (string)(((char*)cmd)+4);
print ("Hello World from Vala! (%s)\n", p);
//core->cmd ("pd 4 @ eip", false);
//core->cmd ("x", false);
/* hack to get address of anal .. FIXME */
RAnal *anal = (RAnal*)(&core->anal);
foreach (var f in anal->fcns) {
print ("fun %s @ 0x%08llx\n", f.name, f.addr);
}
}
return true;
}
return false;
}
private const RCmdHandle plugin = {
"my plugin", mycall
};
const RCmdStruct radare_plugin = {
RLibType.CMD, ref plugin
};