Skip to content
Snippets Groups Projects
Commit a55aa2e5 authored by rswindell's avatar rswindell
Browse files

A handy little binary data dumping/debugging library

parent 117f41be
No related branches found
No related tags found
No related merge requests found
// $Id$
function hexdump(title, val)
{
var i;
if(!val) {
printf("%s: (null)\n", title);
return false;
}
printf("%s: %u bytes\n", title, val.length);
var ascii = '';
for(i=0; i < val.length; i++) {
var ch = val.charCodeAt(i);
if(i && i%16 == 0) {
printf(" %s\n", ascii);
ascii = '';
}
else if(i && i%8 == 0)
printf("- ");
printf("%02X ", ch);
ascii += format("%c", (ch >= 0x20 && ch < 0x7f) ? ch : '.');
}
if(ascii) {
var gap = 0;
if(i%16) {
gap = (16-(i%16))*3;
if((i%16) < 8)
gap += 2;
}
printf("%*s %s\n", gap, "", ascii);
}
print();
return true;
}
function hexdump_file(file)
{
var buf = file.read();
hexdump(file.name, buf);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment