OpenResults.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Copyright (C) 2014 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 OpenResult OpenResult;
  16. public bool OpLockGranted;
  17. public OpenResults(byte[] buffer, int offset)
  18. {
  19. OpenResult = (OpenResult)(buffer[offset] & 0x3);
  20. OpLockGranted = (buffer[offset + 1] & 0x80) > 0;
  21. }
  22. public void WriteBytes(byte[] buffer, int offset)
  23. {
  24. buffer[0] = (byte)OpenResult;
  25. if (OpLockGranted)
  26. {
  27. buffer[1] = 0x80;
  28. }
  29. else
  30. {
  31. buffer[1] = 0x00;
  32. }
  33. }
  34. public void WriteBytes(byte[] buffer, ref int offset)
  35. {
  36. WriteBytes(buffer, offset);
  37. offset += 2;
  38. }
  39. public static OpenResults Read(byte[] buffer, ref int offset)
  40. {
  41. offset += 2;
  42. return new OpenResults(buffer, offset - 2);
  43. }
  44. }
  45. }