Merge pull request #158 from hteso/minimap

minimap minor fixes
This commit is contained in:
Alvaro 2017-04-29 10:19:11 +02:00 committed by GitHub
commit 416ed82149
4 changed files with 21 additions and 160 deletions

View File

@ -20,21 +20,6 @@
<script type="text/javascript" src="qrc:/graph/html/graph/lib/js/disasm.js"></script>
<script type="text/javascript" src="qrc:/graph/html/graph/lib/js/jquery-1.9.0.js"></script>
<script type="text/javascript" src="qrc:/graph/html/graph/lib/js/graph_panel.js"></script>
<script type="text/javascript">
function init(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");
}
}
</script>
</head>
<body style="margin: 0px">
@ -44,6 +29,5 @@
</div>
</div>
</body>
</html>

View File

@ -4,6 +4,21 @@ SVGElement.prototype.getTransformToElement = SVGElement.prototype.getTransformTo
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 = {};
@ -174,20 +189,11 @@ BBGraph.prototype.render = function() {
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.$el.css('pointer-events', 'none');
$("#minimap").css("left", $("#main_panel").width() - minimap_width);
$("#minimap").css("top", $("#center_panel").position().top - 40);
// $("#center_panel").bind('scroll', update_minimap);
// $("#main_panel").bind('scroll', update_minimap);
// $("#disasm_tab").bind('scroll', update_minimap);
// $("#minimap").bind('scroll', update_minimap);
// $("#canvas").bind('scroll', update_minimap);
document.addEventListener('scroll', function (event) {
//if (event.target.id === 'idOfUl') { // or any other filtering condition
console.log('scrolling', event.target);
update_minimap();
//}
if (event.target.id === 'main_panel') update_minimap();
}, true /*Capture event*/);
paper.on( "cell:pointerup", function( cellview, evt, x, y) {
@ -269,6 +275,8 @@ function update_minimap() {
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);

View File

@ -26,142 +26,11 @@ GraphPanel.prototype.init_handlers = function() {
$(document).unbind("dblclick");
// Bind custom functions to mouse and key events
//$("#center_panel").scroll(on_scroll);
//$(document).keypress(handleKeypress);
$(document).click(handleClick);
$(document).dblclick(handleDoubleClick);
};
GraphPanel.prototype.init_context_menu = function() {
// Context menu for disas addresses:
$(document).contextmenu({
delegate: ".addr",
menu: [
{title: "jump to address<kbd>g</kbd>", cmd: "goto"},
{title: "rename<kbd>n</kbd>", cmd: "rename"},
{title: "add comment<kbd>;</kbd>", cmd: "comment"},
{title: "code<kbd>c</kbd>", cmd: "define"},
{title: "undefine<kbd>u</kbd>", cmd: "undefine"},
{title: "random colors<kbd>R</kbd>", cmd: "randomcolors"},
{title: "switch disasm/graph<kbd>s</kbd>", cmd: "switchview"}
],
preventSelect: true,
taphold: true,
preventContextMenuForPopup: true,
show: false,
position: function(event, ui){
return {my: "left+100 top-10", at: "left bottom", of: ui.target};
},
beforeOpen: function(event, ui) {
var address = get_address_from_class(ui.target[0]);
var xrefs_to = [];
var xrefs_from = [];
var xrefto_submenu = null;
var xreffrom_submenu = null;
var refs = [];
var addr = "";
var type = "";
r2.cmd("axf @" + address, function(x){
var lines = x.split('\n');
for (var l in lines) {
if (lines[l] !== "") xrefs_to[xrefs_to.length] = lines[l];
}
});
if (xrefs_to.length > 0) {
$(document).contextmenu("showEntry", "xrefs_to", true);
refs = [];
for (var r in xrefs_to) {
addr = xrefs_to[r].split(' ')[1];
type = xrefs_to[r].split(' ')[0];
refs[refs.length] = {title: addr + "<kbd>" + type + "</kbd>", cmd: "jumpto_" + addr};
}
xrefto_submenu = {title: "xrefs to", children: refs};
}
r2.cmd("axt @" + address, function(x){
var lines = x.split('\n');
for (var l in lines) {
if (lines[l] !== "") xrefs_from[xrefs_from.length] = lines[l];
}
});
if (xrefs_from.length > 0) {
$(document).contextmenu("showEntry", "xrefs_from", true);
refs = [];
for (var r in xrefs_from) {
addr = xrefs_from[r].split(' ')[1];
type = xrefs_from[r].split(' ')[0];
refs[refs.length] = {title: addr + "<kbd>" + type + "</kbd>", cmd: "jumpto_" + addr};
}
xreffrom_submenu = {title: "xrefs from", children: refs};
}
var menu = [
{title: "jump to address<kbd>g</kbd>", cmd: "goto"},
{title: "rename<kbd>n</kbd>", cmd: "rename"},
{title: "add comment<kbd>;</kbd>", cmd: "comment"},
{title: "code<kbd>c</kbd>", cmd: "define"},
{title: "undefine<kbd>u</kbd>", cmd: "undefine"},
{title: "random colors<kbd>R</kbd>", cmd: "randomcolors"},
{title: "switch disasm/graph<kbd>s</kbd>", cmd: "switchview"}
];
if (xreffrom_submenu !== null || xrefto_submenu !== null) {
if (xrefto_submenu !== null) menu[menu.length] = xrefto_submenu;
if (xreffrom_submenu !== null) menu[menu.length] = xreffrom_submenu;
}
$(document).contextmenu("replaceMenu", menu);
r2.cmdj("pdj 1 @" + address, function(x) {
if(x) {
if(x[0].fcn_addr == x[0].offset) {
$(document).contextmenu("showEntry", "define", false);
$(document).contextmenu("showEntry", "undefine", true);
} else {
$(document).contextmenu("showEntry", "define", true);
$(document).contextmenu("showEntry", "undefine", false);
}
}
});
if (ui.target.hasClass('insaddr')) {
$(document).contextmenu("showEntry", "comment", true);
$(document).contextmenu("showEntry", "rename", true);
} else {
$(document).contextmenu("showEntry", "comment", false);
$(document).contextmenu("showEntry", "rename", true);
$(document).contextmenu("showEntry", "define", false);
$(document).contextmenu("showEntry", "undefine", false);
}
if (ui.target.hasClass('reloc') || ui.target.hasClass('symbol') || ui.target.hasClass('import')) {
$(document).contextmenu("showEntry", "comment", false);
$(document).contextmenu("showEntry", "rename", false);
$(document).contextmenu("showEntry", "define", false);
$(document).contextmenu("showEntry", "undefine", false);
}
// Context manu on disasm panel
if (!$.contains($("#disasm_tab")[0], ui.target[0])) {
$(document).contextmenu("showEntry", "switchview", false);
}
},
select: function(event, ui) {
$(document).contextmenu("close");
var target = ui.target[0];
var address = get_address_from_class(target);
if (ui.cmd.indexOf("jumpto_") === 0) {
address = ui.cmd.substring(ui.cmd.indexOf("jumpto_") + 7);
do_jumpto(address);
}
switch (ui.cmd) {
case "goto": do_goto(); break;
case "comment": do_comment(target); break;
case "rename": do_rename(target, event); break;
case "define": do_define(target); break;
//case "undefine": do_undefine(target); break;
case "randomcolors": do_randomcolors(target); break;
//case "switchview": do_switchview(target); break;
}
}
});
};
GraphPanel.prototype.render = function(theme) {
// Set theme

View File

@ -1561,9 +1561,9 @@ void MemoryWidget::create_graph(QString off)
QSettings settings;
if (settings.value("dark").toBool())
{
ui->graphWebView->page()->runJavaScript(QString("init('dark');"));
ui->graphWebView->page()->runJavaScript(QString("init_panel('dark');"));
} else {
ui->graphWebView->page()->runJavaScript(QString("init('light');"));
ui->graphWebView->page()->runJavaScript(QString("init_panel('light');"));
}
}