Catpured packet and inserting into ArrayBuffer.
This commit is contained in:
parent
a4a3e502e8
commit
7616ab95f3
4 changed files with 28 additions and 1 deletions
|
@ -3,7 +3,7 @@
|
|||
Playing around with parsing dns packets in Javascript.
|
||||
|
||||
## ToDo
|
||||
- [ ] Import packet string into Arraybuffer
|
||||
- [x] Import packet string into Arraybuffer
|
||||
- [ ] Parse the headers into a Javascript object
|
||||
- [ ] Test/Fix browser JS compatibility
|
||||
|
||||
|
|
BIN
data
Normal file
BIN
data
Normal file
Binary file not shown.
3
encoded
Normal file
3
encoded
Normal file
|
@ -0,0 +1,3 @@
|
|||
1MOyoQIABAAAAAAAAAAAAAAABAABAAAAKPfFWWMZCwBRAAAAUQAAAExg3kp+6eSzGAoxpggARQAA
|
||||
Q66CQABAEXgXCgAAEAoAAAG90gA1AC+qDJSEAQAAAQAAAAAAAAphc3NldHMtY2RuBmdpdGh1YgNj
|
||||
b20AAAEAAQ==
|
24
index.js
Normal file
24
index.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
if(typeof(atob) === 'undefined') {
|
||||
var atob = require("atob");
|
||||
}
|
||||
(function(){
|
||||
'use strict';
|
||||
|
||||
var encodedPacket = "1MOyoQIABAAAAAAAAAAAAAAABAABAAAAKPfFWWMZCwBRAAAAUQAAAExg3kp+6eSzGAoxpggARQAAQ66CQABAEXgXCgAAEAoAAAG90gA1AC+qDJSEAQAAAQAAAAAAAAphc3NldHMtY2RuBmdpdGh1YgNjb20AAAEAAQ=="
|
||||
var packet = atob(encodedPacket);
|
||||
|
||||
console.log(packet.length);
|
||||
|
||||
var buffer = new ArrayBuffer(packet.length);
|
||||
|
||||
var view = new DataView(buffer)
|
||||
|
||||
for(var i = 0; i < packet.length; ++i) {
|
||||
view.setUint8(i, packet.charCodeAt(i), true);
|
||||
}
|
||||
|
||||
for(i = 0; i < packet.length; ++i) {
|
||||
console.log(view.getUint8(i).toString(16));
|
||||
}
|
||||
|
||||
})();
|
Loading…
Reference in a new issue