OpenResults.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. public struct OpenResults // 2 bytes
  14. {
  15. public const int Length = 2;
  16. public OpenResult OpenResult;
  17. public bool OpLockGranted;
  18. public OpenResults(byte[] buffer, int offset)
  19. {
  20. OpenResult = (OpenResult)(buffer[offset + 0] & 0x3);
  21. OpLockGranted = (buffer[offset + 1] & 0x80) > 0;
  22. }
  23. public void WriteBytes(byte[] buffer, int offset)
  24. {
  25. buffer[offset + 0] = (byte)OpenResult;
  26. if (OpLockGranted)
  27. {
  28. buffer[offset + 1] = 0x80;
  29. }
  30. else
  31. {
  32. buffer[offset + 1] = 0x00;
  33. }
  34. }
  35. public void WriteBytes(byte[] buffer, ref int offset)
  36. {
  37. WriteBytes(buffer, offset);
  38. offset += Length;
  39. }
  40. public static OpenResults Read(byte[] buffer, ref int offset)
  41. {
  42. offset += Length;
  43. return new OpenResults(buffer, offset - Length);
  44. }
  45. }
  46. }