Skip to content

Instantly share code, notes, and snippets.

@rebrec
Created May 16, 2016 16:27
Show Gist options
  • Save rebrec/cadb698ab99b1e44fe3d95d95b1aec17 to your computer and use it in GitHub Desktop.
Save rebrec/cadb698ab99b1e44fe3d95d95b1aec17 to your computer and use it in GitHub Desktop.
const StringDecoder = require('string_decoder').StringDecoder;
const decoder = new StringDecoder('utf8');
var x = [49, // opcode
10,0,0,0, // cnt
0,0,0,0, // Highlight 1
77,69, 32,70, 85,67, 75,32, 73,83, 76,65, 77,0, // NAME 1 (length=14)
0,0,0,0, // HL 2
0, // NAME 2 (length=0)
0,0,0,0, // HL 3
97, 100,101, 108,105, 110,0, // NAME 3 (length=7)
0,0,0,0, // HL 4
115,116,97,110,100,97,110,50,0, // NAME 4 (length=9)
0,0,0,0, // HL 5
105,32,103,105,118,101,32,121,111,117,32,109,97,115,115,0, // NAME 5 (length=16)
0,0,0,0, // HL 6
76,79,79,75,32,73,39,77,32,70,73,82,83,84,0, // NAME 6 (length=15)
0,0,0,0, // HL 7
0, // NAME 7
0,0,0,0, // HL 8
0, // NAME 8
0,0,0,0, // HL 9
84,85,82,75,83,0, // NAME 9
0,0,0,0, // HL 10
110,97,115,97,0 // NAME 10
];
var u8a = new Uint8Array(x);
var dv = new DataView(u8a.buffer);
console.log('Packet Length : ' + u8a.length);
var offset = 0;
var opcode = dv.getUint8(offset);
offset += 1;
console.log('opcode ' + opcode);
var cnt = dv.getUint32(offset, true);
offset += 4;
console.log('Count : ' + cnt);
for (var i=0; i<cnt; i++) { // iterate through each (Highlight,Nick) structure
var highlight = dv.getUint32(offset, true);
console.log('Highlight : ' + (highlight !== 0));
offset += 4;
// looking for the null terminated str
var j=0;
while (dv.getUint8(offset+j) != 0) {j++;}
console.log('NAME' + (i+1) + ' Length = ' + j);
var nickBuf = new Buffer(u8a.subarray(offset, offset+j));
console.log('NAME' + (i+1) + ' : ' + decoder.write(nickBuf));
offset +=j+1;
}
/* OUTPUT :
/usr/local/bin/node --debug-brk=46792 sang.js
Debugger listening on port 46792
Packet Length : 120
opcode 49
Count : 10
Highlight : false
NAME1 Length = 13
NAME1 : ME FUCK ISLAM
Highlight : false
NAME2 Length = 0
NAME2 :
Highlight : false
NAME3 Length = 6
NAME3 : adelin
Highlight : false
NAME4 Length = 8
NAME4 : standan2
Highlight : false
NAME5 Length = 15
NAME5 : i give you mass
Highlight : false
NAME6 Length = 14
NAME6 : LOOK I'M FIRST
Highlight : false
NAME7 Length = 0
NAME7 :
Highlight : false
NAME8 Length = 0
NAME8 :
Highlight : false
NAME9 Length = 5
NAME9 : TURKS
Highlight : false
NAME10 Length = 4
NAME10 : nasa
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment