1
0
mirror of synced 2025-02-25 14:04:49 +01:00

71 lines
1.6 KiB
JavaScript
Raw Normal View History

/**
* NetBIOS operations.
*
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2017
* @license Apache-2.0
*
* @namespace
*/
const NetBIOS = {
/**
* @constant
* @default
*/
OFFSET: 65,
/**
* Encode NetBIOS Name operation.
*
* @param {byteArray} input
* @param {Object[]} args
* @returns {byteArray}
*/
runEncodeName: function(input, args) {
2017-04-13 18:08:50 +01:00
let output = [],
offset = args[0];
if (input.length <= 16) {
let len = input.length;
input.length = 16;
input.fill(32, len, 16);
for (let i = 0; i < input.length; i++) {
output.push((input[i] >> 4) + offset);
output.push((input[i] & 0xf) + offset);
}
}
return output;
},
/**
* Decode NetBIOS Name operation.
*
* @param {byteArray} input
* @param {Object[]} args
* @returns {byteArray}
*/
runDecodeName: function(input, args) {
2017-04-13 18:08:50 +01:00
let output = [],
offset = args[0];
2017-12-15 19:53:09 -05:00
if (input.length <= 32 && (input.length % 2) === 0) {
for (let i = 0; i < input.length; i += 2) {
output.push((((input[i] & 0xff) - offset) << 4) |
(((input[i + 1] & 0xff) - offset) & 0xf));
}
2017-12-19 14:12:18 +00:00
for (let i = output.length - 1; i > 0; i--) {
if (output[i] === 32) output.splice(i, i);
else break;
}
}
return output;
},
};
export default NetBIOS;