mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-03 04:05:06 +00:00
* Fixes for the GUILE bindings
- Added accessors for RAsmAop-buf-hex and RAsmAop-buf-asm - Added test case for r_asm API
This commit is contained in:
parent
d9f56b1bab
commit
3f883a7c54
7
TODO
7
TODO
@ -3,13 +3,6 @@
|
||||
| < V . | . V . < _/ .-' _/| () |
|
||||
|__\__|_|__|___/__|__|_\__\___/ |____(_)____/
|
||||
|
||||
|
||||
UNDER DEVELOPMENT
|
||||
=================
|
||||
* r2-swig : Distribute generated .i files and cxx files.. so build is faster
|
||||
- ./configure --without-valaswig # compile without generating cxx files
|
||||
- build with swig/
|
||||
|
||||
Random stuff
|
||||
-----------
|
||||
* For each "call" or "push offset"+"ret" create a function.
|
||||
|
@ -411,3 +411,11 @@ R_API int r_asm_modify(RAsm *a, ut8 *buf, int field, ut64 val) {
|
||||
ret = a->cur->modify (a, buf, field, val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API char *r_asm_aop_get_hex(RAsmAop *aop) {
|
||||
return strdup (aop->buf_hex);
|
||||
}
|
||||
|
||||
R_API char *r_asm_aop_get_asm(RAsmAop *aop) {
|
||||
return strdup (aop->buf_asm);
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ enum {
|
||||
|
||||
typedef struct r_asm_aop_t {
|
||||
int inst_len;
|
||||
// But this is pretty slow..so maybe we should add some accessors
|
||||
ut8 buf[R_ASM_BUFSIZE];
|
||||
char buf_asm[R_ASM_BUFSIZE];
|
||||
char buf_hex[R_ASM_BUFSIZE];
|
||||
@ -113,6 +114,10 @@ R_API void* r_asm_code_free(struct r_asm_code_t *acode);
|
||||
R_API int r_asm_code_set_equ (RAsmCode *code, const char *key, const char *value);
|
||||
R_API char *r_asm_code_equ_replace (RAsmCode *code, char *str);
|
||||
|
||||
// accessors, to make bindings happy
|
||||
R_API char *r_asm_aop_get_hex(RAsmAop *aop);
|
||||
R_API char *r_asm_aop_get_asm(RAsmAop *aop);
|
||||
|
||||
/* plugin pointers */
|
||||
extern RAsmPlugin r_asm_plugin_dummy;
|
||||
extern RAsmPlugin r_asm_plugin_bf;
|
||||
|
@ -15,8 +15,7 @@ cd ${LNG}
|
||||
|
||||
#valaswig-cc ${LNG} ${MOD} -I../../libr/include ../../libr/vapi/${MOD}.vapi -l${MOD} -L../../libr/$(echo ${MOD} | sed -e s,r_,,)
|
||||
|
||||
echo "CFLAGS = $CFLAGS"
|
||||
echo "LIBS = `pkg-config --libs ${MOD}`"
|
||||
echo "Build ${MOD} `pkg-config --libs ${MOD}`"
|
||||
|
||||
valaswig-cc ${LNG} ${MOD} ${VALASWIGFLAGS} \
|
||||
-x --vapidir=../vapi ../vapi/${MOD} \
|
||||
|
@ -3,3 +3,13 @@ LANG_EXT=scm
|
||||
LIBS_PFX=
|
||||
|
||||
include ../rules.mk
|
||||
|
||||
patch:
|
||||
cd ../ ; patch -p2 < guile/vapi.patch
|
||||
|
||||
unpatch:
|
||||
cd ../ ; patch -R -p2 < guile/vapi.patch
|
||||
|
||||
run:
|
||||
GUILE_WARN_DEPRECATED=no guile test-asm.scm
|
||||
GUILE_WARN_DEPRECATED=no guile test-util.scm
|
||||
|
30
swig/guile/test-asm.scm
Normal file
30
swig/guile/test-asm.scm
Normal file
@ -0,0 +1,30 @@
|
||||
; Test example in scheme and r_asm api
|
||||
; pancake@nopcode.org // radare2 @ 2011
|
||||
|
||||
(load-extension "./r_asm" "SWIG_init")
|
||||
(define asm (new-RAsm))
|
||||
|
||||
(define op (new-RAsmAop))
|
||||
(define (assemble-opcode arch opstr)
|
||||
(RAsm-use asm arch)
|
||||
(RAsm-assemble asm op opstr)
|
||||
(let ((bytes (RAsmAop-get-hex op)))
|
||||
(display (string-append "opcode: " opstr))
|
||||
(newline)
|
||||
(if (equal? bytes "")
|
||||
(begin
|
||||
(display " * Oops. cannot assemble")
|
||||
(newline)
|
||||
)
|
||||
(begin
|
||||
(display (string-append " * bytes: " bytes))
|
||||
(newline)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(define arch "x86.olly")
|
||||
(assemble-opcode arch "invalid opcode")
|
||||
(assemble-opcode arch "nop")
|
||||
(assemble-opcode arch "mov eax, 33")
|
@ -2,4 +2,7 @@
|
||||
;
|
||||
(load-extension "./r_util.so" "SWIG_init")
|
||||
(r-sys-cmd "echo Hello World")
|
||||
(r-sys-sleep 1)
|
||||
; (let num (new-MNum #nil 0))
|
||||
(display "Hello World")
|
||||
(newline)
|
||||
|
32
swig/guile/vapi.patch
Normal file
32
swig/guile/vapi.patch
Normal file
@ -0,0 +1,32 @@
|
||||
diff -r 5dd73dc3dbf1 swig/vapi/r_bin.vapi
|
||||
--- a/swig/vapi/r_bin.vapi Thu Feb 17 16:14:27 2011 +0100
|
||||
+++ b/swig/vapi/r_bin.vapi Thu Feb 17 21:28:36 2011 +0100
|
||||
@@ -42,7 +42,8 @@
|
||||
public int has_dbg_linenums();
|
||||
public int has_dbg_syms();
|
||||
public int has_dbg_relocs();
|
||||
- public int meta_get_line(uint64 addr, ref string file, int len, out int line);
|
||||
+ public int meta_get_line(uint64 addr, out string file, int len, out int line);
|
||||
+ //XXX: workaround for GUILE public int meta_get_line(uint64 addr, ref string file, int len, out int line);
|
||||
public string meta_get_source_line(uint64 addr);
|
||||
|
||||
[CCode (cname="RBinArch", free_function="", ref_function="", unref_function="")]
|
||||
diff -r 5dd73dc3dbf1 swig/vapi/r_parse.vapi
|
||||
--- a/swig/vapi/r_parse.vapi Thu Feb 17 16:14:27 2011 +0100
|
||||
+++ b/swig/vapi/r_parse.vapi Thu Feb 17 21:28:36 2011 +0100
|
||||
@@ -9,9 +9,15 @@
|
||||
|
||||
public int list();
|
||||
public bool use(string name);
|
||||
+/* XXX this must be ref... but SWIG fails with the GUILE backend .. workaround */
|
||||
+ public bool filter(RFlag flag, out string data, out string str, int len);
|
||||
+ public bool assemble(out string dst, out string src);
|
||||
+ public bool parse(void *dst, out string src);
|
||||
+/*
|
||||
public bool filter(RFlag flag, ref string data, ref string str, int len);
|
||||
public bool assemble(ref string dst, ref string src);
|
||||
public bool parse(void *dst, ref string src);
|
||||
+*/
|
||||
/*
|
||||
|
||||
public void set_user_ptr(void *user);
|
@ -49,12 +49,15 @@ public class RAsm {
|
||||
|
||||
[Compact]
|
||||
[CCode (cname="RAsmAop", destroy_function="")]
|
||||
public struct Aop {
|
||||
public class Aop {
|
||||
public int inst_len;
|
||||
public uint8 *buf;
|
||||
public string buf_asm;
|
||||
public string buf_hex;
|
||||
public string buf_err;
|
||||
// accessors for bindings
|
||||
public string get_hex();
|
||||
public string get_asm();
|
||||
}
|
||||
|
||||
[Compact]
|
||||
|
Loading…
x
Reference in New Issue
Block a user