forked from radareorg/radare2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (44 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Author : pancake <[email protected]>
Date: 2015-03-31
From inside r2
r2 -c '#!pipe node index.js' /bin/ls
Or from the shell:
node .
*/
var r2p = require ("r2pipe")
var http = require('http');
var express = require('express');
function runWebServer(r) {
r.cmd ("e http.root", function(wwwroot) {
wwwroot = wwwroot.trim ();
r.cmd ("e http.port", function(port) {
port = +port.trim ();
r.cmd ("e scr.color=false", function() {});
r.cmd ("e scr.interactive=false", function() {});
r.cmd ("e scr.html=true", function(){});
var app = express();
app.all('/cmd/*', function(req,res) {
var cmd = unescape (req.url.substring (5));
console.log ("cmd:", cmd);
r.cmd (cmd, function (data) {
res.send(data);
});
});
app.use(express.static(wwwroot));
r.cmd ("?e http://localhost:`e http.port`/p", function (data) {
console.log (data.replace(' ','').trim());
})
app.listen (port);
});
});
}
if (process.env.R2PIPE_IN) {
var r = r2p.rlangpipe(runWebServer);
} else {
var targetfile = "/bin/ls";
if (process.argv.length>2) {
targetfile = process.argv[2];
}
var r = r2p.pipe (targetfile, runWebServer);
}