本文整理汇总了C#中System.IO.BinaryReader.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.Seek方法的具体用法?C# BinaryReader.Seek怎么用?C# BinaryReader.Seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.Seek方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFromFile
public static void ReadFromFile(IndexUnit indexPage, BinaryReader reader)
{
long initPos = reader.Seek(100L + (indexPage.UnitID * 0x1000L));
if (reader.ReadByte() != 2)
{
throw new FileDBException("PageID {0} is not a Index Page", new object[] { indexPage.UnitID });
}
indexPage.NextUnitID = reader.ReadUInt32();
indexPage.NodeIndex = reader.ReadByte();
reader.Seek(initPos + 0x2eL);
for (int i = 0; i <= indexPage.NodeIndex; i++)
{
IndexNode node = indexPage.Nodes[i];
node.ID = reader.ReadGuid();
node.IsDeleted = reader.ReadBoolean();
node.Right.Index = reader.ReadByte();
node.Right.PageID = reader.ReadUInt32();
node.Left.Index = reader.ReadByte();
node.Left.PageID = reader.ReadUInt32();
node.DataPageID = reader.ReadUInt32();
node.FileName = reader.ReadString(0x29);
node.FileExtension = reader.ReadString(5);
node.FileLength = reader.ReadUInt32();
}
}
示例2: ReadFromFile
public static void ReadFromFile(IndexPage indexPage, BinaryReader reader)
{
// Seek the stream to the fist byte on page
long initPos = reader.Seek(Header.HEADER_SIZE + ((long)indexPage.PageID * BasePage.PAGE_SIZE));
if (reader.ReadByte() != (byte)PageType.Index)
throw new FileDBException("PageID {0} is not a Index Page", indexPage.PageID);
indexPage.NextPageID = reader.ReadUInt32();
indexPage.NodeIndex = reader.ReadByte();
// Seek the stream to end of header data page
reader.Seek(initPos + IndexPage.HEADER_SIZE);
for (int i = 0; i <= indexPage.NodeIndex; i++)
{
var node = indexPage.Nodes[i];
node.ID = reader.ReadGuid();
node.IsDeleted = reader.ReadBoolean();
node.Right.Index = reader.ReadByte();
node.Right.PageID = reader.ReadUInt32();
node.Left.Index = reader.ReadByte();
node.Left.PageID = reader.ReadUInt32();
node.DataPageID = reader.ReadUInt32();
node.FileName = reader.ReadString(IndexNode.FILENAME_SIZE);
node.FileExtension = reader.ReadString(IndexNode.FILE_EXTENSION_SIZE);
node.FileLength = reader.ReadUInt32();
}
}
示例3: InternalRead
private void InternalRead(BinaryReader reader)
{
reader.Seek(CVM_HEADER_SIZE + ISO_RESERVED_SIZE, SeekOrigin.Begin);
byte sectorType = reader.ReadByte();
while (sectorType != ID_PRIM_VOLUME_DESC)
{
reader.Seek(ISO_BLOCKSIZE - 1, SeekOrigin.Current);
sectorType = reader.ReadByte();
}
reader.Seek(ISO_ROOTDIRECTORY_OFFSET - 1, SeekOrigin.Current);
_rootDirectory = new ISODirectoryRecord(reader, null);
}
示例4: GetBasePage
public static Unit GetBasePage(uint pageID, BinaryReader reader)
{
reader.Seek(100L + (pageID * 0x1000L));
if (reader.ReadByte() == 2)
{
return GetIndexPage(pageID, reader);
}
return GetDataPage(pageID, reader, true);
}
示例5: GetBasePage
public static BasePage GetBasePage(uint pageID, BinaryReader reader)
{
// Seek the stream at begin of page
long initPos = reader.Seek(Header.HEADER_SIZE + ((long)pageID * BasePage.PAGE_SIZE));
if (reader.ReadByte() == (byte)PageType.Index)
return GetIndexPage(pageID, reader);
else
return GetDataPage(pageID, reader, true);
}
示例6: ELFHeader
internal ELFHeader(BinaryReader reader)
{
uint elfMagic = reader.ReadUInt32();
if (elfMagic != ELF_MAGIC)
{
throw new InvalidDataException("ELF header signature mismatch.");
}
ei_class = reader.ReadByte();
ei_data = reader.ReadByte();
ei_version = reader.ReadByte();
ei_osabi = reader.ReadByte();
ei_abiversion = reader.ReadByte();
// seek past padding
reader.Seek(0x07, SeekOrigin.Current);
e_type = reader.ReadUInt16();
e_machine = reader.ReadUInt16();
e_version = reader.ReadUInt32();
if (ei_class == (byte)ELFSizeFormat.ELF32)
{
e_entry = reader.ReadUInt32();
e_phoff = reader.ReadUInt32();
e_shoff = reader.ReadUInt32();
}
else if (ei_class == (byte)ELFSizeFormat.ELF64)
{
e_entry = reader.ReadUInt64();
e_phoff = reader.ReadUInt64();
e_shoff = reader.ReadUInt64();
}
else
{
throw new InvalidDataException("Unknown ELF size format value");
}
e_flags = reader.ReadUInt32();
e_ehsize = reader.ReadUInt16();
e_phentsize = reader.ReadUInt16();
e_phnum = reader.ReadUInt16();
e_shentsize = reader.ReadUInt16();
e_shnum = reader.ReadUInt16();
e_shstrndx = reader.ReadUInt16();
}
示例7: GetNameFromStringTable
internal void GetNameFromStringTable(ELFSection stringTableSection, BinaryReader reader)
{
reader.Seek((long)(stringTableSection._header.sh_offset + _header.sh_name), SeekOrigin.Begin);
_name = reader.ReadCString();
}
示例8: DDTDirectoryEntry
public DDTDirectoryEntry(BinaryReader reader, DDTEntry parent, int nameOffset, uint dataOffset, int numChildren)
{
_parent = parent;
_nameOffset = nameOffset;
_dataOffset = dataOffset;
_name = reader.ReadCStringAtOffset(_nameOffset);
_numChildren = numChildren;
_childEntries = new DDTEntry[numChildren];
reader.Seek(dataOffset, SeekOrigin.Begin);
for (int i = 0; i < numChildren; i++)
{
_childEntries[i] = DDTEntryFactory.GetEntry(this, reader);
}
}
示例9: GetEntry
public static DDTEntry GetEntry(DDTEntry parent, BinaryReader reader)
{
int nameOffset = reader.ReadInt32();
uint dataOffset = reader.ReadUInt32();
int numData = reader.ReadInt32();
long posNextEntry = reader.GetPosition();
DDTEntry entry;
if (numData < 0)
{
int numChildren = ~numData + 1;
entry = new DDTDirectoryEntry(reader, parent, nameOffset, dataOffset, numChildren);
}
else
{
entry = new DDTFileEntry(reader, parent, nameOffset, dataOffset, numData);
}
reader.Seek(posNextEntry, SeekOrigin.Begin);
return entry;
}
示例10: InternalRead
private void InternalRead(BinaryReader reader)
{
long posStart = reader.GetPosition();
byte length = reader.ReadByte();
byte extLength = reader.ReadByte();
_LBA = reader.ReadInt32();
reader.Seek(0x04, SeekOrigin.Current); // LBA_BE
_size = reader.ReadInt32();
reader.Seek(0x04 + 0x07, SeekOrigin.Current); // size_BE + datetime
_flags = reader.ReadByte();
reader.Seek(0x06, SeekOrigin.Current); // unit size + interleave gap + volume seq number
byte nameLength = reader.ReadByte();
byte[] nameBytes = reader.ReadBytes(nameLength);
if (nameBytes.Length == 1)
{
if (nameBytes[0] == 0)
_name = ".";
else if (nameBytes[0] == 1)
_name = "..";
}
else
{
_name = Encoding.ASCII.GetString(nameBytes).Split(';')[0];
}
bool isDirectory = (_flags & (int)RecordFlags.DirectoryRecord) == (int)RecordFlags.DirectoryRecord;
bool isNotParentOrGrandparentDirectory = nameLength != 1 || _parent == null;
if (isDirectory && isNotParentOrGrandparentDirectory)
{
reader.Seek(CVMFile.CVM_HEADER_SIZE + ((long)_LBA * CVMFile.ISO_BLOCKSIZE), SeekOrigin.Begin);
_subEntries = new List<ISODirectoryRecord>();
// Set the initial sector start position
long posSubEntriesSectorStart = reader.BaseStream.Position;
long posSubEntriesDataEnd = posSubEntriesSectorStart + _size;
while (reader.BaseStream.Position < posSubEntriesDataEnd)
{
ISODirectoryRecord record = new ISODirectoryRecord(reader, this);
_subEntries.Add(record);
// Skip padding
byte test = reader.ReadByte();
while (test == 0 && reader.BaseStream.Position < posSubEntriesDataEnd)
{
test = reader.ReadByte();
}
// Break out of the loop if we've read to or past the end position
if (reader.BaseStream.Position >= posSubEntriesDataEnd)
{
break;
}
// We've found a non-zero byte, seek back
reader.BaseStream.Position -= 1;
}
}
reader.Seek(posStart + length + extLength, SeekOrigin.Begin);
}
示例11: GetDebugVariableValue
/// <summary>
/// Get debug variable value from the specified frame.
/// </summary>
/// <param name="ID">Debug variable ID.</param>
/// <param name="frame">[OPTIONAL] The frame in which the debug variable was
/// created. If <code>frame</code> is negative this value will be ignored.</param>
/// <returns>Returns the debug variable as a multi-dimensional array.</returns>
public static Array GetDebugVariableValue(int ID, int frame = -1)
{
// for each pass
foreach (Uniforms unif in passes.Values)
{
// not debug output in this pass?
if (unif.data == null)
continue;
// to be able to read basic types the binary array
// needs to be converted into a BinaryReader
var mem = new BinaryReader(new MemoryStream(unif.data));
// for each shader stage
for (int stage = 0; stage < 6; stage++)
{
// offset of the current stage
mem.Seek(16 * stage_size * stage, SeekOrigin.Begin);
// READ DEBUG BUFFER HEADER
// number of debug rows (vec4)
int numDbgRows = mem.ReadInt32();
int dbgFrame = mem.ReadInt32();
mem.Seek(8);
// no debug information for
// this stage in this frame
if (frame >= 0 && frame != dbgFrame)
continue;
// for each debug variable in this stage
// -- i += 1 + rows ... one header row + <rows> data rows
for (int i = 0, rows; i < numDbgRows; i += 1 + rows)
{
// READ DEBUG VAR HEADER
int type = mem.ReadInt32();
rows = mem.ReadInt32();
int cols = mem.ReadInt32();
int varID = mem.ReadInt32();
// this is not the debug variable we want
if (varID != ID)
{
// skip debug variable
mem.Seek(16 * rows);
continue;
}
// convert and return the debug variable
switch (type)
{
case 1/*BOOL */:
case 2/*INT */: return mem?.ReadArray<int>(rows, cols, 16);
case 3/*UINT */: return mem?.ReadArray<uint>(rows, cols, 16);
case 4/*FLOAT*/: return mem?.ReadArray<float>(rows, cols, 16);
}
}
}
}
return null;
}
示例12: InternalRead
internal void InternalRead(BinaryReader reader)
{
_idLength = reader.ReadByte();
_colorMapType = reader.ReadByte();
_dataType = (TGAEncoding)reader.ReadByte();
_paletteStartIndex = reader.ReadInt16();
_paletteLength = reader.ReadInt16();
_paletteDepth = reader.ReadByte();
_xOrigin = reader.ReadInt16();
_yOrigin = reader.ReadInt16();
_width = reader.ReadInt16();
_height = reader.ReadInt16();
_bpp = reader.ReadByte();
_imageDescriptor = reader.ReadByte();
// format check
if (EncodingUsesRLEOrCmp(_dataType) || _dataType == TGAEncoding.Grayscale)
{
throw new NotImplementedException($"Data type not supported: {_dataType}");
}
else if (_dataType == TGAEncoding.None)
{
return;
}
// skip user data
reader.Seek(_idLength, SeekOrigin.Current);
if (IsIndexed)
{
// read palette and indices
_palette = ReadPalette(reader, _paletteLength, _bpp, _paletteDepth);
_paletteIndices = ReadIndices(reader, _dataType, _bpp, _width, _height);
}
else
{
// read pixels
_pixels = ReadPixels(reader, _dataType, _bpp, _width, _height);
}
}
示例13: InternalRead
private void InternalRead(BinaryReader reader)
{
long posFileStart = reader.GetPosition();
short flag = reader.ReadInt16();
short userID = reader.ReadInt16();
int length = reader.ReadInt32();
string tag = reader.ReadCString(4);
int unused = reader.ReadInt32();
if (tag != TAG)
{
throw new InvalidDataException("Identifier mismatch.");
}
int numTypeTableEntries = reader.ReadInt32();
int numUnknown = reader.ReadInt32();
reader.AlignPosition(16);
TypeTableEntry[] typeTable = new TypeTableEntry[numTypeTableEntries];
for (int i = 0; i < numTypeTableEntries; i++)
{
typeTable[i] = new TypeTableEntry(reader);
}
System.Diagnostics.Debug.Assert(typeTable[(int)TypeTableType.Strings].elementCount == 0xF0);
for (int i = 0; i < numTypeTableEntries; i++)
{
reader.Seek(posFileStart + typeTable[i].dataOffset, SeekOrigin.Begin);
switch ((TypeTableType)typeTable[i].type)
{
case TypeTableType.Procedures:
ReadCodeLabels(reader, ref _procedures, typeTable[i].elementCount, out _requireSortProcedures);
break;
case TypeTableType.JumpLabels:
ReadCodeLabels(reader, ref _jumpLabels, typeTable[i].elementCount, out _requireSortJumps);
break;
case TypeTableType.Opcodes:
{
bool hasExtendedOpcodes;
_opcodes = BFDisassembler.ParseCodeblock(reader.ReadUInt32Array(typeTable[i].elementCount), out hasExtendedOpcodes);
if (hasExtendedOpcodes) // only fix up the opcode indices if they have to be
FixupOpcodeIndices(); // this function is kinda 2*O(n^2)
}
break;
case TypeTableType.Messages:
if (typeTable[i].elementCount > 0)
_messageFile = new BMDFile(StreamHelper.ReadStream(reader, typeTable[i].elementCount), false);
break;
case TypeTableType.Strings:
// TODO: Implement this
break;
}
}
}
示例14: InternalRead
internal void InternalRead(BinaryReader reader)
{
_header = new ELFHeader(reader);
_sections = new List<ELFSection>(_header.e_shnum);
if (_header.e_shoff != 0)
{
reader.Seek((long)_header.e_shoff, SeekOrigin.Begin);
_sections[_header.e_shstrndx] = new ELFSection(reader, SizeFormat);
for (int i = 0; i < _header.e_shnum; i++)
{
_sections.Add(new ELFSection(reader, SizeFormat));
}
for (int i = 0; i < _header.e_shnum; i++)
{
_sections[i].GetNameFromStringTable(_sections[_header.e_shstrndx], reader);
}
}
}