From b5af1bfe24c27199168b28a82a04275e6403d24d Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 9 Oct 2017 10:56:02 -0600 Subject: [PATCH] WIP output byte indexes while parsing --- bin/debug.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/bin/debug.js b/bin/debug.js index a41ec48..18d8a5b 100644 --- a/bin/debug.js +++ b/bin/debug.js @@ -45,8 +45,6 @@ console.log('ancount', ancount); console.log('nscount', nscount); console.log('arcount', arcount); -var total = 12; - function unpackQuestion(dv, total, len) { var qnames = []; var labelLen; @@ -77,10 +75,11 @@ function unpackQuestion(dv, total, len) { console.log('label:', label); qnames.push(label); } - console.log('QNAME:', qnames.join('.')); - console.log('QTYPE:', dv.getUint16(total), false); + // leading length and (potentially) trailing null + console.log('QNAME (len ' + (qnames.join('.').length + 1 + (labelLen ? 0 : 1)) + '):', qnames.join('.')); + console.log('QTYPE (len 2):', dv.getUint16(total, false)); total += 2; - console.log('QCLASS:', dv.getUint16(total), false); + console.log('QCLASS (len 2):', dv.getUint16(total, false)); total += 2; return { @@ -89,8 +88,9 @@ function unpackQuestion(dv, total, len) { }; } -var q = { total: total }; -function mapChar(ch) { return String.fromCharCode(ch) + '(' + ch + ')'; } +var q = { total: 12 }; +function mapChar(ch) { return JSON.stringify(String.fromCharCode(ch)) + '(' + ch + ')'; } + console.log(''); console.log('//////////////////'); @@ -98,7 +98,8 @@ console.log('// QUESTION //'); console.log('//////////////////'); console.log(''); for (count = 0; count < qdcount; count += 1) { - console.log('Question', count + 1, 'of', qdcount); + console.log(''); + console.log('Question ' + (count + 1) + ' of ' + qdcount + ' (byte index: ' + q.total + ')'); q = unpackQuestion(dv, q.total, ab.byteLength); console.log(''); } @@ -109,7 +110,8 @@ console.log('// ANSWER //'); console.log('//////////////////'); console.log(''); for (count = 0; count < ancount; count += 1) { - console.log('Answer', count + 1, 'of', ancount); + console.log(''); + console.log('Answer', count + 1, 'of', ancount + ' (byte index: ' + q.total + ')'); q = unpackQuestion(dv, q.total, ab.byteLength); console.log(''); } @@ -121,16 +123,18 @@ console.log('// AUTHORITY //'); console.log('//////////////////'); console.log(''); for (count = 0; count < nscount; count += 1) { - console.log('Authority', count + 1, 'of', nscount); + console.log(''); + console.log('Authority', count + 1, 'of', nscount + ' (byte index: ' + q.total + ')'); q = unpackQuestion(dv, q.total, ab.byteLength); - console.log('ttl:', dv.getUint32(q.total, false)); + console.log('ttl (len 4):', dv.getUint32(q.total, false)); q.total += 4; q.rdlength = dv.getUint16(q.total, false); - console.log('rdlen:', q.rdlength); + console.log('rdlen (len 2):', q.rdlength); q.total += 2; - console.log('rrdata:'); - console.log([].slice.call(new Uint8Array(ab), q.total, q.total + q.rdlength).map(mapChar)); + console.log('rrdata (len ' + q.rdlength + '):'); + console.log([].slice.call(new Uint8Array(ab), q.total, q.total + q.rdlength).map(mapChar).join(' ')); q.total += q.rdlength; + console.log(''); } console.log(''); @@ -139,7 +143,8 @@ console.log('// ADDITIONAL //'); console.log('//////////////////'); console.log(''); for (count = 0; count < arcount; count += 1) { - console.log('Additional', count + 1, 'of', arcount); + console.log(''); + console.log('Additional', count + 1, 'of', arcount + ' (byte index: ' + q.total + ')'); q = unpackQuestion(dv, q.total, ab.byteLength); console.log(''); }