* Fix 'const char*' issue in valaswig bindings

- 'unowned string' is the correct vala type
  - Depends on valaswig tip
  - type checking is now more strict
* Build libr.so again for swig bindings
* Added test-r_bin.py
This commit is contained in:
pancake 2010-02-12 00:43:11 +01:00
parent d1aceaaa80
commit 648f8ebe23
24 changed files with 149 additions and 107 deletions

View File

@ -231,14 +231,15 @@ R_API int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, const char
if (a->cur) {
if (a->cur->assemble)
ret = a->cur->assemble(a, aop, buf);
else /* find callback if no assembler support in current plugin */
list_for_each_prev(pos, &a->asms) {
struct r_asm_handle_t *h = list_entry(pos, struct r_asm_handle_t, list);
if (h->arch && h->assemble && has_bits(h, a->bits) && !strcmp(a->cur->arch, h->arch)) {
ret = h->assemble(a, aop, buf);
break;
}
/* find callback if no assembler support in current plugin */
else list_for_each_prev(pos, &a->asms) {
RAsmHandle *h = list_entry(pos, RAsmHandle, list);
if (h->arch && h->assemble && has_bits(h, a->bits)
&& !strcmp(a->cur->arch, h->arch)) {
ret = h->assemble(a, aop, buf);
break;
}
}
}
if (aop && ret > 0) {
r_hex_bin2str(aop->buf, ret, aop->buf_hex);

View File

@ -57,7 +57,7 @@ R_API struct r_config_node_t *r_config_node_get(struct r_config_t *cfg, const ch
return NULL;
}
R_API const char *r_config_get(struct r_config_t *cfg, const char *name)
R_API char *r_config_get(struct r_config_t *cfg, const char *name)
{
struct r_config_node_t *node =
r_config_node_get(cfg, name);
@ -67,7 +67,7 @@ R_API const char *r_config_get(struct r_config_t *cfg, const char *name)
return (const char *)
(((!strcmp("true", node->value))
|| (!strcmp("1", node->value)))?
(const char *)1:NULL);
(char *)1:NULL); // XXX (char*)1 is ugly
return node->value;
}
cfg->last_notfound = 1;

View File

@ -55,7 +55,7 @@ R_API RCons *r_cons_new ()
return &I;
}
R_API RCons *r_cons_free ()
R_API RCons *r_cons_free (RCons *foo)
{
/* do nothing */
return NULL;

View File

@ -28,8 +28,8 @@ static inline void **r_array_new(int n) {
}
static inline void **r_array_prev(void **it) {
void **p = it;
return (--it==*it)?p:it;
void **p = it--;
return (it==*it)?p:it;
}
static inline void r_array_set(void **it, int idx, void *data) {

View File

@ -68,33 +68,33 @@ enum {
};
#ifdef R_API
R_API struct r_bp_t *r_bp_init(struct r_bp_t *bp);
R_API struct r_bp_t *r_bp_new();
R_API struct r_bp_t *r_bp_free(struct r_bp_t *bp);
R_API RBreakpoint *r_bp_init(RBreakpoint *bp);
R_API RBreakpoint *r_bp_new();
R_API RBreakpoint *r_bp_free(RBreakpoint *bp);
R_API int r_bp_del(struct r_bp_t *bp, ut64 addr);
R_API int r_bp_del(RBreakpoint *bp, ut64 addr);
R_API int r_bp_handle_add(struct r_bp_t *bp, struct r_bp_handle_t *foo);
R_API int r_bp_use(struct r_bp_t *bp, const char *name);
R_API int r_bp_handle_del(struct r_bp_t *bp, const char *name);
R_API void r_bp_handle_list(struct r_bp_t *bp);
R_API int r_bp_handle_add(RBreakpoint *bp, struct r_bp_handle_t *foo);
R_API int r_bp_use(RBreakpoint *bp, const char *name);
R_API int r_bp_handle_del(RBreakpoint *bp, const char *name);
R_API void r_bp_handle_list(RBreakpoint *bp);
R_API int r_bp_in(struct r_bp_t *bp, ut64 addr, int rwx);
R_API int r_bp_list(struct r_bp_t *bp, int rad);
R_API int r_bp_get_bytes(struct r_bp_t *bp, ut8 *buf, int len, int endian, int idx);
R_API int r_bp_set_trace(struct r_bp_t *bp, ut64 addr, int set);
//R_API int r_bp_set_trace_bp(struct r_bp_t *bp, ut64 addr, int set);
R_API struct r_bp_item_t *r_bp_enable(struct r_bp_t *bp, ut64 addr, int set);
R_API int r_bp_in(RBreakpoint *bp, ut64 addr, int rwx);
R_API int r_bp_list(RBreakpoint *bp, int rad);
R_API int r_bp_get_bytes(RBreakpoint *bp, ut8 *buf, int len, int endian, int idx);
R_API int r_bp_set_trace(RBreakpoint *bp, ut64 addr, int set);
//R_API int r_bp_set_trace_bp(RBreakpoint *bp, ut64 addr, int set);
R_API RBreakpointItem *r_bp_enable(RBreakpoint *bp, ut64 addr, int set);
R_API int r_bp_add_cond(struct r_bp_t *bp, const char *cond);
R_API int r_bp_del_cond(struct r_bp_t *bp, int idx);
R_API int r_bp_add_fault(struct r_bp_t *bp, ut64 addr, int size, int rwx);
R_API int r_bp_add_cond(RBreakpoint *bp, const char *cond);
R_API int r_bp_del_cond(RBreakpoint *bp, int idx);
R_API int r_bp_add_fault(RBreakpoint *bp, ut64 addr, int size, int rwx);
R_API struct r_bp_item_t *r_bp_add_sw(struct r_bp_t *bp, ut64 addr, int size, int rwx);
R_API struct r_bp_item_t *r_bp_add_hw(struct r_bp_t *bp, ut64 addr, int size, int rwx);
R_API RBreakpointItem *r_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int rwx);
R_API RBreakpointItem *r_bp_add_hw(RBreakpoint *bp, ut64 addr, int size, int rwx);
R_API RBreakpointItem *r_bp_at_addr(RBreakpoint *bp, ut64 addr, int rwx);
R_API int r_bp_restore(struct r_bp_t *bp, int set);
R_API int r_bp_recoil(struct r_bp_t *bp, ut64 addr);
R_API int r_bp_restore(RBreakpoint *bp, int set);
R_API int r_bp_recoil(RBreakpoint *bp, ut64 addr);
#endif
/* plugin pointers */

View File

@ -35,9 +35,9 @@ typedef struct r_config_t {
} RConfig;
#ifdef R_API
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 RConfig *r_config_new(void *user);
R_API int r_config_free(RConfig *cfg);
R_API int r_config_init(RConfig *core, void *user);
R_API void r_config_lock(RConfig *cfg, int l);
R_API int r_config_eval(RConfig *cfg, const char *str);
R_API struct r_config_node_t *r_config_set_i(RConfig *cfg, const char *name, const ut64 i);
@ -46,10 +46,10 @@ R_API struct r_config_node_t *r_config_set_i_cb(RConfig *cfg, const char *name,
R_API int r_config_rm(RConfig *cfg, const char *name);
R_API struct r_config_node_t *r_config_set(RConfig *cfg, const char *name, const char *value);
R_API ut64 r_config_get_i(RConfig *cfg, const char *name);
R_API const char *r_config_get(RConfig *cfg, const char *name);
R_API char *r_config_get(RConfig *cfg, const char *name);
R_API void r_config_list(RConfig *cfg, const char *str, int rad);
R_API struct r_config_node_t *r_config_node_get(RConfig *cfg, const char *name);
R_API struct r_config_node_t *r_config_node_new(const char *name, const char *value);
R_API RConfigNode *r_config_node_get(RConfig *cfg, const char *name);
R_API RConfigNode *r_config_node_new(const char *name, const char *value);
R_API int r_config_swap(RConfig *cfg, const char *name);
#endif

View File

@ -83,7 +83,7 @@ extern char r_cons_palette[CONS_PALETTE_SIZE][8];
//extern char *r_cons_filterline;
//extern char *r_cons_teefile;
// not needed anymoar
extern int (*r_cons_user_fgets)(char *buf, int len);
//extern int (*r_cons_user_fgets)(char *buf, int len);
/* plain colors */
@ -147,6 +147,9 @@ enum {
#ifdef R_API
R_API RCons *r_cons_new ();
R_API RCons *r_cons_free (RCons *foo);
R_API void r_cons_break(void (*cb)(void *u), void *user);
R_API void r_cons_break_end();
@ -174,7 +177,7 @@ R_API void r_cons_newline();
R_API void r_cons_flush();
/* input */
R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv);
//R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv);
R_API int r_cons_readchar();
R_API void r_cons_any_key();
R_API int r_cons_eof();

View File

@ -100,6 +100,20 @@ typedef struct r_debug_pid_t {
} RDebugPid;
#ifdef R_API
R_API int r_debug_attach(struct r_debug_t *dbg, int pid);
R_API int r_debug_detach(struct r_debug_t *dbg, int pid);
R_API int r_debug_startv(struct r_debug_t *dbg, int argc, char **argv);
R_API int r_debug_start(struct r_debug_t *dbg, const char *cmd);
R_API int r_debug_stop_reason(struct r_debug_t *dbg);
R_API int r_debug_wait(struct r_debug_t *dbg);
R_API int r_debug_step_over(struct r_debug_t *dbg, int steps);
R_API int r_debug_continue_until(struct r_debug_t *dbg, ut64 addr);
R_API int r_debug_continue_syscall(struct r_debug_t *dbg, int sc);
R_API int r_debug_pid_add(struct r_debug_t *dbg);
R_API int r_debug_pid_add_thread(struct r_debug_t *dbg);
R_API int r_debug_pid_del(struct r_debug_t *dbg);
R_API int r_debug_pid_del_thread(struct r_debug_t *dbg);
R_API int r_debug_use(struct r_debug_t *dbg, const char *str);
R_API int r_debug_handle_add(struct r_debug_t *dbg, struct r_debug_handle_t *foo);
R_API int r_debug_handle_init(struct r_debug_t *dbg);

View File

@ -195,6 +195,7 @@ R_API int r_io_map(struct r_io_t *io, const char *file, ut64 offset);
R_API int r_io_map_read_at(struct r_io_t *io, ut64 off, ut8 *buf, int len);
//R_API int r_io_map_read_rest(struct r_io_t *io, ut64 off, ut8 *buf, ut64 len);
R_API int r_io_map_write_at(struct r_io_t *io, ut64 off, const ut8 *buf, int len);
R_API RIOMap *r_io_map_resolve(struct r_io_t *io, int fd);
R_API int r_io_section_rm(struct r_io_t *io, int idx);
R_API void r_io_section_add(struct r_io_t *io, ut64 from, ut64 to, ut64 vaddr, ut64 physical, int rwx, const char *comment);

View File

@ -80,7 +80,7 @@ R_API int r_search_set_blocksize(struct r_search_t *s, ut32 bsize);
// TODO: this is internal API?
R_API int r_search_mybinparse_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
R_API int r_search_aes_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
R_API int r_search_strings_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len, int enc);
R_API int r_search_strings_update(struct r_search_t *s, ut64 from, const char *buf, int len, int enc);
R_API int r_search_regexp_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
R_API int r_search_xrefs_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);

View File

@ -62,16 +62,16 @@ typedef struct r_syscall_arch_handle_t {
} RSyscallArchHandle;
#ifdef R_API
struct r_syscall_t *r_syscall_new();
void r_syscall_free(struct r_syscall_t *ctx);
void r_syscall_init(struct r_syscall_t *ctx);
R_API struct r_syscall_t *r_syscall_new();
R_API void r_syscall_free(struct r_syscall_t *ctx);
R_API void r_syscall_init(struct r_syscall_t *ctx);
int r_syscall_setup(struct r_syscall_t *ctx, int arch, int os);
int r_syscall_setup_file(struct r_syscall_t *ctx, const char *path);
int r_syscall_get(struct r_syscall_t *ctx, const char *str);
struct r_syscall_list_t *r_syscall_get_n(struct r_syscall_t *ctx, int n);
const char *r_syscall_get_i(struct r_syscall_t *ctx, int num, int swi);
void r_syscall_list(struct r_syscall_t *ctx);
R_API int r_syscall_setup(struct r_syscall_t *ctx, int arch, int os);
R_API int r_syscall_setup_file(struct r_syscall_t *ctx, const char *path);
R_API int r_syscall_get(struct r_syscall_t *ctx, const char *str);
R_API RSyscallList *r_syscall_get_n(struct r_syscall_t *ctx, int n);
R_API const char *r_syscall_get_i(struct r_syscall_t *ctx, int num, int swi); // XXX const char *
R_API void r_syscall_list(struct r_syscall_t *ctx);
#endif
#endif

View File

@ -54,7 +54,7 @@ static int is_encoded(int encoding, unsigned char c)
return 0;
}
R_API int r_search_strings_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len, int enc)
R_API int r_search_strings_update(struct r_search_t *s, ut64 from, const char *buf, int len, int enc)
{
int i = 0;
int widechar = 0;

View File

@ -1,4 +1,4 @@
/* radare 2008 GPL -- pancake <youterm.com> */
/* radare 2008-2010 GPL -- pancake <youterm.com> */
#include "r_types.h"
#include "r_syscall.h"
@ -10,10 +10,9 @@ extern struct r_syscall_list_t syscalls_linux_x86[];
extern struct r_syscall_list_t syscalls_freebsd_x86[];
extern struct r_syscall_list_t syscalls_darwin_x86[];
struct r_syscall_t *r_syscall_new()
{
struct r_syscall_t *ctx;
ctx = (struct r_syscall_t *)malloc(sizeof(struct r_syscall_t));
R_API RSyscall* r_syscall_new() {
RSyscall *ctx;
ctx = (RSyscall*) malloc (sizeof (RSyscall));
if (ctx == NULL)
return NULL;
ctx->fd = NULL;
@ -21,19 +20,16 @@ struct r_syscall_t *r_syscall_new()
return ctx;
}
void r_syscall_init(struct r_syscall_t *ctx)
{
R_API void r_syscall_init(struct r_syscall_t *ctx) {
ctx->fd = NULL;
ctx->sysptr = syscalls_linux_x86;
}
void r_syscall_free(struct r_syscall_t *ctx)
{
free(ctx);
R_API void r_syscall_free(struct r_syscall_t *ctx) {
free (ctx);
}
int r_syscall_setup(struct r_syscall_t *ctx, int os, int arch)
{
R_API int r_syscall_setup(struct r_syscall_t *ctx, int os, int arch) {
switch(arch) {
case R_SYSCALL_ARCH_X86:
default:
@ -55,52 +51,49 @@ int r_syscall_setup(struct r_syscall_t *ctx, int os, int arch)
break;
}
if (ctx->fd)
fclose(ctx->fd);
fclose (ctx->fd);
ctx->fd = NULL;
return 0;
}
int r_syscall_setup_file(struct r_syscall_t *ctx, const char *path)
{
R_API int r_syscall_setup_file(struct r_syscall_t *ctx, const char *path) {
if (ctx->fd)
fclose(ctx->fd);
ctx->fd = fopen(path, "r");
fclose (ctx->fd);
ctx->fd = fopen (path, "r");
if (ctx->fd == NULL)
return 1;
/* TODO: load info from file */
return 0;
}
int r_syscall_get(struct r_syscall_t *ctx, const char *str)
{
R_API int r_syscall_get(struct r_syscall_t *ctx, const char *str) {
int i;
for(i=0;ctx->sysptr[i].num;i++)
if (!strcmp(str, ctx->sysptr[i].name))
for (i=0;ctx->sysptr[i].num;i++)
if (!strcmp (str, ctx->sysptr[i].name))
return ctx->sysptr[i].num;
return 0;
}
struct r_syscall_list_t *r_syscall_get_n(struct r_syscall_t *ctx, int n)
R_API RSyscallList *r_syscall_get_n(struct r_syscall_t *ctx, int n)
{
int i;
for(i=0;ctx->sysptr[i].num && i!=n;i++)
for (i=0;ctx->sysptr[i].num && i!=n;i++)
return &ctx->sysptr[i];
return NULL;
}
const char *r_syscall_get_i(struct r_syscall_t *ctx, int num, int swi)
R_API char *r_syscall_get_i(struct r_syscall_t *ctx, int num, int swi)
{
int i;
for(i=0;ctx->sysptr[i].num;i++)
for (i=0;ctx->sysptr[i].num;i++)
if (num == ctx->sysptr[i].num && (swi == -1 || swi == ctx->sysptr[i].swi))
return ctx->sysptr[i].name;
return NULL;
}
void r_syscall_list(struct r_syscall_t *ctx)
{
R_API void r_syscall_list(struct r_syscall_t *ctx) {
int i;
for(i=0;ctx->sysptr[i].num;i++) {
for (i=0; ctx->sysptr[i].num; i++) {
printf("%02x: %d = %s\n",
ctx->sysptr[i].swi, ctx->sysptr[i].num, ctx->sysptr[i].name);
}

View File

@ -1,15 +1,14 @@
r_asm
r_hash
r_config
r_core
r_line
r_cons
r_search
r_diff
r_io
r_lib
r_syscall
r_bp
r_reg
r_util
r_debug
r_diff
r_lib
r_search
r_syscall

View File

@ -33,7 +33,7 @@ public class Radare.RBreakpoint {
[Compact]
[CCode (cname="RBreakpointItem")]
public struct Item {
public class Item {
uint64 addr;
int size;
int rwx;

View File

@ -8,12 +8,22 @@ namespace Radare {
public int eval(string str);
public int get(string name);
public string get_i(string name);
public string get(string name);
public uint64 get_i(string name);
public string set(string name, string val);
public string set_i(string name, string val);
public RConfigNode set(string name, string val);
public RConfigNode set_i(string name, uint64 val);
public void list(string? foo, int bar);
}
[CCode (cname="RConfigNode", free_function="")]
public class RConfigNode {
string name;
int hash;
int flags;
string @value;
uint64 i_value;
/* TODO: moar */
}
}

View File

@ -12,7 +12,7 @@ public class Radare.RDebug {
public bool attach(int pid);
public bool detach(int pid);
// TODO: add attribute to invert arraylen
public bool startv(string[] argv); // XXX
//public bool startv(string[] argv); // XXX
public bool start(string cmd);
public int stop_reason();

View File

@ -8,7 +8,7 @@ namespace Radare {
public int buffers (uint8* a, int la, uint8* b, int lb);
//public int set_callback(...);
public int buffers_distance (uint8 *a, int la, uint8 *b, int lb, out uint32 distance, out double similarity);
public static int lines (string file, string sa, int la, string file2, string sb, int lb);
//public static int lines (string file, string sa, int la, string file2, string sb, int lb);
[Compact]
[CCode (cname="struct r_diff_handle_t", destroy_function="", free_function="" )]

View File

@ -64,7 +64,7 @@ namespace Radare {
/* maps */
[CCode (cname="RIOMap", cprefix="r_io_map_")]
public struct Map {
public class Map {
int fd;
uint64 from;
uint64 to;
@ -94,6 +94,7 @@ namespace Radare {
int flags;
const string name;
}
public bool desc_add(int fd, string file, Perm perms, Handle handle);
// int perms -> RIOPerm ?
public bool desc_add(int fd, string file, int perms, Handle handle);
}
}

View File

@ -6,14 +6,14 @@ namespace Radare {
public class RLibrary {
public RLibrary(string symname);
public RLibrary init(string symname);
public bool close(void *ptr);
public void* opendir(string path);
public string types_get(int idx);
public bool close(string file);
public int opendir(string path);
//public string types_get(int idx);
/* lowlevel api */
public static void* dl_open(string libname);
public void* dl_sym(string symname);
public static bool dl_close(void *lh);
public static bool dl_close(void *handle);
public static bool dl_check_filename(string file);
/* handlers */
// we need delegates here (function pointerz)
@ -22,6 +22,7 @@ namespace Radare {
public Handler get_handler(int type);
//public struct Struct { }
[Compact]
[CCode (cname="struct r_lib_handler_t*")]
public struct Handler {
int type;
string desc;

View File

@ -5,7 +5,7 @@
public class Radare.RSearch {
public RSearch (Mode mode);
public bool set_mode (Mode mode);
public bool set_string_limits (uint32 min, uint32 max);
// public bool set_string_limits (uint32 min, uint32 max);
public bool begin();
public void kw_reset();
public void reset();
@ -13,12 +13,12 @@ public class Radare.RSearch {
public bool update_i(uint64 from, uint8 *buf, long len);
public bool kw_add(string kw, string binmask);
public bool kw_add_hex(string kw, string binmask);
public bool kw_add_bin(string kw, uint32 kw_len, string binmask, long bm_len);
public bool kw_add_bin(uint8 *kw, uint32 kw_len, uint8 *binmask, long bm_len);
public Keyword kw_list();
public int set_callback(Callback cb, void *user);
public int pattern_update(int size); // this is uint? long?
public int set_pattern_size(int size); // this is uint? long?
public int strings_update(uint64 addr, char *buf, int len, int enc);
//public int pattern_update(int size); // this is uint? long?
//public int set_pattern_size(int size); // this is uint? long?
public int strings_update(uint64 addr, string *buf, int len, int enc);
[CCode (cprefix="R_SEARCH_", cname="int")]
public enum Mode {
@ -32,7 +32,7 @@ public class Radare.RSearch {
[Compact]
[CCode (cname="struct r_search_kw_t")]
public struct Keyword {
public class Keyword {
public unowned string keyword;
public unowned string binmask;
public uint8 *bin_keyword;

View File

@ -1,5 +1,6 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
[Compact]
[CCode (cheader_filename="r_syscall.h", cname="struct r_syscall_t", free_function="r_syscall_free", cprefix="r_syscall_")]
public class Radare.RSyscall {
@ -16,11 +17,20 @@ public class Radare.RSyscall {
X86 = 0, PPC, ARM, MIPS, SPARC
}
[CCode (cname="struct r_syscall_list_t", free_function="r_syscall_free")]
public class List {
string name;
int swi;
int num;
int args;
string sargs;
}
public RSyscall();
public void setup(int os, int arch);
public void setup_file(string file);
public int get(string syscall);
public string get_i(int num, int swi);
public string get_n(int num);
public unowned string get_i(int num, int swi);
public unowned List get_n(int num);
public void list();
}

View File

@ -0,0 +1,8 @@
from r_bin import *
b=RBin ()
b.load ("/bin/ls", None)
baddr = b.get_baddr ()
for i in b.get_imports ():
print "offset=0x%08x va=0x%08x name=%s" % (
i.offset, baddr+i.rva, i.name)

View File

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