Added 'fj' command, multiple @ per command and more

Support multiple @ for a single command (define offset+bytes)
Add 'fj' command to show flags in json format
Use monospaced font in vdoc
More work on the webui
This commit is contained in:
pancake 2013-01-16 12:17:14 +01:00
parent b5b8a78e87
commit a4c8b96e20
14 changed files with 217 additions and 55 deletions

View File

@ -14,6 +14,7 @@ Broken stuff to fixe before release
0.9.4
=====
* @b: @f: doesnt support temporary seek address?? support multiple @?
* search for CALL instructions in text segment.
- analyze the destination address of each call destination
* Analysis: assume there is a function at the end of each function

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 - nibble, pancake */
/* radare - LGPL - Copyright 2009-2013 - nibble, pancake */
#include <r_core.h>
#include <r_anal.h>
@ -157,7 +157,7 @@ static int cmd_alias(void *data, const char *input) {
strcat (out, args);
r_core_cmd0 (core, out);
free (out);
} else eprintf ("Cannot malloc\n");
} else eprintf ("cannot malloc\n");
} else {
r_core_cmd0 (core, v);
}
@ -296,7 +296,7 @@ static int cmd_interpret(void *data, const char *input) {
break;
case ' ':
if (!r_core_cmd_file (core, input+1))
eprintf ("Cannot interpret file.\n");
eprintf ("cannot interpret file.\n");
break;
case '!':
/* from command */
@ -353,7 +353,7 @@ static int cmd_bsize(void *data, const char *input) {
flag = r_flag_get (core->flags, input+2);
if (flag)
r_core_block_size (core, flag->size);
else eprintf ("bf: Cannot find flag named '%s'\n", input+2);
else eprintf ("bf: cannot find flag named '%s'\n", input+2);
} else eprintf ("Usage: bf [flagname]\n");
break;
case '\0':
@ -492,7 +492,7 @@ static int cmd_eval(void *data, const char *input) {
if (input[1]) {
const char *key = input+((input[1]==' ')?2:1);
if (!r_config_readonly (core->config, key))
eprintf ("Cannot find key '%s'\n", key);
eprintf ("cannot find key '%s'\n", key);
} else eprintf ("Usage: er [key]\n");
break;
case ' ':
@ -670,6 +670,8 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd) {
int i, ret, pipefd;
const char *tick = NULL;
const char *quotestr = "`";
char *arroba = NULL;
int usemyblock = 0;
cmd = r_str_trim_head_tail (cmd);
@ -820,7 +822,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd) {
free (core->oobi);
core->oobi = (ut8*)r_file_slurp (str, &core->oobi_len);
if (core->oobi == NULL)
eprintf ("Cannot open file\n");
eprintf ("cannot open file\n");
else if (ptr == cmd)
return r_core_cmd_buffer (core, (const char *)core->oobi);
}
@ -902,8 +904,8 @@ next2:
return ret;
}
}
// TODO must honor " and `
// TODO must honor " and `
/* grep the content */
ptr = (char *)r_str_lastbut (cmd, '~', quotestr);
//ptr = strchr (cmd, '~');
@ -913,7 +915,7 @@ next2:
}
r_cons_grep (ptr);
/* seek commands */
/* temporary seek commands */
if (*cmd!='(' && *cmd!='"') {
ptr = strchr (cmd, '@');
if (ptr == cmd+1 && *cmd=='?')
@ -929,9 +931,14 @@ next2:
tmpoff = core->offset;
tmpbsz = core->blocksize;
*ptr = '\0';
for (ptr++;*ptr== ' ';ptr++); ptr--;
*ptr = '\0'; for (ptr++; *ptr== ' '; ptr++); ptr--;
arroba = strchr (ptr+2, '@');
repeat_arroba:
if (arroba)
*arroba = 0;
if (ptr[2]==':') {
usemyblock = 1;
switch (ptr[1]) {
case 'f':
f = r_file_slurp (ptr+3, &sz);
@ -942,9 +949,9 @@ next2:
core->block = buf;
core->blocksize = sz;
memcpy (core->block, f, sz);
} else eprintf ("Cannot alloc %d", sz);
} else eprintf ("cannot alloc %d", sz);
free (f);
} else eprintf ("Cannot open '%s'\n", ptr+3);
} else eprintf ("cannot open '%s'\n", ptr+3);
break;
case '8':
case 'b':
@ -966,10 +973,8 @@ next2:
default:
goto ignore;
}
ret = r_cmd_call (core->rcmd, r_str_trim_head (cmd));
*ptr = '@';
r_core_block_size (core, tmpbsz);
return ret;
goto next_arroba; //ignore; //return ret;
}
ignore:
for (ptr++;*ptr== ' ';ptr++); ptr--;
@ -1000,15 +1005,26 @@ ignore:
if (ch=='-' || ch=='+')
addr = core->offset+addr;
}
next_arroba:
if (arroba) {
ptr = arroba; //-3;
arroba = NULL;
goto repeat_arroba;
}
if (ptr[1]=='@') {
// TODO: remove temporally seek (should be done by cmd_foreach)
ret = r_core_cmd_foreach (core, cmd, ptr+2);
//ret = -1; /* do not run out-of-foreach cmd */
} else {
if (!ptr[1] || r_core_seek (core, addr, 1)) {
r_core_block_read (core, 0);
if (usemyblock) {
core->offset = addr;
ret = r_cmd_call (core->rcmd, r_str_trim_head (cmd));
} else ret = 0;
} else {
if (!ptr[1] || r_core_seek (core, addr, 1)) {
r_core_block_read (core, 0);
ret = r_cmd_call (core->rcmd, r_str_trim_head (cmd));
} else ret = 0;
}
}
if (ptr2) {
*ptr2 = '!';
@ -1107,7 +1123,7 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
core->rcmd->macro.counter++;
}
fclose (fd);
} else eprintf ("Cannot open file '%s' to read offsets\n", each+1);
} else eprintf ("cannot open file '%s' to read offsets\n", each+1);
}
break;
default:

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 - pancake */
/* radare - LGPL - Copyright 2009-2013 - pancake */
static int cmd_flag(void *data, const char *input) {
RCore *core = (RCore *)data;
@ -198,10 +198,9 @@ static int cmd_flag(void *data, const char *input) {
}
break;
case '*':
r_flag_list (core->flags, 1);
break;
case '\0':
r_flag_list (core->flags, 0);
case 'j':
r_flag_list (core->flags, *input);
break;
case 'd':
{
@ -231,6 +230,7 @@ static int cmd_flag(void *data, const char *input) {
"Usage: f[?] [flagname]\n"
" f ; list flags\n"
" f* ; list flags in r commands\n"
" fj ; list flags in JSON format\n"
" fs ; display flagspaces\n"
" fs * ; set all flagspace\n"
" fs sections ; set flagspace (f will only list flags from selected ones)\n"

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2012 - pancake */
/* radare - LGPL - Copyright 2007-2013 - pancake */
#include <r_flags.h>
#include <r_util.h>
@ -49,6 +49,22 @@ R_API void r_flag_list(RFlag *f, int rad) {
RListIter *iter;
RFlagItem *flag;
if (rad=='j') {
int first = 1;
r_cons_printf ("[");
r_list_foreach_prev (f->flags, iter, flag) {
if ((f->space_idx != -1) && (flag->space != f->space_idx))
continue;
r_cons_printf ("%s{\"name\":\"%s\",\"size\":\"%"PFMT64d"\",\"offset\":%"PFMT64d,
first?"":",", flag->name, flag->size, flag->offset);
if (flag->comment)
r_cons_printf (",\"comment\":\"}");
else r_cons_printf ("}");
first = 0;
}
r_cons_printf ("]\n");
return;
}
r_list_foreach_prev (f->flags, iter, flag) {
if ((f->space_idx != -1) && (flag->space != f->space_idx))
continue;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2012 - pancake */
/* radare - LGPL - Copyright 2007-2013 - pancake */
#include "r_util.h"
#define R_NUM_USE_CALC 1

View File

@ -101,6 +101,8 @@ vdoc:
-rm -rf vdoc
cat vapi/r_*.vapi > libr.vapi
valadoc --package-version=${VERSION} --package-name=libr -o vdoc libr.vapi
sed -e 's,font-family:.*,font-family:monospace;,' vdoc/style.css > vdoc/.style.css
mv vdoc/.style.css vdoc/style.css
-rm -f libr.vapi
# rsync -avz vdoc/* pancake@radare.org:/srv/http/radareorg/vdoc/

View File

@ -4,12 +4,29 @@ namespace Radare {
[Compact]
[CCode (cheader_filename="r_flags.h,r_anal.h,r_core.h,r_bin.h,r_parse.h,r_lang.h,r_sign.h,r_reg.h,r_list.h,r_types_base.h", cname="RCore", free_function="r_core_free", cprefix="r_core_")]
public class RCore {
/**
* RBin instance
*/
public RBin bin;
/**
* RConfig instance
*/
public RConfig config;
/**
* Current working offset
*/
public uint64 offset;
/**
* Size of the working block
*/
public uint32 blocksize;
/**
* Limit maximum size for the working block
*/
public uint32 blocksize_max;
/**
* Pointer to the first byte of the working block
*/
public uint8 *block;
public uint8 *oobi;
public int ffio;
@ -21,11 +38,29 @@ public class RCore {
public bool vmode;
public int interrupted;
/**
* RCons instance
*/
public RCons cons;
/**
* KeyValue database instance
*/
public RPair kv;
/**
* RIO instance
*/
public RIO io;
/**
* Current working file
*/
public RCore.File file;
/**
* List containing all the opened files
*/
public RList<RCore.File> files;
/**
* RNum instance with hooks to resolve flags and registers
*/
public RNum num;
public RLib lib;
public RCmd rcmd;
@ -70,8 +105,10 @@ public class RCore {
// XXX. must be const in .h public int cmd_foreach(string cmd, string each);
/**
* Execute every line of the given file as radare commands
*
* @return true if file exists and has been executed
*/
public int cmd_file(string file);
public bool cmd_file(string file);
public int cmd_command(string cmd);
public unowned string cmd_str(string cmd);
public unowned string cmd_str_pipe(string cmd);

File diff suppressed because one or more lines are too long

View File

@ -10,15 +10,15 @@ enyo.kind({
{kind: "FittableRows", fit: true, components: [
{kind: "onyx.InputDecorator", classes: "r2ui-input", components: [
{tag: "p", content: "opcode", style:"margin-right:20px"},
{kind: "Input", value: '', onkeydown: "assembleOpcode", attributes: {autocapitalize:"off"}, name: "opcode"},
{kind: "Input", value: '', style:"width:90%", onkeydown: "assembleOpcode", attributes: {autocapitalize:"off"}, name: "opcode"},
]},
{kind: "onyx.InputDecorator", classes: "r2ui-input", components: [
{tag: "p", content: "bytes", style:"margin-right:20px"},
{kind: "Input", value: '', onkeydown: "assembleOpcode", attributes: {autocapitalize:"off"}, name: "bytes"},
{kind: "Input", value: '', style:"width:90%", onkeydown: "assembleOpcode", attributes: {autocapitalize:"off"}, name: "bytes"},
]},
{kind: "onyx.InputDecorator", classes: "r2ui-input", components: [
{tag: "p", content: "offset", style:"margin-right:20px"},
{kind: "Input", value: 'entry0', onkeydown: "assembleOpcode", attributes: {autocapitalize:"off"}, name: "offset"},
{kind: "Input", value: 'entry0', style:"width:90%", onkeydown: "assembleOpcode", attributes: {autocapitalize:"off"}, name: "offset"},
]}
]}
]}
@ -30,13 +30,14 @@ enyo.kind({
switch (inSender.name) {
case 'opcode':
var hex = this.$.bytes;
r2.cmd ('"pa :'+arg+'"', function (x) {
hex.setValue (x); // ? s/\n/;/g
r2.assemble (off, arg, function (bytes) {
hex.setValue (bytes); // ? s/\n/;/g
});
break;
case 'bytes':
var op = this.$.opcode;
r2.cmd ("pi 1@b:"+arg, function (x) {
//r2.cmd ("pi 1@b:"+arg, function (x) {
r2.disassemble (off, arg, function (x) {
op.setValue (x); // ? s/\n/;/g
});
break;

View File

@ -1,10 +1,18 @@
enyo.kind({
name: "Hexdump",
kind: "Scroller",
style: "background-color:#303030",
style: "background-color:#f0f0f0",
components: [
{tag: "center", components: [
{tag: "h1", style: "color:#f0f0f0", content: "hexdump"},
{tag: "h1", style: "color:#303030", content: "hexdump"},
{tag: "pre", name: "output"}
]}
]
],
create: function() {
this.inherited (arguments);
var output = this.$.output;
r2.cmd ("px 8192", function(a) {
output.setContent (a);
});
}
});

View File

@ -19,6 +19,7 @@ enyo.kind ({
this.$.lp.openCallback = function (idx) {
mp.openPage (idx);
};
this.$.mp.ra = this;
this.$.lp.ra = this;
var data = [
{ name: "Disassembler", active: true },

View File

@ -8,7 +8,7 @@ enyo.kind ({
data: null,
refresh: function () {
this.$.list.setCount (this.data.length);
this.$.list.refresh ();
this.$.list.refresh (); // necessary?? // inherit??
},
buttonClicked: function (x) {
alert ("let's play!");
@ -20,21 +20,40 @@ enyo.kind ({
{kind: "FittableColumns", noStretch: true, classes: "onyx-toolbar onyx-toolbar-inline", components: [
{kind: "Scroller", thumb: false, fit: true, touch: false, vertical: "hidden", style: "margin: 0;", components: [
{classes: "onyx-toolbar-inline", style: "white-space: nowrap;", components: [
{kind: "onyx.PickerDecorator", components: [
{kind: "onyx.Button", content: "Actions"},
{kind: "onyx.Picker", components: [
{content: "Analyze"},
{content: "Rename"},
{content: "Comment"},
{content: "Flag"}
]}
]},
{kind: "onyx.Button", content: "=", ontap: "openSidebar"},
{kind: "onyx.Button", content: "<", ontap: "prevSeek"},
{kind: "onyx.Button", content: ">", ontap: "nextSeek"},
{kind: "onyx.InputDecorator", style: "width: 200px;", components: [
{kind: "onyx.Input", value: 'entry0', onchange: "gotoSeek"}
]},
{kind: "onyx.Button", content: "Go", ontap: "gotoSeek"},
{kind: "onyx.PickerDecorator", components: [
{kind: "onyx.Button", content: "Actions"},
{kind: "onyx.Picker", components: [
{content: "Analyze"},
{content: "Rename"},
{content: "Comment"},
{content: "Flag"},
{content: "Copy"},
{content: "Paste"}
]}
]},
{kind: "onyx.PickerDecorator", components: [
{kind: "onyx.Button", content: "Convert"},
{kind: "onyx.Picker", components: [
{content: "Data"},
{content: "Code"},
{content: "String"},
]}
]},
{kind: "onyx.PickerDecorator", components: [
{kind: "onyx.Button", content: "Write"},
{kind: "onyx.Picker", components: [
{content: "File"},
{content: "Hexpair"},
{content: "String"},
]}
]},
/*
{kind: "onyx.Button", content: "Add", ontap: "addPanel"},
{kind: "onyx.Button", content: "Delete", ontap: "deletePanel"}
@ -56,7 +75,11 @@ enyo.kind ({
this.inherited(arguments);
//this.$.samplePanels.setArrangerKind ("CardArranger");
// if (enyo.Panels.isScreenNarrow()) {
this.$.samplePanels.setIndex(0);
this.$.samplePanels.setIndex(0);
},
ra: null,
openSidebar: function() {
this.ra.setIndex (this.ra.index? 0:1);
},
rendered: function() {
this.inherited(arguments);
@ -92,7 +115,7 @@ enyo.kind ({
var sp = this.$.samplePanels;
//this.openPage (this.$.input.getValue());
//sp.components[3].setContent ("JAJAJ");
this.$.page3.setContent ("PUTA");
this.$.page3.setContent ("content-a");
alert (sp.components[3].content);
sp.components[3].content = "JAJAJ";
sp.reflow();

View File

@ -41,6 +41,34 @@ function Ajax (method, uri, body, fn) {
x.send (body);
}
r2.assemble = function (offset, opcode, fn) {
var off = offset? "@"+offset:'';
r2.cmd ('"pa '+opcode+'"'+off, fn);
}
r2.disassemble = function (offset, bytes, fn) {
var off = offset? "@"+offset:'';
var str = 'pi 1@b:'+bytes+off;
r2.cmd (str, fn);
}
r2.config_set = function (fn) {
// TODO
}
r2.config_get = function (fn) {
// TODO
}
r2.set_flag_space = function (ns, fn) {
// TODO
r2.cmd ("fs ", fn);
}
r2.get_flags = function (fn) {
r2.cmd ("fj", fn);
}
r2.get_opcodes = function (off, n, cb) {
r2.cmd ("pdj @"+off+"!"+n, function (json) {
var o = JSON.parse (json);

View File

@ -1,26 +1,55 @@
enyo.kind ({
name: "RightPanel",
classes: "onyx onyx-toolbar",
kind: enyo.Control,
kind: "Control",
style: "width:25px",
components: [
{kind: "onyx.MenuDecorator", onSelect: "itemSelected", components: [
{content: "List elements"},
{kind: "onyx.Menu", onchange: "doSomething", components: [
{kind: "onyx.Menu", components: [
{content: "symbols", value: "1"},
{content: "imports", value: "1"},
{content: "functions", value: "1"},
{content: "comments", value: "1"},
{classes: "onyx-menu-divider"},
{content: "registers", value: "1"},
{content: "stack", value: "2"},
{content: "backtrace", value: "3"},
{classes: "onyx-menu-divider"},
{content: "settings", value: "4"},
{content: "flags", value: "2"},
{content: "flagspaces", value: "2"},
]}
]},
{kind: "List", name: "list", style:"height:400px", realtimeFit:false, onSetupItem: "setupItem", components: [
{kind: "onyx.Item", layoutKind: "HFlexLayout", style:"padding:0px", components: [
{tag: "h3", style:"background-color:red",name: "msg", fit:true, active: true, ontap: "rowTap"}
]}
]}
],
doSomething: function() {
alert("jaja");
rowTap: function () {
/* do something here */
},
create: function() {
this.inherited (arguments);
this.$.list.setCount (3);
},
data: [],
setupItem: function (inSender, inIndex) {
var idx = inIndex.index;
this.$.msg.setContent (this.data[idx]);
return true;
},
itemSelected: function(inSender, inEvent) {
var self = this;
var selected = inEvent.originator.content;
switch (selected) {
case "flags":
r2.get_flags (function (flags) {
// trycatch here or wtf
self.data = JSON.parse (flags);
self.$.list.setCount (self.data.length);
});
break;
}
}
});