Skip to content

Instantly share code, notes, and snippets.

@lunixbochs
Forked from staticshock/bookmarklets.js
Last active January 3, 2016 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunixbochs/8516057 to your computer and use it in GitHub Desktop.
Save lunixbochs/8516057 to your computer and use it in GitHub Desktop.
// Bind F7 to 'step'
javascript:$(document).bind('keydown', function(e) { e.which == 118 && parse('s'); }); void(0)
// Add a 'readhex' command that works just like 'read' but dumps nothing but the hex
javascript:cpu._readhex =
function(e) {
if (!e[1]) return write(" Please give an expression to read the memory at."), void 0;
var t = cpu.to_addr(e[1]);
cpu.get("/cpu/dbg/memory/" + t + "?len=" + (parseInt(e[2], 16) + (15 - parseInt(e[2], 16) & 15) || 32), function(e) {
for (var n = atob(e.raw), i = "", o = " ", s = 0; s < n.length; s++) s % 2 == 0 && (o += " "), o += pad(n.charCodeAt(s).toString(16), 2), s % 8 == 7 && (i += " " + o + "\n", o = " ");
write(i);
})
}; void(0)
// Add a 'disassemble' command that takes the same arguments as read/readhex
// and disassembles the instructions starting at that address
javascript:cpu._disassemble =
function(e) {
if (!e[1]) return write(" Please give an expression to read the memory at."), void 0;
var t = cpu.to_addr(e[1]);
cpu.get("/cpu/dbg/memory/" + t + "?len=" + (parseInt(e[2], 16) + (15 - parseInt(e[2], 16) & 15) || 32), function(e) {
for (var n = atob(e.raw), i = "", o = "", s = 0; s < n.length; s++) s % 2 == 0 && (o += ""), o += pad(n.charCodeAt(s).toString(16), 2), s % 8 == 7 && (i += o, o = "");
cpu.get("/cpu/dbg/disasm?obj=" + i, function(e) {
write(e.error ? "ERROR: " + e.error : e.data.insns.join("\n"));
}, 1)
})
}; void(0)
// add highlight and show address when clicking in memory view
javascript:$('.usedmemory pre span').click((function() {
var border = '1px orange dashed';
var handler = function(e) {
var el = e.target;
var addr = el.id.replace('memorylocation', '');
if (! addr) {
return;
}
el = $(el);
var parent = el.parent();
parent.children('.usedmemory pre span').removeAttr('style');
var real = parent.data('real-addr');
var cur = parent.html().match(/^[a-f0-9]+/)[0];
if (addr != cur && addr != real) {
el.css('border', border);
}
if (! real) {
parent.data('real-addr', cur);
real = cur;
}
if (addr == cur) {
addr = real;
}
parent.html(parent.html().replace(cur, addr));
parent.children('.usedmemory pre span').click(handler);
};
return handler;
})()); void(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment