public Iso9660PathTableRecord(byte[] pathBytes, bool isLittleEndian) { this.LengthOfDirectoryIdentifier = ParseFile.ParseSimpleOffset(pathBytes, 0, 1)[0]; this.ExtendedAttributeRecordLength = ParseFile.ParseSimpleOffset(pathBytes, 1, 1)[0]; if (isLittleEndian) { this.LocationOfExtent = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(pathBytes, 2, 4), 0); } else { this.LocationOfExtent = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(pathBytes, 2, 4)); } if (isLittleEndian) { this.DirectoryNumberOfParentDirectory = BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(pathBytes, 6, 2), 0); } else { this.DirectoryNumberOfParentDirectory = ByteConversion.GetUInt16BigEndian(ParseFile.ParseSimpleOffset(pathBytes, 6, 2)); } this.DirectoryIdentifierBytes = ParseFile.ParseSimpleOffset(pathBytes, 8, this.LengthOfDirectoryIdentifier); this.DirectoryIdentifier = ByteConversion.GetEncodedText(this.DirectoryIdentifierBytes, ByteConversion.GetPredictedCodePageForTags(this.DirectoryIdentifierBytes)); if (this.LengthOfDirectoryIdentifier % 2 == 1) { this.PaddingByte = ParseFile.ParseSimpleOffset(pathBytes, this.LengthOfDirectoryIdentifier + 8, 1)[0]; } }
protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pExtractAdxStruct, DoWorkEventArgs e) { ExtractAdxStruct extractAdxStruct = (ExtractAdxStruct)pExtractAdxStruct; long offset = 0; uint copyrightOffset; byte[] copyrightBytes; uint totalHeaderSize; int encodingType; uint blockSize; uint bitDepth; uint channelCount; uint sampleRate; uint totalSamples; uint fileSize; int fileCount = 0; string outputPath = Path.Combine(Path.GetDirectoryName(pPath), "_cri_adx_ext"); string outputFileName; string outputFilePath; FileInfo fi = new FileInfo(pPath); using (FileStream fs = File.Open(pPath, FileMode.Open, FileAccess.Read)) { outputPath = Path.Combine(Path.GetDirectoryName(pPath), String.Format("{0}_ADXs", Path.GetFileNameWithoutExtension(pPath))); while ((offset = ParseFile.GetNextOffset(fs, offset, ADX_SIG_BYTES)) > -1) { if (!this.CancellationPending) { // get offset to copyright string copyrightOffset = (uint)ByteConversion.GetUInt16BigEndian(ParseFile.ParseSimpleOffset(fs, offset + 2, 2)); copyrightBytes = ParseFile.ParseSimpleOffset(fs, offset + copyrightOffset - 2, CRI_COPYRIGHT_BYTES.Length); // check that copyright bytes are present if (ParseFile.CompareSegment(copyrightBytes, 0, CRI_COPYRIGHT_BYTES)) { // verify this is standard ADX encodingType = ParseFile.ParseSimpleOffset(fs, offset + 4, 1)[0]; if (encodingType != 3) { fileSize = 1; } else { // get other info blockSize = (uint)ParseFile.ParseSimpleOffset(fs, offset + 5, 1)[0]; bitDepth = (uint)ParseFile.ParseSimpleOffset(fs, offset + 6, 1)[0]; channelCount = (uint)ParseFile.ParseSimpleOffset(fs, offset + 7, 1)[0]; sampleRate = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(fs, offset + 8, 4)); totalSamples = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(fs, offset + 0xC, 4)); totalHeaderSize = copyrightOffset + 4; // calculate file size fileSize = (((totalSamples + 0x1F) / (bitDepth * 8)) * channelCount * blockSize) + totalHeaderSize + blockSize; // extract file outputFileName = String.Format("{0}_{1}.adx", Path.GetFileNameWithoutExtension(pPath), fileCount.ToString("X8")); outputFilePath = Path.Combine(outputPath, outputFileName); this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("{0} - offset: 0x{1} size: 0x{2}{3}", outputFileName, offset.ToString("X8"), fileSize.ToString("X8"), Environment.NewLine); ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); ParseFile.ExtractChunkToFile(fs, offset, (int)fileSize, outputFilePath, true, true); fileCount++; } offset += fileSize; } else { offset += 1; } } else { e.Cancel = true; return; } } } }
public NullDcGdiDirectoryRecord(byte[] directoryBytes, bool volumeContainsXaData) { byte[] xaAttributes; ushort xaItemDetails; this.LengthOfDirectoryRecord = directoryBytes[0]; if (this.LengthOfDirectoryRecord > 0) { this.ExtendedAttributeRecordLength = directoryBytes[1]; this.LocationOfExtent = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(directoryBytes, 2, 4), 0); this.DataLength = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(directoryBytes, 0x0A, 4), 0); if (ParseFile.CompareSegmentUsingSourceOffset(directoryBytes, 0x12, Iso9660.EMPTY_FILE_DATETIME.Length, Iso9660.EMPTY_FILE_DATETIME)) { this.RecordingDateAndTime = DateTime.MinValue; } else { this.RecordingDateAndTime = new DateTime(directoryBytes[0x12] + 1900, directoryBytes[0x13], directoryBytes[0x14], directoryBytes[0x15], directoryBytes[0x16], directoryBytes[0x17]); } this.FileFlags = directoryBytes[0x19]; this.FlagExistance = (this.FileFlags & 0x1) == 0x1 ? true : false; this.FlagDirectory = (this.FileFlags & 0x2) == 0x2 ? true : false; this.FlagAssociatedFile = (this.FileFlags & 0x4) == 0x4 ? true : false; this.FlagRecord = (this.FileFlags & 0x08) == 0x08 ? true : false; this.FlagProtection = (this.FileFlags & 0x10) == 0x10 ? true : false; this.FlagMultiExtent = (this.FileFlags & 0x80) == 0x80 ? true : false; this.FileUnitSize = directoryBytes[0x1A]; this.InterleaveGapSize = directoryBytes[0x1B]; this.VolumeSequenceNumber = BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(directoryBytes, 0x1C, 2), 0); this.LengthOfFileIdentifier = directoryBytes[0x20]; this.FileIdentifier = ParseFile.ParseSimpleOffset(directoryBytes, 0x21, this.LengthOfFileIdentifier); // parse identifier if ((this.LengthOfFileIdentifier == 1) && (this.FileIdentifier[0] == 0)) { this.FileIdentifierString = "."; } else if ((this.LengthOfFileIdentifier == 1) && (this.FileIdentifier[0] == 1)) { this.FileIdentifierString = ".."; } else if (this.LengthOfFileIdentifier > 0) { this.FileIdentifierString = ByteConversion.GetEncodedText(this.FileIdentifier, ByteConversion.GetPredictedCodePageForTags(this.FileIdentifier)); } if (this.LengthOfFileIdentifier % 2 == 0) { this.PaddingField = ParseFile.ParseSimpleOffset(directoryBytes, 0x21 + this.LengthOfFileIdentifier, 1); } else { this.PaddingField = new byte[0]; } this.ItemMode = CdSectorType.Unknown; // CD-XA if (volumeContainsXaData) { if (directoryBytes.Length >= (0x21 + this.LengthOfFileIdentifier + this.PaddingField.Length + 0xE)) { xaAttributes = ParseFile.ParseSimpleOffset(directoryBytes, 0x21 + this.LengthOfFileIdentifier + this.PaddingField.Length, 0xE); //verify cut size // verify this is an XA entry if (ParseFile.CompareSegmentUsingSourceOffset(xaAttributes, 6, XA_SIGNATURE.Length, XA_SIGNATURE)) { xaItemDetails = ByteConversion.GetUInt16BigEndian(ParseFile.ParseSimpleOffset(xaAttributes, 4, 2)); if ((xaItemDetails & XA_ATTR_INTERLEAVED) == XA_ATTR_INTERLEAVED) { this.ItemMode = CdSectorType.XaInterleaved; this.DataLength = (uint)(this.DataLength / (uint)CdRom.NON_RAW_SECTOR_SIZE) * (uint)CdRom.RAW_SECTOR_SIZE; } else if ((xaItemDetails & XA_ATTR_MODE2FORM1) == XA_ATTR_MODE2FORM1) { this.ItemMode = CdSectorType.Mode2Form1; } else if ((xaItemDetails & XA_ATTR_MODE2FORM2) == XA_ATTR_MODE2FORM2) { this.ItemMode = CdSectorType.Mode2Form2; this.DataLength = (uint)(this.DataLength / (uint)CdRom.NON_RAW_SECTOR_SIZE) * (uint)CdRom.RAW_SECTOR_SIZE; } else if ((xaItemDetails & XA_ATTR_CDDA) == XA_ATTR_CDDA) { this.ItemMode = CdSectorType.Audio; this.DataLength = (uint)(this.DataLength / (uint)CdRom.NON_RAW_SECTOR_SIZE) * (uint)CdRom.RAW_SECTOR_SIZE; } else { this.ItemMode = CdSectorType.Unknown; } } } } /* * public byte[] SystemUse { set; get; } */ } }
public GreenBookCdiDirectoryRecord(byte[] directoryBytes) { this.LengthOfDirectoryRecord = directoryBytes[0]; if (this.LengthOfDirectoryRecord > 0) { this.ExtendedAttributeRecordLength = directoryBytes[1]; this.LocationOfExtent = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directoryBytes, 6, 4)); this.DataLength = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directoryBytes, 0x0E, 4)); this.RecordingDateAndTime = new DateTime(directoryBytes[0x12] + 1900, directoryBytes[0x13], directoryBytes[0x14], directoryBytes[0x15], directoryBytes[0x16], directoryBytes[0x17]); this.FileFlags = directoryBytes[this.LengthOfDirectoryRecord - 6]; ushort cdiItemDetails = ByteConversion.GetUInt16BigEndian(ParseFile.ParseSimpleOffset(directoryBytes, this.LengthOfDirectoryRecord - 6, 2)); if ((cdiItemDetails & CDI_ATTR_DIRECTORY) == CDI_ATTR_DIRECTORY) { this.FlagDirectory = true; } //else if ((cdiItemDetails & CDI_ATTR_MODE2FORM1) == CDI_ATTR_MODE2FORM1) //{ // this.ItemMode = CdSectorType.Mode2Form1; //} //else if ((cdiItemDetails & CDI_ATTR_MODE2FORM2) == CDI_ATTR_MODE2FORM2) //{ // this.ItemMode = CdSectorType.Mode2Form2; // this.DataLength = (uint)(this.DataLength / (uint)CdRom.NON_RAW_SECTOR_SIZE) * (uint)CdRom.RAW_SECTOR_SIZE; //} //else if ((cdiItemDetails & CDI_ATTR_CDDA) == CDI_ATTR_CDDA) //{ // this.ItemMode = CdSectorType.Audio; // this.DataLength = (uint)(this.DataLength / (uint)CdRom.NON_RAW_SECTOR_SIZE) * (uint)CdRom.RAW_SECTOR_SIZE; //} //else //{ // this.ItemMode = CdSectorType.Unknown; //} /* * this.FlagExistance = (this.FileFlags & 0x1) == 0x1 ? true : false; * this.FlagDirectory = (this.FileFlags & 0x2) == 0x2 ? true : false; * this.FlagAssociatedFile = (this.FileFlags & 0x4) == 0x4 ? true : false; * this.FlagRecord = (this.FileFlags & 0x08) == 0x08 ? true : false; * this.FlagProtection = (this.FileFlags & 0x10) == 0x10 ? true : false; * this.FlagMultiExtent = (this.FileFlags & 0x80) == 0x80 ? false : true; */ this.FileUnitSize = directoryBytes[0x1A]; this.InterleaveGapSize = directoryBytes[0x1B]; this.VolumeSequenceNumber = BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(directoryBytes, 0x1E, 2), 0); this.LengthOfFileIdentifier = directoryBytes[0x20]; this.FileIdentifier = ParseFile.ParseSimpleOffset(directoryBytes, 0x21, this.LengthOfFileIdentifier); // parse identifier if (this.LengthOfFileIdentifier > 1) { this.FileIdentifierString = ByteConversion.GetEncodedText(this.FileIdentifier, ByteConversion.GetPredictedCodePageForTags(this.FileIdentifier)); } else if (this.FileIdentifier[0] == 0) { this.FileIdentifierString = "."; } else if (this.FileIdentifier[0] == 1) { this.FileIdentifierString = ".."; } /* * * public byte[] PaddingField { set; get; } * public byte[] SystemUse { set; get; } */ } }
public void Initialize(FileStream isoStream, long offset, bool isRawDump) { byte[] sectorBytes; byte[] sectorDataBytes; this.FormatDescription = GreenBookCdi.FORMAT_DESCRIPTION_STRING; this.VolumeType = VolumeDataType.Data; this.IsRawDump = isRawDump; this.DirectoryStructureArray = new ArrayList(); this.VolumeBaseOffset = this.IsRawDump ? (offset - Iso9660.EMPTY_HEADER_SIZE_RAW) : (offset - Iso9660.EMPTY_HEADER_SIZE); this.SectorSize = this.IsRawDump ? (int)CdRom.RAW_SECTOR_SIZE : (int)CdRom.NON_RAW_SECTOR_SIZE; // parse inital level sector sectorBytes = ParseFile.ParseSimpleOffset(isoStream, offset, this.SectorSize); sectorDataBytes = CdRom.GetDataChunkFromSector(sectorBytes, this.IsRawDump); this.VolumeDescriptorType = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x00, 1)[0]; this.StandardIdentifier = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x01, 5); this.VolumeDescriptorVersion = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x06, 1)[0]; this.UnusedField1 = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x07, 1)[0]; this.SystemIdentifier = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x08, 0x20)).Trim(); this.VolumeIdentifier = ByteConversion.GetAsciiText(FileUtil.ReplaceNullByteWithSpace(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x28, 0x20))).Trim(); this.UnusedField2 = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x48, 0x08); this.VolumeSpaceSize = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x54, 0x04)); this.UnusedField3 = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x58, 0x20); this.VolumeSetSize = ByteConversion.GetUInt16BigEndian(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x7A, 0x02)); this.VolumeSequenceNumber = ByteConversion.GetUInt16BigEndian(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x7E, 0x02)); this.LogicalBlockSize = ByteConversion.GetUInt16BigEndian(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x82, 0x02)); this.PathTableSize = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x88, 0x04)); this.LocationOfOccurrenceOfTypeLPathTable = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x8C, 0x04), 0); this.LocationOfOptionalOccurrenceOfTypeLPathTable = BitConverter.ToUInt32(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x90, 0x04), 0); this.LocationOfOccurrenceOfTypeMPathTable = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x94, 0x04)); this.LocationOfOptionalOccurrenceOfTypeMPathTable = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x98, 0x04)); this.DirectoryRecordForRootDirectoryBytes = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x9C, 0x22); this.DirectoryRecordForRootDirectory = new GreenBookCdiDirectoryRecord(this.DirectoryRecordForRootDirectoryBytes); this.VolumeSetIdentifier = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(sectorDataBytes, 0xBE, 0x80)).Trim(); this.PublisherIdentifier = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x13E, 0x80)).Trim(); this.DataPreparerIdentifier = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x1BE, 0x80)).Trim(); this.ApplicationIdentifier = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x23E, 0x80)).Trim(); this.CopyrightFileIdentifier = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x2BE, 0x25)).Trim(); this.AbstractFileIdentifier = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x2E3, 0x25)).Trim(); this.BibliographicFileIdentifier = ByteConversion.GetAsciiText(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x308, 0x25)).Trim(); this.VolumeCreationDateAndTime = Iso9660.GetIsoDateTime(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x32D, 0x11)); this.VolumeModificationDateAndTime = Iso9660.GetIsoDateTime(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x33E, 0x11)); this.VolumeExpirationDateAndTime = Iso9660.GetIsoDateTime(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x34F, 0x11)); this.VolumeEffectiveDateAndTime = Iso9660.GetIsoDateTime(ParseFile.ParseSimpleOffset(sectorDataBytes, 0x360, 0x11)); this.FileStructureVersion = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x371, 1)[0]; this.Reserved1 = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x372, 1)[0]; this.ApplicationUse = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x373, 0x200); this.Reserved2 = ParseFile.ParseSimpleOffset(sectorDataBytes, 0x573, 0x28D); this.LoadDirectories(isoStream); }
public static string ExtractAdxStreams(string path, string filePrefix, string outputFolder, out string messages) { string extractedToFolder = String.Empty; StringBuilder messageBuffer = new StringBuilder(); messages = String.Empty; long offset = 0; uint copyrightOffset; byte[] copyrightBytes; uint totalHeaderSize; int encodingType; uint blockSize; uint bitDepth; uint channelCount; uint sampleRate; uint totalSamples; uint fileSize; int fileCount = 0; string outputFileName; string outputFilePath; FileInfo fi = new FileInfo(path); using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read)) { if (!String.IsNullOrEmpty(outputFolder)) { extractedToFolder = outputFolder; } else { extractedToFolder = Path.Combine(Path.GetDirectoryName(path), String.Format("{0}_ADXs", Path.GetFileNameWithoutExtension(path))); } while ((offset = ParseFile.GetNextOffset(fs, offset, ADX_SIG_BYTES)) > -1) { // get offset to copyright string copyrightOffset = (uint)ByteConversion.GetUInt16BigEndian(ParseFile.ParseSimpleOffset(fs, offset + 2, 2)); copyrightBytes = ParseFile.ParseSimpleOffset(fs, offset + copyrightOffset - 2, CRI_COPYRIGHT_BYTES.Length); // check that copyright bytes are present if (ParseFile.CompareSegment(copyrightBytes, 0, CRI_COPYRIGHT_BYTES)) { // verify this is standard ADX encodingType = ParseFile.ParseSimpleOffset(fs, offset + 4, 1)[0]; if (encodingType != 3) { fileSize = 1; } else { // get other info blockSize = (uint)ParseFile.ParseSimpleOffset(fs, offset + 5, 1)[0]; bitDepth = (uint)ParseFile.ParseSimpleOffset(fs, offset + 6, 1)[0]; channelCount = (uint)ParseFile.ParseSimpleOffset(fs, offset + 7, 1)[0]; sampleRate = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(fs, offset + 8, 4)); totalSamples = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(fs, offset + 0xC, 4)); totalHeaderSize = copyrightOffset + 4; // calculate file size fileSize = (((totalSamples + 0x1F) / (bitDepth * 8)) * channelCount * blockSize) + totalHeaderSize + blockSize; // extract file if (!String.IsNullOrEmpty(filePrefix)) { outputFileName = String.Format("{0}_{1}.adx", filePrefix, fileCount.ToString("X8")); } else { outputFileName = String.Format("{0}_{1}.adx", Path.GetFileNameWithoutExtension(path), fileCount.ToString("X8")); } outputFilePath = Path.Combine(extractedToFolder, outputFileName); ParseFile.ExtractChunkToFile(fs, offset, (int)fileSize, outputFilePath, true, true); messageBuffer.AppendFormat("{0} - offset: 0x{1} size: 0x{2}{3}", outputFileName, offset.ToString("X8"), fileSize.ToString("X8"), Environment.NewLine); fileCount++; } offset += fileSize; } else { offset += 1; } } } messages = messageBuffer.ToString(); return(extractedToFolder); }