DecodeNetBIOSName.mjs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @author n1474335 [n1474335@gmail.com]
  3. * @copyright Crown Copyright 2017
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation";
  7. /**
  8. * Decode NetBIOS Name operation
  9. */
  10. class DecodeNetBIOSName extends Operation {
  11. /**
  12. * DecodeNetBIOSName constructor
  13. */
  14. constructor() {
  15. super();
  16. this.name = "Decode NetBIOS Name";
  17. this.module = "Default";
  18. this.description = "NetBIOS names as seen across the client interface to NetBIOS are exactly 16 bytes long. Within the NetBIOS-over-TCP protocols, a longer representation is used.<br><br>There are two levels of encoding. The first level maps a NetBIOS name into a domain system name. The second level maps the domain system name into the 'compressed' representation required for interaction with the domain name system.<br><br>This operation decodes the first level of encoding. See RFC 1001 for full details.";
  19. this.inputType = "byteArray";
  20. this.outputType = "byteArray";
  21. this.args = [
  22. {
  23. "name": "Offset",
  24. "type": "number",
  25. "value": 65
  26. }
  27. ];
  28. }
  29. /**
  30. * @param {byteArray} input
  31. * @param {Object[]} args
  32. * @returns {byteArray}
  33. */
  34. run(input, args) {
  35. const output = [],
  36. offset = args[0];
  37. if (input.length <= 32 && (input.length % 2) === 0) {
  38. for (let i = 0; i < input.length; i += 2) {
  39. output.push((((input[i] & 0xff) - offset) << 4) |
  40. (((input[i + 1] & 0xff) - offset) & 0xf));
  41. }
  42. for (let i = output.length - 1; i > 0; i--) {
  43. if (output[i] === 32) output.splice(i, i);
  44. else break;
  45. }
  46. }
  47. return output;
  48. }
  49. }
  50. export default DecodeNetBIOSName;