diff --git a/shlr/www/p/r2.js b/shlr/www/p/r2.js new file mode 100644 index 0000000000..849cd0fe7e --- /dev/null +++ b/shlr/www/p/r2.js @@ -0,0 +1,593 @@ +/* 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 + " " + space + "\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, "function:"); + x = x.replace (/;(\s+)/g, ";"); + x = x.replace (/;(.*)/g, "// $1"); + x = x.replace (/(bl|goto|call)/g, "call"); + x = x.replace (/(jmp|bne|beq|js|jnz|jae|jge|jbe|jg|je|jl|jz|jb|ja|jne)/g, "$1"); + x = x.replace (/(dword|qword|word|byte|movzx|movsxd|cmovz|mov\ |lea\ )/g, "$1"); + x = x.replace (/(hlt|leave|iretd|retn|ret)/g, "$1"); + x = x.replace (/(add|sbb|sub|mul|div|shl|shr|and|not|xor|inc|dec|sar|sal)/g, "$1"); + x = x.replace (/(push|pop)/g, "$1"); + x = x.replace (/(test|cmp)/g, "$1"); + x = x.replace (/(outsd|out|string|invalid|int |int3|trap|main|in)/g, "$1"); + x = x.replace (/nop/g, "nop"); + x = x.replace (/(sym|fcn|str|imp|loc)\.([^:<(\\\/ \|)\->]+)/g, "$1.$2"); + } + x = x.replace (/0x([a-zA-Z0-9]+)/g, "0x$1"); + // 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; +} + diff --git a/shlr/www/t/app.js b/shlr/www/t/app.js new file mode 100644 index 0000000000..04459ae88c --- /dev/null +++ b/shlr/www/t/app.js @@ -0,0 +1,3 @@ +function _(e){return document.getElementById(e)}var Tiled=function(e){var r=document.getElementById(e);this.curframe=void 0,this.frames=[];var t=20,i=3,s=0;this.update_size=function(e,r){i=e||window.innerWidth,s=r||window.innerHeight},this.max_width=function(e){var r=this.curframe[1];for(var r in this.frames)for(var t in this.frames[r])this.frames[r][t].mw=!1;this.curframe[0].mw=e},this.max_height=function(e){if(this.curframe){var r=this.curframe[1];for(var t in this.frames[r]){var i=this.frames[r][t];i.mh=!1}this.curframe[0].mh=e}},this.ctr2=0,this.tile=function(){function e(e,r){if(e.frames[r])for(var t in e.frames[r]){var i=e.frames[r][t];if(i&&(i.mh||i.selected))return!0}return!1}if(this.maximize&&this.curframe){var r=t,a=0,h=i,f=s-r,n=this.curframe[0];return n.obj.style.position="absolute",n.obj.style.top=r,n.obj.style.left=a,n.obj.style.zIndex=99999+this.ctr2++,n.obj.style.width=h,n.obj.style.height=f,void(n.update&&n.update(n.obj))}var m=this.frames.length,a=0,c=!0;for(var l in this.frames){var o=this.frames[l].length,r=t,m=this.frames.length,u=e(this,l),h=i/m,f=(s-t)/o;this.curframe&&c&&this.frames.length>1&&(h=l==this.curframe[1]?i/2:i/2/(m-1));for(var d in this.frames[l]){var n=this.frames[l][d];if(u&&this.frames[l].length>1)if(n.selected)f=1.7*((s-t)/o);else{var v=1.7*(s-t)/o;f=(s-v)/(o-1)}else f=(s-t)/o;f=0|f,n.obj.style.position="absolute",n.obj.style.top=r,n.obj.style.left=a,n.obj.style.width=h,0==d&&(f-=22),n.obj.style.height=f,n.update&&n.update(n.obj),r+=f}a+=h}},this.num=0,this.defname=function(e){return e=e||"noname",this.num++,e+"_"+this.num},this.unselect_frames=function(){for(var e in this.frames)for(var r in this.frames[e]){var t=this.frames[e][r];t.selected=!1}},this.move_frame=function(e){if(this.curframe){var r=this.curframe[1];switch(e){case"up":break;case"down":break;case"right":if(r==this.frames.length-1)return!1;alert("moveright Col is "+r);var t,i,s;t=this.frames[r],i=this.frames.splice(r),s=i.splice(1).slice(1),alert("AAAA "+this.frames.length),alert("C "+i.length),alert("D "+s.length),t&&this.frames.push(t),i.length>0&&(alert("SET COL "+this.frames.length),this.frames.push(i));for(var a=0;a0){t--;var i=this.frames[r][t];this.select_frame(i.name),this.curframe=[i,r,t],this.run()}break;case"down":var r=+this.curframe[1],t=+this.curframe[2];if(t<=this.frames[r].length){t++;var i=this.frames[r][t];i&&(this.select_frame(i.name),this.curframe=[i,r,t],this.run())}break;case"left":var r=+this.curframe[1];if(r>0){r--;var i=this.frames[r][0];i&&(this.select_frame(i.name),this.curframe=[i,r,0],this.run())}break;case"right":var r=+this.curframe[1];if(r>=this.frames.length-1&&(r=-1),r1)for(var h=this.frames[i].splice(s).slice(1),f=0;ft?(t++,r(a)):(o=!0,e()))},iteration:function(){return t-1},"break":function(){o=!0,e()}};return a.next(),a}function dump(n){var r="";for(var e in n)r+=e+"\n";alert(r)}function objtostr(n){var r="";for(var e in n)r+=e+": "+n[e]+",\n";return r}function Ajax(n,r,e,t){if("undefined"==typeof XMLHttpRequest)return!1;var o=new XMLHttpRequest;return o?(o.open(n,r,!1),o.setRequestHeader("Accept","text/plain"),o.setRequestHeader("Accept","text/html"),o.setRequestHeader("Content-Type","application/x-ww-form-urlencoded; charset=UTF-8"),o.onreadystatechange=function(){200==o.status?t&&t(o.responseText):console.error("ajax "+o.status)},o.send(e),!0):!1}function _internal_cmd(n,r){if("undefined"!=typeof r2cmd&&(hascmd=r2cmd),hascmd){if("undefined"==typeof r2plugin)return hascmd(n,r);r(r2cmd(n))}else Ajax("GET",r2.root+"/cmd/"+encodeURI(n),"",function(n){r&&r(n)})}var r2={},backward=!1,next_curoff=0,next_lastoff=0,prev_curoff=0,prev_lastoff=0,hascmd=!1;"undefined"!=typeof module&&(module.exports=function(n){return hascmd="function"==typeof n?n:n.cmd,r2}),r2.project_name="",r2.plugin=function(){console.error("r2.plugin is not available in this environment")};try{r2plugin&&(r2.plugin=r2plugin)}catch(e){}r2.root="",r2.analAll=function(){r2.cmd("aa",function(){})},r2.analOp=function(n,r){r2.cmd("aoj 1 @ "+n,function(n){try{r(JSON.parse(n)[0])}catch(e){console.error(e),r(n)}})},r2.varMap=[],r2.argMap=[],r2.assemble=function(n,r,e){var t=n?"@"+n:"";r2.cmd('"pa '+r+'"'+t,e)},r2.disassemble=function(n,r,e){var t=n?"@"+n:"",o="pi @b:"+r+t;r2.cmd(o,e)},r2.get_hexdump=function(n,r,e){r2.cmd("px "+r+"@"+n,e)},r2.get_disasm=function(n,r,e){r2.cmd("pD "+r+"@"+n,e)},r2.get_disasm_before=function(n,r,e){var t=[];r2.cmd("pdj -"+r+"@"+n,function(n){t=JSON.parse(n)}),e(t)},r2.get_disasm_after=function(n,r,e){var t=[];r2.cmd("pdj "+r+"@"+n,function(n){t=JSON.parse(n)}),e(t)},r2.get_disasm_before_after=function(n,r,e,t){var o=[],a=[];r2.cmd("pdj "+r+" @"+n,function(n){o=JSON.parse(n)}),r2.cmd("pdj "+e+"@"+n,function(n){a=JSON.parse(n)});var c=o.concat(a);t(c)},r2.Config=function(n,r,e){return"function"!=typeof r&&r?r2.cmd("e "+n+"="+r,e):r2.cmd("e "+n,e||r),r2},r2.sections={},r2.load_mmap=function(){r2.cmdj("iSj",function(n){void 0!==n&&null!==n&&(r2.sections=n)})},r2.get_address_type=function(n){var r=parseInt(n,16);for(var e in r2.sections)if(r>=r2.sections[e].addr&&r-1?"instruction":"memory";return""},r2.settings={},r2.load_settings=function(){r2.cmd("e asm.arch",function(n){r2.settings["asm.arch"]=n.trim()}),r2.cmd("e asm.bits",function(n){r2.settings["asm.bits"]=n.trim()}),r2.cmd("e asm.bytes",function(n){r2.settings["asm.bytes"]=toBoolean(n.trim())}),r2.cmd("e asm.flags",function(n){r2.settings["asm.flags"]=toBoolean(n.trim())}),r2.cmd("e asm.offset",function(n){r2.settings["asm.offset"]=toBoolean(n.trim())}),r2.cmd("e asm.lines",function(n){r2.settings["asm.lines"]=toBoolean(n.trim())}),r2.cmd("e asm.xrefs",function(n){r2.settings["asm.xrefs"]=toBoolean(n.trim())}),r2.cmd("e asm.cmtright",function(n){r2.settings["asm.cmtright"]=toBoolean(n.trim())}),r2.cmd("e asm.pseudo",function(n){r2.settings["asm.pseudo"]=toBoolean(n.trim())})},r2.flags={},r2.update_flags=function(){r2.cmd("fs *;fj",function(n){var r=JSON.parse(n);if(void 0!==r&&null!==r){r2.flags={};for(var e in r){var t="0x"+r[e].offset.toString(16);if(t=address_canonicalize(t),t in r2.flags){var o=r2.flags[t];o[o.length]={name:r[e].name,size:r[e].size},r2.flags[t]=o}else r2.flags[t]=[{name:r[e].name,size:r[e].size}]}}})},r2.get_flag_address=function(n){for(var r in r2.flags)for(var e in r2.flags[r])if(n==r2.flags[r][e].name)return r;return null},r2.get_flag_names=function(n){var r=[];for(var e in r2.flags[n])r[r.length]=r2.flags[n][e].name;return r},r2.set_flag_space=function(n,r){r2.cmd("fs "+n,r)},r2.get_flags=function(n){r2.cmd("fj",function(r){n(r?JSON.parse(r):[])})},r2.get_opcodes=function(n,r,e){r2.cmd("pdj @"+n+"!"+r,function(n){e(JSON.parse(n))})},r2.get_bytes=function(n,r,e){r2.cmd("pcj @"+n+"!"+r,function(n){e(JSON.parse(n))})},r2.asm_config={},r2.store_asm_config=function(){config={},r2.cmd("e",function(n){conf=n.split("\n");for(var r in conf){var e=conf[r].split(" ");3==e.length&&0==e[0].trim().indexOf("asm.")&&(config[e[0].trim()]=e[2].trim())}r2.asm_config=config})},r2.restore_asm_config=function(){cmd="";for(var n in r2.asm_config)cmd+="e "+n+"="+r2.asm_config[n]+";";r2.cmd(cmd,function(){})},r2.get_info=function(n){r2.cmd("ij",function(r){n(JSON.parse(r))})},r2.bin_relocs=function(n){r2.cmd("irj",function(r){n(JSON.parse(r))})},r2.bin_imports=function(n){r2.cmd("iij",function(r){n(JSON.parse(r))})},r2.bin_symbols=function(n){r2.cmd("isj",function(r){n(JSON.parse(r))})},r2.bin_sections=function(n){r2.cmd("iSj",function(r){n(JSON.parse(r))})},r2.cmds=function(n,r){function e(){void 0!=t&&0!=n.length&&(t=n[0],n=n.splice(1),r2.cmd(t,e),r&&r())}if(0!=n.length){var t=n[0];n=n.splice(1),r2.cmd(t,e)}},r2.cmd=function(n,r){if(Array.isArray(n)){var e=[],t=0;asyncLoop(n.length,function(r){_internal_cmd(n[t],function(n){t=r.iteration(),e[t]=n.replace(/\n$/,""),t++,r.next()})},function(){r(e)})}else _internal_cmd(n,r)},r2.cmdj=function(n,r){r2.cmd(n,function(n){try{r(JSON.parse(n))}catch(e){r(null)}})},r2.alive=function(n){r2.cmd("b",function(r){var e=!1;r&&r.length()>0&&(e=!0),n&&n(r)})},r2.getTextLogger=function(n){return"object"!=typeof n&&(n={}),n.last=0,n.events={},n.interval=null,r2.cmd("Tl",function(r){n.last=+r}),n.load=function(r){r2.cmd('"Tj '+(n.last+1)+'"',function(n){r&&r(JSON.parse(n))})},n.clear=function(n){r2.cmd("T-",n)},n.send=function(n,r){r2.cmd('"T '+n+'"',r)},n.refresh=function(r){n.load(function(e){for(var t=0;tn.last&&(n.last=o[0])}r&&r()})},n.autorefresh=function(r){function e(){return n.refresh(function(){}),"Logs"===r2ui.selected_panel?setTimeout(e,1e3*r):console.log("Not in logs :("),!0}return r?void(n.interval=setTimeout(e,1e3*r)):void(n.interval&&n.interval.stop())},n.on=function(r,e){return n.events[r]=e,n},n},r2.filter_asm=function(n,r){function e(n){return"p"==n[0]&&"d"==n[1]?!0:-1!=n.indexOf(";pd")}var t=backward?prev_curoff:next_curoff,o=backward?prev_lastoff:next_lastoff,a=n.split(/\n/g);r2.cmd("s",function(n){t=n});for(var c=a.length-1;c>0;c--){var i=a[c].match(/0x([a-fA-F0-9]+)/);if(i&&i.length>0){o=i[0].replace(/:/g,"");break}}if("afl"==r){for(var s="",c=0;c"+u+"\n")}n=s}}else if("i"==r[0]&&r[1]){for(var s="",c=0;cfunction:"),n=n.replace(/;(\s+)/g,";"),n=n.replace(/;(.*)/g,"// $1"),n=n.replace(/(bl|goto|call)/g,"call"),n=n.replace(/(jmp|bne|beq|js|jnz|jae|jge|jbe|jg|je|jl|jz|jb|ja|jne)/g,"$1"),n=n.replace(/(dword|qword|word|byte|movzx|movsxd|cmovz|mov\ |lea\ )/g,"$1"),n=n.replace(/(hlt|leave|iretd|retn|ret)/g,"$1"),n=n.replace(/(add|sbb|sub|mul|div|shl|shr|and|not|xor|inc|dec|sar|sal)/g,"$1"),n=n.replace(/(push|pop)/g,"$1"),n=n.replace(/(test|cmp)/g,"$1"),n=n.replace(/(outsd|out|string|invalid|int |int3|trap|main|in)/g,"$1"),n=n.replace(/nop/g,"nop"),n=n.replace(/(sym|fcn|str|imp|loc)\.([^:<(\\\/ \|)\->]+)/g,"$1.$2")),n=n.replace(/0x([a-zA-Z0-9]+)/g,"0x$1"),backward?(prev_curoff=t,prev_lastoff=o):(next_curoff=t,next_lastoff=o,prev_curoff||(prev_curoff=next_curoff)),n}; +function findPos(e){var n=curtop=0;if(e.offsetParent)for(n=e.offsetLeft,curtop=e.offsetTop;e=e.offsetParent;)n+=e.offsetLeft,curtop+=e.offsetTop;return[n,curtop]}window.onload=function(){function e(){function e(e){setTimeout(function(){document.getElementById("randomcolors").onclick=function(){r2.cmd("ecr",function(){s.update_all()})}},1);const n="This is the new and experimental tiled webui for r2\n\nPress 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";return"

Help

"+n+"
"}var n=s.defname("help");s.new_frame(n,e(n),function(e){var t=_(n+"_help");if(t){var o=(t.style.offsetTop,findPos(t));t.style.height=e.offsetHeight-o[1]+20,t.style.width=e.style.width-o[0]}})}function n(){function e(e){return'
"}var n=s.defname("console");s.new_frame(n,e(n),function(e){var t=_(n+"_console");if(t){var o=(t.style.offsetTop,findPos(t));t.style.height=e.offsetHeight-o[1]+20,t.style.width=e.style.width-o[0]}},a,function(){var e=_(n+"_input");e.onkeyup=function(t){13==t.keyCode&&r2.cmd(e.value,function(t){_(n+"_output").innerHTML="
"+t+"
",e.value=""})}})}function t(){function e(){return"

Debug

"}var n="debug",t=s.defname(n),o=function(){r2.cmdj("drj",function(e){r2.cmd("pxQ@rsp",function(t){r2.cmd("dbt",function(o){r2.cmd("dm",function(i){var r=function(e){return document.getElementById(e)};setTimeout(function(){function e(){s.update_all()}r("dbg-step").onclick=function(){r2.cmd("ds;.dr*",e())},r("dbg-over").onclick=function(){r2.cmd("dso;.dr*",e())},r("dbg-skip").onclick=function(){r2.cmd("dss;.dr*",e())},r("dbg-cont").onclick=function(){r2.cmd("dc;.dr*",e())},r("dbg-until").onclick=function(){var n=prompt("Until");n&&r2.cmd("dcu "+n+";.dr*",e())}},1);var f="";f+=" [step]",f+=" [over]",f+=" [skip]",f+=" [cont]",f+=" [until]",f+="
Registers",f+="";for(var c in e){var d="0x"+(+e[c]).toString(16);f+=""}f+="
"+c+""+d+"
",f+="
Backtrace:
"+o+"
",f+="
Stack:
"+t+"
",f+="
Maps:
"+i+"
",document.getElementById(n+"_frame").innerHTML=f})})})})};s.new_frame(t,e(t),function(e){var n=_(t+"_frame");if(n){var o=(n.style.offsetTop,findPos(n));n.style.height=e.offsetHeight-o[1]+20,n.style.width=e.style.width-o[0]}},a,function(){try{o()}catch(e){}})}function o(){function e(e){return setTimeout(function(){r2.cmd("fs *;f",function(n){document.getElementById(e+"_flags").innerHTML="
"+n+"
"})},1),"

Flags

"}var n=s.defname("flags");s.new_frame(n,e(n),function(e){var t=_(n+"_flags");if(t){var o=(t.style.offsetTop,findPos(t));t.style.height=e.offsetHeight-o[1]+20,t.style.width=e.style.width-o[0]}},a)}function i(){var e=s.defname("hexdump"),n="
";s.new_frame(e,n,function(n){var t=_(e+"code");if(t){var o=(t.style.offsetTop,findPos(t));t.style.height=n.offsetHeight-o[1]+20,t.style.width=n.style.width-o[0]}},a,function(n,t){function o(){var t=n.offset||0;r2.cmd("px 1024 @ "+t,function(t){var o=e+"_hexdump_hex_prev",i=e+"_hexdump_hex_next",r=e+"_hexdump_hex_goto";_(e+"_hexdump").innerHTML="
[PREV][GOTO][NEXT]
"+t+"
";var f=document.getElementById(o);f.onclick=function(){n.offset=0|n.offset,n.offset-=512,n.refresh()};var f=document.getElementById(i);f.onclick=function(){n.offset=0|n.offset,n.offset+=512,n.refresh()};var f=document.getElementById(r);f.onclick=function(){var e=prompt("Goto");e&&r2.cmd("?v "+e,function(e){n.offset=0|+e,n.refresh()})}})}n=t,n.offset?o(n):r2.cmd("?v entry0",function(e){n.offset=+e,o(n)})})}function r(){var e=s.defname("notes"),n="
";s.new_frame(e,n,function(n){var t=_(e+"_notes");if(t){var o=(t.style.offsetTop,findPos(t));t.style.height=n.offsetHeight-o[1]+20,t.style.width=n.style.width-o[0]}},a,function(){})}function f(){var e=s.defname("settings"),n="
";s.new_frame(e,n,function(n){var t=_(e+"_settings");if(t){var o=(t.style.offsetTop,findPos(t));t.style.height="100%",t.style.width=n.style.width-o[0]}},a,function(){r2.cmd("e??",function(n){_(e+"_settings").innerHTML="
"+n+"
"})})}function c(){var e=s.defname("disas"),n="
";s.new_frame(e,n,function(n){var t=_(e+"_code");if(t){var o=(t.style.offsetTop,findPos(t));t.style.height="100%",t.style.width=n.style.width-o[0]}},a,function(n,t){n=n.curframe[0],n=t;var o=n.offset||"entry0";r2.cmd("pd 200 @ "+o,function(t){var o=e+"_code_prev",i=e+"_code_next",r=e+"_code_goto";_(e+"_code").innerHTML="
[PREV][GOTO][NEXT]
"+t+"
";var f=document.getElementById(o);f.onclick=function(){n.offset=0|n.offset,n.offset-=512,n.refresh()};var f=document.getElementById(i);f.onclick=function(){n.offset=0|n.offset,n.offset+=512,n.refresh()};var f=document.getElementById(r);f.onclick=function(){var e=prompt("Goto");e&&r2.cmd("?v "+e,function(t){t&&(n.offset=e,n.refresh())})}})})}function d(e){u++,a=e,s.new_frame("window_"+u,"",e),s.run(),s.update=function(){r2.cmd(s.cmd,function(e){_(s.key).innerHTML="
"+e+"
"})},_("cmd_"+u).onclick=function(){s.key="div_"+u,s.cmd=prompt(),s.update()}}var a="right",s=new Tiled("canvas"),u=0;_("settings").onclick=function(){f()},_("refresh").onclick=function(){s.update_all()},_("maximize").onclick=function(){s.maximize=!s.maximize,s.run()},_("open-hex").onclick=function(){i()},_("open-dis").onclick=function(){c()},_("open-fla").onclick=function(){o()},_("open-dbg").onclick=function(){t()},_("open-hlp").onclick=function(){e()},_("open-con").onclick=function(){n()},_("open-not").onclick=function(){r()},_("add-column").onclick=function(){d("right")},_("add-row").onclick=function(){u++,a="bottom",s.new_frame("window_"+u,"","bottom"),s.run(),s.update=function(){r2.cmd(s.cmd,function(e){_(s.key).innerHTML="
"+e+"
"})},_("cmd_"+u).onclick=function(){s.key="div_"+u,s.cmd=prompt(),s.update()}},i(),c(),s.run(),window.onresize=function(){s.run()},document.t=s,_("body").onkeyup=function(e){var n=String.fromCharCode(e.keyCode);if(e.altKey)switch(n=e.keyCode){case 67:s.curframe&&(s.oldframe=s.curframe),s.del_frame(),s.run();break;case 189:case 173:d("bottom");break;case 220:case 49:d("right");break;case 190:s.maximize=!s.maximize,s.run();break;case 72:s.other_frame("left");break;case 74:s.other_frame("down");break;case 75:s.other_frame("up");break;case 76:s.other_frame("right");break;case 88:case"x":i();break;case 68:case"d":c();break;case"i":r2.cmd("pi 2",function(e){alert(e)});break;case"!":r2.cmd(prompt("Command to execute"),function(e){alert(e)})}}}; \ No newline at end of file diff --git a/shlr/www/t/index.html b/shlr/www/t/index.html index 883fb83839..ea34c53d83 100644 --- a/shlr/www/t/index.html +++ b/shlr/www/t/index.html @@ -1 +1,35 @@ -r2pm -i www-t + + + + + + + +
+
+[#] +[@] +[^] +[|] +[-] +  +[n] +[c] +[d] +[x] +[f] +[D] +[?] + +
+ + +
+ + + diff --git a/shlr/www/t/rlogo.png b/shlr/www/t/rlogo.png new file mode 100644 index 0000000000..95d380f9e5 Binary files /dev/null and b/shlr/www/t/rlogo.png differ diff --git a/shlr/www/t/stylesheet.css b/shlr/www/t/stylesheet.css new file mode 100644 index 0000000000..1f5c340c66 --- /dev/null +++ b/shlr/www/t/stylesheet.css @@ -0,0 +1 @@ +img,p,textarea{border:0}.canvas,iframe{width:100%}p{margin:0}textarea{background-color:#203040;color:#fff;padding:5px}.frame,iframe{border:1px solid #000}a{color:#a06000}.link,a:hover{color:#fff}body,html{overflow:hidden}.frame{font-family:monospace;height:100%;background-color:#506070;color:#e0e0e0}.frame_title,input{color:#fff;font-family:monospace}.frame_title{background-color:#000;padding:0;top:0;height:20px;width:100%}.frame_body{background-color:#304050;overflow:scroll;height:100%}.canvas{padding-top:3px;height:100%;background-color:#00f;border-top:5px;font-size:12px;font-family:monospace}input{border:1px solid #000;text-align:right;background-color:rgba(0,0,0,.3);overflow:hidden}h2{padding:0;color:#000;border:0;margin:10px}.minibut{text-decoration:none;font-weight:700;font-family:monospace;color:#a0a0f0} \ No newline at end of file