From 16866fe50464dbd67f87e11c9690f71dee7706ce Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 9 Oct 2011 21:54:14 +0200 Subject: [PATCH] * Do not build asm.x86_as or asm.x86_nasm - Deprecated as being problematic. x86.nz and x86.olly ftw * Fix singleton crash in swig bindings - Requires valabind-tip * Added 'wa*' and 'waf*' commands to show bytes instead of writing --- TODO | 3 +++ libr/asm/p/asm_x86_as.c | 2 +- libr/cons/cons.c | 4 +++- libr/core/cmd.c | 38 ++++++++++++++++++++++------------- plugins.def.cfg | 4 ++-- r2-bindings/vapi/r_cons.vapi | 5 +++-- r2-bindings/vapi/r_debug.vapi | 2 +- r2-bindings/vapi/r_line.vapi | 8 +++++--- 8 files changed, 42 insertions(+), 24 deletions(-) diff --git a/TODO b/TODO index 3fec715c7d..ca8717d06f 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,9 @@ ------8<-------------------8<--------------------8<-----------------8<---------- +* Add command to assemble opcodes and files without writing + - wan? wax? wafx? + ====[[ 0.8.6 ]]==== * asm.pseudo for brainfuck * implement 'ax' to get/set xrefs (better than afl ) diff --git a/libr/asm/p/asm_x86_as.c b/libr/asm/p/asm_x86_as.c index 0661e0db39..2b9030c5b6 100644 --- a/libr/asm/p/asm_x86_as.c +++ b/libr/asm/p/asm_x86_as.c @@ -66,7 +66,7 @@ RAsmPlugin r_asm_plugin_x86_as = { .init = NULL, .fini = NULL, .disassemble = NULL, - .assemble = &assemble, + .assemble = &assemble, }; #ifndef CORELIB diff --git a/libr/cons/cons.c b/libr/cons/cons.c index c15c285fb5..f6ee40177c 100644 --- a/libr/cons/cons.c +++ b/libr/cons/cons.c @@ -124,8 +124,10 @@ R_API RCons *r_cons_new () { } R_API RCons *r_cons_free () { - if (I.buffer) + if (I.buffer) { free (I.buffer); + I.buffer = NULL; + } return NULL; } diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 901165f515..9d703eaac4 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -3022,30 +3022,40 @@ static int cmd_write(void *data, const char *input) { } break; case 'a': - if (input[1]==' ') { + if (input[1]==' '||input[1]=='*') { + const char *file = input[1]=='*'? input+2: input+1; RAsmCode *acode; r_asm_set_pc (core->assembler, core->offset); - acode = r_asm_massemble (core->assembler, input+1); + acode = r_asm_massemble (core->assembler, file); if (acode) { - if (r_config_get_i (core->config, "scr.prompt")) - eprintf ("Written %d bytes (%s)=wx %s\n", acode->len, input+1, acode->buf_hex); - r_core_write_at (core, core->offset, acode->buf, acode->len); - WSEEK (core, acode->len); + if (input[1]=='*') { + r_cons_printf ("wx %s\n", acode->buf_hex); + } else { + if (r_config_get_i (core->config, "scr.prompt")) + eprintf ("Written %d bytes (%s)=wx %s\n", acode->len, input+1, acode->buf_hex); + r_core_write_at (core, core->offset, acode->buf, acode->len); + WSEEK (core, acode->len); + r_core_block_read (core, 0); + } r_asm_code_free (acode); - r_core_block_read (core, 0); } } else - if (input[1]=='f' && input[2]==' ') { + if (input[1]=='f' && (input[2]==' '||input[2]=='*')) { + const char *file = input[2]=='*'? input+4: input+3; RAsmCode *acode; r_asm_set_pc (core->assembler, core->offset); - acode = r_asm_assemble_file (core->assembler, input+3); + acode = r_asm_assemble_file (core->assembler, file); if (acode) { - if (r_config_get_i (core->config, "scr.prompt")) - eprintf ("Written %d bytes (%s)=wx %s\n", acode->len, input+1, acode->buf_hex); - r_core_write_at (core, core->offset, acode->buf, acode->len); - WSEEK (core, acode->len); + if (input[2]=='*') { + r_cons_printf ("wx %s\n", acode->buf_hex); + } else { + if (r_config_get_i (core->config, "scr.prompt")) + eprintf ("Written %d bytes (%s)=wx %s\n", acode->len, input+1, acode->buf_hex); + r_core_write_at (core, core->offset, acode->buf, acode->len); + WSEEK (core, acode->len); + r_core_block_read (core, 0); + } r_asm_code_free (acode); - r_core_block_read (core, 0); } else eprintf ("Cannot assemble file\n"); } else eprintf ("Wrong argument\n"); break; diff --git a/plugins.def.cfg b/plugins.def.cfg index 56556e59df..4d6c734be3 100644 --- a/plugins.def.cfg +++ b/plugins.def.cfg @@ -3,6 +3,8 @@ # fs.hfsplus # fs.hfs # fs.jfs +# do not build : asm.x86_as +# do not build : asm.x86_nasm STATIC="asm.java asm.bf asm.arm @@ -16,9 +18,7 @@ asm.sparc asm.ppc asm.x86 asm.x86_olly -asm.x86_nasm asm.x86_nz -asm.x86_as asm.msil anal.sh anal.x86 diff --git a/r2-bindings/vapi/r_cons.vapi b/r2-bindings/vapi/r_cons.vapi index 31f3705f0f..aabe8c54ed 100644 --- a/r2-bindings/vapi/r_cons.vapi +++ b/r2-bindings/vapi/r_cons.vapi @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2010 pancake */ +/* radare - LGPL - Copyright 2009-2011 pancake */ [CCode (cheader_filename="r_cons.h", cprefix="r_cons", lower_case_cprefix="r_cons_")] namespace Radare { @@ -6,7 +6,8 @@ namespace Radare { [CCode (cname="struct r_cons_t", free_function="", cprefix="r_cons_")] /* XXX: LEAK */ public class RCons { - public RCons (); +// public RCons (); + public static RCons singleton (); static void free(); [CCode (cname="Color_RED")] diff --git a/r2-bindings/vapi/r_debug.vapi b/r2-bindings/vapi/r_debug.vapi index 58dccd3507..fdd80207ef 100644 --- a/r2-bindings/vapi/r_debug.vapi +++ b/r2-bindings/vapi/r_debug.vapi @@ -38,7 +38,7 @@ public class Radare.RDebug { public bool map_dealloc (RDebug.Map map); //public RList map_list_new (); //public void map_list_free (RList maps); - public void map_list (uint64 addr); + public void map_list (uint64 addr, bool rad); public RDebug.Map map_get(uint64 addr); public bool map_sync (); diff --git a/r2-bindings/vapi/r_line.vapi b/r2-bindings/vapi/r_line.vapi index 8bfd75c3b6..91533c08fc 100644 --- a/r2-bindings/vapi/r_line.vapi +++ b/r2-bindings/vapi/r_line.vapi @@ -1,11 +1,13 @@ -/* radare - LGPL - Copyright 2009 pancake */ +/* radare - LGPL - Copyright 2009-2011 pancake */ namespace Radare { [Compact] - [CCode (cheader_filename="r_line.h", cprefix="r_line_")] + [CCode (cname="RLine", cheader_filename="r_line.h", cprefix="r_line_")] public class RLine { - public RLine(); //string symname); + //public RLine(); + public static RLine singleton(); public static bool readline (); //int argc, char **argv); + public static void set_prompt (string promp); public static bool hist_load (string file); public static bool hist_add (string line);