manageiq-smartstate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (305) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +4 -0
  4. data/.rspec_ci +4 -0
  5. data/.travis.yml +15 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE.txt +202 -0
  8. data/README.md +45 -0
  9. data/Rakefile +23 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/MiqContainerGroup/MiqContainerGroup.rb +31 -0
  13. data/lib/MiqVm/MiqLocalVm.rb +50 -0
  14. data/lib/MiqVm/MiqRhevmVm.rb +179 -0
  15. data/lib/MiqVm/MiqVm.rb +355 -0
  16. data/lib/MiqVm/miq_azure_vm.rb +96 -0
  17. data/lib/MiqVm/miq_scvmm_vm.rb +38 -0
  18. data/lib/MiqVm/test/camcorder_fleece_test.rb +60 -0
  19. data/lib/MiqVm/test/localVm.rb +45 -0
  20. data/lib/MiqVm/test/partitionAlignmentCheck.rb +76 -0
  21. data/lib/MiqVm/test/remoteVm.rb +65 -0
  22. data/lib/MiqVm/test/rhevmNfsTest.rb +62 -0
  23. data/lib/MiqVm/test/rhevmNfsTest2.rb +66 -0
  24. data/lib/MiqVm/test/rhevmTest.rb +70 -0
  25. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackCommon.rb +107 -0
  26. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackImage.rb +67 -0
  27. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackInstance.rb +182 -0
  28. data/lib/Scvmm/miq_hyperv_disk.rb +273 -0
  29. data/lib/Scvmm/miq_scvmm_parse_powershell.rb +75 -0
  30. data/lib/Scvmm/miq_scvmm_vm_ssa_info.rb +135 -0
  31. data/lib/Scvmm/test/miq_hyperv_disk_test.rb +33 -0
  32. data/lib/Scvmm/test/miq_scvmm_vm_ssa_info_test.rb +41 -0
  33. data/lib/VmLocalDiskAccess/test/localCfg.rb +97 -0
  34. data/lib/VolumeManager/LVM/logical_volume.rb +75 -0
  35. data/lib/VolumeManager/LVM/lv_segment.rb +43 -0
  36. data/lib/VolumeManager/LVM/lvm2disk.rb +158 -0
  37. data/lib/VolumeManager/LVM/parser.rb +138 -0
  38. data/lib/VolumeManager/LVM/physical_volume.rb +19 -0
  39. data/lib/VolumeManager/LVM/scanner.rb +156 -0
  40. data/lib/VolumeManager/LVM/thin/btree.rb +83 -0
  41. data/lib/VolumeManager/LVM/thin/constants.rb +86 -0
  42. data/lib/VolumeManager/LVM/thin/data_map.rb +44 -0
  43. data/lib/VolumeManager/LVM/thin/mapping_tree.rb +19 -0
  44. data/lib/VolumeManager/LVM/thin/space_maps.rb +58 -0
  45. data/lib/VolumeManager/LVM/thin/superblock.rb +136 -0
  46. data/lib/VolumeManager/LVM/thin.rb +6 -0
  47. data/lib/VolumeManager/LVM/volume_group.rb +97 -0
  48. data/lib/VolumeManager/LVM.rb +8 -0
  49. data/lib/VolumeManager/MiqLdm.rb +546 -0
  50. data/lib/VolumeManager/MiqLvm.rb +17 -0
  51. data/lib/VolumeManager/MiqNativeVolumeManager.rb +150 -0
  52. data/lib/VolumeManager/MiqVolumeManager.rb +277 -0
  53. data/lib/VolumeManager/VolMgrPlatformSupport.rb +18 -0
  54. data/lib/VolumeManager/VolMgrPlatformSupportLinux.rb +77 -0
  55. data/lib/VolumeManager/VolMgrPlatformSupportWin.rb +17 -0
  56. data/lib/VolumeManager/test/blockDevTest.rb +40 -0
  57. data/lib/VolumeManager/test/ldm.rb +97 -0
  58. data/lib/blackbox/VmBlackBox.rb +103 -0
  59. data/lib/blackbox/xmlStorage.rb +180 -0
  60. data/lib/db/MiqBdb/MiqBdb.rb +309 -0
  61. data/lib/db/MiqBdb/MiqBdbBtree.rb +219 -0
  62. data/lib/db/MiqBdb/MiqBdbHash.rb +199 -0
  63. data/lib/db/MiqBdb/MiqBdbPage.rb +159 -0
  64. data/lib/db/MiqBdb/MiqBdbUtil.rb +18 -0
  65. data/lib/db/MiqSqlite/MiqSqlite3.rb +330 -0
  66. data/lib/db/MiqSqlite/MiqSqlite3Cell.rb +167 -0
  67. data/lib/db/MiqSqlite/MiqSqlite3Page.rb +151 -0
  68. data/lib/db/MiqSqlite/MiqSqlite3Table.rb +124 -0
  69. data/lib/db/MiqSqlite/MiqSqlite3Util.rb +32 -0
  70. data/lib/disk/DiskProbe.rb +68 -0
  71. data/lib/disk/MiqDisk.rb +317 -0
  72. data/lib/disk/camcorder_test.rb +90 -0
  73. data/lib/disk/dos_mbr.img +0 -0
  74. data/lib/disk/modules/AzureBlobDisk.rb +101 -0
  75. data/lib/disk/modules/LocalDevMod.rb +47 -0
  76. data/lib/disk/modules/LocalDevProbe.rb +6 -0
  77. data/lib/disk/modules/MSCommon.rb +352 -0
  78. data/lib/disk/modules/MSVSDiffDisk.rb +91 -0
  79. data/lib/disk/modules/MSVSDiskProbe.rb +61 -0
  80. data/lib/disk/modules/MSVSDynamicDisk.rb +42 -0
  81. data/lib/disk/modules/MSVSFixedDisk.rb +45 -0
  82. data/lib/disk/modules/MiqLargeFile.rb +63 -0
  83. data/lib/disk/modules/MiqLargeFileWin32.rb +107 -0
  84. data/lib/disk/modules/QcowDisk.rb +692 -0
  85. data/lib/disk/modules/QcowDiskProbe.rb +34 -0
  86. data/lib/disk/modules/RawBlockIO.rb +116 -0
  87. data/lib/disk/modules/RawDisk.rb +45 -0
  88. data/lib/disk/modules/RawDiskProbe.rb +7 -0
  89. data/lib/disk/modules/RhevmDescriptor.rb +167 -0
  90. data/lib/disk/modules/RhevmDiskProbe.rb +52 -0
  91. data/lib/disk/modules/VMWareCowdDisk.rb +207 -0
  92. data/lib/disk/modules/VMWareDescriptor.rb +214 -0
  93. data/lib/disk/modules/VMWareDiskProbe.rb +74 -0
  94. data/lib/disk/modules/VMWareSparseDisk.rb +189 -0
  95. data/lib/disk/modules/VhdxDisk.rb +625 -0
  96. data/lib/disk/modules/VhdxDiskProbe.rb +46 -0
  97. data/lib/disk/modules/VixDiskMod.rb +54 -0
  98. data/lib/disk/modules/VixDiskProbe.rb +6 -0
  99. data/lib/disk/modules/miq_disk_cache.rb +135 -0
  100. data/lib/disk/modules/miq_dummy_disk.rb +41 -0
  101. data/lib/disk/modules/vhdx_bat_entry.rb +10 -0
  102. data/lib/disk/test.rb +66 -0
  103. data/lib/fs/MetakitFS/MetakitFS.rb +530 -0
  104. data/lib/fs/MetakitFS/test/Makefile +14 -0
  105. data/lib/fs/MetakitFS/test/MkCollectFiles.rb +165 -0
  106. data/lib/fs/MetakitFS/test/MkSelectFiles.rb +30 -0
  107. data/lib/fs/MetakitFS/test/collect_files.yaml +70 -0
  108. data/lib/fs/MetakitFS/test/init.rb +3 -0
  109. data/lib/fs/MetakitFS/test/mk2vmdk.rb +64 -0
  110. data/lib/fs/MetakitFS/test/mk4test.c +92 -0
  111. data/lib/fs/MetakitFS/test/mkFsTest.rb +113 -0
  112. data/lib/fs/MetakitFS/test/proto.rb +97 -0
  113. data/lib/fs/MiqFS/FsProbe.rb +39 -0
  114. data/lib/fs/MiqFS/MiqFS.rb +515 -0
  115. data/lib/fs/MiqFS/modules/AUFSProbe.rb +26 -0
  116. data/lib/fs/MiqFS/modules/Ext3.rb +305 -0
  117. data/lib/fs/MiqFS/modules/Ext3Probe.rb +25 -0
  118. data/lib/fs/MiqFS/modules/Ext4.rb +304 -0
  119. data/lib/fs/MiqFS/modules/Ext4Probe.rb +25 -0
  120. data/lib/fs/MiqFS/modules/Fat32.rb +318 -0
  121. data/lib/fs/MiqFS/modules/Fat32Probe.rb +30 -0
  122. data/lib/fs/MiqFS/modules/HFSProbe.rb +18 -0
  123. data/lib/fs/MiqFS/modules/Iso9660.rb +293 -0
  124. data/lib/fs/MiqFS/modules/Iso9660Probe.rb +18 -0
  125. data/lib/fs/MiqFS/modules/LocalFS.rb +105 -0
  126. data/lib/fs/MiqFS/modules/NTFS.rb +287 -0
  127. data/lib/fs/MiqFS/modules/NTFSProbe.rb +21 -0
  128. data/lib/fs/MiqFS/modules/NativeFS.rb +155 -0
  129. data/lib/fs/MiqFS/modules/ReFSProbe.rb +17 -0
  130. data/lib/fs/MiqFS/modules/RealFS.rb +79 -0
  131. data/lib/fs/MiqFS/modules/RealFSProbe.rb +6 -0
  132. data/lib/fs/MiqFS/modules/Reiser4Probe.rb +18 -0
  133. data/lib/fs/MiqFS/modules/ReiserFS.rb +315 -0
  134. data/lib/fs/MiqFS/modules/ReiserFSProbe.rb +42 -0
  135. data/lib/fs/MiqFS/modules/UnionFSProbe.rb +18 -0
  136. data/lib/fs/MiqFS/modules/WebDAV.rb +127 -0
  137. data/lib/fs/MiqFS/modules/WebDAVFile.rb +68 -0
  138. data/lib/fs/MiqFS/modules/XFS.rb +300 -0
  139. data/lib/fs/MiqFS/modules/XFSProbe.rb +26 -0
  140. data/lib/fs/MiqFS/modules/ZFSProbe.rb +18 -0
  141. data/lib/fs/MiqFS/test.rb +59 -0
  142. data/lib/fs/MiqFsUtil.rb +383 -0
  143. data/lib/fs/MiqMountManager.rb +209 -0
  144. data/lib/fs/MiqNativeMountManager.rb +101 -0
  145. data/lib/fs/MountManagerProbe.rb +29 -0
  146. data/lib/fs/ReiserFS/block.rb +209 -0
  147. data/lib/fs/ReiserFS/directory.rb +136 -0
  148. data/lib/fs/ReiserFS/directory_entry.rb +140 -0
  149. data/lib/fs/ReiserFS/file_data.rb +111 -0
  150. data/lib/fs/ReiserFS/superblock.rb +140 -0
  151. data/lib/fs/ReiserFS/utils.rb +95 -0
  152. data/lib/fs/VimDatastoreFS/VimDatastoreFS.rb +192 -0
  153. data/lib/fs/ext3/alloc_bitmap.rb +38 -0
  154. data/lib/fs/ext3/block_pointers_path.rb +130 -0
  155. data/lib/fs/ext3/directory.rb +51 -0
  156. data/lib/fs/ext3/directory_entry.rb +67 -0
  157. data/lib/fs/ext3/ex_attrib_header.rb +14 -0
  158. data/lib/fs/ext3/ex_attrib_name.rb +23 -0
  159. data/lib/fs/ext3/file_data.rb +130 -0
  160. data/lib/fs/ext3/group_descriptor_entry.rb +65 -0
  161. data/lib/fs/ext3/group_descriptor_table.rb +54 -0
  162. data/lib/fs/ext3/hash_tree_entry.rb +18 -0
  163. data/lib/fs/ext3/hash_tree_header.rb +15 -0
  164. data/lib/fs/ext3/inode.rb +228 -0
  165. data/lib/fs/ext3/posix_acl_entry.rb +29 -0
  166. data/lib/fs/ext3/posix_acl_header.rb +11 -0
  167. data/lib/fs/ext3/superblock.rb +406 -0
  168. data/lib/fs/ext3/test/tc_Ext3BlockPointersPath.rb +74 -0
  169. data/lib/fs/ext4/alloc_bitmap.rb +38 -0
  170. data/lib/fs/ext4/directory.rb +87 -0
  171. data/lib/fs/ext4/directory_entry.rb +77 -0
  172. data/lib/fs/ext4/ex_attrib_header.rb +14 -0
  173. data/lib/fs/ext4/ex_attrib_name.rb +23 -0
  174. data/lib/fs/ext4/extent.rb +35 -0
  175. data/lib/fs/ext4/extent_header.rb +40 -0
  176. data/lib/fs/ext4/extent_index.rb +33 -0
  177. data/lib/fs/ext4/group_descriptor_entry.rb +69 -0
  178. data/lib/fs/ext4/group_descriptor_table.rb +54 -0
  179. data/lib/fs/ext4/hash_tree_entry.rb +58 -0
  180. data/lib/fs/ext4/hash_tree_header.rb +35 -0
  181. data/lib/fs/ext4/inode.rb +465 -0
  182. data/lib/fs/ext4/posix_acl_entry.rb +29 -0
  183. data/lib/fs/ext4/posix_acl_header.rb +11 -0
  184. data/lib/fs/ext4/superblock.rb +412 -0
  185. data/lib/fs/fat32/boot_sect.rb +379 -0
  186. data/lib/fs/fat32/directory.rb +222 -0
  187. data/lib/fs/fat32/directory_entry.rb +540 -0
  188. data/lib/fs/fat32/file_data.rb +128 -0
  189. data/lib/fs/iso9660/boot_sector.rb +170 -0
  190. data/lib/fs/iso9660/directory.rb +90 -0
  191. data/lib/fs/iso9660/directory_entry.rb +147 -0
  192. data/lib/fs/iso9660/file_data.rb +78 -0
  193. data/lib/fs/iso9660/rock_ridge.rb +329 -0
  194. data/lib/fs/iso9660/util.rb +57 -0
  195. data/lib/fs/modules/LinuxMount.rb +300 -0
  196. data/lib/fs/modules/LinuxMountProbe.rb +29 -0
  197. data/lib/fs/modules/WinMount.rb +97 -0
  198. data/lib/fs/modules/WinMountProbe.rb +24 -0
  199. data/lib/fs/ntfs/attrib_attribute_list.rb +131 -0
  200. data/lib/fs/ntfs/attrib_bitmap.rb +26 -0
  201. data/lib/fs/ntfs/attrib_data.rb +74 -0
  202. data/lib/fs/ntfs/attrib_file_name.rb +110 -0
  203. data/lib/fs/ntfs/attrib_header.rb +194 -0
  204. data/lib/fs/ntfs/attrib_index_allocation.rb +19 -0
  205. data/lib/fs/ntfs/attrib_index_root.rb +247 -0
  206. data/lib/fs/ntfs/attrib_object_id.rb +40 -0
  207. data/lib/fs/ntfs/attrib_standard_information.rb +107 -0
  208. data/lib/fs/ntfs/attrib_type.rb +49 -0
  209. data/lib/fs/ntfs/attrib_volume_information.rb +53 -0
  210. data/lib/fs/ntfs/attrib_volume_name.rb +31 -0
  211. data/lib/fs/ntfs/boot_sect.rb +253 -0
  212. data/lib/fs/ntfs/data_run.rb +358 -0
  213. data/lib/fs/ntfs/directory_index_node.rb +114 -0
  214. data/lib/fs/ntfs/index_node_header.rb +69 -0
  215. data/lib/fs/ntfs/index_record_header.rb +85 -0
  216. data/lib/fs/ntfs/mft_entry.rb +288 -0
  217. data/lib/fs/ntfs/utils.rb +43 -0
  218. data/lib/fs/test/camcorder_fs_test.rb +108 -0
  219. data/lib/fs/test/collect_files_direct.yaml +22 -0
  220. data/lib/fs/test/collect_files_in.yaml +24 -0
  221. data/lib/fs/test/collect_files_in_nc.yaml +22 -0
  222. data/lib/fs/test/collect_files_out.yaml +6 -0
  223. data/lib/fs/test/collect_files_rm.yaml +6 -0
  224. data/lib/fs/test/copyTest.rb +126 -0
  225. data/lib/fs/test/fsTest.rb +87 -0
  226. data/lib/fs/test/updateTest.rb +184 -0
  227. data/lib/fs/xfs/allocation_group.rb +160 -0
  228. data/lib/fs/xfs/bmap_btree_block.rb +125 -0
  229. data/lib/fs/xfs/bmap_btree_record.rb +80 -0
  230. data/lib/fs/xfs/bmap_btree_root_node.rb +72 -0
  231. data/lib/fs/xfs/directory.rb +133 -0
  232. data/lib/fs/xfs/directory2_data_header.rb +27 -0
  233. data/lib/fs/xfs/directory3_data_header.rb +34 -0
  234. data/lib/fs/xfs/directory_block_tail.rb +22 -0
  235. data/lib/fs/xfs/directory_data_header.rb +46 -0
  236. data/lib/fs/xfs/directory_entry.rb +106 -0
  237. data/lib/fs/xfs/inode.rb +532 -0
  238. data/lib/fs/xfs/inode_map.rb +100 -0
  239. data/lib/fs/xfs/short_form_directory_entry.rb +91 -0
  240. data/lib/fs/xfs/short_form_header.rb +44 -0
  241. data/lib/fs/xfs/superblock.rb +556 -0
  242. data/lib/lib/tasks/azure.rake +52 -0
  243. data/lib/manageiq/smartstate/version.rb +5 -0
  244. data/lib/manageiq/smartstate.rb +7 -0
  245. data/lib/manageiq-smartstate.rb +1 -0
  246. data/lib/metadata/MIQExtract/MIQExtract.rb +297 -0
  247. data/lib/metadata/MIQExtract/test/extractTest.rb +41 -0
  248. data/lib/metadata/MIQExtract/test/full_extract_test.rb +68 -0
  249. data/lib/metadata/ScanProfile/HostScanItem.rb +4 -0
  250. data/lib/metadata/ScanProfile/HostScanProfile.rb +4 -0
  251. data/lib/metadata/ScanProfile/HostScanProfiles.rb +41 -0
  252. data/lib/metadata/ScanProfile/ScanItemBase.rb +63 -0
  253. data/lib/metadata/ScanProfile/ScanProfileBase.rb +51 -0
  254. data/lib/metadata/ScanProfile/ScanProfilesBase.rb +60 -0
  255. data/lib/metadata/ScanProfile/VmScanItem.rb +4 -0
  256. data/lib/metadata/ScanProfile/VmScanProfile.rb +4 -0
  257. data/lib/metadata/ScanProfile/VmScanProfiles.rb +38 -0
  258. data/lib/metadata/ScanProfile/modules/HostScanItemFile.rb +51 -0
  259. data/lib/metadata/ScanProfile/modules/HostScanItemNteventlog.rb +84 -0
  260. data/lib/metadata/ScanProfile/modules/VmScanItemFile.rb +39 -0
  261. data/lib/metadata/ScanProfile/modules/VmScanItemNteventlog.rb +34 -0
  262. data/lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb +64 -0
  263. data/lib/metadata/VMMount/VMMount.rb +81 -0
  264. data/lib/metadata/VMMount/VMPlatformMount.rb +18 -0
  265. data/lib/metadata/VMMount/VMPlatformMountLinux.rb +75 -0
  266. data/lib/metadata/VMMount/VMPlatformMountWin.rb +13 -0
  267. data/lib/metadata/VmConfig/GetNativeCfg.rb +45 -0
  268. data/lib/metadata/VmConfig/VmConfig.rb +947 -0
  269. data/lib/metadata/VmConfig/cfgConfig.rb +45 -0
  270. data/lib/metadata/VmConfig/ovfConfig.rb +99 -0
  271. data/lib/metadata/VmConfig/test/GetVMwareCfgTest.rb +40 -0
  272. data/lib/metadata/VmConfig/vmcConfig.rb +116 -0
  273. data/lib/metadata/VmConfig/vmtxConfig.rb +4 -0
  274. data/lib/metadata/VmConfig/vmxConfig.rb +162 -0
  275. data/lib/metadata/VmConfig/xmlConfig.rb +79 -0
  276. data/lib/metadata/VmConfig/xmlMsHyperVConfig.rb +41 -0
  277. data/lib/metadata/linux/InitProcHash.rb +632 -0
  278. data/lib/metadata/linux/LinuxInitProcs.rb +142 -0
  279. data/lib/metadata/linux/LinuxOSInfo.rb +237 -0
  280. data/lib/metadata/linux/LinuxPackages.rb +209 -0
  281. data/lib/metadata/linux/LinuxSystemd.rb +130 -0
  282. data/lib/metadata/linux/LinuxUsers.rb +289 -0
  283. data/lib/metadata/linux/LinuxUtils.rb +197 -0
  284. data/lib/metadata/linux/MiqConaryPackages.rb +41 -0
  285. data/lib/metadata/linux/MiqRpmPackages.rb +160 -0
  286. data/lib/metadata/linux/test/Name +0 -0
  287. data/lib/metadata/linux/test/Packages +0 -0
  288. data/lib/metadata/linux/test/rpoTest.rb +5 -0
  289. data/lib/metadata/linux/test/tc_LinuxUtils.rb +4157 -0
  290. data/lib/metadata/util/event_log_filter.rb +61 -0
  291. data/lib/metadata/util/md5deep.rb +280 -0
  292. data/lib/metadata/util/win32/Win32Accounts.rb +764 -0
  293. data/lib/metadata/util/win32/Win32EventLog.rb +743 -0
  294. data/lib/metadata/util/win32/Win32Services.rb +86 -0
  295. data/lib/metadata/util/win32/Win32Software.rb +326 -0
  296. data/lib/metadata/util/win32/Win32System.rb +333 -0
  297. data/lib/metadata/util/win32/boot_info_win.rb +59 -0
  298. data/lib/metadata/util/win32/fleece_hives.rb +220 -0
  299. data/lib/metadata/util/win32/ms-registry.rb +650 -0
  300. data/lib/metadata/util/win32/peheader.rb +868 -0
  301. data/lib/metadata/util/win32/remote-registry.rb +142 -0
  302. data/lib/metadata/util/win32/system_path_win.rb +103 -0
  303. data/lib/metadata/util/win32/versioninfo.rb +17 -0
  304. data/manageiq-smartstate.gemspec +35 -0
  305. metadata +486 -0
@@ -0,0 +1,114 @@
1
+ require 'binary_struct'
2
+ require 'fs/ntfs/attrib_file_name'
3
+ require 'fs/ntfs/utils'
4
+
5
+ module NTFS
6
+ DIR_INDEX_NODE = BinaryStruct.new([
7
+ 'Q', 'mft_ref', # MFT file reference for file name (goofy ref).
8
+ 'S', 'length', # Length of entry.
9
+ 'S', 'content_len', # Length of $FILE_NAME attrib
10
+ 'L', 'flags', # See IN_ below (note: these will eventually become general flags)
11
+ ])
12
+ # Here follows a $FILE_NAME attribute if content_len > 0.
13
+ # Last 8 bytes starting on 8 byte boundary are the VCN of the child node in $INDEX_ALLOCATION (if IN_HAS_CHILD is set).
14
+ SIZEOF_DIR_INDEX_NODE = DIR_INDEX_NODE.size
15
+
16
+ class DirectoryIndexNode
17
+ IN_HAS_CHILD = 0x00000001
18
+ IN_LAST_ENTRY = 0x00000002
19
+
20
+ attr_reader :refMft, :length, :contentLen, :flags, :child, :afn, :mftEntry
21
+
22
+ def self.nodeFactory(buf)
23
+ nodes = []
24
+ loop do
25
+ node = DirectoryIndexNode.new(buf)
26
+ buf = buf[node.length..-1]
27
+ nodes << node
28
+ break if node.isLast?
29
+ end
30
+
31
+ nodes
32
+ end
33
+
34
+ def initialize(buf)
35
+ raise "MIQ(NTFS::DirectoryIndexNode.initialize) Nil buffer" if buf.nil?
36
+ buf = buf.read(buf.length) if buf.kind_of?(DataRun)
37
+ # Decode the directory index node structure.
38
+ @din = DIR_INDEX_NODE.decode(buf)
39
+
40
+ # Get accessor data.
41
+ @mftEntry = nil
42
+ @refMft = NTFS::Utils.MkRef(@din['mft_ref'])
43
+ @length = @din['length']
44
+ @contentLen = @din['content_len']
45
+ @flags = @din['flags']
46
+
47
+ # If there's a $FILE_NAME attrib get it.
48
+ @afn = FileName.new(buf[SIZEOF_DIR_INDEX_NODE, buf.size]) if @contentLen > 0
49
+
50
+ # If there's a child node VCN get it.
51
+ if NTFS::Utils.gotBit?(@flags, IN_HAS_CHILD)
52
+ # Child node VCN is located 8 bytes before 'length' bytes.
53
+ # NOTE: If the node has 0 contents, it's offset 16.
54
+ @child = buf[@contentLen == 0 ? 16 : @length - 8, 8].unpack('Q')[0]
55
+ if @child.class == Bignum
56
+ # buf.hex_dump(:obj => STDOUT, :meth => :puts, :newline => false)
57
+ raise "MIQ(NTFS::DirectoryIndexNode.initialize) Bad child node: #{@child}"
58
+ end
59
+ end
60
+ end
61
+
62
+ # String rep.
63
+ def to_s
64
+ "\#<#{self.class}:0x#{'%08x' % object_id} name='#{name}'>"
65
+ end
66
+
67
+ # Return file name (if resolved).
68
+ def name
69
+ @afn.nil? ? nil : @afn.name
70
+ end
71
+
72
+ # Return namespace.
73
+ def namespace
74
+ @afn.nil? ? nil : @afn.namespace
75
+ end
76
+
77
+ # Return true if has children.
78
+ def hasChild?
79
+ NTFS::Utils.gotBit?(@flags, IN_HAS_CHILD)
80
+ end
81
+
82
+ # Return true if this is the last entry.
83
+ def isLast?
84
+ NTFS::Utils.gotBit?(@flags, IN_LAST_ENTRY)
85
+ end
86
+
87
+ # If content is 0, then obviously not a directory.
88
+ def isDir?
89
+ return false if @contentLen == 0
90
+ @mftEntry.isDir?
91
+ end
92
+
93
+ # Resolves this node's file reference.
94
+ def resolve(bs)
95
+ if @contentLen > 0
96
+ @mftEntry = bs.mftEntry(@refMft[1])
97
+ raise "MIQ(NTFS::DirectoryIndexNode.resolve) Stale reference: #{inspect}" if @refMft[0] != @mftEntry.sequenceNum
98
+ end
99
+ @mftEntry
100
+ end
101
+
102
+ # Dumps object.
103
+ def dump
104
+ out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
105
+ out << " Mft Ref : seq #{@refMft[0]}, entry #{@refMft[1]}\n"
106
+ out << " Length : #{@length}\n"
107
+ out << " Content : #{@contentLen}\n"
108
+ out << " Flags : 0x#{'%08x' % @flags}\n"
109
+ out << @afn.dump if @contentLen > 0
110
+ out << " Child ref: #{@child}\n" if NTFS::Utils.gotBit?(@flags, IN_HAS_CHILD)
111
+ out << "---\n"
112
+ end
113
+ end
114
+ end # module NTFS
@@ -0,0 +1,69 @@
1
+ require 'binary_struct'
2
+
3
+ module NTFS
4
+ #
5
+ # INDEX_HEADER
6
+ #
7
+ # This is the header for indexes, describing the INDEX_ENTRY records, which
8
+ # follow the INDEX_HEADER. Together the index header and the index entries
9
+ # make up a complete index.
10
+ #
11
+ # IMPORTANT NOTE: The offset, length and size structure members are counted
12
+ # relative to the start of the index header structure and not relative to the
13
+ # start of the index root or index allocation structures themselves.
14
+ #
15
+
16
+ INDEX_NODE_HEADER = BinaryStruct.new([
17
+ 'L', 'entries_offset', # Byte offset from the INDEX_HEADER to first INDEX_ENTRY, aligned to 8-byte boundary
18
+ 'L', 'index_length', # Data size in byte of the INDEX_ENTRY's, including the INDEX_HEADER, aligned to 8.
19
+ 'L', 'allocated_size', # Offset to end of allocated index entry list buffer (relative to start of node header).
20
+
21
+ #
22
+ # For the index root attribute, the above two numbers are always
23
+ # equal, as the attribute is resident and it is resized as needed.
24
+ #
25
+ # For the index allocation attribute, the attribute is not resident
26
+ # and the allocated_size is equal to the index_block_size specified
27
+ # by the corresponding INDEX_ROOT attribute minus the INDEX_BLOCK
28
+ # size not counting the INDEX_HEADER part (i.e. minus -24).
29
+ #
30
+
31
+ 'L', 'flags', # See NH_ below.
32
+ ])
33
+ SIZEOF_INDEX_NODE_HEADER = INDEX_NODE_HEADER.size
34
+ # Here follows a list of IndexNodeEntries.
35
+
36
+ class IndexNodeHeader
37
+ NH_HAS_CHILDREN = 0x0001
38
+
39
+ attr_reader :startEntries, :endEntries, :flags
40
+
41
+ def initialize(buf)
42
+ raise "MIQ(NTFS::IndexNodeHeader.initialize) Nil buffer" if buf.nil?
43
+ buf = buf.read(buf.length) if buf.kind_of?(DataRun)
44
+ @inh = INDEX_NODE_HEADER.decode(buf)
45
+
46
+ # Get accessor data.
47
+ @flags = @inh['flags']
48
+ @endEntries = @inh['index_length']
49
+ @startEntries = @inh['entries_offset']
50
+ end
51
+
52
+ def to_s
53
+ "0x#{'%08x' % @flags}"
54
+ end
55
+
56
+ def hasChildren?
57
+ (@flags & NH_HAS_CHILDREN) == NH_HAS_CHILDREN
58
+ end
59
+
60
+ def dump
61
+ out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
62
+ out << " Entries Offset : #{@startEntries}\n"
63
+ out << " Index Length : #{@endEntries}\n"
64
+ out << " Allocated Size : #{@inh['allocated_size']}\n"
65
+ out << " Flags : 0x#{'%08x' % @flags}\n"
66
+ out << "---\n"
67
+ end
68
+ end
69
+ end # module NTFS
@@ -0,0 +1,85 @@
1
+ require 'fs/ntfs/utils'
2
+ require 'binary_struct'
3
+
4
+ module NTFS
5
+ #
6
+ # INDEX_BLOCK - Attribute: Index allocation (0xa0).
7
+ #
8
+ # NOTE: Always non-resident (doesn't make sense to be resident anyway!).
9
+ #
10
+ # This is an array of index blocks. Each index block starts with an
11
+ # INDEX_BLOCK structure containing an index header, followed by a sequence of
12
+ # index entries (INDEX_ENTRY structures), as described by the INDEX_HEADER.
13
+ #
14
+
15
+ INDEX_RECORD_HEADER = BinaryStruct.new([
16
+ 'a4', 'signature', # Always 'INDX'
17
+ 'S', 'usa_offset', # Offset to the Update Sequence Array (usa) from the start of the ntfs record.
18
+ 'S', 'usa_count', # Number of u16 sized entries in the usa including the Update Sequence Number (usn),
19
+ # thus the number of fixups is the usa_count minus 1.
20
+ 'Q', 'lsn', # $LogFile sequence number of the last modification of this index block
21
+ 'Q', 'index_block_vcn', # VCN of this record in the full index stream.
22
+ ])
23
+ # Here follows the fixup array.
24
+ # Here follows an index node header.
25
+ SIZEOF_INDEX_RECORD_HEADER = INDEX_RECORD_HEADER.size
26
+
27
+ class IndexRecordHeader
28
+ EXPECTED_SIGNATURE = 'INDX'
29
+
30
+ attr_reader :valid, :signature, :vcn
31
+ attr_accessor :data
32
+
33
+ def self.size
34
+ SIZEOF_INDEX_RECORD_HEADER
35
+ end
36
+
37
+ def initialize(buf, bps)
38
+ log_prefix = "MIQ(NTFS::IndexRecordHeader.initialize)"
39
+ raise "#{log_prefix} Nil buffer" if buf.nil?
40
+ raise "#{log_prefix} Nil bytes per sector" if bps.nil?
41
+
42
+ buf = buf.read(buf.length) if buf.kind_of?(DataRun)
43
+ @data = buf
44
+ @bps = bps
45
+
46
+ # Decode the index record header structure.
47
+ @irh = INDEX_RECORD_HEADER.decode(buf)
48
+ @signature = @irh['signature']
49
+ @vcn = @irh['index_block_vcn']
50
+ @valid = true
51
+
52
+ begin
53
+ # Check for proper signature.
54
+ NTFS::Utils.validate_signature(@irh['signature'], EXPECTED_SIGNATURE)
55
+ # Process per-sector "fixups" that NTFS uses to detect corruption of multi-sector data structures
56
+ @data = NTFS::Utils.process_fixups(@data, @bps, @irh['usa_offset'], @irh['usa_count'])
57
+ rescue => err
58
+ @valid = false
59
+ $log.error("#{log_prefix} Invalid Index Record Header because: <#{err.message}>\n#{dump}")
60
+ end
61
+ end
62
+
63
+ def isValid?
64
+ @valid
65
+ end
66
+
67
+ def to_s
68
+ @irh['signature']
69
+ end
70
+
71
+ def dump(withData = nil)
72
+ out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
73
+ out << " Signature : #{@irh['signature']}\n"
74
+ out << " USA Offset : #{@irh['usa_offset']}\n"
75
+ out << " USA Count : #{@irh['usa_count']}\n"
76
+ out << " $LogFile sequence number : #{@irh['lsn']}\n"
77
+ out << " Index Block VCN : #{@irh['index_block_vcn']}\n"
78
+ if withData
79
+ out << "Raw Data:\n"
80
+ out << @data.hex_dump
81
+ end
82
+ out << "---\n"
83
+ end
84
+ end
85
+ end # module NTFS
@@ -0,0 +1,288 @@
1
+ # Utilities.
2
+ require 'binary_struct'
3
+ require 'fs/ntfs/utils'
4
+
5
+ # Attribute types & names.
6
+ require 'fs/ntfs/attrib_type'
7
+
8
+ # Classes.
9
+
10
+ # An attribute header preceeds each attribute.
11
+ require 'fs/ntfs/attrib_header'
12
+
13
+ # A data run is storage for non-resident attributes.
14
+ require 'fs/ntfs/data_run'
15
+
16
+ # These are the attribute types (so far these are the only types processed).
17
+ require 'fs/ntfs/attrib_attribute_list'
18
+ require 'fs/ntfs/attrib_bitmap'
19
+ require 'fs/ntfs/attrib_standard_information'
20
+ require 'fs/ntfs/attrib_file_name'
21
+ require 'fs/ntfs/attrib_object_id'
22
+ require 'fs/ntfs/attrib_volume_name'
23
+ require 'fs/ntfs/attrib_volume_information'
24
+ require 'fs/ntfs/attrib_data'
25
+ require 'fs/ntfs/attrib_index_root'
26
+ require 'fs/ntfs/attrib_index_allocation'
27
+
28
+ module NTFS
29
+ #
30
+ # MFT_RECORD - An MFT record layout
31
+ #
32
+ # The mft record header present at the beginning of every record in the mft.
33
+ # This is followed by a sequence of variable length attribute records which
34
+ # is terminated by an attribute of type AT_END which is a truncated attribute
35
+ # in that it only consists of the attribute type code AT_END and none of the
36
+ # other members of the attribute structure are present.
37
+ #
38
+
39
+ # One MFT file record, also called MFT Entry.
40
+ FILE_RECORD = BinaryStruct.new([
41
+ 'a4', 'signature', # Always 'FILE'
42
+ 'S', 'usa_offset', # Offset to the Update Sequence Array (usa) from the start of the ntfs record.
43
+ 'S', 'usa_count', # Number of u16 sized entries in the usa including the Update Sequence Number (usn),
44
+ # thus the number of fixups is the usa_count minus 1.
45
+ 'Q', 'lsn', # $LogFile sequence number for this record.
46
+ # Changed every time the record is modified
47
+ 'S', 'seq_num', # Number of times this MFT record has been reused
48
+ 'S', 'hard_link_count', # Number of links to this file
49
+ 'S', 'offset_to_attrib', # Byte offset to the first attribute in this mft record from the start of the mft record.
50
+ # NOTE: Must be aligned to 8-byte boundary.
51
+ 'S', 'flags', # File record flags
52
+ 'L', 'bytes_in_use', # Number of bytes used in this mft record.
53
+ # NOTE: Must be aligned to 8-byte boundary.
54
+ 'L', 'bytes_allocated', # Number of bytes allocated for this mft record. This should be equal
55
+ # to the mft record size
56
+ 'Q', 'base_mft_record', # This is zero for base mft records. When it is not zero it is a mft reference
57
+ # pointing to the base mft record to which this record belongs (this is then
58
+ # used to locate the attribute list attribute present in the base record which
59
+ # describes this extension record and hence might need modification when the
60
+ # extension record itself is modified, also locating the attribute list also
61
+ # means finding the other potential extents, belonging to the non-base mft record).
62
+ 'S', 'next_attrib_id', # The instance number that will be assigned to the next attribute added to this
63
+ # mft record.
64
+ # NOTE: Incremented each time after it is used.
65
+ # NOTE: Every time the mft record is reused this number is set to zero.
66
+ # NOTE: The first instance number is always 0
67
+
68
+ #
69
+ # The 2 fields below are specific to NTFS 3.1+ (Windows XP and above):
70
+ #
71
+ 'S', 'unused1', # Reserved/alignment
72
+ 'L', 'mft_rec_num', # Number of this mft record.
73
+
74
+ # When (re)using the mft record, we place the update sequence array at this
75
+ # offset, i.e. before we start with the attributes. This also makes sense,
76
+ # otherwise we could run into problems with the update sequence array
77
+ # containing in itself the last two bytes of a sector which would mean that
78
+ # multi sector transfer protection wouldn't work. As you can't protect data
79
+ # by overwriting it since you then can't get it back...
80
+ # When reading we obviously use the data from the ntfs record header.
81
+ #
82
+ 'S', 'fixup_seq_num', # Magic word at end of sector
83
+ ])
84
+ # Here follows the fixup array (WORD).
85
+ SIZEOF_FILE_RECORD = FILE_RECORD.size
86
+
87
+ # MftEntry represents one single MFT entry.
88
+ class MftEntry
89
+ DEBUG_TRACE_MFT = false && $log
90
+
91
+ attr_reader :sequenceNum, :recNum, :boot_sector, :mft_entry, :attribs
92
+
93
+ MFT_RECORD_IN_USE = 0x0001 # Not set if file has been deleted
94
+ MFT_RECORD_IS_DIRECTORY = 0x0002 # Set if record describes a directory
95
+ MFT_RECORD_IS_4 = 0x0004 # MFT_RECORD_IS_4 exists on all $Extend sub-files. It seems that it marks it is a metadata file with MFT record >24, however, it is unknown if it is limited to metadata files only.
96
+ MFT_RECORD_IS_VIEW_INDEX = 0x0008 # MFT_RECORD_IS_VIEW_INDEX exists on every metafile with a non directory index, that means an INDEX_ROOT and an INDEX_ALLOCATION with a name other than "$I30". It is unknown if it is limited to metadata files only.
97
+
98
+ EXPECTED_SIGNATURE = 'FILE'
99
+
100
+ def initialize(bs, recordNumber)
101
+ log_prefix = "MIQ(NTFS::MftEntry.initialize)"
102
+ raise "#{log_prefix} Nil boot sector" if bs.nil?
103
+
104
+ @attribs = []
105
+ @attribs_by_type = Hash.new { |h, k| h[k] = [] }
106
+
107
+ # Buffer boot sector & seek to requested record.
108
+ @boot_sector = bs
109
+ bs.stream.seek(bs.mftRecToBytePos(recordNumber))
110
+
111
+ # Get & decode the FILE_RECORD.
112
+ @buf = bs.stream.read(bs.bytesPerFileRec)
113
+ @mft_entry = FILE_RECORD.decode(@buf)
114
+
115
+ # Adjust for older versions (don't have unused1 and mft_rec_num).
116
+ version = bs.version
117
+ if !version.nil? && version < 4.0
118
+ @mft_entry['fixup_seq_num'] = @mft_entry['unused1']
119
+ @mft_entry['mft_rec_num'] = recordNumber
120
+ end
121
+
122
+ # Set accessor data.
123
+ @sequenceNum = @mft_entry['seq_num']
124
+ @recNum = @mft_entry['mft_rec_num']
125
+ @flags = @mft_entry['flags']
126
+
127
+ begin
128
+ # Check for proper signature.
129
+ NTFS::Utils.validate_signature(@mft_entry['signature'], EXPECTED_SIGNATURE)
130
+ # Process per-sector "fixups" that NTFS uses to detect corruption of multi-sector data structures
131
+ @buf = NTFS::Utils.process_fixups(@buf, @boot_sector.bytesPerSector, @mft_entry['usa_offset'], @mft_entry['usa_count'])
132
+ rescue => err
133
+ emsg = "#{log_prefix} Invalid MFT Entry <#{recordNumber}> because: <#{err.message}>"
134
+ $log.error("#{emsg}\n#{dump}")
135
+ raise emsg
136
+ end
137
+
138
+ @buf = @buf[@mft_entry['offset_to_attrib']..-1]
139
+
140
+ loadAttributeHeaders
141
+ end
142
+
143
+ # For string rep, if valid return record number.
144
+ def to_s
145
+ @mft_entry['mft_rec_num'].to_s
146
+ end
147
+
148
+ def isDeleted?
149
+ !NTFS::Utils.gotBit?(@flags, MFT_RECORD_IN_USE)
150
+ end
151
+
152
+ def isDir?
153
+ NTFS::Utils.gotBit?(@flags, MFT_RECORD_IS_DIRECTORY)
154
+ end
155
+
156
+ def indexRoot
157
+ if @indexRoot.nil?
158
+ @indexRoot = getFirstAttribute(AT_INDEX_ROOT)
159
+ @indexRoot.bitmap = getFirstAttribute(AT_BITMAP) unless @indexRoot.nil?
160
+ @indexRoot.allocations = getAttributes(AT_INDEX_ALLOCATION) unless @indexRoot.nil?
161
+ end
162
+
163
+ @indexRoot
164
+ end
165
+
166
+ def attributeData
167
+ if @attributeData.nil?
168
+ dataArray = getAttributes(AT_DATA)
169
+
170
+ unless dataArray.nil?
171
+ dataArray.compact!
172
+ if dataArray.size > 0
173
+ @attributeData = dataArray.shift
174
+ dataArray.each { |datum| @attributeData.data.addRun(datum.run) }
175
+ end
176
+ end
177
+ end
178
+
179
+ @attributeData
180
+ end
181
+
182
+ def rootAttributeData
183
+ loadFirstAttribute(AT_DATA)
184
+ end
185
+
186
+ def attributeList
187
+ @attributeList ||= loadFirstAttribute(AT_ATTRIBUTE_LIST)
188
+ end
189
+
190
+ def loadAttributeHeaders
191
+ offset = 0
192
+ while h = AttribHeader.new(@buf[offset..-1])
193
+ break if h.type.nil? || h.type == AT_END
194
+ $log.debug "NtfsMftEntry.loadAttributeHeaders - MFT(#{@recNum}) adding Attr: #{h.typeName}" if DEBUG_TRACE_MFT
195
+ attrib = {"type" => h.type, "offset" => offset, "header" => h}
196
+ @attribs << attrib
197
+ @attribs_by_type[h.type] << attrib
198
+ offset += h.length
199
+ end
200
+ @attribs_by_type.each { |k, v| $log.debug "NtfsMftEntry.loadAttributeHeaders - MFT(#{@recNum}) Attr: #{TypeName[k]} => Count: #{v.size}" } if DEBUG_TRACE_MFT
201
+ end
202
+
203
+ def getFirstAttribute(attribType)
204
+ getAttributes(attribType).first
205
+ end
206
+
207
+ def getAttributes(attribType)
208
+ $log.debug "NtfsMftEntry.getAttributes - MFT(#{@recNum}) getting Attr: #{TypeName[attribType]}" if DEBUG_TRACE_MFT
209
+ attributeList.nil? ? loadAttributes(attribType) : attributeList.loadAttributes(attribType)
210
+ end
211
+
212
+ def loadFirstAttribute(attribType)
213
+ loadAttributes(attribType).first
214
+ end
215
+
216
+ def loadAttributes(attribType)
217
+ result = []
218
+ if @attribs_by_type.key?(attribType)
219
+ $log.debug "NtfsMftEntry.loadAttributes - MFT(#{@recNum}) loading Attr: #{TypeName[attribType]}" if DEBUG_TRACE_MFT
220
+
221
+ @attribs_by_type[attribType].each do |attrib|
222
+ attrib["attr"] = createAttribute(attrib["offset"], attrib["header"]) unless attrib.key?('attr')
223
+ result << attrib["attr"]
224
+ end
225
+ end
226
+ result
227
+ end
228
+
229
+ def createAttribute(offset, header)
230
+ $log.debug "NtfsMftEntry.createAttribute >> type=#{TypeName[header.type]} header=#{header.inspect}" if DEBUG_TRACE_MFT
231
+
232
+ buf = header.get_value(@buf[offset..-1], @boot_sector)
233
+
234
+ return StandardInformation.new(buf) if header.type == AT_STANDARD_INFORMATION
235
+ return FileName.new(buf) if header.type == AT_FILE_NAME
236
+ return ObjectId.new(buf) if header.type == AT_OBJECT_ID
237
+ return VolumeName.new(buf) if header.type == AT_VOLUME_NAME
238
+ return VolumeInformation.new(buf) if header.type == AT_VOLUME_INFORMATION
239
+ return AttributeList.new(buf, @boot_sector) if header.type == AT_ATTRIBUTE_LIST
240
+ return AttribData.create_from_header(header, buf) if header.type == AT_DATA
241
+ return IndexRoot.create_from_header(header, buf, @boot_sector) if header.type == AT_INDEX_ROOT
242
+ return IndexAllocation.create_from_header(header, buf) if header.type == AT_INDEX_ALLOCATION
243
+ return Bitmap.create_from_header(header, buf) if header.type == AT_BITMAP
244
+
245
+ # Attribs are unrecognized if they don't appear in TypeName.
246
+ unless TypeName.key?(header.type)
247
+ msg = "MIQ(NTFS::MftEntry.createAttribute) Unrecognized attribute type: 0x#{'%08x' % header.type} -- header: #{header.inspect}"
248
+ $log.warn(msg) if $log
249
+ raise(msg)
250
+ end
251
+
252
+ nil
253
+ end
254
+
255
+ def dump
256
+ ref = NTFS::Utils.MkRef(@mft_entry['base_mft_record'])
257
+
258
+ out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
259
+ out << " Signature : #{@mft_entry['signature']}\n"
260
+ out << " USA Offset : #{@mft_entry['usa_offset']}\n"
261
+ out << " USA Count : #{@mft_entry['usa_count']}\n"
262
+ out << " Log file seq num: #{@mft_entry['lsn']}\n"
263
+ out << " Sequence number : #{@mft_entry['seq_num']}\n"
264
+ out << " Hard link count : #{@mft_entry['hard_link_count']}\n"
265
+ out << " Offset to attrib: #{@mft_entry['offset_to_attrib']}\n"
266
+ out << " Flags : 0x#{'%04x' % @mft_entry['flags']}\n"
267
+ out << " Real size of rec: #{@mft_entry['bytes_in_use']}\n"
268
+ out << " Alloc siz of rec: #{@mft_entry['bytes_allocated']}\n"
269
+ out << " Ref to base rec : seq #{ref[0]}, entry #{ref[1]}\n"
270
+ out << " Next attrib id : #{@mft_entry['next_attrib_id']}\n"
271
+ out << " Unused1 : #{@mft_entry['unused1']}\n"
272
+ out << " MFT rec num : #{@mft_entry['mft_rec_num']}\n"
273
+ out << " Fixup seq num : 0x#{'%04x' % @mft_entry['fixup_seq_num']}\n"
274
+ @attribs.each do |hash|
275
+ begin
276
+ header = hash["header"]
277
+ out << header.dump
278
+
279
+ attrib = hash["attr"]
280
+ out << attrib.dump unless attrib.nil?
281
+ rescue NoMethodError
282
+ end
283
+ end
284
+
285
+ out
286
+ end
287
+ end
288
+ end # module NTFS
@@ -0,0 +1,43 @@
1
+ # encoding: US-ASCII
2
+
3
+ module NTFS
4
+ module Utils
5
+ # Make a reference (upper two bytes are seq num, lower six are entry).
6
+ def self.MkRef(ref)
7
+ ref.divmod(2**48)
8
+ end
9
+
10
+ def self.gotBit?(flags, bit)
11
+ (flags & bit) == bit
12
+ end
13
+
14
+ # Process per-sector "fixups" that NTFS uses to detect corruption of
15
+ # multi-sector data structures, like MFT records.
16
+ def self.process_fixups(buf, fixup_offset, usa_offset, usa_count)
17
+ #
18
+ # The signature value we must look for is stored just before the fix-up array.
19
+ #
20
+ fu_sig = buf[usa_offset, 2].unpack('S')[0]
21
+
22
+ #
23
+ # For each end-of-sector, check that the last two bytes equal the fixup signature.
24
+ # If so, replace them with original data stored in the update sequence array.
25
+ #
26
+ 1.upto(usa_count - 1) do |i|
27
+ sig = buf[i * fixup_offset - 2, 2].unpack('S')[0]
28
+ raise "NTFS Fixup Error: fixup signature:<#{fu_sig}> does not match signature[#{i}]=<#{sig}> - consider running chkdsk" if sig != fu_sig
29
+ buf[i * fixup_offset - 2, 2] = buf[i * 2 + usa_offset, 2]
30
+ end
31
+
32
+ buf
33
+ end
34
+
35
+ def self.validate_signature(signature, expected)
36
+ if signature != expected
37
+ raise "Uninitialized" if signature == "\000\000\000\000"
38
+ raise "Bad Sector" if signature == 'BAAD'
39
+ raise "Invalid Signature <#{signature}>"
40
+ end
41
+ end
42
+ end
43
+ end