radare2/shlr/www/p/main.js
2017-03-19 02:29:55 +01:00

1 line
8.6 KiB
JavaScript

function scroll_to_element(e){if(void 0!==e&&null!==e){var n=Math.max(0,e.documentOffsetTop()-window.innerHeight/2);$("#center_panel").scrollTo(n,{axis:"y"}),r2ui._dis.scroll_offset=n}}function store_scroll_offset(){r2ui._dis.scroll_offset=$("#center_panel").scrollTop()}function scroll_to_last_offset(){null!==r2ui._dis.scroll_offset&&$("#center_panel").scrollTo(r2ui._dis.scroll_offset,{axis:"y"})}function load_binary_details(){r2.cmdj("isj",function(e){render_symbols(e)}),r2.cmdj("aflj",function(e){render_functions(e)}),r2.cmdj("iij",function(e){render_imports(e)}),r2.cmdj("irj",function(e){render_relocs(e)}),r2.cmdj("fs *;fj",function(e){render_flags(e)}),r2.cmd("i",function(e){$("#information").html("<pre>"+e+"</pre>")}),r2.cmdj("iSj",function(e){render_sections(e)}),render_history()}function update_binary_details(){r2.cmdj("isj",function(e){render_symbols(e)}),r2.cmdj("aflj",function(e){render_functions(e)}),r2.cmdj("iij",function(e){render_imports(e)}),r2.cmdj("irj",function(e){render_relocs(e)}),r2.cmdj("fs *;fj",function(e){render_flags(e)}),render_history()}function render_functions(e){var n=null;r2.cmdj("iij",function(e){n=e});var t=[];for(var r in e){var o=e[r];if(void 0!==o.name){var s=!1;for(var i in n)o.offset===n[i].plt&&(s=!0);if(s)continue;var l={offset:o.offset,label:"<span class='flag function addr addr_0x"+o.offset.toString(16)+"'>"+o.name+"</span>",children:[{label:"offset: 0x"+o.offset.toString(16)},{label:"size: "+o.size}]};if(o.callrefs.length>0){var a={label:"xrefs:",children:[]};for(var d in o.callrefs)a.children[a.children.length]="<span class='xref addr addr_0x"+o.callrefs[d].addr.toString(16)+"'>0x"+o.callrefs[d].addr.toString(16)+"</span> ("+("C"==o.callrefs[d].type?"call":"jump")+")";l.children[l.children.length]=a}t[t.length]=l}}t=t.sort(function(e,n){return e.offset-n.offset}),$("#functions").tree({data:[],selectable:!1,slide:!1,useContextMenu:!1,autoEscape:!1}),$("#functions").tree("loadData",t),$("#functions_label").html("Functions <span class='right_label'>"+t.length+"</span>")}function render_imports(e){var n=[];for(var t in e){var r=e[t];if(void 0!==r.name){var o={label:"<span class='flag import addr addr_0x"+r.plt.toString(16)+"'>"+r.name+"</span>",children:[{label:"plt: 0x"+r.plt.toString(16)},{label:"ord: "+t}]};n[n.length]=o}}$("#imports").tree({data:[],selectable:!1,slide:!1,useContextMenu:!1,autoEscape:!1}),$("#imports").tree("loadData",n),$("#imports_label").html("Imports <span class='right_label'>"+n.length+"</span>")}function render_symbols(e){var n=[];for(var t in e){var r=e[t],o={offset:r.addr,label:"<span class='flag symbol addr addr_0x"+r.addr.toString(16)+"'>"+r.name+"</span>",children:[{label:"offset: 0x"+r.addr.toString(16)},{label:"size: "+r.size}]};n[n.length]=o}n=n.sort(function(e,n){return e.offset-n.offset}),$("#symbols").tree({data:n,selectable:!1,slide:!1,useContextMenu:!1,autoEscape:!1}),$("#symbols_label").html("Symbols <span class='right_label'>"+n.length+"</span>")}function render_relocs(e){var n=[];for(var t in e){var r=e[t],o={offset:r.vaddr,label:"<span class='flag reloc addr addr_0x"+r.vaddr.toString(16)+"'>"+r.name+"</span>",children:[{label:"offset: 0x"+r.vaddr.toString(16)},{label:"type: "+r.type}]};n[n.length]=o}n=n.sort(function(e,n){return e.offset-n.offset}),$("#relocs").tree({data:[],selectable:!1,slide:!1,useContextMenu:!1,autoEscape:!1}),$("#relocs").tree("loadData",n),$("#relocs_label").html("Relocs <span class='right_label'>"+n.length+"</span>")}function render_flags(e){var n=[];for(var t in e){var r=e[t],o={offset:r.offset,label:"<span class='flag addr addr_0x"+r.offset.toString(16)+"'>"+r.name+"</span>",children:[{label:"offset: 0x"+r.offset.toString(16)},{label:"size: "+r.size}]};n[n.length]=o}n=n.sort(function(e,n){return e.offset-n.offset}),$("#flags").tree({data:[],selectable:!1,slide:!1,useContextMenu:!1,autoEscape:!1}),$("#flags").tree("loadData",n),$("#flags_label").html("Flags <span class='right_label'>"+n.length+"</span>")}function render_sections(e){var n=[];for(var t in e){var r=e[t],o={offset:r.paddr,label:"0x"+r.addr.toString(16)+": "+r.name,children:[{label:"vaddr: 0x"+r.vaddr.toString(16)},{label:"paddr: 0x"+r.paddr.toString(16)},{label:"flags: "+r.flags},{label:"size: "+r.size},{label:"vsize: "+r.vsize}]};n[n.length]=o}n=n.sort(function(e,n){return e.offset-n.offset}),$("#sections").tree({data:[],selectable:!1,slide:!1,useContextMenu:!1}),$("#sections").tree("loadData",n),$("#sections_label").html("Sections <span class='right_label'>"+n.length+"</span>")}function render_history(){var e="<div>";for(var n in r2ui.history)if(n>r2ui.history_idx-8&&n<r2ui.history_idx+3){var t=r2.get_flag_names(r2ui.history[n]);t=t.length>0?t[0]:r2ui.history[n],e+=n==r2ui.history_idx-1?" &gt; <span class='history history_idx addr addr_"+r2ui.history[n]+" history_idx_"+n+"'>"+t+"</span>":" &gt; <span class='history addr addr_"+r2ui.history[n]+" history_idx_"+n+"'>"+t+"</span>"}e+="</div>",$("#history").html(e)}var myLayout;$(document).ready(function(){r2.cmd("e scr.html=false"),$("#main_panel").tabs({select:function(e,n){n.tab.innerHTML.indexOf("Entropy")>-1?r2ui._ent.render():n.tab.innerHTML.indexOf("Strings")>-1?r2ui._str.render():n.tab.innerHTML.indexOf("Types")>-1?r2ui._typ.render():n.tab.innerHTML.indexOf("Settings")>-1?r2ui._set.render():n.tab.innerHTML.indexOf("Projects")>-1?r2ui._prj.render():n.tab.innerHTML.indexOf("Hex")>-1?r2ui._hex.render():n.tab.innerHTML.indexOf("Logs")>-1&&r2ui._log.render()},activate:function(e,n){n.newTab[0].innerHTML.indexOf("Disas")>-1&&r2ui._dis.render()}}),myLayout=$("body").layout({west__size:200,east__size:200,south__size:200,north__resizable:!1,center__onresize:function(){"graph"==r2ui._dis.display&&r2ui._dis.minimap&&update_minimap()},west__onresize:$.layout.callbacks.resizePaneAccordions,east__onresize:$.layout.callbacks.resizePaneAccordions}),$("#accordion1").accordion({heightStyle:"fill"}),$("#accordion2").accordion({heightStyle:"fill"}),r2.update_flags(),r2.analAll(),r2.load_mmap(),r2ui.load_colors(),r2.load_settings(),load_binary_details();var disasm_panel=new DisasmPanel,hex_panel=new HexPanel,entropy_panel=new EntropyPanel,strings_panel=new StringsPanel,types_panel=new TypesPanel,settings_panel=new SettingsPanel,projects_panel=new ProjectsPanel,logs_panel=new LogsPanel;r2ui._ent=entropy_panel,r2ui._dis=disasm_panel,r2ui._str=strings_panel,r2ui._typ=types_panel,r2ui._set=settings_panel,r2ui._hex=hex_panel,r2ui._prj=projects_panel,r2ui._log=logs_panel,r2ui.ra={},r2ui.mp={},r2ui.ra.getIndex=function(){},r2ui.ra.setIndex=function(){},r2ui.mp.openPage=function(){};var console_history=[],console_history_idx=0;$("#command").keypress(function(inEvent){var key=inEvent.keyCode||inEvent.charCode||inEvent.which||0;if(13===key){var cmd=inEvent.target.value.trim(),reloadUI=""==cmd;if(console_history[console_history.length]=cmd,console_history_idx+=1,""!=cmd)if("r2"==r2ui.console_lang)r2.cmd(inColor(cmd),function(e){var n=$("#cmd_output").text();$("#cmd_output").html(n+"\n> "+cmd+"\n"+e),$("#cmd_output").scrollTo($("#cmd_output")[0].scrollHeight)}),0===cmd.indexOf("s ")&&r2ui.history_push(r2ui._dis.selected_offset);else if("js"==r2ui.console_lang){x=eval(cmd);var old_value=$("#cmd_output").text();$("#cmd_output").html(old_value+"\n> "+cmd+"\n"+x),$("#cmd_output").scrollTo($("#cmd_output")[0].scrollHeight)}inEvent.target.value="",reloadUI&&"r2"==r2ui.console_lang&&(r2.load_settings(),r2ui.load_colors(),update_binary_details(),r2ui.seek("$$",!1),scroll_to_element(r2ui._dis.selected))}}),$("input").bind("keydown",function(e){"38"!=e.keyCode&&"40"!=e.keyCode||e.preventDefault()}),$("#command").keydown(function(e){var n=e.keyCode||e.charCode||e.which||0;40===n&&(console_history_idx++,console_history_idx>console_history.length-1&&(console_history_idx=console_history.length),e.target.value=void 0===console_history[console_history_idx]?"":console_history[console_history_idx]),38===n&&(console_history_idx--,console_history_idx<0&&(console_history_idx=0),e.target.value=void 0===console_history[console_history_idx]?"":console_history[console_history_idx])}),$("#console_panel").contextmenu({menu:[{title:"clear buffer<kbd></kbd>",cmd:"clearbuffer"},{title:"switch r2/JS<kbd>s</kbd>",cmd:"switchlang"}],preventSelect:!0,taphold:!0,preventContextMenuForPopup:!0,show:!1,select:function(e,n){switch($(document).contextmenu("close"),n.cmd){case"clearbuffer":$("#cmd_output").html("");break;case"switchlang":r2ui.toggle_console_lang()}}}),r2.cmdj("Pnj",function(e){null!==e&&$("#pnotes").html(atob(e))}),$("#pnotes").donetyping(function(){r2.cmd("Pnj "+btoa($("#pnotes").val())),r2.cmd("Po",function(e){""===e&&alert("Notes won't be persited until a project is opened. Use Project's tab or 'Ps name' to save current project")})}),$("#switch_button").click(function(){do_switchview()}),r2ui._dis.render()});