diff --git a/libr/core/asm.c b/libr/core/asm.c index 9dcb508bfc..5f36dc7f01 100644 --- a/libr/core/asm.c +++ b/libr/core/asm.c @@ -47,14 +47,16 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6 RList *hits; ut64 at, toff = core->offset; ut8 *buf; - char *tok, *tokens[1024], *code = NULL; + char *tok, *tokens[1024], *code = NULL, *ptr; int idx, tidx, ret, len; int tokcount, matchcount; + if (!(ptr = strdup (input))) + return NULL; if (!(hits = r_core_asm_hit_list_new ())) return NULL; for (tokcount=0;;tokcount++) { - if (tokcount==0) tok = (char*)strtok ((char*)input, ";"); + if (tokcount==0) tok = (char*)strtok (ptr, ";"); else tok = (char*)strtok (NULL, ";"); if (tok == NULL) break; @@ -115,5 +117,7 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6 } r_asm_set_pc (core->assembler, toff); free (buf); + free (ptr); + free (code); return hits; } diff --git a/swig/vapi/r_bin.vapi b/swig/vapi/r_bin.vapi index 2045775266..5732313ed9 100644 --- a/swig/vapi/r_bin.vapi +++ b/swig/vapi/r_bin.vapi @@ -9,7 +9,7 @@ namespace Radare { public RBin(); - public int load(string file, int dummy); + public int load(string file, bool dummy); public int list(); public uint64 get_baddr(); public RBin.Addr get_main(); @@ -43,7 +43,7 @@ namespace Radare { public int32 vsize; public int64 rva; public int64 offset; - public int32 rwx; + public int32 srwx; } [CCode (cname="RBinSymbol", free_function="", ref_function="", unref_function="")] diff --git a/swig/vapi/r_config.vapi b/swig/vapi/r_config.vapi index c5714403b3..c50085a4b1 100644 --- a/swig/vapi/r_config.vapi +++ b/swig/vapi/r_config.vapi @@ -16,7 +16,7 @@ namespace Radare { public void list(string? foo, int bar); } - [CCode (cname="RConfigNode", free_function="")] + [CCode (cname="RConfigNode", free_function="", unref_function="")] public class RConfigNode { string name; int hash; diff --git a/swig/vapi/r_core.vapi b/swig/vapi/r_core.vapi index 0368eb22e5..9d2efde0f9 100644 --- a/swig/vapi/r_core.vapi +++ b/swig/vapi/r_core.vapi @@ -61,8 +61,8 @@ public class RCore { [CCode (cname="RCoreAsmHit", free_function="", ref_function="", unref_function="")] public class AsmHit { - string code; - uint64 addr; + public string code; + public uint64 addr; } /* files */ diff --git a/swig/vapi/t/Makefile b/swig/vapi/t/Makefile index e3ab74595c..7aec87df63 100644 --- a/swig/vapi/t/Makefile +++ b/swig/vapi/t/Makefile @@ -1,4 +1,4 @@ -all: plugin.so bin lang core regs hash sc socket asm search db io list rgot +all: plugin.so bin lang core asmsearch regs hash sc socket asm search db io list rgot @true plugin.so: @@ -65,7 +65,6 @@ core: -lr_lib -Wl,-R../../lib -L../../lib \ -lr_parse -Wl,-R../../parse -L../../parse \ -lr_flags -Wl,-R../../flags -L../../flags \ - -lr_meta -Wl,-R../../meta -L../../meta \ -lr_print -Wl,-R../../print -L../../print \ -lr_config -Wl,-R../../config -L../../config \ -lr_search -Wl,-R../../search -L../../search \ @@ -75,6 +74,9 @@ core: -lr_bp -Wl,-R../../bp -L../../bp \ -g -o core +asmsearch: + valac --vapidir=.. asmsearch.vala --pkg r_core --pkg r_bin -o asmsearch + search: valac -C --vapidir=${PWD}/.. search.vala --pkg r_search --pkg r_util gcc search.c `pkg-config gobject-2.0 --libs --cflags` -I../../../libr/include/ \ @@ -103,4 +105,4 @@ socket: gcc socket.c `pkg-config gobject-2.0 --libs --cflags` -I../../../libr/include/ -lr_socket -Wl,-R../../socket -L../../socket -o socket clean: - -rm -f *.c hash sc *.o *.h core socket asm search bin io rgot reloc + -rm -f *.c hash sc *.o *.h core socket asm search bin io rgot reloc asmsearch diff --git a/swig/vapi/t/asmsearch.vala b/swig/vapi/t/asmsearch.vala new file mode 100644 index 0000000000..425b7a31a0 --- /dev/null +++ b/swig/vapi/t/asmsearch.vala @@ -0,0 +1,14 @@ +using Radare; + +public static void main(string[] args) +{ + var c = new RCore(); + var b = new RBin(); + c.file_open("/bin/ls", 0); + b.load("/bin/ls", false); + uint64 baddr = b.get_baddr(); + foreach (var scn in b.get_sections()) + if ((scn.srwx & 0x1) != 0) + foreach (var hit in c.asm_strsearch("jmp e; ret", scn.offset, scn.offset+scn.size)) + print("0x%08"+uint64.FORMAT_MODIFIER+"x - %s\n", baddr+hit.addr, hit.code); +} diff --git a/swig/vapi/t/bin.vala b/swig/vapi/t/bin.vala index 120471c112..0fb2418a63 100644 --- a/swig/vapi/t/bin.vala +++ b/swig/vapi/t/bin.vala @@ -7,7 +7,7 @@ public void main (string[] args) { error ("Usage: %s \n", args[0]); var bin = new RBin (); - if (bin.load (args[1], null) != 1) + if (bin.load (args[1], false) != 1) error ("Cannot open binary file\n"); uint64 baddr = bin.get_baddr();