WIP line-by-line debug

This commit is contained in:
AJ ONeal 2017-10-06 20:53:03 -06:00
parent 6b8a8664f8
commit 2f4807d1b4
1 changed files with 54 additions and 0 deletions

54
bin/debug.js Normal file
View File

@ -0,0 +1,54 @@
(function () {
'use strict';
var input = process.argv[2];
var fs = require('fs');
var nb = fs.readFileSync(input, null);
var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength)
var dv = new DataView(ab);
//
// read header
//
console.log('');
console.log('//////////////////');
console.log('// HEADER //');
console.log('//////////////////');
console.log('');
console.log('id (int)', dv.getUint16(0));
var i = dv.getUint16(2, false);
console.log('header 0x', i.toString(16));
var flagsstr = ''
+ 'qr ' + ((i & 0x8000) >> 15) + ', '
+ 'opcode ' + ((i & 0x7800) >> 11) + ', '
+ 'aa ' + ((i & 0x400) >> 10) + ', '
+ 'tc ' + ((i & 0x200) >> 9) + ', '
+ 'rd ' + ((i & 0x100) >> 8) + ', '
+ 'ra ' + ((i & 0x80) >> 7) + ', '
+ 'res1 ' + ((i & 0x40) >> 6) + ', '
+ 'res2 ' + ((i & 0x20) >> 5) + ', '
+ 'res3 ' + ((i & 0x10) >> 4) + ', '
+ 'rcode ' + ((i & 0xF));
console.log('(flags: ' + flagsstr);
var qdcount = dv.getUint16(4, false); // query count
var ancount = dv.getUint16(6, false); // answer count
var nscount = dv.getUint16(8, false); // authority count
var arcount = dv.getUint16(10, false); // additional count
console.log('qdcount', qdcount);
console.log('ancount', ancount);
console.log('nscount', nscount);
console.log('arcount', arcount);
console.log('');
console.log('//////////////////');
console.log('// QUESTION //');
console.log('//////////////////');
console.log('');
}());