public STDFManager(STDFFileMode mode, string fileName) { this.Processor = BYTE_ORIENTATION.UNKNOWN; this.Mode = mode; this.FileProcessing = fileName; if (this.Mode == STDFFileMode.Write) { try { if (fileName == @"c:\StdfTest.std") { File.Delete(fileName); } this.fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None, 0x4000); this.bw = new BinaryWriter(this.fs); this.Logger("File:{0} Created for output.\n", new object[] { fileName }); return; } catch { this.Logger("Unable to create file:{0} (File may already exist)\n", new object[] { fileName }); throw; } } if (this.Mode == STDFFileMode.Read) { try { this.fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 0x4000); this.Logger("File:{0} opened for Reading\n", new object[] { fileName }); this.FileLength = this.fs.Length; if (this.FileLength < 0x19L) { throw new Exception("File length less than 25 bytes " + fileName.ToString() + " is not a valid stdf file"); } //Read all bytes into an array from the specified file. int nBytes = (int)fs.Length;//计算流的长度 byte[] byteArray = new byte[nBytes];//初始化用于MemoryStream的Buffer int nBytesRead = fs.Read(byteArray, 0, nBytes);//将File里的内容一次性的全部读到byteArray中去 MemoryStream stream = new MemoryStream(byteArray);//初始化MemoryStream,并将Buffer指向FileStream this.br = new BinaryReader(stream); this.Processor = BYTE_ORIENTATION.UNKNOWN; return; } catch { this.Logger("Unable to open file:{0} for reading\n", new object[] { fileName }); throw; } } throw new Exception("STDFManager:Unknown File Mode Requested"); }
public STDFManager(STDFFileMode mode, string fileName) { this.Processor = BYTE_ORIENTATION.UNKNOWN; this.Mode = mode; this.FileProcessing = fileName; if (this.Mode == STDFFileMode.Write) { try { if (fileName == @"c:\StdfTest.std") { File.Delete(fileName); } this.fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None, 0x4000); this.bw = new BinaryWriter(this.fs); this.Logger("File:{0} Created for output.\n", new object[] { fileName }); return; } catch { this.Logger("Unable to create file:{0} (File may already exist)\n", new object[] { fileName }); throw; } } if (this.Mode == STDFFileMode.Read) { try { this.fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 0x4000); this.Logger("File:{0} opened for Reading\n", new object[] { fileName }); this.FileLength = this.fs.Length; if (this.FileLength < 0x19L) { throw new Exception("File length less than 25 bytes " + fileName.ToString() + " is not a valid stdf file"); } //Read all bytes into an array from the specified file. int nBytes = (int)fs.Length; //计算流的长度 byte[] byteArray = new byte[nBytes]; //初始化用于MemoryStream的Buffer int nBytesRead = fs.Read(byteArray, 0, nBytes); //将File里的内容一次性的全部读到byteArray中去 MemoryStream stream = new MemoryStream(byteArray); //初始化MemoryStream,并将Buffer指向FileStream this.br = new BinaryReader(stream); this.Processor = BYTE_ORIENTATION.UNKNOWN; return; } catch { this.Logger("Unable to open file:{0} for reading\n", new object[] { fileName }); throw; } } throw new Exception("STDFManager:Unknown File Mode Requested"); }
public STDFManager(STDFFileMode mode, string fileName) { this.Processor = BYTE_ORIENTATION.UNKNOWN; this.Mode = mode; this.FileProcessing = fileName; if (this.Mode == STDFFileMode.Write) { try { if (fileName == @"c:\StdfTest.std") { File.Delete(fileName); } this.fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None, 0x4000); this.bw = new BinaryWriter(this.fs); this.Logger("File:{0} Created for output.\n", new object[] { fileName }); return; } catch { this.Logger("Unable to create file:{0} (File may already exist)\n", new object[] { fileName }); throw; } } if (this.Mode == STDFFileMode.Read) { try { this.fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 0x4000); this.Logger("File:{0} opened for Reading\n", new object[] { fileName }); this.FileLength = this.fs.Length; if (this.FileLength < 0x19L) { throw new Exception("File length less than 25 bytes " + fileName.ToString() + " is not a valid stdf file"); } this.br = new BinaryReader(this.fs); this.Processor = BYTE_ORIENTATION.UNKNOWN; return; } catch { this.Logger("Unable to open file:{0} for reading\n", new object[] { fileName }); throw; } } throw new Exception("STDFManager:Unknown File Mode Requested"); }
public int MakeIndex() { int capacity = 0x3d0900; ushort num2 = 0; byte num3 = 0; STDFRecordType nAN = STDFRecordType.NAN; long fPosition = 0L; long length = 0L; uint num7 = 1; this.Logger("Indexing File:{0}{1}{0}", new object[] { Environment.NewLine, this.FileProcessing.ToString() }); if (this.Mode != STDFFileMode.Read) { throw new Exception("Cannot index a file opened for write."); } long position = this.br.BaseStream.Position; this.br.BaseStream.Position = 0L; length = this.br.BaseStream.Length; if (this.Processor == BYTE_ORIENTATION.UNKNOWN) { this.Processor = this.DetermineProcessorType(this.br); } this.RecIndexList = new List <STDFRecordIndex>(capacity); do { fPosition = this.br.BaseStream.Position; num2 = this.br.ReadUInt16(); if (this.Processor != BYTE_ORIENTATION.IBMPC) { uint num9 = Convert.ToUInt32(num2); num9 = ((num9 >> 8) | (num9 << 8)) & 0xffff; num2 = Convert.ToUInt16(num9); } num3 = this.br.ReadByte(); nAN = (STDFRecordType)((this.br.ReadByte() << 8) + num3); this.RecIndexList.Add(new STDFRecordIndex(nAN, num2, fPosition, num7++, RecordLookup(nAN))); this.br.ReadBytes(num2); }while (this.br.BaseStream.Position < length); this.br.BaseStream.Position = position; this.RecIndex = 0; return(0); }
private BYTE_ORIENTATION DetermineProcessorType(BinaryReader br) { long position = br.BaseStream.Position; byte num2 = 0; byte num3 = 0; byte num4 = 0; ushort num5 = 0; br.BaseStream.Position = 0L; BYTE_ORIENTATION uNKNOWN = BYTE_ORIENTATION.UNKNOWN; num5 = br.ReadUInt16(); num2 = br.ReadByte(); num3 = br.ReadByte(); num4 = br.ReadByte(); if ((num2 != 0) || (num3 != 10)) { throw new Exception("First Record is not a far record, unable to process file\n"); } if (num5 == 2) { uNKNOWN = BYTE_ORIENTATION.IBMPC; } else { switch (num4) { case 0: uNKNOWN = BYTE_ORIENTATION.DEC; break; case 1: uNKNOWN = BYTE_ORIENTATION.SUN; break; case 2: throw new Exception("First Record Length does not match processor type, unable to process file"); } } br.BaseStream.Position = position; return(uNKNOWN); }
public STDFRecord ReadRecord() { ushort num = 0; byte num2 = 0; byte num3 = 0; long position = 0L; STDFRecord record = null; if (this.Mode == STDFFileMode.Write) { throw new Exception("Cannot read from a file opened for write"); } position = this.br.BaseStream.Position; this.BeginningOfBadRecord = position; if (this.Processor == BYTE_ORIENTATION.UNKNOWN) { this.Processor = this.DetermineProcessorType(this.br); } if ((position + 4L) > this.FileLength) { return(null); } num = this.br.ReadUInt16(); num2 = this.br.ReadByte(); num3 = this.br.ReadByte(); if (this.Processor != BYTE_ORIENTATION.IBMPC) { uint num5 = Convert.ToUInt32(num); num5 = ((num5 >> 8) | (num5 << 8)) & 0xffff; num = Convert.ToUInt16(num5); } if ((position + num) >= this.FileLength) { throw new Exception("File not long enough, Probable File Corruption at offset:" + this.br.BaseStream.Position.ToString()); } int num6 = (num3 << 8) + num2; switch (num6) { case 0xa14: record = new BPSRecord(); break; case 0xa32: record = new GDRRecord(); break; case 0xa00: record = new FARRecord(); break; case 0xa01: record = new MIRRecord(); break; case 0xa02: record = new WIRRecord(); break; case 0xa05: record = new PIRRecord(); break; case 0xa0f: record = new PTRRecord(); break; case 0x1400: record = new ATRRecord(); break; case 0x1401: record = new MRRRecord(); break; case 0x1402: record = new WRRRecord(); break; case 0x1405: record = new PRRRecord(); break; case 0xf0f: record = new MPRRecord(); break; case 0x1e01: record = new PCRRecord(); break; case 0x1e02: record = new WCRRecord(); break; case 0x1414: record = new EPSRecord(); break; case 0x140f: record = new FTRRecord(); break; case 0x2801: record = new HBRRecord(); break; case 0x3201: record = new SBRRecord(); break; case 0x1e0a: record = new TSRRecord(); break; case 0x1e32: record = new DTRRecord(); break; case 0x3c01: record = new PMRRecord(); break; case 0x3e01: record = new PGRRecord(); break; case 0x3f01: record = new PLRRecord(); break; case 0x4601: record = new RDRRecord(); break; case 0x5001: record = new SDRRecord(); break; default: { StringBuilder builder = new StringBuilder(0x800); builder.AppendFormat("Corrupt stdf file encountered {0}\n", this.FileProcessing); builder.AppendFormat("\tLast Known Good Position 0x{0:X}\n", this.LastGoodFilePosition); builder.AppendFormat("\tLast Known Good Record {0)\n", this.LastGoodSTDFRecord.ToString()); builder.AppendFormat("\tBeginning of Bad Record 0x{0:X}\n", this.BeginningOfBadRecord); break; } } record.REC_LEN = num; record.RemainingBytes = num; record.RecordNumber = this.RecordCount += 1L; record.RECORD_TYPE = (STDFRecordType)num6; record.Processor = this.Processor; record.FilePos = position; record.Read(this.br); this.br.BaseStream.Position = (record.FilePos + record.REC_LEN) + 4L; this.LastGoodFilePosition = position; this.LastGoodSTDFRecord = record.RECORD_TYPE; if (this.FileLength > 0L) { this.Percent = (Convert.ToDouble(position) / Convert.ToDouble(this.FileLength)) * 100.0; return(record); } this.Percent = 0.0; return(record); }
public STDFManager() { this.Processor = BYTE_ORIENTATION.UNKNOWN; throw new Exception("Must Create STDFManager with parameters STDFFileMode.xxx (read or write) and a STDF file name to read or write"); }
public STDFRecord ReadRecord() { ushort num = 0; byte num2 = 0; byte num3 = 0; long position = 0L; STDFRecord record = null; if (this.Mode == STDFFileMode.Write) { throw new Exception("Cannot read from a file opened for write"); } position = this.br.BaseStream.Position; this.BeginningOfBadRecord = position; if (this.Processor == BYTE_ORIENTATION.UNKNOWN) { this.Processor = this.DetermineProcessorType(this.br); } if ((position + 4L) > this.FileLength) { return null; } num = this.br.ReadUInt16(); num2 = this.br.ReadByte(); num3 = this.br.ReadByte(); if (this.Processor != BYTE_ORIENTATION.IBMPC) { uint num5 = Convert.ToUInt32(num); num5 = ((num5 >> 8) | (num5 << 8)) & 0xffff; num = Convert.ToUInt16(num5); } if ((position + num) >= this.FileLength) { throw new Exception("File not long enough, Probable File Corruption at offset:" + this.br.BaseStream.Position.ToString()); } int num6 = (num3 << 8) + num2; switch (num6) { case 0xa14: record = new BPSRecord(); break; case 0xa32: record = new GDRRecord(); break; case 0xa00: record = new FARRecord(); break; case 0xa01: record = new MIRRecord(); break; case 0xa02: record = new WIRRecord(); break; case 0xa05: record = new PIRRecord(); break; case 0xa0f: record = new PTRRecord(); break; case 0x1400: record = new ATRRecord(); break; case 0x1401: record = new MRRRecord(); break; case 0x1402: record = new WRRRecord(); break; case 0x1405: record = new PRRRecord(); break; case 0xf0f: record = new MPRRecord(); break; case 0x1e01: record = new PCRRecord(); break; case 0x1e02: record = new WCRRecord(); break; case 0x1414: record = new EPSRecord(); break; case 0x140f: record = new FTRRecord(); break; case 0x2801: record = new HBRRecord(); break; case 0x3201: record = new SBRRecord(); break; case 0x1e0a: record = new TSRRecord(); break; case 0x1e32: record = new DTRRecord(); break; case 0x3c01: record = new PMRRecord(); break; case 0x3e01: record = new PGRRecord(); break; case 0x3f01: record = new PLRRecord(); break; case 0x4601: record = new RDRRecord(); break; case 0x5001: record = new SDRRecord(); break; default: { StringBuilder builder = new StringBuilder(0x800); builder.AppendFormat("Corrupt stdf file encountered {0}\n", this.FileProcessing); builder.AppendFormat("\tLast Known Good Position 0x{0:X}\n", this.LastGoodFilePosition); builder.AppendFormat("\tLast Known Good Record {0)\n", this.LastGoodSTDFRecord.ToString()); builder.AppendFormat("\tBeginning of Bad Record 0x{0:X}\n", this.BeginningOfBadRecord); break; } } record.REC_LEN = num; record.RemainingBytes = num; record.RecordNumber = this.RecordCount += 1L; record.RECORD_TYPE = (STDFRecordType) num6; record.Processor = this.Processor; record.FilePos = position; record.Read(this.br); this.br.BaseStream.Position = (record.FilePos + record.REC_LEN) + 4L; this.LastGoodFilePosition = position; this.LastGoodSTDFRecord = record.RECORD_TYPE; if (this.FileLength > 0L) { this.Percent = (Convert.ToDouble(position) / Convert.ToDouble(this.FileLength)) * 100.0; return record; } this.Percent = 0.0; return record; }
public int MakeIndex() { int capacity = 0x3d0900; ushort num2 = 0; byte num3 = 0; STDFRecordType nAN = STDFRecordType.NAN; long fPosition = 0L; long length = 0L; uint num7 = 1; this.Logger("Indexing File:{0}{1}{0}", new object[] { Environment.NewLine, this.FileProcessing.ToString() }); if (this.Mode != STDFFileMode.Read) { throw new Exception("Cannot index a file opened for write."); } long position = this.br.BaseStream.Position; this.br.BaseStream.Position = 0L; length = this.br.BaseStream.Length; if (this.Processor == BYTE_ORIENTATION.UNKNOWN) { this.Processor = this.DetermineProcessorType(this.br); } this.RecIndexList = new List<STDFRecordIndex>(capacity); do { fPosition = this.br.BaseStream.Position; num2 = this.br.ReadUInt16(); if (this.Processor != BYTE_ORIENTATION.IBMPC) { uint num9 = Convert.ToUInt32(num2); num9 = ((num9 >> 8) | (num9 << 8)) & 0xffff; num2 = Convert.ToUInt16(num9); } num3 = this.br.ReadByte(); nAN = (STDFRecordType) ((this.br.ReadByte() << 8) + num3); this.RecIndexList.Add(new STDFRecordIndex(nAN, num2, fPosition, num7++, RecordLookup(nAN))); this.br.ReadBytes(num2); } while (this.br.BaseStream.Position < length); this.br.BaseStream.Position = position; this.RecIndex = 0; return 0; }