FindInformationEntry.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. namespace SMBLibrary.SMB1
  11. {
  12. public abstract class FindInformationEntry
  13. {
  14. private bool m_returnResumeKeys;
  15. public FindInformationEntry(bool returnResumeKeys)
  16. {
  17. m_returnResumeKeys = returnResumeKeys;
  18. }
  19. public abstract void WriteBytes(byte[] buffer, ref int offset, bool isUnicode);
  20. public abstract int GetLength(bool isUnicode);
  21. public bool ReturnResumeKeys
  22. {
  23. get
  24. {
  25. return m_returnResumeKeys;
  26. }
  27. }
  28. public static FindInformationEntry ReadEntry(byte[] buffer, ref int offset, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys)
  29. {
  30. switch (informationLevel)
  31. {
  32. case FindInformationLevel.SMB_INFO_STANDARD:
  33. return new FindInfoStandard(buffer, ref offset, isUnicode, returnResumeKeys);
  34. case FindInformationLevel.SMB_INFO_QUERY_EA_SIZE:
  35. return new FindInfoQueryEASize(buffer, ref offset, isUnicode, returnResumeKeys);
  36. case FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST:
  37. return new FindInfoQueryExtendedAttributesFromList(buffer, ref offset, isUnicode, returnResumeKeys);
  38. case FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO:
  39. return new FindFileDirectoryInfo(buffer, ref offset, isUnicode);
  40. case FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO:
  41. return new FindFileFullDirectoryInfo(buffer, ref offset, isUnicode);
  42. case FindInformationLevel.SMB_FIND_FILE_NAMES_INFO:
  43. return new FindFileNamesInfo(buffer, ref offset, isUnicode);
  44. case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
  45. return new FindFileBothDirectoryInfo(buffer, ref offset, isUnicode);
  46. default:
  47. throw new InvalidRequestException();;
  48. }
  49. }
  50. }
  51. }