* Add bindings for go

* Add swig/go/test-r_bin.go for testing r_bin from go
* Fix build for r_bp and r_search bindings
* Rename enum VarType to VarClass in r_anal.vapi to avoid conflicts
* Add flag -R to rabin_cmd in r2 start up
This commit is contained in:
Nibble 2010-09-12 12:31:18 +02:00
parent f4ada2309f
commit 5733497a0b
12 changed files with 77 additions and 11 deletions

1
TODO
View File

@ -41,6 +41,7 @@ Build system:
TODO nibble
-----------
* Better way to fix got_offset issue?
* use r_anal_value everywhere in r_anal
* make x86_x86im the default backend for x86 analysis
* implement analysis for more instructions in x86_x86im

View File

@ -221,7 +221,7 @@ int main(int argc, char **argv) {
}
if (!has_project && run_rc) {
rabin_cmd = r_str_dup_printf ("rabin2 -rSIeMzis%s %s",
rabin_cmd = r_str_dup_printf ("rabin2 -rSIeMzisR%s %s",
(debug||r.io->va)?"v":"", r.file->filename);
if (threaded) {
/* TODO: only load data if no project is used */

View File

@ -173,7 +173,7 @@ R_API int r_bin_load(RBin *bin, const char *file, const char *plugin_name) {
list_for_each (pos, &bin->bins) {
RBinPlugin *h = list_entry (pos, RBinPlugin, list);
if ((plugin_name && !strcmp (h->name, plugin_name)) ||
(h->check && h->check (bin)))
(h->check && h->check (bin)))
bin->cur = h;
}
if (bin->cur && bin->cur->load && bin->cur->load (bin))

View File

@ -1,6 +1,6 @@
-include config.mk
all: supported.langs ruby perl python lua
all: supported.langs ruby perl python lua go
supported.langs:
sh check-langs.sh
@ -39,6 +39,9 @@ ruby:
lua:
@-[ "`grep lua supported.langs`" ] && cd lua && make
go:
@-[ "`grep go supported.langs`" ] && cd go && make
java:
@-[ "`grep java supported.langs`" ] && cd java && make
@ -47,6 +50,7 @@ test:
cd python && make test
cd ruby && make test
cd lua && make test
cd go && make test
cd java && make test
install-python:
@ -70,6 +74,14 @@ install-lua:
done ; \
fi
install-go:
@if [ -n "${GOROOT}" -a -n "${GOOS}" -a -n "${GOARCH}" ]; then \
echo "Installing r2 modules in ${GOROOT}/pkg/${GOOS}_${GOARCH}" ; \
cp -f go/*.a go/*.so ${GOROOT}/pkg/${GOOS}_${GOARCH} ; \
else \
echo "You have to set the following vars: GORROT, GOOS and GOARCH" ; \
fi
install-java:
@echo "TODO: install-java"
@ -102,7 +114,7 @@ install-vapi:
@${INSTALL_DIR} ${DESTDIR}${PREFIX}/share/vala/vapi
${INSTALL_DATA} vapi/*.vapi vapi/*.deps ${DESTDIR}${PREFIX}/share/vala/vapi
install: install-python install-ruby install-perl install-lua install-java install-vapi
install: install-python install-ruby install-perl install-lua install-go install-java install-vapi
deinstall: uninstall
uninstall:
@ -117,7 +129,8 @@ clean:
cd perl && make clean
cd ruby && make clean
cd lua && make clean
cd go && make clean
cd java && make clean
cd vapi/t && ${MAKE} clean
.PHONY: ruby lua java python perl clean oldtest test all vdoc
.PHONY: ruby lua go java python perl clean oldtest test all vdoc

View File

@ -1,6 +1,6 @@
#!/bin/sh
SUP_LANGS=""
LANGS="python perl ruby lua java"
LANGS="python perl ruby lua go java"
for a in ${LANGS}; do
printf "Checking $a support for valaswig... "
valaswig-cc --test $a

25
swig/go/Makefile Normal file
View File

@ -0,0 +1,25 @@
LANG=go
LANG_EXT=go
LIBS_PFX=
include ../rules.mk
%.so:
@-test ../../libr/vapi/`echo $@|sed -e s,.so,.vapi,` -nt ${LIBS_PFX}$@ ; \
if [ ! $$? = 0 ]; then \
if [ ! -e ${LIBS_PFX}$@ ]; then \
true ; \
else \
false ; \
fi ; \
fi ; \
if [ ${GOARCH} = "amd64" ]; then \
FLAGS_6c=-D_64BIT ; \
fi ; \
if [ $$? = 0 ]; then \
(cd .. && sh do-swig.sh ${LANG} `echo $@ | sed -e s,.so,,`) ; \
sed -i 's,^\(const UT.*\) int,\1 uint,' `echo $@ | sed -e s,.so,.go,` ; \
6g `echo $@ | sed -e s,.so,.go,` ; \
6c ${FLAGS_6c} -I ${GOROOT}/pkg/${GOOS}_${GOARCH} `echo $@ | sed -e s,.so,_gc.c,` ; \
gopack grc `echo $@ | sed -e s,.so,.a,` `echo $@ | sed -e s,.so,.6,` `echo $@ | sed -e s,.so,_gc.6,` ; \
fi

27
swig/go/test-r_bin.go Normal file
View File

@ -0,0 +1,27 @@
package main
import (
"fmt"
"r_bin"
)
func main() {
b := r_bin.NewRBin ();
b.Load ("/bin/ls", "")
baddr := b.GetBaddr ()
sv := b.Get_sections ()
fmt.Println ("-> Sections")
fmt.Printf ("baddr=%08x\n", baddr)
nsects := sv.Size ()
for i := 0; i < nsects; i++ {
s := sv.Get (i);
fmt.Printf ("offset=0x%08x va=0x%08x size=%05d %s\n",
s.GetOffset (), baddr+s.GetRva (), s.GetSize (), s.GetName())
}
/*
for _, s:= range b.Get_sections () {
fmt.Printf ("offset=0x%08x va=0x%08x size=%05d %s\n",
s.GetOffset (), baddr+s.GetRva (), s.GetSize (), s.GetName())
}
*/
}

View File

@ -33,7 +33,7 @@ public class RAnal {
*/
[CCode (cprefix="R_ANAL_VAR_TYPE_")]
public enum VarType {
public enum VarClass {
NULL,
GLOBAL,
LOCAL,
@ -196,7 +196,6 @@ public class RAnal {
public RList<RAnal.VarAccess> accessess;
}
/*
[Compact]
[CCode (cname="RAnalVarType")]
public class VarType {
@ -204,7 +203,6 @@ public class RAnal {
public string fmt;
public uint size;
}
*/
[Compact]
[CCode (cname="RAnalRefline", free_function="")]

1
swig/vapi/r_bp.deps Normal file
View File

@ -0,0 +1 @@
r_util

View File

@ -1,7 +1,7 @@
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
[Compact]
[CCode (cheader_filename="r_bp.h,r_list.h", cname="struct r_bp_t", free_function="r_bp_free", cprefix="r_bp_")]
[CCode (cheader_filename="r_bp.h,r_types_base.h,r_list.h", cname="struct r_bp_t", free_function="r_bp_free", cprefix="r_bp_")]
public class Radare.RBreakpoint {
public RBreakpoint ();
public RList<Item> bps;

1
swig/vapi/r_search.deps Normal file
View File

@ -0,0 +1 @@
r_util

View File

@ -1,7 +1,7 @@
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
[Compact]
[CCode (cheader_filename="r_list.h,r_search.h", cname="struct r_search_t", free_function="r_search_free", cprefix="r_search_")]
[CCode (cheader_filename="r_types_base.h,r_list.h,r_search.h", cname="struct r_search_t", free_function="r_search_free", cprefix="r_search_")]
public class Radare.RSearch {
[CCode (cname="RSearchCallback", has_target="false")]
public delegate int Callback(Keyword s, void *user, uint64 addr);