Add demo graph view for www, add pad command remove a8

Enhacements for the r2irc bot (code cleanup and config)
Fix r_bin.vapi and other nodejs related issues
This commit is contained in:
pancake 2012-09-19 03:15:36 +02:00
parent 9448a64c51
commit 063ed1615a
20 changed files with 2307 additions and 95 deletions

View File

@ -219,26 +219,16 @@ case 'o':
r_cons_break (NULL, NULL);
switch (input[0]) {
case 'b':
case '8':
if (input[1]==' ') {
int len;
ut8 *buf = malloc (strlen (input));
len = r_hex_str2bin (input+2, buf);
if (len>0) {
if (len>0)
r_core_anal_bytes (core, buf, len);
}
free (buf);
} else eprintf ("Usage: ab [hexpair-bytes]\n");
break;
case '8':
if (input[1]==' ') {
RAsmCode *c = r_asm_mdisassemble_hexstr (core->assembler, input+2);
if (c) {
r_cons_puts (c->buf_asm);
r_asm_code_free (c);
} else eprintf ("Invalid hexstr\n");
} else eprintf ("Usage: a8 [hexpair-bytes]\n");
break;
case 'x':
switch (input[1]) {
case '\0':
@ -831,8 +821,7 @@ case 'o':
r_cons_printf (
"Usage: a[?obdfrgtv]\n"
" aa ; analyze all (fcns + bbs)\n"
" a8 [hexpairs] ; analyze bytes as disassemble\n"
" ab [hexpairs] ; analyze bytes as opcodes\n"
" a8 [hexpairs] ; analyze bytes\n"
" ad ; analyze data trampoline (wip)\n"
" ap ; find and analyze function preludes\n"
" ad [from] [to] ; analyze data pointers to (from-to)\n"

View File

@ -175,7 +175,15 @@ static int cmd_print(void *data, const char *input) {
}
break;
case 'a':
{
if (input[1]=='d') {
RAsmCode *c;
r_asm_set_pc (core->assembler, core->offset);
c = r_asm_mdisassemble_hexstr (core->assembler, input+2);
if (c) {
r_cons_puts (c->buf_asm);
r_asm_code_free (c);
} else eprintf ("Invalid hexstr\n");
} else {
RAsmCode *acode;
r_asm_set_pc (core->assembler, core->offset);
acode = r_asm_massemble (core->assembler, input+1);

View File

@ -652,9 +652,8 @@ toro:
if (idx>=len) {// && (invbreak && !lastfail)) {
if (invbreak && lines<l) {
buf = nbuf = malloc (len);
r_io_read_at (core->io, addr+idx, buf, len);
addr += idx;
//eprintf ("EOF %d %d\n", lines, l);
r_core_read_at (core, addr, buf, len);
goto toro;
}
}

View File

@ -74,10 +74,8 @@ R_API int r_core_rtr_http(RCore *core, int launch) {
const char *root = r_config_get (core->config, "http.root");
char path[1024];
// fix crosspath
if (!strcmp (rs->path, "/")) {
free (rs->path);
rs->path = strdup ("/index.html");
}
if (rs->path [strlen (rs->path)-1] == '/')
rs->path = r_str_concat (rs->path, "index.html");
snprintf (path, sizeof (path), "%s/%s", root, rs->path);
if (r_file_exists (path)) {
int sz = 0;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2011 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2007-2012 pancake */
#include <r_flags.h>
#include <r_util.h>

View File

@ -0,0 +1,8 @@
all: node_modules
node r2irc.js
node_modules:
npm install
clean:
rm -rf node_modules

View File

@ -0,0 +1,7 @@
{
"name": "r2node-tests",
"version": "0.0.1",
"dependencies": {
"irc.js": "*"
}
}

View File

@ -1,60 +1,76 @@
#!/usr/bin/node
/* TODO: use node-daemon and chroot */
const nick = "r2bot";
/* config */
const nick = "r2bot"
const channel = "#radare"
const msgtimeout = 1000;
const msgtimeout = 1000
const host = "irc.freenode.net"
const port = 6667;
const port = 6667
const file = "/bin/ls"
const Chi = "\x1b[32m"
const Cend = "\x1b[0m"
const print = console.log
var irc;
function finalize() {
if (irc) irc.privmsg (channel, "byebye");
print ("^C :D");
process.exit (0);
}
process.on ('SIGINT', finalize);
process.on ('SIGTERM', finalize);
/* r2 stuff */
print (Chi, "[=>] Initializing r2 core...", Cend);
var r2 = require ('../r_core');
var core = new r2.RCore(), cons = r2.RCons;
var fileName = process.argv[2] || '/bin/ls';
const JS = JSON.stringify;
const JP = JSON.parse;
const JSHDR = {'Content-type': 'application/json'};
/* XXX FAIL
var c = core.config
var b = core.bin
c.set ("io.va", "true");
console.log ("iova= "+ c.get ("io.va"));
process.exit(0);
var fileName = process.argv[2] || file;
core.bin.load (fileName, 0);
core.bin.select_idx (0);
var info = core.bin.get_info();
core.bin_load ('');
console.log ("TYPE: "+info.type);
core.config.set ("asm.arch", "x86");
core.config.set ("asm.bits", "64");
//core.bin = bin;
*/
core.config.set ("asm.bits", "32");
core.file_open (fileName, 0, 0);
console.log ("core->bin = "+core.config);
core.bin_load (null);
core.cmd0 ('? entry0')
core.cmd0 ('pd @entry0')
core.config.set ("io.va", "true");
print ("iova= "+ core.config.get ("io.va"));
core.file_open (fileName, 0, 0);
print ("core->bin = "+core.config);
core.bin.select_idx (0);
core.bin_load (null);
core.cmd0 ('? entry0')
core.cmd0 ('pd @entry0')
var IRC = require('irc.js');
var irc = new IRC(host, port);
/* initialize irc connection */
print (Chi, "[=>] Connecting to irc ",Cend)
print (Chi, " HOST: ", host,":",port,Cend)
print (Chi, " NICK: ",nick," ",channel, Cend);
var IRC = require ('irc.js');
irc = new IRC (host, port);
irc.on ('raw', function (data) {
console.log (data);
});
print (data);
});
irc.on ('connected', function (s) {
irc.nick ("r2bot");
irc.nick (nick);
irc.join (channel, function (x) {
irc.privmsg (channel, "hi");
});
console.log ("connected");
print ("connected");
});
if (typeof String.prototype.startsWith != 'function') {
@ -63,16 +79,19 @@ if (typeof String.prototype.startsWith != 'function') {
};
}
irc.on('privmsg', function(from, to, msg) {
console.log('<' + from + '> to ' + to + ': ' + msg);
irc.on ('privmsg', function (from, to, msg) {
print('<' + from + '> to ' + to + ': ' + msg);
if (to[0] != "#" && from == "pancake") {
if (msg.startsWith ("nick "))
irc.nick (msg.slice (5));
else if (msg.startsWith ("join "))
irc.join (msg.slice (5));
else if (msg.startsWith ("part "))
irc.part (msg.slice (5));
else irc.privmsg (channel, msg)
} else
switch (to) {
case "#radare":
case "#radarebot":
case channel:
default:
if (!msg.startsWith ("!")) return;
var o = "";
@ -83,40 +102,33 @@ irc.on('privmsg', function(from, to, msg) {
msg = msg.replace (/\t/g, " ");
var cmds = msg.split (";");
for (var i in cmds) {
msg = cmds[i];
msg = msg.replace (/^\ */, "");
if (msg.startsWith ("q")) o = "not now";
else
if (msg.startsWith ("o") && msg.length >1) o = "no open allowed";
else
if (msg.startsWith ("V")) o = "i cant do visuals on irc :(";
else
if (msg.startsWith ("ag")) o = "graphs cant be seen here.";
else o = core.cmd_str_pipe (msg);
msg = cmds[i];
msg = msg.replace (/^\ */, "");
if (msg.startsWith ("q"))
o = "not now";
else if (msg.startsWith ("o") && msg.length >1)
o = "no open allowed";
else if (msg.startsWith ("V"))
o = "i cant do visuals on irc :(";
else if (msg.startsWith ("ag"))
o = "graphs cant be seen here.";
else o = core.cmd_str_pipe (msg);
}
if (o != "")
(function () {
var a = o.split (o.indexOf ("\r") ==-1? "\n": "\r");
if (o != "") (
function () {
var a = o.split (o.indexOf ("\r")!=-1?
"\r": "\n");
var timedmsg = function (x) {
irc.privmsg (to, a[0]);
a = a.slice (1);
if (a.length>0)
irc.privmsg (to, a[0]);
a = a.slice (1);
if (a.length>0)
setTimeout (timedmsg, msgtimeout);
}
setTimeout (timedmsg, msgtimeout);
}
setTimeout (timedmsg, msgtimeout);
})();
break;
}
) ();
break;
}
);
function finalize() {
irc.privmsg (channel, "byebye");
console.log ("byebye");
process.exit (0);
}
process.on ('SIGINT', finalize);
process.on ('SIGTERM', finalize);
});
irc.connect (nick, 'http://www.radare.org/', 'r2');

View File

@ -113,6 +113,7 @@ namespace Radare {
public char machine[256]; // FIXME proper static strings w/o hardcoded size
public char os[256]; // FIXME proper static strings w/o hardcoded size
public char subsystem[256]; // FIXME proper static strings w/o hardcoded size
public char rpath[256]; // FIXME proper static strings w/o hardcoded size
public int bits;
public bool has_va;
public bool big_endian;

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 827 B

187
shlr/www/graph/index.html Normal file
View File

@ -0,0 +1,187 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>js-graph.it homepage</title>
<script type="text/javascript" src="js-graph-it.js"></script>
<link rel="stylesheet" type="text/css" href="jsgraph.css" />
<link rel="stylesheet" type="text/css" href="sf-homepage.css" />
<style>
p {
white-space: pre;
font-family: monospace;
display: block;
}
body {
overflow:hidden;
}
</style>
<script>
<!--
function onLoad() {
setMenu();
resizeCanvas();
initPageObjects();
}
/**
* Resizes the main canvas to the maximum visible height.
*/
function resizeCanvas() {
var divElement = document.getElementById("mainCanvas");
var screenHeight = window.innerHeight || document.body.offsetHeight;
divElement.style.height = (screenHeight - 16) + "px";
}
/**
* sets the active menu scanning for a menu item which url is a prefix
* of the one of the current page ignoring file extension.
* Nice trick!
*/
function setMenu()
{
var url = document.location.href;
// strip extension
url = stripExtension(url);
var ulElement = document.getElementById("menu");
var links = ulElement.getElementsByTagName("A");
var i;
for(i = 0; i < links.length; i++)
{
if(url.indexOf(stripExtension(links[i].href)) == 0)
{
links[i].className = "active_menu";
return;
}
}
}
/**
* Strips the file extension and everything after from a url
*/
function stripExtension(url)
{
var lastDotPos = url.lastIndexOf('.');
if(lastDotPos > 0)
return url.substring(0, lastDotPos - 1);
else
return url;
}
/**
* this function opens a popup to show samples during explanations.
*/
function openSample(url)
{
var popup = window.open(url, "sampleWindow", "width=400,height=300");
popup.focus();
return false;
}
//-->
</script>
</head>
<body onload="onLoad();">
<h1><a href="../"> back</a></h1>
<table class="main_table" style="height: 100%;">
<tr>
<!--
<td colspan=3>
<a href=''>File</a> | Edit
</td>
</tr>
<tr>
<td width="1" style="vertical-align: top;" class="menu">
<ul id="menu">
<select>
<option>Functions</option>
<option>Exports</option>
<option>Imports</option>
</select>
</ul>
</td>
-->
<td style="vertical-align: top; padding: 0px;">
<div id="mainCanvas" class="canvas" style="width: 100%; height: 400px;">
<div class="connector _0x100001478 _0x10000149d">
<img class="connector-end" src="img/arrow.gif" /></div>
<p class="block draggable" style="top: 0px; left: 10px; width: 500px;" id="_0x100001478">
; [0] va=0x100001478 pa=0x00001478 sz=14575 vsz=14575 rwx=-r-x 0.__text
/ function: section.0.__text (60)
| 0x100001478 section.0.__text:
| 0x100001478 push 0x0
| 0x10000147a mov rbp, rsp
| 0x10000147d and rsp, 0xfffffffffffffff0
| 0x100001481 mov rdi, [rbp+0x8]
| 0x100001485 lea rsi, [rbp+0x10]
| 0x100001489 mov edx, edi
| 0x10000148b add edx, 0x1
| 0x10000148e shl edx, 0x3
| 0x100001491 add rdx, rsi
| 0x100001494 mov rcx, rdx
| 0x100001497 jmp loc.10000149d
</p><div class="connector _0x100001478 _0x10000149d">
<img class="connector-end" src="img/arrow.gif" /></div>
<p class="block draggable" style="top: 0px; left: 10px; width: 500px;" id="_0x100001499">
; CODE (JMP) XREF 0x1000014a1 (section.0.__text)
/ loc: loc.100001499 (27)
| 0x100001499 loc.100001499:
| 0x100001499 add rcx, 0x8
</p><div class="connector _0x100001478 _0x100001499">
<img class="connector-end" src="img/arrow.gif" /></div>
<div class="connector _0x100001478 _0x1000014a3">
<img class="connector-end" src="img/arrow.gif" /></div>
<p class="block draggable" style="top: 0px; left: 10px; width: 500px;" id="_0x10000149d">
; CODE (JMP) XREF 0x100001497 (section.0.__text)
/ loc: loc.10000149d (23)
| 0x10000149d loc.10000149d:
| 0x10000149d cmp qword [rcx], 0x0
| 0x1000014a1 jnz loc.100001499
</p><div class="connector _0x100001478 _0x100004eca">
<img class="connector-end" src="img/arrow.gif" /></div>
<p class="block draggable" style="top: 0px; left: 10px; width: 500px;" id="_0x1000014a3">
| 0x1000014a3 add rcx, 0x8
| 0x1000014a7 call dword fcn.100002404
| ; fcn.100002404() (fcn.100002404+0)
| 0x1000014ac mov edi, eax
| 0x1000014ae call dword imp.__symbol_stub1_exit
| ; imp.__symbol_stub1_exit() (imp.__symbol_stub1_exit+0)
\ 0x1000014b3 hlt
; DATA XREF 0x1000014a1 (section.0.__text)
; DATA XREF 0x100001497 (section.0.__text)
/ function: fcn.1000014b4 (109)
| 0x1000014b4 fcn.1000014b4:
| 0x1000014b4 push rbp
| 0x1000014b5 mov rbp, rsp
| 0x1000014b8 lea rax, [rdi+0x68]
| 0x1000014bc lea rdi, [rsi+0x68]
| 0x1000014c0 mov rsi, rax
| 0x1000014c3 leave
| 0x1000014c4 jmp dword imp.__symbol_stub1_strcoll
</p>
<p class="block draggable" style="top: 0px; left: 10px; width: 500px;" id="_0x100004eca">
; CODE (JMP) XREF 0x1000014c4 (fcn.1000014b4)
; CODE (JMP) XREF 0x1000014d6 (fcn.1000014b4)
; CODE (JMP) XREF 0x10000150d (fcn.1000014b4)
; CODE (JMP) XREF 0x100001754 (fcn.100001722)
; CODE (JMP) XREF 0x10000170e (fcn.1000016dc)
; CODE (JMP) XREF 0x1000016d2 (fcn.1000016a0)
; CODE (JMP) XREF 0x10000168c (fcn.10000165a)
; CODE (JMP) XREF 0x100001647 (fcn.10000161a)
; CODE (JMP) XREF 0x100001607 (fcn.1000015da)
; CODE (JMP) XREF 0x1000015c7 (fcn.10000159a)
; CODE (JMP) XREF 0x100001590 (fcn.100001561)
; CODE (JMP) XREF 0x10000154e (fcn.100001521)
/ loc: imp.__symbol_stub1_strcoll (958)
| 0x100004eca imp.__symbol_stub1_strcoll:
| 0x100004eca jmp qword [rip+0x1340]
</p>
</td>
<td width="1" style="vertical-align: top;" class="menu">
<ul id="menu"> </ul>
</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,24 @@
.draggable
{
position: absolute;
cursor: move;
z-index: 1;
}
.connector
{
background-color: black;
}
.dock_point
{
height: 1px;
width: 1px;
overflow: hidden;
padding: 0px !important;
border: none !important;
margin: 0px !important;
position: absolute;
font-size: 1px;
visibility: hidden;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,157 @@
.draggable
{
position: absolute;
}
div.block, h1.block, h2.block, p.block
{
border: 1px solid #9DA3B3;
background-color: #E0E8FF;
padding: 5px;
}
div.canvas
{
border: 1px solid #262A37;
background-color: white;
background-image: url('gradient.jpg');
background-repeat: no-repeat;
background-position: top right;
padding: 0px;
}
.highlighter
{
border: 1px solid #CFDF62 !important;
background-color: #F1FF90 !important;
margin-bottom: 2px !important;
padding: 0px !important;
z-index: 3;
}
.highlighter .highlighter
{
border: 1px solid #7DAB76 !important;
background-color: #BAFFB0 !important;
margin-left: 2px !important;
margin-right: 2px !important;
}
html
{
padding: 0px;
margin: 0px;
}
body
{
font-family: verdana;
font-size: 11px;
color: #33333F;
padding: 3px;
margin: 0px;
background-color: white;
}
h1
{
color: #FF7521;
margin: 0px;
font-size: 20px;
}
h2
{
font-size: 15px;
margin: 0px;
}
p, div
{
font-size: 11px;
margin: 0px;
}
a
{
text-decoration: none;
color: #FF9900;
}
.middle-label, .source-label, .destination-label
{
font-size: 11px;
font-weight: bold;
padding: 5px;
}
div.connector
{
background-color: #ff9900;
z-index: 1000;
}
table.main_table
{
width: 100%;
border-collapse: separate;
}
td.menu
{
padding: 5px;
}
.menu ul
{
margin: 0px;
padding: 0px;
list-style-type: none;
list-style-position: outside;
}
.menu li
{
border: none;
padding: 0px;
font-size: 12px;
margin-bottom: 3px;
}
.menu li a
{
display: block;
border: 1px solid #262A37;
width: 100px;
color: #262A37;
text-decoration: none;
padding: 1px;
background-color: #E0E8FF;
}
.menu li a.active_menu
{
color: #FF9900;
border-color: #FF9900;
}
.menu li a:hover
{
color: #FF9900;
border-color: #FF9900;
}
.block ol, .block ul
{
margin-top: 3px;
margin-bottom: 3px;
margin-left: 0px;
padding-left: 25px;
}
.code
{
font-family: monospace;
line-height: 1.5em !important;
}

View File

@ -54,16 +54,17 @@ function show_popup_about () {
"This is the r2w ui for radare2"+
"<br /><br />"+
"It runs on top of an embedded webserver in radare2. Here's some commands to try:"+nl2+
"<a href=\"/graph/\">graph demo</a>"+nl2+
"<a href=\"javascript:cmd('!rax2 -s 20e296b20ae296b220e296b20a');popup_hide();\">triforce!</a>"+nl2+
"<a href=\"javascript:cmd('? '+prompt('expression'));popup_hide();\">calculator</a>"+nl2+
"<a href=\"javascript:cmd('s '+prompt('offset')+';pd');popup_hide();\">seek</a>"+nl2+
"<a href=\"javascript:cmd('b '+prompt('blocksize'));popup_hide();\">blocksize</a>"+nl2+
"<a href=\"javascript:cmd('af;aa;pd');popup_hide();\">analyze code</a>"+nl2+
"<a href=\"javascript:cmd('ap;pd');popup_hide();\">analyze preludes</a>"+nl2+
"<a href=\"javascript:panel_functions_load();popup_hide();\">list functions</a>"+nl2+
"<a href=\"javascript:cmd('pd');popup_hide();\">disassemble block</a>"+nl2+
"<a href=\"javascript:cmd('pdr');popup_hide();\">disassemble function</a>"+nl2+
"<a href=\"javascript:cmd('x');popup_hide();\">hexdump</a>"+nl2+
"<a href=\"javascript:cmd('af;aa;pd');popup_hide();\">analyze code</a>"+nl2+
"<a href=\"javascript:cmd('ap;pd');popup_hide();\">analyze preludes</a>"+nl2+
"";
popup_show ("Help", txt);
}

View File

@ -49,19 +49,19 @@ input {
margin-left:2px;
padding:10px;
width:270px;
height:232px;
/* height:232px; */
text-align:left;
vertical-align:top;
overflow:auto;
/* overflow:auto; */
background-color:#f0f0f0;
}
.console {
font-size:8px;
width:310px;
height:310px;
height:100%;
text-align:left;
overflow:auto;
/* overflow:auto; */
background-color:#f0f0f0;
}