From 5bd79506ac76ba991292998e366df339ff4efc2c Mon Sep 17 00:00:00 2001 From: xarkes Date: Mon, 2 Oct 2017 00:25:33 +0200 Subject: [PATCH] Removed old web graph view --- src/html/graph/index.html | 33 - src/html/graph/lib/css/graph.css | 365 - src/html/graph/lib/css/graph_dark.css | 51 - src/html/graph/lib/css/graph_light.css | 50 - src/html/graph/lib/css/joint.min.css | 9 - src/html/graph/lib/js/disasm.js | 1045 -- src/html/graph/lib/js/graph_panel.js | 426 - src/html/graph/lib/js/joint.js | 14 - .../lib/js/joint.layout.DirectedGraph.js | 9 - src/html/graph/lib/js/jquery-1.9.0.js | 9555 ----------------- src/html/graph/lib/js/r2.js | 591 - src/html/graph/lib/js/r2ui.js | 199 - src/resources.qrc | 14 - src/widgets/MemoryWidget.cpp | 96 +- src/widgets/MemoryWidget.h | 10 +- src/widgets/MemoryWidget.ui | 386 +- 16 files changed, 163 insertions(+), 12690 deletions(-) delete mode 100644 src/html/graph/index.html delete mode 100644 src/html/graph/lib/css/graph.css delete mode 100644 src/html/graph/lib/css/graph_dark.css delete mode 100644 src/html/graph/lib/css/graph_light.css delete mode 100644 src/html/graph/lib/css/joint.min.css delete mode 100644 src/html/graph/lib/js/disasm.js delete mode 100644 src/html/graph/lib/js/graph_panel.js delete mode 100644 src/html/graph/lib/js/joint.js delete mode 100644 src/html/graph/lib/js/joint.layout.DirectedGraph.js delete mode 100644 src/html/graph/lib/js/jquery-1.9.0.js delete mode 100644 src/html/graph/lib/js/r2.js delete mode 100644 src/html/graph/lib/js/r2ui.js diff --git a/src/html/graph/index.html b/src/html/graph/index.html deleted file mode 100644 index 77d503f3..00000000 --- a/src/html/graph/index.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - radare2 - - - - - - - - - - - - - - - - -
-
-
-
-
- - - diff --git a/src/html/graph/lib/css/graph.css b/src/html/graph/lib/css/graph.css deleted file mode 100644 index 516c839f..00000000 --- a/src/html/graph/lib/css/graph.css +++ /dev/null @@ -1,365 +0,0 @@ - - -/* Basic Block graph */ -.bbcanvas { float: left; } - -.flatcanvas { float: left; } - -.insaddr { - min-width: 7em; - display: inline-block; -} - -#outergbox { - position: absolute; - height: 100%; - width: 100%; -} - -.instruction { - font-family: monospace; - white-space: nowrap; -} - -.instructiondesc { - display: inline-block; -} - -.data { - text-align: right; - min-width: 18px; - padding-top: 0px; - padding-bottom: 0px; -} - -.instructionbox { - position: absolute; -} - -#gbox { - position: relative; - /*margin: 10px;*/ -} - -.bytes { - display: inline-block; - width: 170px; -} - -input:focus {outline: none; } - -.hidden {display:none;} - -.lines {margin-left: 100px;} - -.basicblock { - border: 1px solid; - padding: 5px; - position: absolute; - pointer-events: none; - -webkit-user-select: none; - box-sizing: border-box; - z-index: 2; -} - -.basicblock .instruction, -.basicblock input { - pointer-events: auto; -} - -#canvas { - position: relative; - display: inline-block; - background: transparent; - width:100%; - height:100%; - margin:10px; -} - -#canvas svg, -#minimap svg { - background: transparent; -} - -#minimap svg .link, -#canvas svg .link { - pointer-events: none; -} - -#minimap svg .connection { - stroke-width: 5; -} - -#minimap { - position:absolute; - width:200px; - height:200px; - z-index: +10; - opacity: 0.8; - filter: alpha(opacity=80); /* For IE8 and earlier */ -} - -#minimap .basicblock { - display: none; -} - -#canvas #minimap_area { - display: none; - z-index: 0; -} - -#canvas #minimap_area svg { - stroke: transparent; -} - -#minimap_area { - border: 1px solid black; - position:absolute; - background: black; - opacity: 0.2; - filter: alpha(opacity=20); /* For IE8 and earlier */ -} - -#main_panel { - overflow: auto; -} - -.right_label { - float: right; -} - -/* CUSTOMIZE/OVERRIDE THE DEFAULT CSS */ -/* remove padding and scrolling from elements that contain an Accordion OR a content-div */ -.ui-layout-center , /* has content-div */ -.ui-layout-west , /* has Accordion */ -.ui-layout-east , /* has content-div ... */ -.ui-layout-east .ui-layout-content { /* content-div has Accordion */ - padding: 0; - overflow: hidden; -} - -.ui-layout-center P.ui-layout-content { - line-height: 1.4em; - margin: 0; /* remove top/bottom margins from

used as content-div */ -} - -.ui-layout-resizer { - background-color: #373737 !important; - -} - -.ui-layout-east h4 { /* Footer in East-pane */ - font-size: 0.9em; - font-weight: normal; - /*border-width: 1px 0 0;*/ -} - -.ui-layout-pane { - border: none !important; -} - -.ui-layout-toggler { - background-color: #797979 !important; - border: none !important; -} - -.ui-layout-center { - /* remove default padding on center-pane so tabs widget fills it */ - padding: 0; -} - -.ui-helper-clearfix:before, -.ui-helper-clearfix:after { - content: ""; - display: table; -} -.ui-helper-clearfix:after { - clear: both; -} -.ui-helper-clearfix { - min-height: 0; - support: IE7 -} - -.ui-tabs .ui-tabs-nav { - font-size: 0.8em; - background: #c0c0c0; - border: 1px solid #797979; - color: rgb(89, 89, 89); - border-width: 0 0 1px; - padding: 7px 10px; - height: 17px; - margin: 0; -} - -.ui-tabs .ui-tabs-nav li { - list-style: none; - float: left; - position: relative; - top: 0; - margin: 1px .2em 0 0; - border-bottom: 0; - padding: 0px 25px; - white-space: nowrap; - text-decoration: none; - background-color: #c0c0c0; - height: 20px; - -} - -.ui-tabs .ui-tabs-nav li a { - float: left; - padding: 0px; - text-decoration: none; - outline: none; - font-weight: normal; -} - -.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { - color: #555555; - text-decoration: none; - outline: none; -} - -.ui-widget-header { - border: 1px solid #aaaaaa; - background: #cccccc; - font-weight: bold; -} - -.ui-tabs-nav li.ui-tabs-active a { - /*color: rgb(107, 105, 9);*/ - color:white; - font-weight: normal; -} - -.ui-tabs-nav li.ui-tabs-active { - background-color: rgb(127,127,127); - border-bottom: 10px solid rgb(127,127,127); - border-top: 10px solid rgb(127,127,127); - height: 14px; - margin-top: -10px; -} - -.ui-tabs .ui-tabs-panel { - padding: 1em 0em; -} - -.entry { - font-size: 0.8em; - padding: 0px 0px 0px 10px; - -} - -.jqtree-tree { - margin-top: 5px; -} - -.jqtree-tree .jqtree-element { - margin: -0.2em 0; - font-family: monospace; - cursor: auto; - padding: 0px 5px; -} - -.jqtree-tree .jqtree-folder { - margin-left: 5px; -} -.jqtree-tree .jqtree-title { - color: rgb(127,127,127); - margin-left: 1em; -} -.jqtree-tree .jqtree-toggler { - color: rgb(127,127,127); - font-size: 0.8em; - cursor: pointer; -} - -.jqtree-tree .autohighlighti { - background-color: rgb(127, 127, 127); - color: rgb(20,20,20); -} - -.history.autohighlighti { - background-color: transparent; -} - -.hex .autohighlighti { - background-color: yellow; - color: rgb(20,20,20); -} - -.history_idx { - background-color: rgb(127,127,127) !important; - border-bottom: 6px solid rgb(127,127,127); - border-top: 4px solid rgb(127,127,127); - border-right: 3px solid rgb(127,127,127); - border-left: 3px solid rgb(127,127,127); - height: 14px; - margin-top: -10px; - color: white; -} - -h3, h4 { /* Headers & Footer in Center & East panes */ - font-size: 0.8em; - background: #c0c0c0; - border: 1px solid #797979; - color: rgb(89, 89, 89); - border-width: 0 0 1px; - padding: 7px 10px; - margin: 0; - cursor: pointer; - font-weight: normal; -} - -p { - margin: 0 !important; -} - -#center_panel { - padding: 0px; - margin: 0px; -} - - -#command { - background: #c0c0c0; - border: 1px solid #797979; - font-family: Geneva, Arial, Helvetica, sans-serif; - /*font-size: 0.4em;*/ - padding: 5px; - width: 99%; - margin: 2px; -} - -#cmd_output { - /*font-size: 0.8em;*/ - color: rgb(127,127,127); - margin-top: 0px; -} - -#cmd_output > p { - padding: 0px; - margin: 0px; -} - -#history { - background: #c0c0c0; - padding: 3px 5px; - /*font-size: 0.4em;*/ -} - -#information { - margin-left: 10px; -} - -#cmd_input { - position: relative; -} -#cmd_input > label { - position: absolute; - top: 5px; - bottom: 0; - right: 30px; - width: 0%; -} diff --git a/src/html/graph/lib/css/graph_dark.css b/src/html/graph/lib/css/graph_dark.css deleted file mode 100644 index 9225aaf2..00000000 --- a/src/html/graph/lib/css/graph_dark.css +++ /dev/null @@ -1,51 +0,0 @@ -.ec_fline {color: rgb(0,127,127);} -.ec_help {color: rgb(0,127,127);} -.ec_args {color: rgb(0,127,127);} -.ec_label {color: rgb(0,127,127);} -.ec_flow {color: rgb(0,127,127);} -.ec_prompt {color: rgb(0,127,127);} -.ec_input {color: rgb(0,127,127);} -.ec_btext {color: rgb(0,127,127);} -.ec_swi {color: rgb(0,127,127);} -.ec_comment {color: rgb(0,127,127);} -.ec_fname {color: rgb(127,0,0);} -.ec_flag {color: rgb(0,127,127);} -.ec_offset {color: #0661FF;} -.ec_other {color: rgb(127,127,127);} /* byte color bu default */ -.ec_b0x00 {color: rgb(0,127,0);} -.ec_b0x7f {color: rgb(0,127,127);} -.ec_b0xff {color: rgb(127,0,0);} -.ec_math {color: rgb(127,127,0);} -.ec_bin {color: rgb(127,127,0);} -.ec_push {color: rgb(127,0,127);} -.ec_pop {color: rgb(255,0,255);} -.ec_jmp {color: rgb(0,127,0);} -.ec_cjmp {color: rgb(0,127,0);} -.ec_call {color: #EC0000;} -.ec_nop {color: rgb(0,0,127);} -.ec_ret {color: rgb(127,0,0);} -.ec_trap {color: rgb(255,0,0);} -.ec_invalid {color: rgb(255,0,0);} -.ec_cmp {color: rgb(0,127,127);} -.ec_reg {color: rgb(0,127,127);} /* (also applies to qword, brackets, etc) */ -.ec_creg {color: rgb(0,127,127);} -.ec_mov {color: #5C5C5C;} -.ec_num {color: #7B03B0;} - -.ec_gui_cflow {color: rgb(255,255,0);} -.ec_gui_dataoffset {color: rgb(127,127,0);} -.ec_gui_background {background-color: rgb(255,255,255); } -.ec_gui_alt_background {background-color: rgb(64, 64, 64); } -.ec_gui_border {border-color: rgb(0, 0, 0); } - -.autohighlight { background-color: #8AFF77 !important; } -.autohighlighti { background-color: #8AFF77; } - -#minimap { - background: #E9EAEA; - border: 1px solid black; -} -#minimap_area { - border: 1px solid black; - background: black; -} diff --git a/src/html/graph/lib/css/graph_light.css b/src/html/graph/lib/css/graph_light.css deleted file mode 100644 index 7723046e..00000000 --- a/src/html/graph/lib/css/graph_light.css +++ /dev/null @@ -1,50 +0,0 @@ -.ec_fline {color: rgb(0,127,127);} -.ec_help {color: rgb(0,127,127);} -.ec_args {color: rgb(0,127,127);} -.ec_label {color: rgb(0,127,127);} -.ec_flow {color: rgb(0,127,127);} -.ec_prompt {color: rgb(0,127,127);} -.ec_input {color: rgb(0,127,127);} -.ec_btext {color: rgb(0,127,127);} -.ec_swi {color: rgb(0,127,127);} -.ec_comment {color: rgb(0,127,127);} -.ec_fname {color: rgb(127,0,0);} -.ec_flag {color: rgb(0,127,127);} -.ec_offset {color: #0661FF;} -.ec_other {color: rgb(127,127,127);} /* byte color bu default */ -.ec_b0x00 {color: rgb(0,127,0);} -.ec_b0x7f {color: rgb(0,127,127);} -.ec_b0xff {color: rgb(127,0,0);} -.ec_math {color: rgb(127,127,0);} -.ec_bin {color: rgb(127,127,0);} -.ec_push {color: rgb(127,0,127);} -.ec_pop {color: rgb(255,0,255);} -.ec_jmp {color: rgb(0,127,0);} -.ec_cjmp {color: rgb(0,127,0);} -.ec_call {color: #EC0000;} -.ec_nop {color: rgb(0,0,127);} -.ec_ret {color: rgb(127,0,0);} -.ec_trap {color: rgb(255,0,0);} -.ec_invalid {color: rgb(255,0,0);} -.ec_cmp {color: rgb(0,127,127);} -.ec_reg {color: rgb(0,127,127);} /* (also applies to qword, brackets, etc) */ -.ec_creg {color: rgb(0,127,127);} -.ec_mov {color: #5C5C5C;} -.ec_num {color: #7B03B0;} - -.ec_gui_cflow {color: rgb(255,255,0);} -.ec_gui_dataoffset {color: rgb(127,127,0);} -.ec_gui_background {background-color: rgb(255,255,255); } -.ec_gui_alt_background {background-color: rgb(234, 249, 255); } -.ec_gui_border {border-color: rgb(0, 0, 0); } - -.autohighlight { background-color: #8AFF77 !important; } -.autohighlighti { background-color: #8AFF77; } - -#minimap { - background: #A4C5D2; -} -#minimap_area { - border: 1px solid black; - background: black; -} diff --git a/src/html/graph/lib/css/joint.min.css b/src/html/graph/lib/css/joint.min.css deleted file mode 100644 index 5337b69a..00000000 --- a/src/html/graph/lib/css/joint.min.css +++ /dev/null @@ -1,9 +0,0 @@ -/*! JointJS v0.9.2 - JavaScript diagramming library 2014-09-17 - - -This Source Code Form is subject to the terms of the Mozilla Public -License, v. 2.0. If a copy of the MPL was not distributed with this -file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -.viewport{-webkit-user-select:none;-moz-user-select:none;user-select:none}[magnet=true]:not(.element){cursor:crosshair}[magnet=true]:not(.element):hover{opacity:.7}.element{cursor:move}.element *{vector-effect:non-scaling-stroke;-moz-user-select:none;user-drag:none}.connection-wrap{fill:none;stroke:#000;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;opacity:0;cursor:move}.connection-wrap:hover{opacity:.4;stroke-opacity:.4}.connection{fill:none;stroke-linejoin:round}.marker-source,.marker-target{vector-effect:non-scaling-stroke}.marker-vertices{opacity:0;cursor:move}.marker-arrowheads{opacity:0;cursor:move;cursor:-webkit-grab;cursor:-moz-grab}.link-tools{opacity:0;cursor:pointer}.link-tools .tool-options{display:none}.link-tools .tool-remove circle{fill:red}.link-tools .tool-remove path{fill:#fff}.link:hover .marker-vertices,.link:hover .marker-arrowheads,.link:hover .link-tools{opacity:1}.marker-vertex{fill:#1ABC9C}.marker-vertex:hover{fill:#34495E;stroke:none}.marker-arrowhead{fill:#1ABC9C}.marker-arrowhead:hover{fill:#F39C12;stroke:none}.marker-vertex-remove{cursor:pointer;opacity:.1;fill:#fff}.marker-vertex-group:hover .marker-vertex-remove{opacity:1}.marker-vertex-remove-area{opacity:.1;cursor:pointer}.marker-vertex-group:hover .marker-vertex-remove-area{opacity:1}.highlighted{opacity:.7}text.highlighted{fill:red}@media screen and (-webkit-min-device-pixel-ratio:0){.highlighted{outline:2px solid red;opacity:initial}}.element .fobj body{background-color:transparent;margin:0}.element .fobj div{text-align:center;vertical-align:middle;display:table-cell;padding:0 5px} \ No newline at end of file diff --git a/src/html/graph/lib/js/disasm.js b/src/html/graph/lib/js/disasm.js deleted file mode 100644 index c49f4350..00000000 --- a/src/html/graph/lib/js/disasm.js +++ /dev/null @@ -1,1045 +0,0 @@ -// Workaround for Chrome 48 getTransformToElement removal -// https://github.com/clientIO/joint/issues/203 -SVGElement.prototype.getTransformToElement = SVGElement.prototype.getTransformToElement || function(toElement) { - return toElement.getScreenCTM().inverse().multiply(this.getScreenCTM()); -}; - -function init_panel(theme) { - // Load r2 settings (TODO: Do we need this?) - r2.load_settings(); - - // Initialize and render graph - r2ui.graph_panel = new GraphPanel(); - if (r2ui.graph_panel != null) { - r2ui.graph_panel.seek(location.hash.substring(1)); - r2ui.graph_panel.init_handlers(); - if (theme == "dark") r2ui.graph_panel.render("dark"); - else r2ui.graph_panel.render("light"); - } -} - - -// Basic Block Graph -var BBGraph = function () { - this.vertices = {}; - this.edges = []; - this.elements = []; - this.links = []; - this.fcn_offset = 0; - - joint.shapes.html = {}; - joint.shapes.html.Element = joint.shapes.basic.Rect.extend({ - defaults: joint.util.deepSupplement({ - type: 'html.Element', - attrs: { - rect: { stroke: r2ui.colors[".ec_gui_border"], fill: r2ui.colors[".ec_gui_alt_background"] } - } - }, joint.shapes.basic.Rect.prototype.defaults) - }); - - joint.shapes.html.ElementView = joint.dia.ElementView.extend({ - initialize: function() { - _.bindAll(this, 'updateBox'); - joint.dia.ElementView.prototype.initialize.apply(this, arguments); - this.$box = $(_.template(this.model.get('html'))()); - this.$box.find('input').on('mousedown click', function(evt) { evt.stopPropagation(); }); - this.model.on('change', this.updateBox, this); - this.updateBox(); - }, - render: function() { - joint.dia.ElementView.prototype.render.apply(this, arguments); - this.paper.$el.prepend(this.$box); - this.updateBox(); - return this; - }, - updateBox: function(event) { - // move the html mask when moving the svg rect - var bbox = this.model.getBBox(); - this.$box.css({ width: bbox.width + 2, height: bbox.height, left: bbox.x - 1, top: bbox.y + 7}); - } - }); -}; - -BBGraph.prototype.addVertex = function(addr, vlen, dom) { - if (this.vertices[addr] === undefined) { - this.vertices[addr] = {}; - this.vertices[addr].parents = []; - this.vertices[addr].children = []; - if (vlen === undefined) { - this.vertices[addr].len = 1; - dom = document.createElement('div'); - dom.id = "bb_" + addr; - dom.className = "basicblock eny0-selectable ec_gui_background ec_gui_border"; - dom.innerHTML = "

0x" + addr.toString(16) + "
"; - this.vertices[addr].rendered = dom; - } - } - if (vlen !== undefined) { - this.vertices[addr].len = vlen; - this.vertices[addr].rendered = dom; - } -}; - -BBGraph.prototype.addEdge = function(v1, v2, color) { - this.addVertex(v1); - this.addVertex(v2); - this.edges.push({'from': v1, 'to': v2, 'color': color}); - this.vertices[v1].children.push(v2); - this.vertices[v2].parents.push(v1); -}; - -BBGraph.prototype.makeElement = function(addr, width, height, html) { - this.elements.push(new joint.shapes.html.Element({ - id: String(addr), - size: { width: width, height: height }, - html: html - })); -}; - -BBGraph.prototype.makeLink = function(v1, v2, color) { - this.links.push(new joint.dia.Link({ - source: { id: String(v1) }, - target: { id: String(v2) }, - attrs: { - '.marker-target': { - d: 'M 4 0 L 0 2 L 4 4 z', - fill: color, - stroke: color - }, - '.connection': { - 'stroke-width': 1, - stroke: color - } - }, - smooth: true - })); -}; - -BBGraph.prototype.render = function() { - var name = Object.keys(this.vertices).toString(); - var outergbox = document.createElement('div'); - outergbox.id = 'outergbox'; - var bbcanvas = document.getElementById("canvas"); - var gbox = document.createElement('div'); - gbox.id = 'gbox'; - gbox.className = name; - outergbox.appendChild(gbox); - bbcanvas.appendChild(outergbox); - for (var addr in this.vertices) { - var r = this.vertices[addr].rendered; - if (r !== undefined) { - gbox.appendChild(r); - this.makeElement(addr, r.offsetWidth, r.offsetHeight, r.outerHTML); - } - } - for (var j = 0; j < this.edges.length; j++) { - this.makeLink(this.edges[j].from, this.edges[j].to, this.edges[j].color); - } - $("#outergbox").remove(); - - this.makeElement("minimap_area", 1, 1, "
"); - - var items = this.elements.concat(this.links); - var width = $("#center_panel").width(); - var graph = new joint.dia.Graph(); - var paper = new joint.dia.Paper({ - el: $('#canvas'), - gridSize: 1, - width: 10000, - height: 10000, - model: graph, - }); - - var minimap_width = 200; - var minimap_heigh = 200; - $('#minimap').html(""); - $('#minimap').html(""); - var minimap = new joint.dia.Paper({ - el: $('#minimap'), - gridSize: 1, - width: minimap_width, - height: minimap_heigh, - model: graph - }); - - graph.resetCells(items); - - // render graph - joint.layout.DirectedGraph.layout(graph); - - r2ui.graph_panel.graph = graph; - - // reposition graph - reposition_graph(); - - // remove html mask in minimap since its not scaled - $("#minimap .basicblock").remove(); - - // make minimap rect transparent - graph.getCell("minimap_area").attr({rect: { stroke: "transparent"}}); - - var svg_width = $('#canvas svg')[0].getBBox().width; - var svg_height = $('#canvas svg')[0].getBBox().height; - // update paper size with these values - paper.setDimensions(svg_width + 5000, svg_height + 5000); - var ws = Math.ceil(svg_width/minimap_width); - var hs = Math.ceil(svg_height/minimap_heigh); - var scale = 1/Math.max(ws, hs); - var delta = 0; - if (hs > ws) delta = (minimap_width/2) - svg_width*scale/2; - minimap.scale(scale); - minimap.setOrigin(delta,0); - minimap.$el.css('pointer-events', 'none'); - $("#minimap").css("left", $("#main_panel").width() - minimap_width); - $("#minimap").css("top", $("#center_panel").position().top - 40); - document.addEventListener('scroll', function (event) { - if (event.target.id === 'main_panel') update_minimap(); - }, true /*Capture event*/); - - paper.on( "cell:pointerup", function( cellview, evt, x, y) { - var model = cellview.model; - var bbox = model.attributes.position; - var id = String(model.prop("id")); - if (model !== undefined && id !== "minimap_area") { - var color = null; - var bb = r2ui.get_fcn_BB(r2ui.current_fcn_offset, id); - if (bb !== undefined && bb !== null) { - if (bb.x != String(bbox.x) || bb.y != String(bbox.y)) { - bb.x = bbox.x; - bb.y = bbox.y; - r2ui.update_fcn_BB(r2ui.current_fcn_offset, id, bb); - } - } else if (bb !== undefined && bb !== null) { - r2ui.update_fcn_BB(r2ui.current_fcn_offset, id, {x:bbox.x, y:bbox.y}); - } - } - }); - - if (r2ui.graph_panel.minimap) { - update_minimap(); - // $("#minimap_area").draggable({ - // containment: "parent", - // stop: function( event, ui ) { - // var delta_x = ui.position.left/scale; - // var delta_y = ui.position.top/scale; - // if (delta_x < 0) delta_x = 0; - // if (delta_y < 0) delta_y = 0; - // if ($("#radareApp_mp").length) { - // //$("#main_panel").scrollTo({ top:delta_y, left:delta_x - delta/scale } ); - // console.log(1); - // } else { - // //$('#center_panel').scrollTo({ top:delta_y, left:delta_x - delta/scale } ); - // console.log('debug:'); - // console.log(delta_y, delta_x, scale); - // console.log($('#center_panel')); - // } - // } - // }); - } else { - $("#minimap").hide(); - } - -}; - -// Functions - -function toggle_minimap() { - if (r2ui.graph_panel.minimap) { - r2ui.graph_panel.minimap = false; - r2ui.seek(r2ui.graph_panel.selected_offset, false); - $('#minimap').hide(); - } else { - r2ui.graph_panel.minimap = true; - r2ui.seek(r2ui.graph_panel.selected_offset, false); - $('#minimap').show(); - } -} - -function update_minimap() { - if (r2ui.graph_panel.minimap && $('#canvas svg').length) { - var minimap_width = 200; - var minimap_height = 200; - var svg_width = $('#canvas svg')[0].getBBox().width; - var svg_height = $('#canvas svg')[0].getBBox().height; - var ws = Math.ceil(svg_width/minimap_width); - var hs = Math.ceil(svg_height/minimap_height); - var scale = 1/Math.max(ws, hs); - var delta = 0; - if (hs > ws) delta = (minimap_width/2) - svg_width*scale/2; - - // Update MiniMap area position - var el = $('#main_panel'); - var mma_width = el.width()*scale; - var mma_height = el.height()*scale - delta; - var top_offset = el.scrollTop()*scale - var left_offset = el.scrollLeft()*scale + delta; - if (mma_width > minimap_width - left_offset) mma_width = minimap_width - left_offset; - if (mma_height > minimap_height - top_offset) mma_height = minimap_height - top_offset; - if (left_offset > minimap_width) left_offset = minimap_width - if (top_offset > minimap_height) top_offset = minimap_height; - $("#minimap_area").width(mma_width); - $("#minimap_area").height(mma_height); - $("#minimap_area").css("top", top_offset); - $("#minimap_area").css("left", left_offset); - - // Update MiniMap position - el = $('#center_panel'); - $("#minimap").css("left", el.scrollLeft() + el.width() - minimap_width); - $("#minimap").css("top", el.scrollTop()); - } -} - -function reposition_graph() { - var bbs = r2ui.graph_panel.graph.getElements(); - var blocks = r2ui.get_fcn_BBs(r2ui.current_fcn_offset); - var bb_offsets = Object.keys(blocks); - for (var i in bbs) { - found = false; - for (var j in bb_offsets) { - var offset = String(bb_offsets[j]); - var bb = blocks[offset]; - if (bbs[i].prop("id") === offset) { - found = true; - if (bb.x !== "null" && bb.y !== "null") { - bbs[i].translate(bb.x - bbs[i].prop("position").x, bb.y - bbs[i].prop("position").y); - } - var color = bb.color; - if (color !== null && color !== undefined) bbs[i].attr('rect/fill', color); - } - } - } -} - -var flag = 0; - -function render_graph(x) { - var obj; - try { - obj = JSON.parse(x.replace(/\\l/g,'\\n')); - } catch (e) { - console.log("Cannot parse JSON data"); - return false - } - if (obj[0] === undefined) return false; - if (obj[0].blocks === undefined) return false; - var bbgraph = new BBGraph(); - r2ui.current_fcn_offset = obj[0].blocks[0].ops[0].offset; - - for (var bn = 0; bn < obj[0].blocks.length; bn++) { - var bb = obj[0].blocks[bn]; - var addr = bb.offset; - if (bb.trace !== undefined) { - var bbinfo = r2ui.get_fcn_BB(r2ui.current_fcn_offset, addr); - if (bbinfo !== undefined) { - if (bbinfo.color !== "red") - bbinfo.color = "#7592DF"; - } else { - bbinfo = {x:null, y:null, color:"#7592DF"}; - } - r2ui.update_fcn_BB(r2ui.current_fcn_offset, addr, bbinfo); - } - if (bb.length === 0) continue; - - var cnt = bb.ops.length; - var idump = ""; - for (var i in bb.ops) { - var ins = bb.ops[i]; - // ins.offset = "0x" + ins.offset.toString(16); - if (ins.comment === undefined || ins.comment === null) ins.comment = ""; - else { - ins.comment = atob(ins.comment); - } - idump += html_for_instruction(ins); - } - var dom = document.createElement('div'); - dom.id = "bb_" + addr; - dom.className = "basicblock eny0-selectable ec_gui_background ec_gui_border"; - dom.innerHTML = idump; - bbgraph.addVertex(addr, cnt, dom); - if (bb.fail > 0) { - bbgraph.addEdge(addr, bb.fail, "red"); - if (bb.jump > 0) { - bbgraph.addEdge(addr, bb.jump, "green"); - } - } else if (bb.jump > 0) { - bbgraph.addEdge(addr, bb.jump, "blue"); - } - } - bbgraph.render(); - - var element = $("#canvas svg g .element"); - element.on("mousedown", function(event){ - flag = 0; - }); - element.on("mousemove", function(event){ - flag = 1; - }); - element.on("mouseup", function(event){ - if(flag === 0){ - var id = event.target.parentNode.parentNode.parentNode.getAttribute("model-id"); - if (id !== "minimap_area") { - var color = null; - var bb = r2ui.get_fcn_BB(r2ui.current_fcn_offset, id); - if (bb !== undefined && bb !== null) { - if (bb.color === "red") bb.color = r2ui.colors['.ec_gui_alt_background']; - else bb.color = "red"; - } else { - bb = {x:"null", y:"null", color:"red"}; - } - r2ui.update_fcn_BB(r2ui.current_fcn_offset, id, bb); - reposition_graph(); - } - } - }); - $(".addr").css("-webkit-user-select", "text"); - return true; -} - -function render_instructions(instructions) { - var outergbox = document.createElement('div'); - outergbox.id = 'outergbox'; - var flatcanvas = document.getElementById("canvas"); - flatcanvas.innerHTML = ""; - var gbox = document.createElement('div'); - gbox.id = 'gbox'; - gbox.className = 'ec_gui_background'; - outergbox.appendChild(gbox); - flatcanvas.appendChild(outergbox); - - var flatcanvas_rect = getOffsetRect(flatcanvas); - var asm_lines = (r2.settings["asm.lines"]); - var asm_offset = (r2.settings["asm.offset"]); - - var accumulated_heigth = flatcanvas_rect.top; - var lines = []; - var targets = {}; - var first_address = instructions[0].offset; - var last_address = instructions[instructions.length - 1].offset; - for (var i in instructions) { - var ins = instructions[i]; - - if ((ins.type == "jmp" || ins.type == "cjmp") && ins.jump !== undefined && ins.jump !== null) { - var line = {}; - line.from = ins.offset; - if (last_address < ins.jump) { - line.to_end = false; - line.to = last_address; - } else if (first_address > ins.jump) { - line.to_end = false; - line.to = first_address; - } else { - line.to_end = true; - line.to = ins.jump; - } - if (ins.type == "jmp") { - line.color = r2ui.colors[".ec_flow"]; - line.dashed = false; - } else if (ins.type == "cjmp") { - line.color = r2ui.colors[".ec_gui_cflow"]; - line.dashed = true; - } - line.to_start = true; - lines[lines.length] = line; - if (targets[line.to] === undefined) { - targets[line.to] = 0; - } - } - - // ins.offset = "0x" + ins.offset.toString(16); - if (ins.comment === undefined || ins.comment === null) ins.comment = ""; - else { - try { - ins.comment = atob(ins.comment); - } catch(e) { - console.log(ins.comment); - } - } - var dom = document.createElement('div'); - if (asm_lines) dom.className = "instructionbox eny0-selectable lines"; - else dom.className = "instructionbox"; - dom.style.top = accumulated_heigth + "px"; - dom.innerHTML = html_for_instruction(ins); - - gbox.appendChild(dom); - var instruction_rect = getOffsetRect(dom); - var instruction_heigth = instruction_rect.bottom - instruction_rect.top; - accumulated_heigth += instruction_heigth; - } - - - if (asm_lines) { - var canvas = document.createElement("canvas"); - canvas.width = 500; - canvas.height = accumulated_heigth; - canvas.id = "linecanvas"; - canvas.setAttribute("tabindex", "1"); - canvas.setAttribute("style", "outline: none;"); - gbox.appendChild(canvas); - var ctx = canvas.getContext("2d"); - if (!ctx.setLineDash) { - // For browsers that dont support dashed lines - ctx.setLineDash = function () {}; - } - var num_targets = countProperties(targets); - var num_assigned_paths = 0; - var lines_width = 100; - for (var l in lines) { - line = lines[l]; - var from = "0x" + line.from.toString(16); - var to = "0x" + line.to.toString(16); - - if (targets[line.to] === 0) { - // No path assigned for target, assigning a new one - targets[line.to] = (num_targets - num_assigned_paths - 1)*(90/(num_targets+1)); - num_assigned_paths += 1; - } - var from_element = get_element_by_address(from); - var to_element = get_element_by_address(to); - - if (from_element !== null && from_element !== undefined && to_element !== undefined && to_element !== null) { - var x = targets[line.to]; - var from_rect = getOffsetRect(from_element); - var y0 = (from_rect.top + from_rect.bottom) / 2; - var to_rect = getOffsetRect(to_element); - var y1 = (to_rect.top + to_rect.bottom) / 2; - if (line.to == instructions[0].offset) { - y1 = 0; - } - - // main line - ctx.beginPath(); - ctx.moveTo(x, y0); - ctx.lineTo(x, y1); - ctx.strokeStyle = line.color; - if (line.dashed) ctx.setLineDash([2,3]); - ctx.stroke(); - - if (line.to_start) { - // horizontal line at start - ctx.beginPath(); - ctx.moveTo(x, y0); - ctx.lineTo(lines_width - 5, y0); - ctx.strokeStyle = line.color; - if (line.dashed) ctx.setLineDash([2,3]); - ctx.stroke(); - - // circle - ctx.beginPath(); - ctx.arc(lines_width - 5 - 2, y0, 2, 0, 2 * Math.PI, false); - ctx.fillStyle = line.color; - ctx.fill(); - } - - if (line.to_end) { - // horizontal line at end - ctx.beginPath(); - ctx.moveTo(x, y1); - ctx.lineTo(lines_width - 5, y1); - ctx.strokeStyle = line.color; - if (line.dashed) ctx.setLineDash([2,3]); - ctx.stroke(); - - // arrow - ctx.beginPath(); - ctx.moveTo(lines_width - 5, y1); - ctx.lineTo(lines_width - 10, y1-5); - ctx.lineTo(lines_width - 10, y1+5); - ctx.lineWidth = 1; - ctx.fillStyle = line.color; - ctx.fill(); - } - } - } - } - if (!asm_offset) { - var elements = document.getElementsByClassName("insaddr"); - for (var j in elements) { - if (elements[j].style) elements[j].style.display="none"; - } - } - $(".addr").css("-moz-user-select", "text"); - $(".addr").css("-webkit-user-select", "text"); -} - -function getOffsetRect(elem) { - var box = elem.getBoundingClientRect(); - var offset = $('#gbox').offset().top; - var top = box.top - offset; - var bottom = box.bottom - offset; - return {top: Math.round(top), bottom: Math.round(bottom)}; -} - -function countProperties(obj) { - var count = 0; - for(var prop in obj) { - if(obj.hasOwnProperty(prop)) { - ++count; - } - } - return count; -} - -function toBoolean(str) { - if (str === "true") return true; - else if (str === "false") return false; - else return undefined; -} - -function html_for_instruction(ins) { - var idump = '
'; - var offset = "0x" + ins.offset.toString(16); - var address = offset; - var asm_flags = (r2.settings["asm.flags"]); - var asm_bytes = (r2.settings["asm.bytes"]); - var asm_xrefs = (r2.settings["asm.xrefs"]); - var asm_cmtright = (r2.settings["asm.cmtright"]); - - if (ins.fcn_addr > 0 && offset === "0x"+ins.fcn_addr.toString(16)) { - - // Get Instruction info - var results; - var cmd = "afij " + offset; - r2.cmd(cmd, function(x){ - results = x.split("\n"); - }); - for (var i in results) { - if (results[i] !== "") { - try { - var info = JSON.parse(results[i]); - if (info !== null && info !== undefined && info.length > 0) - idump += '
(fcn) ' + info[0].name + '
'; - } catch (err) { - console.log("Error getting instruction information from afij command: " + err); - } - } - } - - // Get function variables - var vars_reg_based = []; - cmd = "afvrj " + offset; - r2.cmd(cmd, function(x){ - vars_reg_based = x.split("\n"); - }); - for (var i in vars_reg_based) { - if (vars_reg_based[i] !== "") { - try { - var vars = JSON.parse(vars_reg_based[i]); - var fvars = []; - for (var i in vars) { - var loc = vars[i].ref.base + (vars[i].ref.offset > 0? "+":"-") + "0x" + trimChar(vars[i].ref.offset.toString(16), '-'); - idump += '
; ' + vars[i].kind + " " + vars[i].type + " " + escapeHTML(vars[i].name) + " @ " + loc + '
'; - fvars[fvars.length] = {name: vars[i].name, id: address_canonicalize(offset) + "_" + loc}; - } - r2.varMap[ins.fcn_addr] = fvars; - } catch (err) { - console.log("Error getting variable information from afvj command: " + err); - } - } - } - - // Get function arguments - var args_merged = []; - var args_bp_based = []; - var args_sp_based = []; - cmd = "afvbj " + offset; - r2.cmd(cmd, function(x){ - args_bp_based = x.split("\n"); - }); - cmd = "afvsj " + offset; - r2.cmd(cmd, function(x){ - args_sp_based = x.split("\n"); - }); - args_merged = args_bp_based.concat(args_sp_based); - for (var i in args_merged) { - if (args_merged[i] !== "") { - try { - var args = JSON.parse(args_merged[i]); - var fargs = []; - for (var i in args) { - var loc = args[i].ref.base + (args[i].ref.offset > 0? "+":"-") + "0x" + trimChar(args[i].ref.offset.toString(16), '-'); - idump += '
; ' + args[i].kind + " " + args[i].type + " " + escapeHTML(args[i].name) + " @ " + loc + '
'; - fargs[fargs.length] = {name: args[i].name, id: address_canonicalize(offset) + "_" + loc}; - } - r2.argMap[ins.fcn_addr] = fargs; - } catch (err) { - console.log("Error getting argument information from afaj command: " + err); - } - } - } - } - if (asm_flags) { - var flags; - if (ins.flags !== undefined && ins.flags !== null) { - flags = ins.flags.join(";"); - } else { - flags = r2.get_flag_names(address_canonicalize(offset)).join(";"); - } - if (flags !== "" && flags !== undefined && flags !== null) idump += '
;-- ' + escapeHTML(flags) + ':
'; - } - if (ins.comment && !asm_cmtright) { - idump += '
; ' + escapeHTML(ins.comment) + '
'; - } - if (asm_xrefs) { - if (ins.xrefs !== undefined && ins.xrefs !== null && ins.xrefs.length > 0) { - var xrefs = ""; - for (var i in ins.xrefs) { - var xref = ins.xrefs[i]; - var name = ''; - var xrefoffset = "0x"+xref.addr.toString(16); - if (r2.get_flag_names(address_canonicalize(xrefoffset)).length > 0) name = ' (' + r2.get_flag_names(address_canonicalize(xrefoffset)).join(";") + ')'; - idump += '
; ' + xref.type.toUpperCase() + ' XREF from ' + - '' + xrefoffset + ' ' + name + '
'; - } - - } - } - - idump += '' + address + ' '; - - if (asm_bytes) { - if (ins.bytes !== undefined && ins.bytes !== null && ins.bytes !== "") { - var dorep = function(a) { - if (a=="00") return '00'; - if (a=="ff") return 'ff'; - if (a=="7f") return '7f'; - }; - var bytes = ins.bytes.replace(new RegExp("(00)|(ff)|(7f)", "g"), dorep); - idump += '' + bytes + ' '; - } - } - - var opcode = highlight_instruction(ins.opcode, true); - if ((r2.varMap[ins.fcn_addr] !== null && r2.varMap[ins.fcn_addr] !== undefined && r2.varMap[ins.fcn_addr].length > 0) || - (r2.argMap[ins.fcn_addr] !== null && r2.argMap[ins.fcn_addr] !== undefined && r2.argMap[ins.fcn_addr].length > 0)) { - for (var i in r2.varMap[ins.fcn_addr]) { - var var_name = r2.varMap[ins.fcn_addr][i].name; - var var_id = r2.varMap[ins.fcn_addr][i].id; - opcode = opcode.replace(" " + var_name + " ", " " + escapeHTML(var_name) + " "); - } - for (var i in r2.argMap[ins.fcn_addr]) { - var arg_name = r2.argMap[ins.fcn_addr][i]; - var arg_id = r2.argMap[ins.fcn_addr][i].id; - opcode = opcode.replace(" " + arg_name + " ", " " + escapeHTML(arg_name) + " "); - } - } - - if (ins.type !== undefined && ins.type !== null) { - if (contains(math, ins.type)) ins.type = "math"; - if (contains(bin, ins.type)) ins.type = "bin"; - if (ins.type == "ill") ins.type = "invalid"; - if (ins.type == "null") ins.type = "invalid"; - if (ins.type == "undefined") ins.type = "invalid"; - if (ins.type == "ujmp") ins.type = "jmp"; - if (ins.type == "upush") ins.type = "push"; - if (ins.type == "upop") ins.type = "pop"; - if (ins.type == "ucall") ins.type = "call"; - if (ins.type == "lea") ins.type = "mov"; - // Add default color if we failed to identify op type - if (!contains(known_types, ins.type)) ins.type = "other"; - idump += '
' + opcode + '
'; - } else { - idump += '
' + opcode + '
'; - } - if (ins.ptr_info) { - idump += '' + escapeHTML(ins.ptr_info) + ''; - } - - if (ins.comment && asm_cmtright) { - idump += ' ; ' + escapeHTML(ins.comment) + ''; - } - - if (ins.type == "ret") { - idump += "
 
"; - } - - idump += '
'; - return idump; -} - -var math = ["add", "sub", "mul", "imul", "div", "idiv", "neg", "adc", "sbb", "inc", "dec", ".byte"]; -var bin = ["xor", "and", "or", "not"]; -var regs = ["EAX", "ECX", "EDX", "EBX", "ESP", "EBP", "ESI", "EDI", "EIP", "RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI", "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15", "RIP"]; -var known_types = ["fline","help","args","label","flow","prompt","input","btext","swi","comment","fname","flag","offset","other","b0x00","b0x7f","b0xff","math","bin","push","pop","jmp","cjmp","call","nop","ret","trap","invalid","cmp","reg","creg","mov","num"]; - -function escapeHTML(text) { - var chr = { '"': '"', '&': '&', '<': '<', '>': '>' }; - var escaped = text? String(text).replace(/[\"&<>]/g, function (a) { return chr[a]; }): ""; - return escaped; -} - -function highlight_instruction(line, instruction) { - if (line === undefined) return "undefined"; - if (instruction === undefined) instruction = true; - var ret = escapeHTML(line); - - // highlight registers and addresses - var re = "(0x[0123456789abcdef]+)"; - // Map with register names as keys and HTML span representing the register as value - var reps = {}; - if (instruction) { - for (var i in regs) { - // Loop all the registers - var rep = '' + regs[i] +''; - reps[regs[i]] = rep; - rep = '' + regs[i].toLowerCase() + ''; - reps[regs[i].toLowerCase()] = rep; - } - for (i in reps) { - // Complete regexp with registers - re += "|(" + i + ")"; - } - } - function dorep(a) { - // If address found - if (a.substr(0, 2) == "0x") { - // Look for imports or functions - var syms = r2.get_flag_names(address_canonicalize(a)); - for (var i in syms) { - if (syms[i].indexOf("sym.imp.")) { - return "" + syms[i] + ""; - } - if (syms[i].indexOf("fcn.")) { - return "" + syms[i] + ""; - } - } - // Is it data address or code address - var cl = get_data_type(a); - if (cl === "") { - // Just an hex value, not an address - return "" + a + ""; - } else if (cl === "datainstruction") { - // An address representing data (memory) or code (instruction) - return "" + a + ""; - } else if (cl === "datamemory") { - // return "" + a + ""; - return "" + a + ""; - } - } else { - // Not an hex value, so a register - return reps[a]; - } - } - return ret.replace(new RegExp(re, "g"), dorep); -} - -function hex2(a) { - if (a === undefined) return "__"; - var ret = a.toString(16); - if (ret.length == 1) return "0" + ret; - return ret; -} - -function hex(a) { - if (a === undefined) { - return ""; - } else { - if (a < 0) a += 0x100000000; - return "0x"+a.toString(16); - } -} - -function get_data_type(v, more) { - var a = r2.get_address_type(v); - if (a === "") return ""; - else { - if (more !== undefined) { - return "data" + a + " addr addr_" + v; - } else { - return "data" + a; - } - } -} - -function fnum(a) { - return parseInt(a, 10); -} - -function get_address_from_class(t, type) { - if (type === undefined) type = "addr"; - var prefix = type+"_"; -if (!t) return undefined; - var l = t.className.split(" ").filter(function(x) { return x.substr(0,prefix.length) == type+"_"; }); - if (l.length != 1) return undefined; - return l[0].split("_")[1].split(" ")[0]; -} - -function rehighlight_iaddress(address, prefix) { - if (prefix === undefined) prefix = "addr"; - $('.autohighlighti').removeClass('autohighlighti'); - $('.' + prefix + '_' + address).addClass('autohighlighti'); - if (prefix === "addr") r2.cmd ("ss " + address, function () {}); -} - -function rehighlight_id(eid) { - $('.autohighlighti').removeClass('autohighlighti'); - $('#' + eid).addClass('autohighlighti'); -} - -function get_element_by_address(address) { - var elements = $(".insaddr.addr_" + address); - if (elements.length === 1) return elements[0]; - else return null; -} - -Element.prototype.documentOffsetTop = function () { - return this.offsetTop + ( this.offsetParent ? this.offsetParent.documentOffsetTop() : 0 ); -}; - -// function scroll_to_address(address) { -// var elements = $(".insaddr.addr_" + address); -// var top = elements[0].documentOffsetTop() - window.innerHeight / 2; -// top = Math.max(0,top); -// $("#main_panel").scrollTo({'top':top, 'left':0}); -// } - -// function has_scrollbar(divnode) { -// if(divnode.scrollHeight > divnode.clientHeight) return true; -// return false; -// } - -// function on_scroll(event) { -// if (!r2ui.graph_panel.scrolling) { -// var panel_disas = $("#main_panel").tabs("option", "active") === 0 ? true : false; -// event.preventDefault(); -// } -// } - -// function scroll_to_element(element) { -// if (element === undefined || element === null) return; -// var top = Math.max(0,element.documentOffsetTop() - ( window.innerHeight / 2 )); -// $('#center_panel').scrollTo(top, {axis: 'y'}); -// r2ui.graph_panel.scroll_offset = top; -// } -// -// function store_scroll_offset() { -// r2ui.graph_panel.scroll_offset = $('#center_panel').scrollTop(); -// } -// -// function scroll_to_last_offset() { -// if (r2ui.graph_panel.scroll_offset !== null) $('#center_panel').scrollTo(r2ui.graph_panel.scroll_offset, {axis: 'y'}); -// } - -function rename(offset, old_value, new_value, space) { - if (space === undefined) space = "functions"; - if (space == "functions") { - // If current offset is the beginning of a function, rename it with afr - r2.cmdj("pdfj @ " + offset, function(x) { - if (x !== null && x !== undefined) { - if ("0x" + x.addr.toString(16) === offset) { - r2.cmd("afn " + new_value + " " + offset, function() { - r2.update_flags(); - return; - }); - } - } - }); - } - // Otherwise just add a flag - var cmd = ""; - if (new_value !== "" && old_value !== "") { - cmd = "fs " + space + ";fr " + old_value + " " + new_value; - r2.cmd(cmd, function() {}); - } else if (new_value === "" && old_value !== "") { - cmd = "fs " + space + ";f-@" + offset; - r2.cmd(cmd, function() {}); - } else if (new_value !== "" && old_value === "") { - cmd = "fs " + space + ";f " + new_value + " @ " + offset; - r2.cmd(cmd, function() {}); - } - r2.update_flags(); -} - -function address_canonicalize(s) { - s = s.substr(2); - while (s.substr(0,1) == '0') s = s.substr(1); - s = "0x" + s; - s = s.toLowerCase(); - return s; -} - -function contains(a, obj) { - for (var i = 0; i < a.length; i++) { - if (a[i] === obj) { - return true; - } - } - return false; -} - -function handleInputTextChange() { - r2ui.graph_panel.handleInputTextChange(); -} - -function show_contextMenu(x,y) { - r2ui.graph_panel.showContextMenu(x,y); -} - -function get_offset_flag(offset) { - var old_value = ""; - r2.cmdj("fs offsets;fj", function(x) { - for (var i in x) { - if ("0x" + x[i].offset.toString(16) == offset) { - old_value = x[i].name; - break; - } - } - }); - return old_value; -} - -function get_symbol_flag(symbol) { - var full_name = symbol; - var found = false; - r2.cmdj("fs symbols;fj", function(x) { - for (var i in x) { - if (x[i].name == symbol) { - found = true; - break; - } - } - if (!found) { - for (var i in x) { - if (x[i].name == "sym." + symbol) { - full_name = "sym." + symbol; - break; - } - } - } - }); - return full_name; -} - -function get_reloc_flag(reloc) { - var full_name = reloc; - var found = false; - r2.cmdj("fs relocs;fj", function(x) { - for (var i in x) { - if (x[i].name == reloc) { - found = true; - break; - } - } - if (!found) { - for (var i in x) { - if (x[i].name == "reloc." + reloc) { - full_name = "reloc." + reloc; - break; - } - } - } - }); - return full_name; -} - -function trimChar(string, charToRemove) { - while(string.charAt(0)==charToRemove) { - string = string.substring(1); - } - - while(string.charAt(string.length-1)==charToRemove) { - string = string.substring(0,string.length-1); - } - - return string; -} - diff --git a/src/html/graph/lib/js/graph_panel.js b/src/html/graph/lib/js/graph_panel.js deleted file mode 100644 index 9069309a..00000000 --- a/src/html/graph/lib/js/graph_panel.js +++ /dev/null @@ -1,426 +0,0 @@ -// Graph Panel -var GraphPanel = function () { - this.graph = null; - this.min = 0; - this.max = 0; - this.block = 512; - this.base = "entry0"; - this.selected = null; - this.selected_offset = null; - this.tmp_address = null; - this.renaming = null; - this.renameOldValue = ""; - this.rbox = null; - this.panel = $("#disasm_tab")[0]; - this.minimap = true; - this.instructions = []; - //this.scroll_offset = null; - //this.scrolling = false; -}; - -GraphPanel.prototype.init_handlers = function() { - // Unbind mouse and key events from document - $("#center_panel").unbind("click"); - $(document).unbind("keypress"); - $(document).unbind("click"); - $(document).unbind("dblclick"); - - // Bind custom functions to mouse and key events - //$(document).keypress(handleKeypress); - $(document).click(handleClick); - $(document).dblclick(handleDoubleClick); -}; - -GraphPanel.prototype.render = function(theme) { - - // Set theme - if (theme === "dark") { - document.getElementById('dark_theme').disabled = false; - document.getElementById('light_theme').disabled = true; - } else if (theme === "light") { - document.getElementById('dark_theme').disabled = true; - document.getElementById('light_theme').disabled = false; - } - r2ui.load_colors(); - - // Show graph and seek to entrypoint - $("#main_panel").removeClass("ec_gui_background"); - $("#main_panel").addClass("ec_gui_alt_background"); - //if ($('#minimap').length) $('#minimap')[0].innerHTML = ""; - - var addr = null; - if (this.selected_offset !== null) { - addr = this.selected_offset; - } else { - addr = this.base; - } - r2ui.seek(addr,true); - if (addr.indexOf("0x") === 0) { - addr = address_canonicalize(addr); - } else { - addr = r2.get_flag_address(addr); - } - //scroll_to_address(addr); -}; - -GraphPanel.prototype.getElementsUnderCursor = function() { - var elements = document.querySelectorAll(':hover'); - var index; - for (index = 0; index < elements.length; ++index) { - var element = elements[index]; - - // Look for an offset item - if (element.className.indexOf("addr") > 0 && element.className.indexOf("ec_offset") > 0) { - return "{'offset':'" + element.innerText + "'}"; - } - } - return "{}"; -} - -GraphPanel.prototype.seek = function(addr, scroll) { - var panel = this.panel; - var error = false; - panel.innerHTML = ""; - r2.cmd("agj " + addr, function(x) { - panel.innerHTML = "
"; - if (render_graph(x) === false) error = true; - }); - if (error) console.log("Render failed, probably address does not belong to function"); - this.selected = get_element_by_address(addr); - this.selected_offset = addr; - - rehighlight_iaddress(addr); -}; - -GraphPanel.prototype.goToAddress = function() { - if (this.renaming === null && this.selected !== null && (this.selected.className.indexOf(" addr ") > -1)) { - var address = get_address_from_class(this.selected); - if (this.selected.className.indexOf("ec_gui_dataoffset") > -1) { - return; - } - if (address !== undefined && address !== null) { - address = address_canonicalize(address); - do_jumpto(address); - } - } -}; - -GraphPanel.prototype.handleInputTextChange = function() { - if (this.renaming !== null && this.rbox.value.length > 0) { - if ($(this.selected).hasClass('insaddr')) { - var old_value = get_offset_flag(r2ui.graph_panel.selected_offset); - var type = "offsets"; - r2.cmdj("afij @ " + r2ui.graph_panel.selected_offset, function(x) { - if (x !== null && x !== undefined) { - if ("0x" + x[0].offset.toString(16) === r2ui.graph_panel.selected_offset) { - type = "functions"; - } - } - }); - rename(r2ui.graph_panel.selected_offset, old_value, this.rbox.value, type); - } else if ($(this.selected).hasClass('faddr')) { - if ($(this.selected).hasClass('fvar')) - r2.cmd("afvn " + r2ui.graph_panel.renameOldValue + " " + r2ui.graph_panel.rbox.value + " @ " + r2ui.graph_panel.selected_offset, function(x){}); - else if ($(this.selected).hasClass('farg')) - r2.cmd("afan " + r2ui.graph_panel.renameOldValue + " " + r2ui.graph_panel.rbox.value + " @ " + r2ui.graph_panel.selected_offset, function(x){}); - } else { - // TODO, try to recognize other spaces - var old_value = r2ui.graph_panel.renameOldValue; - if (old_value.indexOf("0x") === 0) old_value = ""; - rename(r2ui.graph_panel.selected_offset, old_value, r2ui.graph_panel.rbox.value, "*"); - } - var instruction; - instruction = $(this.selected).closest(".instruction").find('.insaddr')[0]; - this.renaming = null; - var address = get_address_from_class(instruction); - update_binary_details(); - r2ui.seek(address, false); - //scroll_to_address(address); - } -}; - -// function scroll_to_address(address, pos) { -// if (address === undefined || address === null) return; -// var offset = 0; -// if (pos == "top") offset = $('#center_panel').height(); -// else if (pos == "bottom") offset = 0; -// else offset = window.innerHeight / 2; -// var elements = $(".insaddr.addr_" + address); -// if (elements === undefined || elements === null) return; -// if (elements[0] === undefined || elements[0] === null) return; -// var top = elements[0].documentOffsetTop() - offset; -// top = Math.max(0,top); -// $('#center_panel').scrollTo(top, {axis: 'y'}); -// r2ui.graph_panel.scroll_offset = top; -// } - -function handleClick(inEvent) { - console.log("CLICK!") - if ($(inEvent.target).hasClass('addr')) { - if ($(inEvent.target).hasClass('history')) { - var idx = inEvent.target.className.split(" ").filter(function(x) { return x.substr(0,"history_idx_".length) == "history_idx_"; }); - idx = String(idx).split("_")[2]; - r2ui.history_idx = idx; - do_jumpto(r2ui.history[idx]); - }  - // If instruction address, add address to history - else if ($(inEvent.target).hasClass('insaddr')) { - var address = get_address_from_class(inEvent.target); - r2ui.graph_panel.selected = inEvent.target; - r2ui.graph_panel.selected_offset = address; - rehighlight_iaddress(address); - - r2ui.history_push(address); - var get_more_instructions = false; - var next_instruction; - var prev_instruction; - - next_instruction = $(r2ui.graph_panel.selected).closest(".instruction").next().find('.insaddr')[0]; - if (next_instruction === undefined || next_instruction === null) { - next_instruction = $(r2ui.graph_panel.selected).closest(".basicblock").next().find('.insaddr')[0]; - } - prev_instruction = $(r2ui.graph_panel.selected).closest(".instruction").prev().find('.insaddr')[0]; - if (prev_instruction === undefined || prev_instruction === null) { - prev_instruction = $(r2ui.graph_panel.selected).closest(".basicblock").prev().find('.insaddr').last()[0]; - } - - if (get_more_instructions) { - r2ui.seek(address, false); - rehighlight_iaddress(address); - //scroll_to_address(address); - } - } - } else if ($(inEvent.target).hasClass('fvar') || $(inEvent.target).hasClass('farg')) { - var eid = null; - address = get_address_from_class(inEvent.target, "faddr"); - r2ui.graph_panel.selected = inEvent.target; - r2ui.graph_panel.selected_offset = address; - var classes = inEvent.target.className.split(' '); - for (var j in classes) { - var klass = classes[j]; - if (klass.indexOf("id_") === 0) eid = klass.substring(3); - } - if (eid !== null) rehighlight_iaddress(eid, "id"); - } -} - -function handleDoubleClick (inEvent) { - console.log("DOUBLE CLICK!") - if ($(inEvent.target).hasClass('addr') && !$(inEvent.target).hasClass('insaddr')) { - var address = get_address_from_class(inEvent.target); - do_jumpto(address); - } -} - -// key handler -/* -function handleKeypress(inEvent) { - console.log("KEYPRESS!") - var keynum = inEvent.keyCode || inEvent.charCode || inEvent.which || 0; - var key = String.fromCharCode(keynum); - - if (inEvent.ctrlKey||inEvent.metaKey) return; - if ($(inEvent.target).prop("tagName") === "INPUT" || $(inEvent.target).prop("tagName") === "TEXTAREA") return; - - if (r2ui.graph_panel.renaming !== null) return; - - if (key === 'm') toggle_minimap(); - - // h Seek to previous address in history - if (key === 'h') do_jumpto(r2ui.history_prev()); - - // l Seek to next address in history - if (key === 'l') do_jumpto(r2ui.history_next()); - - // j Seek to next Instruction - if (key === 'j') { - var get_more_instructions = false; - if ($(r2ui.graph_panel.selected).hasClass("insaddr")) { - var next_instruction; - - next_instruction = $(r2ui.graph_panel.selected).closest(".instruction").next().find('.insaddr')[0]; - if (next_instruction === undefined || next_instruction === null) { - next_instruction = $(r2ui.graph_panel.selected).closest(".basicblock").next().find('.insaddr')[0]; - } - - var address = get_address_from_class(next_instruction); - if (get_more_instructions) { - r2ui.seek(address, false); - } else { - r2ui.history_push(address); - r2ui.graph_panel.selected = next_instruction; - r2ui.graph_panel.selected_offset = address; - } - rehighlight_iaddress(address); - //scroll_to_address(address); - } - } - // k Seek to previous instruction - if (key === 'k') { - var get_more_instructions = false; - if ($(r2ui.graph_panel.selected).hasClass("insaddr")) { - var prev_instruction; - - var prev_instruction = $(r2ui.graph_panel.selected).closest(".instruction").prev().find('.insaddr')[0]; - if (prev_instruction === undefined || prev_instruction === null) { - prev_instruction = $(r2ui.graph_panel.selected).closest(".basicblock").prev().find('.insaddr').last()[0]; - } - - var address = get_address_from_class(prev_instruction); - if (get_more_instructions) { - r2ui.seek(address, false); - } else { - r2ui.history_push(address); - r2ui.graph_panel.selected = prev_instruction; - r2ui.graph_panel.selected_offset = address; - } - rehighlight_iaddress(address); - //scroll_to_address(address); - } - } - // c Define function - if (key === 'c') do_define(r2ui.graph_panel.selected); - - // u Clear function metadata - if (key === 'u') do_undefine(r2ui.graph_panel.selected); - - // g Go to address - if (key === 'g') { - var a = prompt('Go to'); - if (a !== null) do_jumpto(a); - } - - // ; Add comment - if (key === ';') do_comment(r2ui.graph_panel.selected); - - // n Rename - if (key === 'n') do_rename(r2ui.graph_panel.selected, inEvent); - - if (key === 'R') do_randomcolors(); - - // esc - if (keynum === 27) { - // Esc belongs to renaming - if(r2ui.graph_panel.renaming !== null) { - r2ui.graph_panel.renaming.innerHTML = r2ui.graph_panel.renameOldValue; - r2ui.graph_panel.renaming = null; - } else { - // go back in history - var addr = r2ui.history_prev(); - if (addr !== undefined && addr !== null) r2ui.seek(addr, false); - //scroll_to_address(addr); - } - } - // enter - if (keynum === 13) { - r2ui.graph_panel.goToAddress(); - } -} - -function do_jumpto(address) { - var element = $('.insaddr.addr_' + address); - if (element.length > 0) { - r2ui.history_push(address); - r2ui.graph_panel.selected = element[0]; - r2ui.graph_panel.selected_offset = address; - } else { - r2ui.seek(address, true); - } - rehighlight_iaddress(address); - //scroll_to_address(address); -} - -function do_rename(element, inEvent) { - var address = get_address_from_class(element); - if ($(element).hasClass("addr") && $(element).hasClass("flag")) { - var space = "*"; - if ($(element).hasClass("function")) space = "functions"; - if ($(element).hasClass("import")) space = "functions"; - if ($(element).hasClass("symbol")) space = "symbols"; - if ($(element).hasClass("reloc")) space = "relocs"; - if ($(element).hasClass("section")) space = "sections"; - if ($(element).hasClass("string")) space = "strings"; - var old_value = $(element).html(); - var new_name = prompt('New name', old_value); - if (new_name !== null) { - rename(address, old_value, new_name, space); - //store_scroll_offset(); - r2ui.seek("$$", false); - //scroll_to_last_offset(); - } - } else if (r2ui.graph_panel.renaming === null && element !== null && $(element).hasClass("addr")) { - r2ui.graph_panel.selected = element; - r2ui.graph_panel.selected_offset = address; - r2ui.graph_panel.renaming = element; - r2ui.graph_panel.renameOldValue = element.innerHTML; - r2ui.graph_panel.rbox = document.createElement('input'); - r2ui.graph_panel.rbox.setAttribute("type", "text"); - r2ui.graph_panel.rbox.setAttribute("id", "rename"); - r2ui.graph_panel.rbox.setAttribute("style", "border-width: 0;padding: 0;"); - r2ui.graph_panel.rbox.setAttribute("onChange", "handleInputTextChange()"); - if ($(element).hasClass('insaddr')) { - var value = get_offset_flag(address); - r2ui.graph_panel.rbox.setAttribute("value",value); - r2ui.graph_panel.rbox.setSelectionRange(value.length, value.length); - } else { - r2ui.graph_panel.rbox.setAttribute("value", r2ui.graph_panel.renameOldValue); - r2ui.graph_panel.rbox.setSelectionRange(r2ui.graph_panel.renameOldValue.length, r2ui.graph_panel.renameOldValue.length); - } - r2ui.graph_panel.renaming.innerHTML = ""; - r2ui.graph_panel.renaming.appendChild(r2ui.graph_panel.rbox); - setTimeout('r2ui.graph_panel.rbox.focus();', 200); - inEvent.returnValue=false; - inEvent.preventDefault(); - } else if (r2ui.graph_panel.renaming === null && element !== null && $(element).hasClass("faddr")) { - address = get_address_from_class(element, "faddr"); - r2ui.graph_panel.selected = element; - r2ui.graph_panel.selected_offset = address; - r2ui.graph_panel.renaming = element; - r2ui.graph_panel.renameOldValue = element.innerText; - r2ui.graph_panel.rbox = document.createElement('input'); - r2ui.graph_panel.rbox.setAttribute("type", "text"); - r2ui.graph_panel.rbox.setAttribute("id", "rename"); - r2ui.graph_panel.rbox.setAttribute("style", "border-width: 0;padding: 0;"); - r2ui.graph_panel.rbox.setAttribute("onChange", "handleInputTextChange()"); - r2ui.graph_panel.rbox.setAttribute("value", r2ui.graph_panel.renameOldValue); - r2ui.graph_panel.rbox.setSelectionRange(r2ui.graph_panel.renameOldValue.length, r2ui.graph_panel.renameOldValue.length); - r2ui.graph_panel.renaming.innerHTML = ""; - r2ui.graph_panel.renaming.appendChild(r2ui.graph_panel.rbox); - setTimeout('r2ui.graph_panel.rbox.focus();', 200); - inEvent.returnValue=false; - inEvent.preventDefault(); - } - update_binary_details(); -} - -function do_comment(element) { - var address = get_address_from_class(element); - var c = prompt('Comment'); - if (c !== null) { - r2.cmd('CC ' + c + " @ " + address); - r2ui.seek(address, false); - //scroll_to_address(address); - } -} - -function do_undefine(element) { - var address = get_address_from_class(element); - r2.cmd("af-"); - r2.update_flags(); - update_binary_details(); - r2ui.seek(address, false); - //scroll_to_address(address); -} - -function do_define(element) { - var address = get_address_from_class(element); - var msg = prompt ('Function name?'); - if (msg !== null) { - r2.cmd("af " + msg + " @ " + address); - r2.update_flags(); - update_binary_details(); - r2ui.seek(address, false); - //scroll_to_address(address); - } -} -*/ diff --git a/src/html/graph/lib/js/joint.js b/src/html/graph/lib/js/joint.js deleted file mode 100644 index 5a139d17..00000000 --- a/src/html/graph/lib/js/joint.js +++ /dev/null @@ -1,14 +0,0 @@ -/*! JointJS v0.9.2 - JavaScript diagramming library 2014-09-17 - - -This Source Code Form is subject to the terms of the Mozilla Public -License, v. 2.0. If a copy of the MPL was not distributed with this -file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -if(function(a,b){function c(a){var b=a.length,c=fb.type(a);return fb.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||"function"!==c&&(0===b||"number"==typeof b&&b>0&&b-1 in a)}function d(a){var b=ob[a]={};return fb.each(a.match(hb)||[],function(a,c){b[c]=!0}),b}function e(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=fb.expando+Math.random()}function f(a,c,d){var e;if(d===b&&1===a.nodeType)if(e="data-"+c.replace(sb,"-$1").toLowerCase(),d=a.getAttribute(e),"string"==typeof d){try{d="true"===d?!0:"false"===d?!1:"null"===d?null:+d+""===d?+d:rb.test(d)?JSON.parse(d):d}catch(f){}pb.set(a,c,d)}else d=b;return d}function g(){return!0}function h(){return!1}function i(){try{return T.activeElement}catch(a){}}function j(a,b){for(;(a=a[b])&&1!==a.nodeType;);return a}function k(a,b,c){if(fb.isFunction(b))return fb.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return fb.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(Cb.test(b))return fb.filter(b,a,c);b=fb.filter(b,a)}return fb.grep(a,function(a){return bb.call(b,a)>=0!==c})}function l(a,b){return fb.nodeName(a,"table")&&fb.nodeName(1===b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function m(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function n(a){var b=Nb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function o(a,b){for(var c=a.length,d=0;c>d;d++)qb.set(a[d],"globalEval",!b||qb.get(b[d],"globalEval"))}function p(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(qb.hasData(a)&&(f=qb.access(a),g=qb.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)fb.event.add(b,e,j[e][c])}pb.hasData(a)&&(h=pb.access(a),i=fb.extend({},h),pb.set(b,i))}}function q(a,c){var d=a.getElementsByTagName?a.getElementsByTagName(c||"*"):a.querySelectorAll?a.querySelectorAll(c||"*"):[];return c===b||c&&fb.nodeName(a,c)?fb.merge([a],d):d}function r(a,b){var c=b.nodeName.toLowerCase();"input"===c&&Kb.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}function s(a,b){if(b in a)return b;for(var c=b.charAt(0).toUpperCase()+b.slice(1),d=b,e=_b.length;e--;)if(b=_b[e]+c,b in a)return b;return d}function t(a,b){return a=b||a,"none"===fb.css(a,"display")||!fb.contains(a.ownerDocument,a)}function u(b){return a.getComputedStyle(b,null)}function v(a,b){for(var c,d,e,f=[],g=0,h=a.length;h>g;g++)d=a[g],d.style&&(f[g]=qb.get(d,"olddisplay"),c=d.style.display,b?(f[g]||"none"!==c||(d.style.display=""),""===d.style.display&&t(d)&&(f[g]=qb.access(d,"olddisplay",z(d.nodeName)))):f[g]||(e=t(d),(c&&"none"!==c||!e)&&qb.set(d,"olddisplay",e?c:fb.css(d,"display"))));for(g=0;h>g;g++)d=a[g],d.style&&(b&&"none"!==d.style.display&&""!==d.style.display||(d.style.display=b?f[g]||"":"none"));return a}function w(a,b,c){var d=Ub.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||"px"):b}function x(a,b,c,d,e){for(var f=c===(d?"border":"content")?4:"width"===b?1:0,g=0;4>f;f+=2)"margin"===c&&(g+=fb.css(a,c+$b[f],!0,e)),d?("content"===c&&(g-=fb.css(a,"padding"+$b[f],!0,e)),"margin"!==c&&(g-=fb.css(a,"border"+$b[f]+"Width",!0,e))):(g+=fb.css(a,"padding"+$b[f],!0,e),"padding"!==c&&(g+=fb.css(a,"border"+$b[f]+"Width",!0,e)));return g}function y(a,b,c){var d=!0,e="width"===b?a.offsetWidth:a.offsetHeight,f=u(a),g=fb.support.boxSizing&&"border-box"===fb.css(a,"boxSizing",!1,f);if(0>=e||null==e){if(e=Qb(a,b,f),(0>e||null==e)&&(e=a.style[b]),Vb.test(e))return e;d=g&&(fb.support.boxSizingReliable||e===a.style[b]),e=parseFloat(e)||0}return e+x(a,b,c||(g?"border":"content"),d,f)+"px"}function z(a){var b=T,c=Xb[a];return c||(c=A(a,b),"none"!==c&&c||(Rb=(Rb||fb("