Add lookup cmd decoder

This commit is contained in:
Tau
2018-11-26 19:02:30 -05:00
parent b678c0c551
commit 21b90ee323
2 changed files with 36 additions and 0 deletions

View File

@@ -16,10 +16,22 @@ class Decoder extends Transform {
return { gameId, keychipId }
}
static lookup(payload) {
const luid = payload.slice(0x0020, 0x002A)
return { luid, ...Decoder.ident(payload) }
}
_transform(chunk, encoding, callback) {
const cmd = chunk.readUInt16LE(0x04)
switch (cmd) {
case 0x000F:
return callback(null, {
cmd: 'lookup',
...Decoder.lookup(chunk),
})
case 0x0064:
return callback(null, {
cmd: 'hello',

View File

@@ -18,6 +18,30 @@ test('decode hello', () => {
const obj = decode(req)
expect(obj.cmd).toBe('hello')
expect(obj.gameId).toBe('SDBT')
expect(obj.keychipId).toBe('A69E01A9999')
})
test('decode lookup', () => {
const req = Buffer.from([
0x3e, 0xa1, 0x87, 0x30, 0x0f, 0x00, 0x30, 0x00,
0x00, 0x00, 0x53, 0x44, 0x42, 0x54, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x41, 0x36, 0x39, 0x45,
0x30, 0x31, 0x41, 0x39, 0x39, 0x39, 0x39, 0x00,
0x01, 0x03, 0x64, 0x95, 0x85, 0x05, 0x23, 0x03,
0x06, 0x76, 0x01, 0x02, 0x22, 0xc6, 0x4e, 0x00,
])
const obj = decode(req)
expect(obj.cmd).toBe('lookup')
expect(obj.gameId).toBe('SDBT')
expect(obj.keychipId).toBe('A69E01A9999')
expect(obj.luid).toEqual(
Buffer.from([
0x01, 0x03, 0x64, 0x95, 0x85, 0x05, 0x23, 0x03,
0x06, 0x76,
])
)
})