mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-21 23:01:03 +00:00
Remove shlr/www/t, installable from r2pm -i www-t
This commit is contained in:
parent
7235fab252
commit
8a76b2d54a
@ -1,2 +0,0 @@
|
||||
all:
|
||||
r2 -e http.ui=t -e http.root=$$PWD -qc=H /bin/ls
|
@ -1,23 +0,0 @@
|
||||
Tiled r2 webui
|
||||
==============
|
||||
|
||||
widgets required
|
||||
----------------
|
||||
|
||||
notes: notepad with textarea to put your notes there
|
||||
disasm: proper disasm widget
|
||||
hexdump: proper hexdump widget
|
||||
assemble: assemble instructions
|
||||
console:
|
||||
scrips:
|
||||
floating/modal frame. invalidating the rest.
|
||||
|
||||
features
|
||||
--------
|
||||
follow in ->
|
||||
|
||||
Frames must have the following properties:
|
||||
- update() -> refresh the contents (run r2 command again, generate html, etc.)
|
||||
- seek(off) -> used by follow in...
|
||||
- selected
|
||||
- name -> we need a method to rename frames
|
@ -1,37 +1 @@
|
||||
<html>
|
||||
<meta charset="utf-8"> </meta>
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes"/>
|
||||
<link rel=Stylesheet href="style.css" type="text/css" />
|
||||
<script src="tiled.js"></script>
|
||||
<script src="r2.js"></script>
|
||||
<script src="main.js"></script>
|
||||
<body id=body>
|
||||
<div id="canvas" class='canvas'>
|
||||
<div style="right:15px;position:absolute">
|
||||
<a class='minibut' href='#' id='settings'>[#]</a>
|
||||
<a class='minibut' href='#' id='refresh'>[@]</a>
|
||||
<a class='minibut' href='#' id='maximize'>[^]</a>
|
||||
<a class='minibut' href='#' id='add-column'>[|]</a>
|
||||
<a class='minibut' href='#' id='add-row'>[-]</a>
|
||||
|
||||
<a class='minibut' href='#' id='open-not'>[n]</a>
|
||||
<a class='minibut' href='#' id='open-con'>[c]</a>
|
||||
<a class='minibut' href='#' id='open-dis'>[d]</a>
|
||||
<a class='minibut' href='#' id='open-hex'>[x]</a>
|
||||
<a class='minibut' href='#' id='open-fla'>[f]</a>
|
||||
<a class='minibut' href='#' id='open-dbg'>[D]</a>
|
||||
<a class='minibut' href='#' id='open-hlp'>[?]</a>
|
||||
<!--
|
||||
<a style='text-decoration:none' href='#' id='maximize'>[^]</a>
|
||||
<a style='text-decoration:none' href='#' id='maximize'>[v]</a>
|
||||
-->
|
||||
</div>
|
||||
<a href=".."><img height="16" src="../enyo/rlogo-tr.png"></a>
|
||||
<!--
|
||||
<a id="" href='#'>Menu</a>
|
||||
-->
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
r2pm -i www-t
|
||||
|
@ -1,421 +0,0 @@
|
||||
|
||||
function findPos(obj) {
|
||||
var curleft = curtop = 0;
|
||||
if (obj.offsetParent) {
|
||||
curleft = obj.offsetLeft
|
||||
curtop = obj.offsetTop
|
||||
while (obj = obj.offsetParent) {
|
||||
curleft += obj.offsetLeft
|
||||
curtop += obj.offsetTop
|
||||
}
|
||||
}
|
||||
return [curleft,curtop];
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
var position = "right";
|
||||
var t = new Tiled ('canvas');
|
||||
var ctr = 0;
|
||||
function newHelpFrame() {
|
||||
var n = t.defname ("help");
|
||||
function newthing(name) {
|
||||
// TODO: disas_code id
|
||||
setTimeout (function () {
|
||||
document.getElementById("randomcolors").onclick = function() {
|
||||
r2.cmd ("ecr", function () {
|
||||
t.update_all ();
|
||||
});
|
||||
}
|
||||
}, 1);
|
||||
const hlpmsg = "This is the new and experimental tiled webui for r2\n\n"
|
||||
+"Press the 'alt' key and the following key:\n\n"
|
||||
+" hjkl - move left,down,up,right around\n"
|
||||
+" x - spawn an hexdump\n"
|
||||
+" d - spawn an disasfm\n"
|
||||
+" f - spawn an flags panel\n"
|
||||
+" c - close current frame\n"
|
||||
+" . - toggle maximize mode\n"
|
||||
+" - - horizontal split\n"
|
||||
+" | - vertical split\n"
|
||||
+"\n"
|
||||
//+"Blocksize <input type=''></input><br />"
|
||||
+"<input type='button' id='randomcolors' value='randomcolors'></input>"
|
||||
return "<h2>Help</h2>"
|
||||
+"<div id='"+name+"_help' style='background-color:#304050;overflow:scroll;height:100%'><pre>"+hlpmsg+"</div>";
|
||||
}
|
||||
t.new_frame (n, newthing (n), function(obj) {
|
||||
var flags = _(n+'_help');
|
||||
if (flags) {
|
||||
var top = flags.style.offsetTop;
|
||||
var pos = findPos (flags);
|
||||
flags.style.height = obj.offsetHeight - pos[1]+20;
|
||||
flags.style.width = obj.style.width - pos[0];
|
||||
}
|
||||
});
|
||||
}
|
||||
function newConsoleFrame() {
|
||||
var n = t.defname ("console");
|
||||
function newthing(name) {
|
||||
return "<div><input id=\""+name+"_input\"></input></div>"
|
||||
+"<div id='"+name+"_output' class='frame_body'>"
|
||||
+"</div>";
|
||||
}
|
||||
|
||||
t.new_frame (n, newthing (n), function(obj) {
|
||||
var flags = _(n+'_console');
|
||||
if (flags) {
|
||||
var top = flags.style.offsetTop;
|
||||
var pos = findPos (flags);
|
||||
flags.style.height = obj.offsetHeight - pos[1]+20;
|
||||
flags.style.width = obj.style.width - pos[0];
|
||||
}
|
||||
}, position, function () {
|
||||
var input = _(n+"_input");
|
||||
input.onkeyup = function (ev) {
|
||||
if (ev.keyCode == 13) {
|
||||
r2.cmd (input.value, function(x) {
|
||||
_(n+"_output").innerHTML = "<pre>"+x+"</pre>";
|
||||
input.value = "";
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function newDebugFrame() {
|
||||
var name = "debug";
|
||||
var n = t.defname (name);
|
||||
var fillFrame = function () {
|
||||
// TODO: list breakpoints with `dbj`
|
||||
r2.cmdj ("drj", function (regs) {
|
||||
r2.cmd ("pxQ@rsp", function (pxQ) {
|
||||
r2.cmd ("dbt", function (dbt) {
|
||||
r2.cmd ("dm", function (maps) { // TODO: use dmj
|
||||
var _ = function (x) { return document.getElementById(x); }
|
||||
setTimeout(function() {
|
||||
function updateAll() { t.update_all (); }
|
||||
_('dbg-step').onclick = function() {
|
||||
r2.cmd ("ds;.dr*", updateAll ());
|
||||
}
|
||||
_('dbg-over').onclick = function() {
|
||||
r2.cmd ("dso;.dr*", updateAll ());
|
||||
}
|
||||
_('dbg-skip').onclick = function() {
|
||||
r2.cmd ("dss;.dr*", updateAll ());
|
||||
}
|
||||
_('dbg-cont').onclick = function() {
|
||||
r2.cmd ("dc;.dr*", updateAll ());
|
||||
}
|
||||
_('dbg-until').onclick = function() {
|
||||
var until = prompt ("Until");
|
||||
if (until) {
|
||||
r2.cmd ("dcu "+until+";.dr*", updateAll ());
|
||||
}
|
||||
}
|
||||
},1);
|
||||
var str = '';
|
||||
str += " <a id='dbg-step' href='#'>[step]</a>";
|
||||
str += " <a id='dbg-over' href='#'>[over]</a>";
|
||||
str += " <a id='dbg-skip' href='#'>[skip]</a>";
|
||||
str += " <a id='dbg-cont' href='#'>[cont]</a>";
|
||||
str += " <a id='dbg-until' href='#'>[until]</a>";
|
||||
str +="<hr />Registers</hr>";
|
||||
str += '<table>';
|
||||
for (var r in regs) {
|
||||
var v = "0x"+(+regs[r]).toString (16);
|
||||
|
||||
str += "<tr><td>"+
|
||||
r+"</td><td>"+
|
||||
"<a href=#>"+v+"</a></td></tr>";
|
||||
}
|
||||
str += '</table>';
|
||||
str += "<hr />Backtrace:<pre>"+dbt+"</pre>";
|
||||
str += "<hr />Stack:<pre>"+pxQ+"</pre>";
|
||||
str += "<hr />Maps:<pre>"+maps+"</pre>";
|
||||
document.getElementById(name+"_frame").innerHTML=str;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
function newthing() {
|
||||
return "<h2>Debug</h2>"
|
||||
+"<div id='"+name+"_frame' class='frame_body'></div>";
|
||||
}
|
||||
t.new_frame (n, newthing (n), function(obj) {
|
||||
var flags = _(n+'_frame');
|
||||
if (flags) {
|
||||
var top = flags.style.offsetTop;
|
||||
var pos = findPos (flags);
|
||||
flags.style.height = obj.offsetHeight - pos[1]+20;
|
||||
flags.style.width = obj.style.width - pos[0];
|
||||
}
|
||||
}, position, function (){
|
||||
try {
|
||||
fillFrame ();
|
||||
} catch (e) {
|
||||
}
|
||||
});
|
||||
}
|
||||
function newFlagsFrame () {
|
||||
var n = t.defname ("flags");
|
||||
function newthing(name) {
|
||||
// TODO: disas_code id
|
||||
setTimeout (function () {
|
||||
r2.cmd ("fs *;f", function (x) {
|
||||
document.getElementById(name+"_flags").innerHTML="<pre>"+x+"</pre>";
|
||||
});
|
||||
}, 1);
|
||||
return "<h2>Flags</h2>"
|
||||
+"<div id='"+name+"_flags' class='frame_body'></div>";
|
||||
}
|
||||
t.new_frame (n, newthing (n), function(obj) {
|
||||
var flags = _(n+'_flags');
|
||||
if (flags) {
|
||||
var top = flags.style.offsetTop;
|
||||
var pos = findPos (flags);
|
||||
flags.style.height = obj.offsetHeight - pos[1]+20;
|
||||
flags.style.width = obj.style.width - pos[0];
|
||||
}
|
||||
}, position);
|
||||
}
|
||||
function newHexdumpFrame () {
|
||||
var n = t.defname ("hexdump");
|
||||
var msgbody = "<div id='"+n+"_hexdump' class='frame_body'></div>";
|
||||
t.new_frame (n, msgbody, function(obj) {
|
||||
var code = _(n+'code');
|
||||
if (code) {
|
||||
var top = code.style.offsetTop;
|
||||
var pos = findPos (code);
|
||||
code.style.height = obj.offsetHeight - pos[1]+20;
|
||||
code.style.width = obj.style.width - pos[0];
|
||||
}
|
||||
}, position, function(frame, nf) {
|
||||
//frame = frame.curframe[0];
|
||||
frame = nf;
|
||||
function calc() {
|
||||
var off = frame.offset || 0;
|
||||
r2.cmd ("px 1024 @ "+off, function (x) {
|
||||
var id_prev = n + '_hexdump_hex_prev';
|
||||
var id_next = n + '_hexdump_hex_next';
|
||||
var id_goto = n + '_hexdump_hex_goto';
|
||||
_(n+"_hexdump").innerHTML=
|
||||
"<br /><center><a class=link href='#' id="+id_prev+">[PREV]</a>"
|
||||
+"<a class=link href='#' id="+id_goto+">[GOTO]</a>"
|
||||
+"<a class=link href='#' id="+id_next+">[NEXT]</a></center>"
|
||||
+"<pre>"+x+"</pre>"
|
||||
;
|
||||
//var q = document.getElementById(n+'_hexdump_hex_prev');
|
||||
var q = document.getElementById(id_prev);
|
||||
q.onclick = function() {
|
||||
frame.offset = frame.offset | 0;
|
||||
frame.offset -= 512;
|
||||
frame.refresh ();
|
||||
}
|
||||
var q = document.getElementById(id_next);
|
||||
q.onclick = function() {
|
||||
frame.offset = frame.offset | 0;
|
||||
frame.offset += 512;
|
||||
frame.refresh ();
|
||||
}
|
||||
var q = document.getElementById(id_goto);
|
||||
q.onclick = function() {
|
||||
var newoff = prompt ("Goto");
|
||||
if (newoff) {
|
||||
r2.cmd ("?v "+newoff, function(val) {
|
||||
frame.offset = +val | 0;
|
||||
frame.refresh ();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!frame.offset) {
|
||||
r2.cmd ("?v entry0", function(val) {
|
||||
frame.offset = +val;
|
||||
calc (frame);
|
||||
});
|
||||
} else {
|
||||
calc (frame);
|
||||
}
|
||||
});
|
||||
}
|
||||
function newNotesFrame() {
|
||||
var n = t.defname ('notes');
|
||||
var disasmbody = "<div id='"+n+"_notes' class='frame_body'><textarea style='width:100%;height:100%'></textarea></div>";
|
||||
t.new_frame (n, disasmbody, function(obj) {
|
||||
var code = _(n+'_notes');
|
||||
if (code) {
|
||||
var top = code.style.offsetTop;
|
||||
var pos = findPos (code);
|
||||
code.style.height = obj.offsetHeight - pos[1]+20;
|
||||
code.style.width = obj.style.width - pos[0];
|
||||
}
|
||||
}, position, function () {
|
||||
/* nothing */
|
||||
});
|
||||
}
|
||||
function newSettingsFrame() {
|
||||
var n = t.defname ('settings');
|
||||
var settbody = "<div id='"+n+"_settings' class='frame_body'>"
|
||||
+"<input type=button value=RandomColors>"
|
||||
+"</div>";
|
||||
t.new_frame (n, settbody, function(obj) {
|
||||
var code = _(n+'_settings');
|
||||
if (code) {
|
||||
var top = code.style.offsetTop;
|
||||
var pos = findPos (code);
|
||||
code.style.height = "100%"; //obj.offsetHeight - pos[1]+20;
|
||||
code.style.width = obj.style.width - pos[0];
|
||||
}
|
||||
}, position, function () {
|
||||
r2.cmd ("e??", function (x) {
|
||||
_(n+"_settings").innerHTML="<pre>"+x+"</pre>";
|
||||
});
|
||||
});
|
||||
}
|
||||
function newDisasmFrame() {
|
||||
var n = t.defname ('disas');
|
||||
var disasmbody = "<div id='"+n+"_code' class='frame_body'></div>";
|
||||
t.new_frame (n, disasmbody, function(obj) {
|
||||
var code = _(n+'_code');
|
||||
if (code) {
|
||||
var top = code.style.offsetTop;
|
||||
var pos = findPos (code);
|
||||
code.style.height = "100%"; //obj.offsetHeight - pos[1]+20;
|
||||
code.style.width = obj.style.width - pos[0];
|
||||
}
|
||||
}, position, function (frame, nf) {
|
||||
frame = frame.curframe[0];
|
||||
frame = nf;
|
||||
var off = frame.offset || "entry0";
|
||||
r2.cmd ("pd 200 @ "+off, function (x) {
|
||||
var id_prev = n + '_code_prev';
|
||||
var id_next = n + '_code_next';
|
||||
var id_goto = n + '_code_goto';
|
||||
_(n+"_code").innerHTML=
|
||||
"<br /><center><a class=link href='#' id="+id_prev+">[PREV]</a>"
|
||||
+"<a class=link href='#' id="+id_goto+">[GOTO]</a>"
|
||||
+"<a class=link href='#' id="+id_next+">[NEXT]</a></center>"
|
||||
+"<pre>"+x+"</pre>";
|
||||
var q = document.getElementById(id_prev);
|
||||
q.onclick = function() {
|
||||
frame.offset = frame.offset | 0;
|
||||
frame.offset -= 512;
|
||||
frame.refresh ();
|
||||
}
|
||||
var q = document.getElementById(id_next);
|
||||
q.onclick = function() {
|
||||
frame.offset = frame.offset | 0;
|
||||
frame.offset += 512;
|
||||
frame.refresh ();
|
||||
}
|
||||
var q = document.getElementById(id_goto);
|
||||
q.onclick = function() {
|
||||
var newoff = prompt ("Goto");
|
||||
if (newoff) {
|
||||
r2.cmd ("?v "+newoff, function(val) {
|
||||
if (val) {
|
||||
frame.offset = newoff;
|
||||
frame.refresh ();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function addPanel (pos) {
|
||||
ctr++;
|
||||
position = pos;
|
||||
t.new_frame ('window_'+ctr, "<div id='div_"+ctr+"'><a href='#' id='cmd_"+ctr+"'>cmd</a><input></input></div>", pos);
|
||||
t.run ();
|
||||
t.update = function() {
|
||||
r2.cmd (t.cmd, function(x) {
|
||||
_(t.key).innerHTML =
|
||||
"<div class='frame_body'><pre>"+x+"</pre></div>";
|
||||
});
|
||||
}
|
||||
_('cmd_'+ctr).onclick = function() {
|
||||
t.key = 'div_'+ctr;
|
||||
t.cmd = prompt ();
|
||||
t.update ();
|
||||
}
|
||||
}
|
||||
_('settings').onclick = function() { newSettingsFrame (); }
|
||||
_('refresh').onclick = function() { t.update_all(); }
|
||||
_('maximize').onclick = function() { t.maximize = !!!t.maximize; t.run(); }
|
||||
_('open-hex').onclick = function() { newHexdumpFrame(); }
|
||||
_('open-dis').onclick = function() { newDisasmFrame(); }
|
||||
_('open-fla').onclick = function() { newFlagsFrame(); }
|
||||
_('open-dbg').onclick = function() { newDebugFrame(); }
|
||||
_('open-hlp').onclick = function() { newHelpFrame(); }
|
||||
_('open-con').onclick = function() { newConsoleFrame(); }
|
||||
_('open-not').onclick = function() { newNotesFrame(); }
|
||||
_('add-column').onclick = function() {
|
||||
addPanel ("right");
|
||||
}
|
||||
_('add-row').onclick = function() {
|
||||
ctr++;
|
||||
position = "bottom";
|
||||
t.new_frame ('window_'+ctr, "<div id='div_"+ctr+"'><a href='#' id='cmd_"+ctr+"'>cmd</a></div>", "bottom");
|
||||
// t.frames[0].push (t.frames.pop ()[0]);
|
||||
t.run();
|
||||
t.update = function() {
|
||||
r2.cmd (t.cmd, function(x) {
|
||||
_(t.key).innerHTML =
|
||||
"<div class='frame_body'><pre>"+x+"</pre></div>";
|
||||
});
|
||||
}
|
||||
_('cmd_'+ctr).onclick = function() {
|
||||
t.key = 'div_'+ctr;
|
||||
t.cmd = prompt ();
|
||||
t.update ();
|
||||
}
|
||||
}
|
||||
newHexdumpFrame ();
|
||||
newDisasmFrame ();
|
||||
t.run ();
|
||||
window.onresize = function() {
|
||||
t.run ();
|
||||
}
|
||||
document.t = t;
|
||||
|
||||
_('body').onkeyup = function (e) {
|
||||
var key = String.fromCharCode(e.keyCode);
|
||||
//if (!key.altKey) return;
|
||||
if (!e.altKey)
|
||||
return;
|
||||
key = e.keyCode;
|
||||
switch (key) {
|
||||
case 67:/*c*/ if (t.curframe) {t.oldframe = t.curframe; }
|
||||
t.del_frame(); t.run();break;
|
||||
case 189: // chrome
|
||||
case 173:/*-*/ addPanel ("bottom"); break;
|
||||
case 220: // chrome
|
||||
case 49:/*|*/ addPanel ("right"); break;
|
||||
case 190:/*.*/ t.maximize = !!!t.maximize; t.run(); break;
|
||||
case 72:/*h*/ t.other_frame('left'); break;
|
||||
case 74:/*j*/ t.other_frame('down'); break;
|
||||
case 75:/*k*/ t.other_frame('up'); break;
|
||||
case 76:/*l*/ t.other_frame('right'); break;
|
||||
case 88:
|
||||
case 'x': newHexdumpFrame (); break;
|
||||
case 68:
|
||||
case 'd': newDisasmFrame (); break;
|
||||
/*
|
||||
case 'h': t.move_frame ('left'); break;
|
||||
case 'j': t.move_frame ('down'); break;
|
||||
case 'k': t.move_frame ('up'); break;
|
||||
case 'l': t.move_frame ('right'); break;
|
||||
*/
|
||||
case 'i':
|
||||
r2.cmd ("pi 2", function(x){alert(x);});
|
||||
break;
|
||||
case '!':
|
||||
r2.cmd (prompt("Command to execute"), function(x){alert(x);});
|
||||
break;
|
||||
|
||||
}
|
||||
//r2.cmd ("pi 2", alert);
|
||||
}
|
||||
}
|
593
shlr/www/t/r2.js
593
shlr/www/t/r2.js
@ -1,593 +0,0 @@
|
||||
/* radare2 Copyleft 2013-2014 pancake */
|
||||
|
||||
var r2 = {};
|
||||
|
||||
// TODO: avoid globals
|
||||
var backward = false;
|
||||
var next_curoff = 0;
|
||||
var next_lastoff = 0;
|
||||
var prev_curoff = 0;
|
||||
var prev_lastoff = 0;
|
||||
var hascmd = false;
|
||||
|
||||
// async helper
|
||||
function asyncLoop(iterations, func, callback) {
|
||||
var index = 0;
|
||||
var done = false;
|
||||
var loop = {
|
||||
next: function() {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (index < iterations) {
|
||||
index++;
|
||||
func(loop);
|
||||
|
||||
} else {
|
||||
done = true;
|
||||
callback();
|
||||
}
|
||||
},
|
||||
|
||||
iteration: function() {
|
||||
return index - 1;
|
||||
},
|
||||
|
||||
break: function() {
|
||||
done = true;
|
||||
callback();
|
||||
}
|
||||
};
|
||||
loop.next();
|
||||
return loop;
|
||||
}
|
||||
|
||||
if (typeof (module) !== 'undefined') {
|
||||
module.exports = function(r) {
|
||||
if (typeof (r) == 'function') {
|
||||
hascmd = r;
|
||||
} else {
|
||||
hascmd = r.cmd;
|
||||
}
|
||||
return r2;
|
||||
}
|
||||
}
|
||||
|
||||
r2.project_name = "";
|
||||
|
||||
r2.plugin = function() {
|
||||
console.error ("r2.plugin is not available in this environment");
|
||||
}
|
||||
try {
|
||||
if (r2plugin) {
|
||||
r2.plugin = r2plugin
|
||||
}
|
||||
} catch ( e ) {}
|
||||
|
||||
r2.root = ""; // prefix path
|
||||
|
||||
/* helpers */
|
||||
function dump(obj) {
|
||||
var x = "";
|
||||
for (var a in obj) x += a + "\n";
|
||||
if (typeof ('alert') != 'undefined') {
|
||||
alert (x);
|
||||
} else {
|
||||
console.log (x);
|
||||
}
|
||||
}
|
||||
|
||||
r2.analAll = function() {
|
||||
r2.cmd ("aa", function() {});
|
||||
}
|
||||
|
||||
r2.analOp = function(addr, cb) {
|
||||
r2.cmd ("aoj 1 @ " + addr, function(txt) {
|
||||
try {
|
||||
cb(JSON.parse (txt)[0]);
|
||||
} catch ( e ) {
|
||||
console.error (e)
|
||||
cb (txt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
r2.varMap = [];
|
||||
r2.argMap = [];
|
||||
|
||||
function objtostr(obj) {
|
||||
var str = "";
|
||||
for (var a in obj)
|
||||
str += a + ": " + obj[a] + ",\n";
|
||||
return str;
|
||||
}
|
||||
|
||||
function Ajax(method, uri, body, fn) {
|
||||
if (typeof (XMLHttpRequest) == "undefined")
|
||||
return false;
|
||||
var x = new XMLHttpRequest ();
|
||||
if (!x)
|
||||
return false;
|
||||
x.open (method, uri, false);
|
||||
x.setRequestHeader ('Accept', 'text/plain');
|
||||
x.setRequestHeader ('Accept', 'text/html');
|
||||
x.setRequestHeader ("Content-Type", "application/x-ww-form-urlencoded; charset=UTF-8");
|
||||
x.onreadystatechange = function(y) {
|
||||
if (x.status == 200) {
|
||||
if (fn) {
|
||||
fn (x.responseText);
|
||||
}
|
||||
} else {
|
||||
console.error ("ajax " + x.status)
|
||||
}
|
||||
}
|
||||
x.send (body);
|
||||
return true;
|
||||
}
|
||||
|
||||
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 @b:' + bytes + off;
|
||||
r2.cmd (str, fn);
|
||||
}
|
||||
|
||||
r2.get_hexdump = function(offset, length, cb) {
|
||||
r2.cmd ("px " + length + "@" + offset, cb);
|
||||
}
|
||||
|
||||
r2.get_disasm = function(offset, length, cb) {
|
||||
// TODO: honor offset and length
|
||||
r2.cmd ("pD " + length + "@" + offset, cb);
|
||||
}
|
||||
|
||||
r2.get_disasm_before = function(offset, start, cb) {
|
||||
var before = [];
|
||||
r2.cmd("pdj -" + start + "@" + offset, function(x) {
|
||||
before = JSON.parse(x);
|
||||
});
|
||||
cb(before);
|
||||
}
|
||||
|
||||
r2.get_disasm_after = function(offset, end, cb) {
|
||||
var after = [];
|
||||
r2.cmd("pdj " + end + "@" + offset, function(x) {
|
||||
after = JSON.parse(x);
|
||||
});
|
||||
cb(after);
|
||||
}
|
||||
|
||||
r2.get_disasm_before_after = function(offset, start, end, cb) {
|
||||
var before = [];
|
||||
var after = [];
|
||||
r2.cmd("pdj " + start + " @" + offset, function(x) {
|
||||
before = JSON.parse(x);
|
||||
});
|
||||
r2.cmd("pdj " + end + "@" + offset, function(x) {
|
||||
after = JSON.parse(x);
|
||||
});
|
||||
var opcodes = before.concat(after);
|
||||
cb(opcodes);
|
||||
}
|
||||
|
||||
r2.Config = function(k, v, fn) {
|
||||
if (typeof v == 'function' || !v) { // get
|
||||
r2.cmd ("e " + k, fn || v);
|
||||
} else { // set
|
||||
r2.cmd ("e " + k + "=" + v, fn);
|
||||
}
|
||||
return r2;
|
||||
}
|
||||
|
||||
r2.sections = {};
|
||||
|
||||
r2.load_mmap = function() {
|
||||
r2.cmdj("iSj", function(x) {
|
||||
if (x !== undefined && x !== null) {
|
||||
r2.sections = x;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
r2.get_address_type = function(address) {
|
||||
var offset = parseInt(address, 16);
|
||||
for (var i in r2.sections) {
|
||||
if (offset >= r2.sections[i].addr && offset < r2.sections[i].addr + r2.sections[i].size) {
|
||||
if (r2.sections[i].flags.indexOf("x") > -1) {
|
||||
return "instruction";
|
||||
}
|
||||
else {
|
||||
return "memory";
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
r2.settings = {};
|
||||
|
||||
r2.load_settings = function() {
|
||||
r2.cmd ("e asm.arch", function(x) {r2.settings['asm.arch'] = x.trim();});
|
||||
r2.cmd ("e asm.bits", function(x) {r2.settings['asm.bits'] = x.trim();});
|
||||
r2.cmd ("e asm.bytes", function(x) {r2.settings['asm.bytes'] = toBoolean(x.trim());});
|
||||
r2.cmd ("e asm.flags", function(x) {r2.settings['asm.flags'] = toBoolean(x.trim());});
|
||||
r2.cmd ("e asm.offset", function(x) {r2.settings['asm.offset'] = toBoolean(x.trim());});
|
||||
r2.cmd ("e asm.lines", function(x) {r2.settings['asm.lines'] = toBoolean(x.trim());});
|
||||
r2.cmd ("e asm.xrefs", function(x) {r2.settings['asm.xrefs'] = toBoolean(x.trim());});
|
||||
r2.cmd ("e asm.cmtright", function(x) {r2.settings['asm.cmtright'] = toBoolean(x.trim());});
|
||||
r2.cmd ("e asm.pseudo", function(x) {r2.settings['asm.pseudo'] = toBoolean(x.trim());});
|
||||
// console.log("Loading settings from r2");
|
||||
// console.log(r2.settings);
|
||||
}
|
||||
|
||||
|
||||
r2.flags = {};
|
||||
|
||||
r2.update_flags = function() {
|
||||
r2.cmd ("fs *;fj", function(x) {
|
||||
|
||||
var fs = JSON.parse (x);
|
||||
if (fs !== undefined && fs !== null) {
|
||||
r2.flags = {};
|
||||
for (var f in fs) {
|
||||
var addr = "0x" + fs[f].offset.toString(16);
|
||||
addr = address_canonicalize(addr);
|
||||
if (addr in r2.flags) {
|
||||
var fl = r2.flags[addr];
|
||||
fl[fl.length] = { name: fs[f].name, size: fs[f].size};
|
||||
r2.flags[addr] = fl;
|
||||
} else {
|
||||
r2.flags[addr] = [{ name: fs[f].name, size: fs[f].size}];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
r2.get_flag_address = function(name) {
|
||||
for (var f in r2.flags) {
|
||||
for (var v in r2.flags[f]) {
|
||||
if (name == r2.flags[f][v].name) return f;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
r2.get_flag_names = function(offset) {
|
||||
var names = [];
|
||||
for (var i in r2.flags[offset]) {
|
||||
names[names.length] = r2.flags[offset][i].name;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
r2.set_flag_space = function(ns, fn) {
|
||||
r2.cmd ("fs " + ns, fn);
|
||||
}
|
||||
|
||||
r2.get_flags = function(fn) {
|
||||
r2.cmd ("fj", function(x) {
|
||||
fn (x ? JSON.parse (x) : []);
|
||||
});
|
||||
}
|
||||
|
||||
r2.get_opcodes = function(off, n, cb) {
|
||||
r2.cmd ("pdj @" + off + "!" + n, function(json) {
|
||||
cb (JSON.parse (json));
|
||||
});
|
||||
}
|
||||
|
||||
r2.get_bytes = function(off, n, cb) {
|
||||
r2.cmd ("pcj @" + off + "!" + n, function(json) {
|
||||
cb (JSON.parse (json));
|
||||
});
|
||||
}
|
||||
|
||||
r2.asm_config = {};
|
||||
|
||||
r2.store_asm_config = function() {
|
||||
config = {};
|
||||
r2.cmd ("e", function(x) {
|
||||
conf = x.split("\n");
|
||||
for (var prop in conf) {
|
||||
var fields = conf[prop].split(" ");
|
||||
if (fields.length == 3) {
|
||||
// TODO: Dont know why byt e~asm. is not working so filtering here
|
||||
if (fields[0].trim().indexOf("asm.") == 0) config[fields[0].trim()] = fields[2].trim();
|
||||
}
|
||||
}
|
||||
r2.asm_config = config;
|
||||
});
|
||||
}
|
||||
|
||||
r2.restore_asm_config = function() {
|
||||
cmd = "";
|
||||
for (var prop in r2.asm_config) {
|
||||
cmd += "e " + prop + "=" + r2.asm_config[prop] + ";";
|
||||
}
|
||||
r2.cmd (cmd, function(x) {});
|
||||
}
|
||||
|
||||
r2.get_info = function(cb) {
|
||||
r2.cmd ("ij", function(json) {
|
||||
cb (JSON.parse (json));
|
||||
});
|
||||
}
|
||||
r2.bin_relocs = function(cb) {
|
||||
r2.cmd ("irj", function(json) {
|
||||
cb (JSON.parse (json));
|
||||
});
|
||||
}
|
||||
r2.bin_imports = function(cb) {
|
||||
r2.cmd ("iij", function(json) {
|
||||
cb (JSON.parse (json));
|
||||
});
|
||||
}
|
||||
|
||||
r2.bin_symbols = function(cb) {
|
||||
r2.cmd ("isj", function(json) {
|
||||
cb (JSON.parse (json));
|
||||
});
|
||||
}
|
||||
|
||||
r2.bin_sections = function(cb) {
|
||||
r2.cmd ("iSj", function(json) {
|
||||
cb (JSON.parse (json));
|
||||
});
|
||||
}
|
||||
|
||||
r2.cmds = function(cmds, cb) {
|
||||
if (cmds.length == 0) return;
|
||||
var cmd = cmds[0];
|
||||
cmds = cmds.splice (1);
|
||||
function lala() {
|
||||
if (cmd == undefined || cmds.length == 0) {
|
||||
return;
|
||||
}
|
||||
cmd = cmds[0];
|
||||
cmds = cmds.splice (1);
|
||||
r2.cmd (cmd, lala);
|
||||
if (cb) {
|
||||
cb ();
|
||||
}
|
||||
return;
|
||||
}
|
||||
r2.cmd (cmd, lala);
|
||||
}
|
||||
|
||||
function _internal_cmd(c, cb) {
|
||||
if (typeof (r2cmd) != 'undefined') {
|
||||
hascmd = r2cmd;
|
||||
}
|
||||
if (hascmd) {
|
||||
// TODO: use setTimeout for async?
|
||||
if (typeof (r2plugin) != "undefined") {
|
||||
// duktape
|
||||
cb (r2cmd(c));
|
||||
} else {
|
||||
// node
|
||||
return hascmd (c, cb);
|
||||
}
|
||||
} else {
|
||||
Ajax ('GET', r2.root + "/cmd/" + encodeURI(c), '', function(x) {
|
||||
if (cb) {
|
||||
cb (x);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
r2.cmd = function(c, cb) {
|
||||
if (Array.isArray (c)) {
|
||||
var res = [];
|
||||
var idx = 0;
|
||||
asyncLoop (c.length, function(loop) {
|
||||
_internal_cmd (c[idx], function(result) {
|
||||
idx = loop.iteration();
|
||||
res[idx] = result.replace(/\n$/, "");
|
||||
idx++;
|
||||
loop.next ();
|
||||
});
|
||||
}, function() {
|
||||
// all iterations done
|
||||
cb (res);
|
||||
});
|
||||
} else {
|
||||
_internal_cmd (c, cb);
|
||||
}
|
||||
}
|
||||
|
||||
r2.cmdj = function(c, cb) {
|
||||
r2.cmd (c, function(x) {
|
||||
try {
|
||||
cb (JSON.parse(x));
|
||||
} catch ( e ) {
|
||||
cb (null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
r2.alive = function(cb) {
|
||||
r2.cmd ("b", function(o) {
|
||||
var ret = false;
|
||||
if (o && o.length () > 0) {
|
||||
ret = true;
|
||||
}
|
||||
if (cb) {
|
||||
cb (o);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
r2.getTextLogger = function(obj) {
|
||||
if (typeof (obj) != "object") {
|
||||
obj = {};
|
||||
}
|
||||
obj.last = 0;
|
||||
obj.events = {};
|
||||
obj.interval = null;
|
||||
r2.cmd ("Tl", function(x) {
|
||||
obj.last = +x;
|
||||
});
|
||||
obj.load = function(cb) {
|
||||
r2.cmd ("Tj " + (obj.last + 1), function(ret) {
|
||||
if (cb) {
|
||||
cb (JSON.parse (ret));
|
||||
}
|
||||
});
|
||||
}
|
||||
obj.clear = function(cb) {
|
||||
// XXX: fix l-N
|
||||
r2.cmd ("T-", cb); //+obj.last, cb);
|
||||
}
|
||||
obj.send = function(msg, cb) {
|
||||
r2.cmd ("T " + msg, cb);
|
||||
}
|
||||
obj.refresh = function(cb) {
|
||||
obj.load (function(ret) {
|
||||
//obj.last = 0;
|
||||
for (var i = 0; i < ret.length; i++) {
|
||||
var message = ret[i];
|
||||
obj.events["message"] ({
|
||||
"id": message[0],
|
||||
"text": message[1]
|
||||
});
|
||||
if (message[0] > obj.last) {
|
||||
obj.last = message[0];
|
||||
}
|
||||
}
|
||||
if (cb) {
|
||||
cb ();
|
||||
}
|
||||
});
|
||||
}
|
||||
obj.autorefresh = function(n) {
|
||||
if (!n) {
|
||||
if (obj.interval) {
|
||||
obj.interval.stop ();
|
||||
}
|
||||
return;
|
||||
}
|
||||
function to() {
|
||||
obj.refresh (function() {
|
||||
//obj.clear ();
|
||||
});
|
||||
if (r2ui.selected_panel === "Logs")
|
||||
setTimeout (to, n * 1000);
|
||||
else console.log("Not in logs :(");
|
||||
return true;
|
||||
}
|
||||
obj.interval = setTimeout (to, n * 1000);
|
||||
}
|
||||
obj.on = function(ev, cb) {
|
||||
obj.events[ev] = cb;
|
||||
return obj;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
r2.filter_asm = function(x, display) {
|
||||
var curoff = backward ? prev_curoff : next_curoff;
|
||||
;
|
||||
var lastoff = backward ? prev_lastoff : next_lastoff;
|
||||
;
|
||||
var lines = x.split (/\n/g);
|
||||
r2.cmd ("s", function(x) {
|
||||
curoff = x;
|
||||
});
|
||||
for (var i = lines.length - 1; i > 0; i--) {
|
||||
var a = lines[i].match (/0x([a-fA-F0-9]+)/);
|
||||
if (a && a.length > 0) {
|
||||
lastoff = a[0].replace (/:/g, "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (display == "afl") {
|
||||
//hasmore (false);
|
||||
var z = "";
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var row = lines[i].replace (/\ +/g, " ").split (/ /g);
|
||||
z += row[0] + " " + row[3] + "\n";
|
||||
}
|
||||
x = z;
|
||||
} else if (display[0] == 'f') {
|
||||
//hasmore (false);
|
||||
if (display[1] == 's') {
|
||||
var z = "";
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var row = lines[i].replace (/\ +/g, " ").split (/ /g);
|
||||
var mark = row[1] == '*' ? '*' : ' ';
|
||||
var space = row[2] ? row[2] : row[1];
|
||||
if (!space) continue;
|
||||
z += row[0] + " " + mark + " <a href=\"javascript:runcmd('fs " +
|
||||
space + "')\">" + space + "</a>\n";
|
||||
}
|
||||
x = z;
|
||||
} else {
|
||||
}
|
||||
} else if (display[0] == "i") {
|
||||
//hasmore (false);
|
||||
if (display[1]) {
|
||||
var z = "";
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var elems = lines[i].split (/ /g);
|
||||
var name = "";
|
||||
var addr = "";
|
||||
for (var j = 0; j < elems.length; j++) {
|
||||
var kv = elems[j].split (/=/);
|
||||
if (kv[0] == "addr") {
|
||||
addr = kv[1];
|
||||
}
|
||||
if (kv[0] == "name") {
|
||||
name = kv[1];
|
||||
}
|
||||
if (kv[0] == "string") {
|
||||
name = kv[1];
|
||||
}
|
||||
}
|
||||
z += addr + " " + name + "\n";
|
||||
}
|
||||
x = z;
|
||||
}
|
||||
} //else hasmore (true);
|
||||
|
||||
function haveDisasm(x) {
|
||||
if (x[0] == 'p' && x[1] == 'd') return true;
|
||||
if (x.indexOf (";pd") != -1) return true;
|
||||
return false;
|
||||
}
|
||||
if (haveDisasm (display)) {
|
||||
x = x.replace (/function:/g, "<span style=color:green>function:</span>");
|
||||
x = x.replace (/;(\s+)/g, ";");
|
||||
x = x.replace (/;(.*)/g, "// <span style='color:#209020'>$1</span>");
|
||||
x = x.replace (/(bl|goto|call)/g, "<b style='color:green'>call</b>");
|
||||
x = x.replace (/(jmp|bne|beq|js|jnz|jae|jge|jbe|jg|je|jl|jz|jb|ja|jne)/g, "<b style='color:green'>$1</b>");
|
||||
x = x.replace (/(dword|qword|word|byte|movzx|movsxd|cmovz|mov\ |lea\ )/g, "<b style='color:#1070d0'>$1</b>");
|
||||
x = x.replace (/(hlt|leave|iretd|retn|ret)/g, "<b style='color:red'>$1</b>");
|
||||
x = x.replace (/(add|sbb|sub|mul|div|shl|shr|and|not|xor|inc|dec|sar|sal)/g, "<b style='color:#d06010'>$1</b>");
|
||||
x = x.replace (/(push|pop)/g, "<b style='color:#40a010'>$1</b>");
|
||||
x = x.replace (/(test|cmp)/g, "<b style='color:#c04080'>$1</b>");
|
||||
x = x.replace (/(outsd|out|string|invalid|int |int3|trap|main|in)/g, "<b style='color:red'>$1</b>");
|
||||
x = x.replace (/nop/g, "<b style='color:blue'>nop</b>");
|
||||
x = x.replace (/(sym|fcn|str|imp|loc)\.([^:<(\\\/ \|)\->]+)/g, "<a href='javascript:r2ui.seek(\"$1.$2\")'>$1.$2</a>");
|
||||
}
|
||||
x = x.replace (/0x([a-zA-Z0-9]+)/g, "<a href='javascript:r2ui.seek(\"0x$1\")'>0x$1</a>");
|
||||
// registers
|
||||
if (backward) {
|
||||
prev_curoff = curoff;
|
||||
prev_lastoff = lastoff;
|
||||
} else {
|
||||
next_curoff = curoff;
|
||||
next_lastoff = lastoff;
|
||||
if (!prev_curoff) {
|
||||
prev_curoff = next_curoff;
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
@ -1,81 +0,0 @@
|
||||
img {
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin:0px;
|
||||
border:0px;
|
||||
}
|
||||
textarea {
|
||||
background-color: #203040;
|
||||
color:white;
|
||||
border:0px;
|
||||
padding:5px;
|
||||
}
|
||||
a {
|
||||
color: #a06000;
|
||||
}
|
||||
a:hover {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.link {
|
||||
color:white;
|
||||
}
|
||||
html, body {
|
||||
overflow:hidden;
|
||||
}
|
||||
iframe {
|
||||
width:100%;
|
||||
border: 1px solid black;
|
||||
}
|
||||
.frame {
|
||||
font-family: monospace;
|
||||
border: 1px solid black;
|
||||
height:100%;
|
||||
background-color:#506070;
|
||||
color: #e0e0e0;
|
||||
}
|
||||
.frame_title {
|
||||
background-color:black;
|
||||
color:white;
|
||||
padding:0px;
|
||||
top:0px;
|
||||
height:20px;
|
||||
font-family: monospace;
|
||||
width:100%;
|
||||
}
|
||||
.frame_body {
|
||||
background-color:#304050;
|
||||
overflow:scroll;
|
||||
height:100%;
|
||||
}
|
||||
.canvas {
|
||||
padding-top:3px;
|
||||
width:100%;
|
||||
height:100%;
|
||||
background-color:blue;
|
||||
border-top:5px;
|
||||
font-size:12px;
|
||||
font-family:monospace;
|
||||
}
|
||||
input {
|
||||
border: 1px solid black;
|
||||
text-align:right;
|
||||
background-color: rgba(0,0,0,0.3);
|
||||
overflow:hidden;
|
||||
color: white;
|
||||
font-family: monospace;
|
||||
}
|
||||
h2 {
|
||||
padding:0px;
|
||||
color:black;
|
||||
border:0px;
|
||||
margin:10px;
|
||||
}
|
||||
.minibut {
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
font-family: monospace;
|
||||
color: #a0a0f0;
|
||||
}
|
@ -1,447 +0,0 @@
|
||||
function _(x) { return document.getElementById (x); }
|
||||
|
||||
var Tiled = function(id) {
|
||||
var obj = document.getElementById (id);
|
||||
this.curframe = undefined;
|
||||
this.frames = [];
|
||||
var topmargin = 20;
|
||||
var w = 3;
|
||||
var h = 0;
|
||||
this.update_size = function (width, height) {
|
||||
w = width || window.innerWidth;
|
||||
h = height || window.innerHeight;
|
||||
}
|
||||
this.max_width = function (set) {
|
||||
var col = this.curframe[1];
|
||||
for (var col in this.frames) {
|
||||
for (var row in this.frames[col]) {
|
||||
this.frames[col][row].mw = false;
|
||||
}
|
||||
}
|
||||
this.curframe[0].mw = set;
|
||||
}
|
||||
this.max_height = function (set) {
|
||||
if (this.curframe) {
|
||||
var col = this.curframe[1];
|
||||
for (var row in this.frames[col]) {
|
||||
var f = this.frames[col][row];
|
||||
f.mh = false;
|
||||
}
|
||||
this.curframe[0].mh = set;
|
||||
}
|
||||
}
|
||||
this.ctr2 = 0;
|
||||
this.tile = function () {
|
||||
if (this.maximize && this.curframe) {
|
||||
var mtop = topmargin;
|
||||
var left = 0;
|
||||
var width = w;
|
||||
var height = h-mtop;
|
||||
|
||||
var f = this.curframe[0];
|
||||
f.obj.style.position = 'absolute';
|
||||
f.obj.style.top = mtop;
|
||||
f.obj.style.left = left;
|
||||
// always on top.. or hide all the frames
|
||||
f.obj.style.zIndex = 99999+this.ctr2++;
|
||||
// TODO: add proportions
|
||||
f.obj.style.width = width;
|
||||
f.obj.style.height = height;
|
||||
//f.obj.style.backgroundColor = "green";
|
||||
//f.obj.innerHTML =" FUCK";
|
||||
if (f.update)
|
||||
f.update (f.obj);
|
||||
return;
|
||||
}
|
||||
function getmaxh (self,col) {
|
||||
if (self.frames[col]) {
|
||||
for (var row in self.frames[col]) {
|
||||
var f = self.frames[col][row];
|
||||
if (f && (f.mh||f.selected))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function getmaxw () {
|
||||
for (var col in this.frames) {
|
||||
for (var row in this.frames[col]) {
|
||||
var f = this.frames[col][row];
|
||||
if (f && f.mw) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
var cols = this.frames.length;
|
||||
var left = 0;
|
||||
var hasmaxw = true; //getmaxw ();
|
||||
for (var col in this.frames) {
|
||||
var rows = this.frames[col].length;
|
||||
var mtop = topmargin;
|
||||
var cols = this.frames.length;
|
||||
var hasmaxh = getmaxh (this, col);
|
||||
|
||||
var width = w/cols;
|
||||
var height = (h-topmargin)/rows;
|
||||
|
||||
if (this.curframe && hasmaxw && this.frames.length>1) {
|
||||
if (col==this.curframe[1]) {
|
||||
width = w/2;
|
||||
} else {
|
||||
width = (w/2)/(cols-1);
|
||||
}
|
||||
}
|
||||
for (var row in this.frames[col]) {
|
||||
var f = this.frames[col][row];
|
||||
if (hasmaxh && this.frames[col].length>1) {
|
||||
if (f.selected) {
|
||||
height = 1.7* ((h-topmargin)/(rows));
|
||||
} else {
|
||||
var a = 1.7*(h-topmargin)/(rows);
|
||||
height = (h-a)/(rows-1);
|
||||
}
|
||||
} else {
|
||||
height = (h-topmargin)/rows;
|
||||
}
|
||||
height = 0|height;
|
||||
f.obj.style.position = 'absolute';
|
||||
f.obj.style.top = mtop;
|
||||
f.obj.style.left = left;
|
||||
// TODO: add proportions
|
||||
f.obj.style.width = width;
|
||||
if (row==0) {
|
||||
height-=22;
|
||||
}
|
||||
f.obj.style.height = height;
|
||||
|
||||
//f.obj.style.backgroundColor = "green";
|
||||
if (f.update)
|
||||
f.update (f.obj);
|
||||
mtop += height;
|
||||
}
|
||||
left += width;
|
||||
};
|
||||
}
|
||||
|
||||
this.num = 0;
|
||||
this.defname = function (name) {
|
||||
name = name || "noname";
|
||||
this.num++;
|
||||
return name+"_"+this.num;
|
||||
}
|
||||
|
||||
this.unselect_frames = function (name) {
|
||||
for (var col in this.frames) {
|
||||
for (var row in this.frames[col]) {
|
||||
var f = this.frames[col][row];
|
||||
f.selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.move_frame = function (dir) {
|
||||
if (!this.curframe)
|
||||
return;
|
||||
var col = this.curframe[1];
|
||||
switch (dir) {
|
||||
case 'up':
|
||||
// move to new column
|
||||
break;
|
||||
case 'down':
|
||||
// remove from column
|
||||
// remove column if empty
|
||||
// append to previous column
|
||||
break;
|
||||
case 'right':
|
||||
if (col==this.frames.length-1)
|
||||
return false;
|
||||
alert ("moveright Col is "+col);
|
||||
// AAAA B C DDD
|
||||
var b, c, d;
|
||||
b = this.frames[col];
|
||||
c = this.frames.splice (col);
|
||||
d = c.splice (1).slice (1);
|
||||
alert ("AAAA "+this.frames.length);
|
||||
alert ("C "+c.length);
|
||||
alert ("D "+d.length);
|
||||
if (b) this.frames.push (b);
|
||||
if (c.length>0) {
|
||||
alert ("SET COL "+this.frames.length);
|
||||
this.frames.push (c);
|
||||
}
|
||||
for (var i = 0; i<d.length; i++)
|
||||
this.frames.push (d[i]);
|
||||
this.tile ();
|
||||
break;
|
||||
case 'left':
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.other_frame = function (dir) {
|
||||
if (!this.curframe)
|
||||
return;
|
||||
switch (dir) {
|
||||
case 'up':
|
||||
var col = +this.curframe[1];
|
||||
var row = +this.curframe[2];
|
||||
if (row>0) {
|
||||
row--;
|
||||
var f = this.frames[col][row];
|
||||
this.select_frame (f.name);
|
||||
this.curframe = [f,col,row];
|
||||
this.run();
|
||||
}
|
||||
break;
|
||||
case 'down':
|
||||
var col = +this.curframe[1];
|
||||
var row = +this.curframe[2];
|
||||
if (row<=this.frames[col].length) {
|
||||
row++;
|
||||
var f = this.frames[col][row];
|
||||
if (f) {
|
||||
this.select_frame (f.name);
|
||||
this.curframe = [f,col,row];
|
||||
this.run();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'left':
|
||||
var col = +this.curframe[1];
|
||||
if (col>0) {
|
||||
col--;
|
||||
var f = this.frames[col][0];
|
||||
if (f) {
|
||||
this.select_frame (f.name);
|
||||
this.curframe = [f,col,0];
|
||||
this.run();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'right':
|
||||
var col = +this.curframe[1];
|
||||
if (col>=this.frames.length-1)
|
||||
col = -1;
|
||||
if (col<this.frames.length) {
|
||||
col++;
|
||||
var f = this.frames[col]
|
||||
if (f) f = f[0];
|
||||
if (f) {
|
||||
this.select_frame (f.name);
|
||||
this.curframe = [f,col,0];
|
||||
this.run();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.select_frame = function (name) {
|
||||
var ret = undefined;
|
||||
if (!name && this.curframe) {
|
||||
name = this.curframe[0].name;
|
||||
}
|
||||
this.oldframe = this.curframe;
|
||||
for (var col in this.frames) {
|
||||
for (var row in this.frames[col]) {
|
||||
var f = this.frames[col][row];
|
||||
if (f.name === name) {
|
||||
_('frame_'+f.name).style.backgroundColor = "black";
|
||||
f.selected = true;
|
||||
f.mw = true;
|
||||
ret = this.curframe = [f,col,row];
|
||||
} else {
|
||||
_('frame_'+f.name).style.backgroundColor = "#c0c0c0";
|
||||
f.mw = false;
|
||||
f.selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.tile ();
|
||||
return ret;
|
||||
}
|
||||
this.new_frame = function(name, body, update, pos, cb) {
|
||||
var nf = {};
|
||||
nf.name = name = name || this.defname ();
|
||||
|
||||
var obj_title = document.createElement ('div');
|
||||
obj_title.className = 'frame_title';
|
||||
obj_title.id = 'frame_'+name;
|
||||
var d = document.createElement ('div');
|
||||
d.style.backgroundColor = '#c0c0c0';
|
||||
d.style['overflow-x'] = 'hidden';
|
||||
|
||||
var x = document.createElement ('a');
|
||||
x.innerHTML = "[x]";
|
||||
x.href='#';
|
||||
(function (self,name) {
|
||||
x.onclick = function() {
|
||||
//alert ("clicked "+name);
|
||||
self.del_frame (name);
|
||||
}
|
||||
})(this,name);
|
||||
d.appendChild (x);
|
||||
|
||||
var b2 = document.createElement ('a');
|
||||
b2.innerHTML = "[r]";
|
||||
b2.href='#';
|
||||
b2.ival = null;
|
||||
var self = this;
|
||||
b2.onclick = function (x) {
|
||||
// TODO : toggle auto refresh
|
||||
if (b2.ival) {
|
||||
clearInterval (b2.ival);
|
||||
b2.ival = null;
|
||||
b2.innerHTML = "[r]";
|
||||
} else {
|
||||
b2.innerHTML = "[R]";
|
||||
if (cb) {
|
||||
cb (self, nf);
|
||||
b2.ival = setInterval (function () {
|
||||
cb (self, nf);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
d.appendChild (b2);
|
||||
|
||||
var b = document.createElement ('a');
|
||||
b.innerHTML = "[@] ";
|
||||
b.href='#';
|
||||
b.onclick = nf.refresh = function (x) {
|
||||
if (cb) {
|
||||
cb (self, nf);
|
||||
}
|
||||
}
|
||||
d.appendChild (b);
|
||||
//nf.offset = "entry0"; //0x404981;
|
||||
|
||||
var a = document.createElement ('a');
|
||||
a.innerHTML = name;
|
||||
a.href='#';
|
||||
d.appendChild (a);
|
||||
|
||||
/*
|
||||
var inp = document.createElement ('input');
|
||||
inp.value = "entry0";
|
||||
inp.href='#';
|
||||
d.appendChild (inp);
|
||||
*/
|
||||
|
||||
obj_title.appendChild (d);
|
||||
(function (self,name) {
|
||||
a.onclick = function() {
|
||||
//alert ("clicked "+name);
|
||||
var newname = prompt ("title");
|
||||
// self.del_frame (name);
|
||||
}
|
||||
})(this,name);
|
||||
if (typeof (update) === 'string') {
|
||||
pos = update;
|
||||
update = undefined;
|
||||
}
|
||||
nf.update = update;
|
||||
nf.obj = document.createElement ('div');
|
||||
var title = obj_title.outerHTML;
|
||||
nf.obj.className='frame';
|
||||
nf.obj.id = nf.name;
|
||||
nf.obj.appendChild (obj_title);
|
||||
var x= document.createElement ('p');
|
||||
x.innerHTML = body;
|
||||
nf.obj.appendChild (obj_title);
|
||||
nf.obj.appendChild (x);
|
||||
obj.appendChild (nf.obj);
|
||||
switch (pos) {
|
||||
case "bottom":
|
||||
// TODO: append right above the selected row
|
||||
var cc = this.curframe? this.curframe[1]: 0;
|
||||
this.frames.push ([nf]);
|
||||
this.frames[cc].push (this.frames.pop ()[0]);
|
||||
break;
|
||||
case "right":
|
||||
var col = this.curframe? this.curframe[1]: 0;
|
||||
var a = this.frames.slice (0, col+1);
|
||||
var b = this.frames.slice (col+1);
|
||||
a.push ([nf]);
|
||||
this.frames = a.concat (b);
|
||||
break;
|
||||
default:
|
||||
this.frames.push ([nf]);
|
||||
break;
|
||||
}
|
||||
this.select_frame (name);
|
||||
if (cb) {
|
||||
cb (self, nf);
|
||||
}
|
||||
(function (self, name) {
|
||||
var f = _('frame_'+name);
|
||||
f.onmouseup = function() {
|
||||
var f = self.select_frame (name);
|
||||
if (f) {
|
||||
// f[0].obj.innerHTML = f[0].obj.innerHTML+"<br />"; //"pop";
|
||||
//alert (f[0].obj.style.backgroundColor);
|
||||
} else alert ("Cant find frame for "+name);
|
||||
}
|
||||
})(this, name);
|
||||
return nf;
|
||||
}
|
||||
this.update_all = function() {
|
||||
for (var col in this.frames) {
|
||||
for (var row in this.frames[col]) {
|
||||
this.frames[col][row].refresh ();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.del_frame = function (name) {
|
||||
var prev = undefined;
|
||||
if (!name && this.curframe) {
|
||||
name = this.curframe[0].name;
|
||||
}
|
||||
for (var col in this.frames) {
|
||||
for (var row in this.frames[col]) {
|
||||
var x = this.frames[col][row];
|
||||
if (x.name==name) {
|
||||
if (x != this.curframe[0])
|
||||
return;
|
||||
if (this.curframe[0] != this.oldframe[0])
|
||||
return;
|
||||
if (this.frames[col].length>1) {
|
||||
// remove row
|
||||
var a = this.frames[col].splice (row).slice (1);
|
||||
for (var i = 0;i<a.length;i++)
|
||||
this.frames[col].push (a[i]);
|
||||
} else {
|
||||
// remove column
|
||||
var a = this.frames.splice (col).slice (1);
|
||||
for (var i = 0; i<a.length; i++)
|
||||
this.frames.push (a[i]);
|
||||
}
|
||||
obj.removeChild (x.obj);
|
||||
if (!prev) {
|
||||
for (var col in this.frames) {
|
||||
for (var row in this.frames[col]) {
|
||||
prev = this.frames[col][row]
|
||||
break;
|
||||
}
|
||||
}
|
||||
// select next frame
|
||||
}
|
||||
this.select_frame (prev);
|
||||
//this.tile ();
|
||||
return x;
|
||||
}
|
||||
prev = x.name;
|
||||
}
|
||||
}
|
||||
this.tile ();
|
||||
}
|
||||
this.run = function () {
|
||||
this.update_size ();
|
||||
obj.style.position = 'absolute';
|
||||
obj.style.top = 0;
|
||||
obj.style.left = 0;
|
||||
obj.style.width = w;
|
||||
obj.style.height = h;
|
||||
obj.style.backgroundColor = '#202020';
|
||||
this.tile ();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user