FileInformation.cs 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (C) 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 Utilities;
  10. namespace SMBLibrary
  11. {
  12. public abstract class FileInformation
  13. {
  14. public abstract void WriteBytes(byte[] buffer, int offset);
  15. public byte[] GetBytes()
  16. {
  17. byte[] buffer = new byte[this.Length];
  18. WriteBytes(buffer, 0);
  19. return buffer;
  20. }
  21. public abstract FileInformationClass FileInformationClass
  22. {
  23. get;
  24. }
  25. public abstract int Length
  26. {
  27. get;
  28. }
  29. public static FileInformation GetFileInformation(byte[] buffer, int offset, FileInformationClass informationClass)
  30. {
  31. switch (informationClass)
  32. {
  33. case FileInformationClass.FileBasicInformation:
  34. return new FileBasicInformation(buffer, offset);
  35. case FileInformationClass.FileStandardInformation:
  36. return new FileStandardInformation(buffer, offset);
  37. case FileInformationClass.FileInternalInformation:
  38. return new FileInternalInformation(buffer, offset);
  39. case FileInformationClass.FileEaInformation:
  40. return new FileEaInformation(buffer, offset);
  41. case FileInformationClass.FileAccessInformation:
  42. return new FileAccessInformation(buffer, offset);
  43. case FileInformationClass.FileRenameInformation:
  44. return new FileRenameInformationType2(buffer, offset);
  45. case FileInformationClass.FileLinkInformation:
  46. return new FileLinkInformationType2(buffer, offset);
  47. case FileInformationClass.FileNamesInformation:
  48. throw new NotImplementedException();
  49. case FileInformationClass.FileDispositionInformation:
  50. return new FileDispositionInformation(buffer, offset);
  51. case FileInformationClass.FilePositionInformation:
  52. return new FilePositionInformation(buffer, offset);
  53. case FileInformationClass.FileFullEaInformation:
  54. return new FileFullEAInformation(buffer, offset);
  55. case FileInformationClass.FileModeInformation:
  56. return new FileModeInformation(buffer, offset);
  57. case FileInformationClass.FileAlignmentInformation:
  58. return new FileAlignmentInformation(buffer, offset);
  59. case FileInformationClass.FileAllInformation:
  60. return new FileAllInformation(buffer, offset);
  61. case FileInformationClass.FileAllocationInformation:
  62. return new FileAllocationInformation(buffer, offset);
  63. case FileInformationClass.FileEndOfFileInformation:
  64. return new FileEndOfFileInformation(buffer, offset);
  65. case FileInformationClass.FileAlternateNameInformation:
  66. return new FileAlternateNameInformation(buffer, offset);
  67. case FileInformationClass.FileStreamInformation:
  68. return new FileStreamInformation(buffer, offset);
  69. case FileInformationClass.FilePipeInformation:
  70. throw new NotImplementedException();
  71. case FileInformationClass.FilePipeLocalInformation:
  72. throw new NotImplementedException();
  73. case FileInformationClass.FilePipeRemoteInformation:
  74. throw new NotImplementedException();
  75. case FileInformationClass.FileCompressionInformation:
  76. return new FileCompressionInformation(buffer, offset);
  77. case FileInformationClass.FileNetworkOpenInformation:
  78. return new FileNetworkOpenInformation(buffer, offset);
  79. case FileInformationClass.FileAttributeTagInformation:
  80. throw new NotImplementedException();
  81. case FileInformationClass.FileValidDataLengthInformation:
  82. return new FileValidDataLengthInformation(buffer, offset);
  83. case FileInformationClass.FileShortNameInformation:
  84. throw new NotImplementedException();
  85. default:
  86. throw new UnsupportedInformationLevelException();
  87. }
  88. }
  89. }
  90. }