public absHFSPlusBTree(HFSPlusFile knownExtents, volumeStream hfsp) { extents = knownExtents; // grab a bunch of information to ensure the header node is captured byte[] firstBlock = new byte[hfsp.volume.blockSize]; this.fs = new forkStream(hfsp, knownExtents, forkStream.forkType.data); fs.Read(firstBlock, 0, firstBlock.Count()); // nodeSize is byte 30 of header record which comes immediately after 14 byte descriptor this.nodeSize = dataOperations.convToLE(BitConverter.ToUInt16(firstBlock, 32)); byte[] headerData = new byte[nodeSize]; headerData = getNodeData(0, nodeSize); header = new headerNode(ref headerData); // check whether all of the data extents are known long treeSize = header.headerInfo.totalNodes * header.headerInfo.nodeSize; if (fs.Length >= treeSize && fs.Length > 0) { isRawDataComplete = true; buildMap(fs); } }
protected byte[] buildMap(forkStream fs) { List <byte[]> mapContent = new List <byte[]>(); mapContent.Add(header.map.bitmapComponent); uint fLink = this.header.BTNodeDescriptor.fLink; uint mapSize = (uint)header.map.bitmapComponent.Length; // if fLink > 0, there are more map nodes with map data to be read while (fLink > 0) { byte[] nodeRawData = new byte[this.nodeSize]; fs.Seek(fLink * this.nodeSize, System.IO.SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); mapNode currentMap = new mapNode(ref nodeRawData); mapContent.Add(currentMap.bitmapComponent); mapSize += (uint)currentMap.bitmapComponent.Length; fLink = currentMap.BTNodeDescriptor.fLink; } byte[] mapData = new byte[mapSize]; int position = 0; foreach (byte[] component in mapContent) { Array.Copy(component, 0, mapData, position, component.Length); position += component.Length; } return(mapData); }
public absHFSPlusBTree(HFSPlusFile knownExtents, volumeStream hfsp) { extents = knownExtents; // grab a bunch of information to ensure the header node is captured byte[] firstBlock = new byte[hfsp.volume.blockSize]; this.fs = new forkStream(hfsp, knownExtents, forkStream.forkType.data); fs.Read(firstBlock, 0, firstBlock.Count()); // nodeSize is byte 30 of header record which comes immediately after 14 byte descriptor this.nodeSize = dataOperations.convToLE(BitConverter.ToUInt16(firstBlock, 32)); byte[] headerData = new byte[nodeSize]; headerData = getNodeData(0, nodeSize); header = new headerNode(ref headerData); // check whether all of the data extents are known long treeSize = header.headerInfo.totalNodes * header.headerInfo.nodeSize; if (fs.Length >= treeSize && fs.Length > 0) { isRawDataComplete = true; buildMap(fs); } }
protected byte[] getNodeData(uint nodeNumber, ushort nodeSize) { byte[] nodeData = new byte[this.nodeSize]; fs.Seek(nodeNumber * nodeSize, SeekOrigin.Begin); fs.Read(nodeData, 0, this.nodeSize); return(nodeData); }
protected byte[] buildMap(forkStream fs) { List<byte[]> mapContent = new List<byte[]>(); mapContent.Add(header.map.bitmapComponent); uint fLink = this.header.BTNodeDescriptor.fLink; uint mapSize = (uint)header.map.bitmapComponent.Length; // if fLink > 0, there are more map nodes with map data to be read while (fLink > 0) { byte[] nodeRawData = new byte[this.nodeSize]; fs.Seek(fLink * this.nodeSize, System.IO.SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); mapNode currentMap = new mapNode(ref nodeRawData); mapContent.Add(currentMap.bitmapComponent); mapSize += (uint)currentMap.bitmapComponent.Length; fLink = currentMap.BTNodeDescriptor.fLink; } byte[] mapData = new byte[mapSize]; int position = 0; foreach (byte[] component in mapContent) { Array.Copy(component, 0, mapData, position, component.Length); position += component.Length; } return mapData; }
public imageMap(absImageStream ais) { if (ais.scheme == absImageStream.schemeType.GPT) { GPTScheme gpts = new GPTScheme(ais); mapBlock block = new mapBlock(); block.location = 0; if (gpts.protectiveMBRExists) { block.length = 1; block.name = "MBR"; block.type = tileType.MBR; partitionblocks.Add(block); } if (gpts.headerFound) { block.location = 1; block.length = 1; block.name = "GPT Header"; block.type = tileType.GPT; partitionblocks.Add(block); block.location = gpts.tablestart; block.length = gpts.tablelength / ais.sectorSize; if (block.length < 1) block.length = 1; block.name = "GPT Primary Table"; block.type = tileType.GPT; partitionblocks.Add(block); } if (gpts.backupFound) { block.location = gpts.backupHeader.mainheader; block.length = 1; block.name = "Backup GPT Header"; block.type = tileType.GPT; partitionblocks.Add(block); block.location = gpts.backupHeader.tablestart; block.length = gpts.tablelength / ais.sectorSize; if (block.length < 1) block.length = 1; block.name = "GPT Backup Table"; block.type = tileType.GPT; partitionblocks.Add(block); } foreach (GPTScheme.entry entry in gpts.entries) { block.location = entry.partStartLBA; block.length = entry.partLength; block.name = entry.name; block.type = tileType.vol_unknown; if (gpts.findPartitionType(entry) == GPTScheme.partitionType.HFSPlus) { HFSPlus hfsp = new HFSPlus(ais, entry); block.mapSectorsPerBlock = (int)hfsp.volHead.blockSize / ais.sectorSize; forkStream fs = new forkStream(new volumeStream(hfsp), new HFSPlusFile(hfsp.volHead.allocationFile, forkStream.forkType.data), forkStream.forkType.data); block.allocationMap = new byte[(int)fs.Length]; fs.Read(block.allocationMap, 0, (int)fs.Length); } else { block.allocationMap = null; } partitionblocks.Add(block); } } partitionblocks.Sort(CompareBlocksByPosition); }
public imageMap(absImageStream ais) { if (ais.scheme == absImageStream.schemeType.GPT) { GPTScheme gpts = new GPTScheme(ais); mapBlock block = new mapBlock(); block.location = 0; if (gpts.protectiveMBRExists) { block.length = 1; block.name = "MBR"; block.type = tileType.MBR; partitionblocks.Add(block); } if (gpts.headerFound) { block.location = 1; block.length = 1; block.name = "GPT Header"; block.type = tileType.GPT; partitionblocks.Add(block); block.location = gpts.tablestart; block.length = gpts.tablelength / ais.sectorSize; if (block.length < 1) { block.length = 1; } block.name = "GPT Primary Table"; block.type = tileType.GPT; partitionblocks.Add(block); } if (gpts.backupFound) { block.location = gpts.backupHeader.mainheader; block.length = 1; block.name = "Backup GPT Header"; block.type = tileType.GPT; partitionblocks.Add(block); block.location = gpts.backupHeader.tablestart; block.length = gpts.tablelength / ais.sectorSize; if (block.length < 1) { block.length = 1; } block.name = "GPT Backup Table"; block.type = tileType.GPT; partitionblocks.Add(block); } foreach (GPTScheme.entry entry in gpts.entries) { block.location = entry.partStartLBA; block.length = entry.partLength; block.name = entry.name; block.type = tileType.vol_unknown; if (gpts.findPartitionType(entry) == GPTScheme.partitionType.HFSPlus) { HFSPlus hfsp = new HFSPlus(ais, entry); block.mapSectorsPerBlock = (int)hfsp.volHead.blockSize / ais.sectorSize; forkStream fs = new forkStream(new volumeStream(hfsp), new HFSPlusFile(hfsp.volHead.allocationFile, forkStream.forkType.data), forkStream.forkType.data); block.allocationMap = new byte[(int)fs.Length]; fs.Read(block.allocationMap, 0, (int)fs.Length); } else { block.allocationMap = null; } partitionblocks.Add(block); } } partitionblocks.Sort(CompareBlocksByPosition); }