public void FileContent_ZlibAttribute_Compressed() { var nodeId = new CatalogNodeId(1); byte[] compressionAttribute = Convert.FromBase64String("AAAAEAAAAAAAAAAAAAAALWZwbWMDAAAAKgAAAAAAAAB4XksqyMksLjEwuMDBAAaMjAxQBgMq4AQAjygD0wA="); var attributes = new Mock <BTree <AttributeKey> >(MockBehavior.Strict); attributes .Setup(a => a.Find(new AttributeKey(nodeId, "com.apple.decmpfs"))) .Returns(compressionAttribute); var context = new Context() { Attributes = attributes.Object, }; var catalogInfo = new CatalogFileInfo() { FileId = nodeId, }; var file = new HfsPlusFile(context, nodeId, catalogInfo); byte[] buffer = new byte[0x40]; Assert.Equal(42, file.FileContent.Read(0, buffer, 0, buffer.Length)); Assert.Equal("bplist00", Encoding.UTF8.GetString(buffer, 0, 8)); }
public void FileContent_ZlibAttribute_Raw() { var nodeId = new CatalogNodeId(1); byte[] compressionAttribute = Convert.FromBase64String("AAAAEAAAAAAAAAAAAAAAGWZwbWMDAAAACAAAAAAAAAD/QVBQTD8/Pz++"); var attributes = new Mock <BTree <AttributeKey> >(MockBehavior.Strict); attributes .Setup(a => a.Find(new AttributeKey(nodeId, "com.apple.decmpfs"))) .Returns(compressionAttribute); var context = new Context() { Attributes = attributes.Object, }; var catalogInfo = new CatalogFileInfo() { FileId = nodeId, }; var file = new HfsPlusFile(context, nodeId, catalogInfo); byte[] buffer = new byte[0x20]; Assert.Equal(8, file.FileContent.Read(0, buffer, 0, buffer.Length)); Assert.Equal("APPL????", Encoding.UTF8.GetString(buffer, 0, 8)); }
public void ReadFrom_Reads() { byte[] data = Convert.FromBase64String( "AAIAhgAAAAAABXXL00CTs9NFrx3TRa8d00W9aQAAAAAAAAAAAAAAAAAggaQAAAABAAAAAAAAAAAAAAAAAAAAAAAAAA" + "BXH/6dAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALBUAAAAAAAAAAwAVeJkAAAADAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="); var info = new CatalogFileInfo(); Assert.Equal(248, info.ReadFrom(data, 0)); Assert.Equal(new DateTime(2016, 4, 27, 0, 50, 49, DateTimeKind.Utc), info.AccessTime); Assert.Equal(new DateTime(2016, 4, 26, 23, 49, 49, DateTimeKind.Utc), info.AttributeModifyTime); Assert.Equal(new DateTime(1904, 1, 1, 0, 0, 0, DateTimeKind.Utc), info.BackupTime); Assert.Equal(new DateTime(2016, 4, 26, 23, 49, 49, DateTimeKind.Utc), info.ContentModifyTime); Assert.Equal(new DateTime(2016, 4, 23, 2, 51, 31, DateTimeKind.Utc), info.CreateTime); Assert.Collection( info.DataFork.Extents, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }); Assert.Equal(0u, info.DataFork.LogicalSize); Assert.Equal(0x50, info.DataFork.Size); Assert.Equal(0u, info.DataFork.TotalBlocks); Assert.Equal(new CatalogNodeId(357835), info.FileId); Assert.Equal(0u, info.FileInfo.FileCreator); Assert.Equal(0u, info.FileInfo.FileType); Assert.Equal(FinderFlags.None, info.FileInfo.FinderFlags); Assert.Equal(0, info.FileInfo.Point.Horizontal); Assert.Equal(0, info.FileInfo.Point.Vertical); Assert.Equal(0x04, info.FileInfo.Point.Size); Assert.Equal(0x10, info.FileInfo.Size); Assert.Equal(0u, info.FileSystemInfo.DeviceId); Assert.Equal(UnixFileType.None, info.FileSystemInfo.FileType); Assert.Equal(0, info.FileSystemInfo.GroupId); Assert.Equal(0u, info.FileSystemInfo.Inode); Assert.Equal(0, info.FileSystemInfo.LinkCount); Assert.Equal(UnixFilePermissions.GroupRead, info.FileSystemInfo.Permissions); Assert.Equal(0, info.FileSystemInfo.UserId); Assert.Equal(134u, info.Flags); Assert.Equal(CatalogRecordType.FileRecord, info.RecordType); Assert.Collection( info.ResourceFork.Extents, e => { Assert.Equal(0x3u, e.BlockCount); Assert.Equal(0x157899u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }, e => { Assert.Equal(0u, e.BlockCount); Assert.Equal(0u, e.StartBlock); }); Assert.Equal(11285u, info.ResourceFork.LogicalSize); Assert.Equal(0x50, info.ResourceFork.Size); Assert.Equal(3u, info.ResourceFork.TotalBlocks); Assert.Equal(0xf8, info.Size); Assert.Equal(0x81a40000u, info.UnixSpecialField); }
public void WriteTo_Throws() { var info = new CatalogFileInfo(); Assert.Throws <NotImplementedException>(() => info.WriteTo(Array.Empty <byte>(), 0)); }
public void FileContent_ZlibResource() { var nodeId = new CatalogNodeId(1); byte[] compressionAttribute = Convert.FromBase64String("AAAAEAAAAAAAAAAAAAAAEGZwbWMEAAAAowkAAAAAAAA="); byte[] resourceData = Convert.FromBase64String( "AAABAAAAAwEAAAIBAAAAMgA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AAAAAAAAAAAAAAAAAAcADIAAGNtcGYAAAAKAAH//wAAAAAAAAAA"); var attributes = new Mock <BTree <AttributeKey> >(MockBehavior.Strict); attributes .Setup(a => a.Find(new AttributeKey(nodeId, "com.apple.decmpfs"))) .Returns(compressionAttribute); var context = new Context() { Attributes = attributes.Object, VolumeStream = new MemoryStream(resourceData), VolumeHeader = new VolumeHeader() { BlockSize = 0x00001000, }, }; var catalogInfo = new CatalogFileInfo() { FileId = nodeId, ResourceFork = new ForkData() { LogicalSize = 0x0000000000000333, Extents = new ExtentDescriptor[] { new ExtentDescriptor() { StartBlock = 0, BlockCount = 1, }, }, }, }; var file = new HfsPlusFile(context, nodeId, catalogInfo); byte[] buffer = new byte[0x1000]; Assert.Equal(0x9A3, file.FileContent.Read(0, buffer, 0, buffer.Length)); Assert.Equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", Encoding.UTF8.GetString(buffer, 0, 38)); }