mirror of
https://github.com/geohot/qira
synced 2025-03-14 11:03:08 +03:00
flat view fixed
This commit is contained in:
parent
5ac2508a1a
commit
642c14bf44
@ -46,21 +46,67 @@ def gettagsa():
|
||||
@socket_method
|
||||
def getstaticview(haddr, flat, flatrange):
|
||||
fxn = program.static[fhex(haddr)]['function']
|
||||
if fxn == None:
|
||||
return
|
||||
if fxn == None or flat == True:
|
||||
addr = fhex(haddr)
|
||||
|
||||
blocks = []
|
||||
for b in fxn.blocks:
|
||||
bb = []
|
||||
for i in sorted(b.addresses):
|
||||
# not a function, return flat view
|
||||
ret = []
|
||||
# find backward
|
||||
i = addr
|
||||
while len(ret) != abs(flatrange[0]):
|
||||
did_append = False
|
||||
# search up to 256 back
|
||||
for j in range(1, 256):
|
||||
if 'len' in program.static[i-j] and program.static[i-j]['len'] == j:
|
||||
i -= j
|
||||
bbb = {'address': ghex(i)}
|
||||
bbb['bytes'] = map(ord, program.static.memory(i, j))
|
||||
ret.append(bbb)
|
||||
did_append = True
|
||||
break
|
||||
if not did_append:
|
||||
i -= 1
|
||||
bbb = {'address': ghex(i)}
|
||||
bbb['bytes'] = map(ord, program.static.memory(i, 1))
|
||||
ret.append(bbb)
|
||||
ret = ret[::-1]
|
||||
|
||||
# find forward
|
||||
i = addr
|
||||
while len(ret) != abs(flatrange[0]) + flatrange[1]:
|
||||
bbb = {'address': ghex(i)}
|
||||
bbb['comment'] = program.static[i]['comment']
|
||||
bbb['instruction'] = str(program.static[i]['instruction'])
|
||||
bbb['dests'] = map(lambda (x,y): (ghex(x), y), program.static[i]['instruction'].dests())
|
||||
bb.append(bbb)
|
||||
blocks.append(bb)
|
||||
#print program.tags[i]
|
||||
if 'len' in program.static[i]:
|
||||
l = program.static[i]['len']
|
||||
if l == 0:
|
||||
l = 1
|
||||
else:
|
||||
l = 1
|
||||
bbb['bytes'] = map(ord, program.static.memory(i, l))
|
||||
i += l
|
||||
ret.append(bbb)
|
||||
|
||||
emit('function', {'blocks': blocks})
|
||||
for bbb in ret:
|
||||
a = fhex(bbb['address'])
|
||||
bbb['comment'] = program.static[a]['comment']
|
||||
if 'instruction' in program.static[a]:
|
||||
bbb['instruction'] = str(program.static[a]['instruction'])
|
||||
# dests?
|
||||
|
||||
emit('flat', ret)
|
||||
else:
|
||||
blocks = []
|
||||
for b in fxn.blocks:
|
||||
bb = []
|
||||
for i in sorted(b.addresses):
|
||||
bbb = {'address': ghex(i)}
|
||||
bbb['comment'] = program.static[i]['comment']
|
||||
bbb['instruction'] = str(program.static[i]['instruction'])
|
||||
bbb['dests'] = map(lambda (x,y): (ghex(x), y), program.static[i]['instruction'].dests())
|
||||
bb.append(bbb)
|
||||
blocks.append(bb)
|
||||
|
||||
emit('function', {'blocks': blocks})
|
||||
|
||||
@socketio.on('gotoname', namespace='/qira')
|
||||
@socket_method
|
||||
|
1
web/client/controls.js
vendored
1
web/client/controls.js
vendored
@ -104,6 +104,7 @@ $(document).ready(function() {
|
||||
});
|
||||
$('body').on('mousewheel', '.flat', function(e) {
|
||||
var cdr = $(".flat").children();
|
||||
// TODO: HAXX!!!
|
||||
if (e.originalEvent.wheelDelta < 0) {
|
||||
Session.set('iview', get_address_from_class(cdr[16].childNodes[0]));
|
||||
} else if (e.originalEvent.wheelDelta > 0) {
|
||||
|
@ -35,6 +35,12 @@ function display_flat(addrs) {
|
||||
$("#staticpanel").html(idump);
|
||||
}
|
||||
|
||||
function on_flat(addrs) { DS("flat");
|
||||
display_flat(addrs);
|
||||
rehighlight();
|
||||
replace_names();
|
||||
} stream.on('flat', on_flat);
|
||||
|
||||
function on_function(fxn) { DS("function");
|
||||
var graph = new Graph();
|
||||
p(fxn);
|
||||
@ -77,71 +83,3 @@ function on_function(fxn) { DS("function");
|
||||
replace_names();
|
||||
} stream.on('function', on_function);
|
||||
|
||||
function on_tags(addrs, fxn) { DS("tags");
|
||||
if (!fxn) {
|
||||
display_flat(addrs);
|
||||
} else {
|
||||
var graph = new Graph();
|
||||
|
||||
//p(addrs);
|
||||
|
||||
// this renders all the graph vertices
|
||||
var idump = "";
|
||||
var in_basic_block = false;
|
||||
var last_basic_block = false;
|
||||
var last_block_has_flow = false;
|
||||
var cnt = 0;
|
||||
|
||||
function pushBlock() {
|
||||
if (last_basic_block != false) {
|
||||
var dom = $('<div class="basicblock" id="bb_'+ins.address+'">');
|
||||
dom.html(idump);
|
||||
idump = "";
|
||||
cnt = 0;
|
||||
graph.addVertex(last_basic_block, cnt, dom[0]);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i=0;i<addrs.length;i++) {
|
||||
var ins = addrs[i];
|
||||
if (ins.scope == undefined) continue;
|
||||
if (in_basic_block == false) {
|
||||
// accepts control from previous instruction
|
||||
if (ins.flags & 0x10000 && last_basic_block != false) {
|
||||
var color = "blue";
|
||||
if (last_block_has_flow) {
|
||||
color = "red";
|
||||
}
|
||||
graph.addEdge(last_basic_block, ins.address, color);
|
||||
}
|
||||
in_basic_block = ins.address;
|
||||
}
|
||||
if (ins.instruction === undefined) {
|
||||
ins.instruction = "undefined";
|
||||
}
|
||||
cnt += 1;
|
||||
idump += instruction_html_from_tags(ins);
|
||||
|
||||
if (ins.semantics !== undefined && ins.semantics.indexOf("endbb") != -1) {
|
||||
last_basic_block = in_basic_block;
|
||||
//p(ins.flow);
|
||||
last_block_has_flow = false;
|
||||
for (var j = 0; j < ins.flow.length; j++) {
|
||||
graph.addEdge(last_basic_block, ins.flow[j], "green");
|
||||
last_block_has_flow = true;
|
||||
}
|
||||
pushBlock();
|
||||
in_basic_block = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (in_basic_block) pushBlock();
|
||||
|
||||
graph.assignLevels();
|
||||
graph.render();
|
||||
}
|
||||
|
||||
rehighlight();
|
||||
replace_names();
|
||||
} stream.on('tags', on_tags);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user