本文整理匯總了C#中System.IO.BinaryReader.ReadBytes方法的典型用法代碼示例。如果您正苦於以下問題:C# BinaryReader.ReadBytes方法的具體用法?C# BinaryReader.ReadBytes怎麽用?C# BinaryReader.ReadBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.ReadBytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Read
internal override void Read(BinaryReader reader)
{
Version = reader.ReadUInt16();
VersionNeededToExtract = reader.ReadUInt16();
Flags = (HeaderFlags) reader.ReadUInt16();
CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16();
LastModifiedTime = reader.ReadUInt16();
LastModifiedDate = reader.ReadUInt16();
Crc = reader.ReadUInt32();
CompressedSize = reader.ReadUInt32();
UncompressedSize = reader.ReadUInt32();
ushort nameLength = reader.ReadUInt16();
ushort extraLength = reader.ReadUInt16();
ushort commentLength = reader.ReadUInt16();
DiskNumberStart = reader.ReadUInt16();
InternalFileAttributes = reader.ReadUInt16();
ExternalFileAttributes = reader.ReadUInt32();
RelativeOffsetOfEntryHeader = reader.ReadUInt32();
byte[] name = reader.ReadBytes(nameLength);
Name = DecodeString(name);
byte[] extra = reader.ReadBytes(extraLength);
byte[] comment = reader.ReadBytes(commentLength);
Comment = DecodeString(comment);
LoadExtra(extra);
}
示例2: Read
internal override void Read(BinaryReader reader)
{
Version = reader.ReadUInt16();
VersionNeededToExtract = reader.ReadUInt16();
Flags = (HeaderFlags) reader.ReadUInt16();
CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16();
LastModifiedTime = reader.ReadUInt16();
LastModifiedDate = reader.ReadUInt16();
Crc = reader.ReadUInt32();
CompressedSize = reader.ReadUInt32();
UncompressedSize = reader.ReadUInt32();
ushort nameLength = reader.ReadUInt16();
ushort extraLength = reader.ReadUInt16();
ushort commentLength = reader.ReadUInt16();
DiskNumberStart = reader.ReadUInt16();
InternalFileAttributes = reader.ReadUInt16();
ExternalFileAttributes = reader.ReadUInt32();
RelativeOffsetOfEntryHeader = reader.ReadUInt32();
byte[] name = reader.ReadBytes(nameLength);
Name = DecodeString(name);
byte[] extra = reader.ReadBytes(extraLength);
byte[] comment = reader.ReadBytes(commentLength);
Comment = DecodeString(comment);
LoadExtra(extra);
var unicodePathExtra = Extra.FirstOrDefault(u => u.Type == ExtraDataType.UnicodePathExtraField);
if (unicodePathExtra != null)
{
Name = ((ExtraUnicodePathExtraField)unicodePathExtra).UnicodeName;
}
}
示例3: Main
static void Main(string[] args)
{
OpenFileDialog OpenFile = new OpenFileDialog();
OpenFile.Multiselect = false;
OpenFile.Title = "Cartridge";
OpenFile.Filter = "GBA Files (.gba)|*.gba";
OpenFile.FilterIndex = 1;
string Cartridge;
Console.WriteLine("Gneiss - Game Boy Advance Cartridge Reader.");
Console.CursorVisible = false;
if (OpenFile.ShowDialog() == DialogResult.OK)
{
Cartridge = OpenFile.FileName;
BinaryReader BR = new BinaryReader(File.OpenRead(Cartridge));
BR.BaseStream.Seek(0xA0, SeekOrigin.Begin);
Console.WriteLine("\n\nCartridge Name: {0}", Encoding.UTF8.GetString(BR.ReadBytes(12)));
BR.BaseStream.Seek(0xAC, SeekOrigin.Begin);
Console.WriteLine("Serial: {0}", Encoding.UTF8.GetString(BR.ReadBytes(4)));
BR.BaseStream.Seek(0x108, SeekOrigin.Begin);
Console.WriteLine("Name: {0}", Encoding.UTF8.GetString(BR.ReadBytes(24)));
Console.Read();
}
}
示例4: Read
public static ConnectionSettings Read(byte[] data)
{
var cs = new ConnectionSettings();
using (var ms = new MemoryStream(data))
using (var br = new BinaryReader(ms))
{
cs.Version = br.ReadInt32();
cs.Counter = br.ReadInt32();
cs.Autodetect = (Autodetect)br.ReadInt32();
var len = br.ReadInt32();
cs.ProxyServer = Utf8.GetString(br.ReadBytes(len));
len = br.ReadInt32();
cs.ExtraData = Utf8.GetString(br.ReadBytes(len));
len = br.ReadInt32();
cs.AutodetectScript = Utf8.GetString(br.ReadBytes(len));
// So damn lazy.
using (var ms2 = new MemoryStream())
{
var ba = new byte[Environment.SystemPageSize];
while ((len = br.Read(ba, 0, ba.Length)) != 0)
{
ms2.Write(ba, 0, len);
}
cs.Junk = ms2.ToArray();
}
}
return cs;
}
示例5: ReadFile
public static bool ReadFile(string FileName)
{
LCMeshReader.OpenedFile = FileName;
LCMeshReader.pMesh = new tMeshContainer();
BinaryReader b = new BinaryReader( new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read));
LCMeshReader.pMesh.HeaderInfo = new tHeaderInfo();
LCMeshReader.pMesh.HeaderInfo.Format = b.ReadBytes(4);
LCMeshReader.pMesh.HeaderInfo.Version = b.ReadInt32();
LCMeshReader.pMesh.HeaderInfo.MeshDataSize = b.ReadInt32();
LCMeshReader.pMesh.HeaderInfo.MeshCount = b.ReadUInt32();
LCMeshReader.pMesh.HeaderInfo.VertexCount = b.ReadUInt32();
LCMeshReader.pMesh.HeaderInfo.JointCount = b.ReadUInt32();
LCMeshReader.pMesh.HeaderInfo.TextureMaps = b.ReadUInt32();
LCMeshReader.pMesh.HeaderInfo.NormalCount = b.ReadUInt32();
LCMeshReader.pMesh.HeaderInfo.ObjCount = b.ReadUInt32();
LCMeshReader.pMesh.HeaderInfo.UnknownCount = b.ReadUInt32();
LCMeshReader.pMesh.FileName = b.ReadBytes(b.ReadInt32());
LCMeshReader.pMesh.Scale = b.ReadSingle();
LCMeshReader.pMesh.Value1 = b.ReadUInt32();
LCMeshReader.pMesh.FilePath = FileName;
bool flag = false;
if (LCMeshReader.pMesh.HeaderInfo.Version == 16)
{
if (LCMeshReader.ReadV10(b, b.BaseStream.Position))
flag = true;
}
else if (LCMeshReader.pMesh.HeaderInfo.Version == 17 && LCMeshReader.ReadV11(b, b.BaseStream.Position))
flag = true;
b.Close();
return flag;
}
示例6: ReadBlendomatic
public static void ReadBlendomatic(FileStream file)
{
BinaryReader reader = new BinaryReader(file);
NumberOfBlendingModes = reader.ReadUInt32();
NumberOfTiles = reader.ReadUInt32();
BlendingModes = new Dictionary<byte, BlendingMode>();
Console.WriteLine("Number of blending modes: " + NumberOfBlendingModes);
Console.WriteLine("Number of tiles: " + NumberOfTiles);
for (var i = 0; i < NumberOfBlendingModes; i++ )
{
BlendingMode mode;
mode.TileSize = reader.ReadUInt32();
mode.Tiles = new Dictionary<byte, byte[]>();
var TileFlags = reader.ReadBytes(31); // all 1 wtf
reader.ReadBytes((int)mode.TileSize * 4);
for (var j = 0; j < NumberOfTiles; j++)
{
mode.Tiles[(byte)j] = reader.ReadBytes((int)mode.TileSize);
}
BlendingModes[(byte)i] = mode;
}
}
示例7: Read
internal void Read(BinaryReader reader, float CoordZ, float scale)
{
SkinVertIndex = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
for (int i = 0; i < SkinVertPos.Length; i++)
SkinVertPos[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0)* scale;
SkinVertPos[2] *= CoordZ;
}
示例8: RPF7File
public RPF7File(Stream inputStream, String filname = "")
{
this.Filename = filname;
Stream = inputStream;
Info = new Structs.RPF7Header(Stream);
if (new string(Info.Magic) != "RPF7")
{
throw new Exception("Invalid RPF Magic");
}
sixteenRoundsDecrypt = (Info.Flag >> 28) == 0xf;
if (sixteenRoundsDecrypt)
{
throw new Exception("Needed to be tested first");
}
using (BinaryReader binaryStream = new BinaryReader(AES.DecryptStream(new StreamKeeper(this.Stream), sixteenRoundsDecrypt)))
{
MemoryStream entriesInfo = new MemoryStream(binaryStream.ReadBytes(0x10 * Info.EntriesCount));
MemoryStream filenames = new MemoryStream(binaryStream.ReadBytes(Info.EntriesNamesLength));
this.Root = Entry.CreateFromHeader(new Structs.RPF7EntryInfoTemplate(entriesInfo), this, entriesInfo, filenames);
}
if (!(this.Root is DirectoryEntry))
{
throw new Exception("Expected root to be directory");
}
}
示例9: NameResolutionRecord
internal NameResolutionRecord(BinaryReader reader)
{
UInt16 type = reader.ReadUInt16();
int valueLength = reader.ReadUInt16();
if (type != EndRecordType)
{
int entriesLength = valueLength;
if (type == Ip6RecordType)
{
this.IsIpVersion6 = true;
this.IpAddress = reader.ReadBytes(Ip6Length);
entriesLength -= Ip6Length;
}
else
{
this.IsIpVersion6 = false;
this.IpAddress = reader.ReadBytes(Ip4Length);
entriesLength -= Ip4Length;
}
this.DnsEntries = this.ReadDnsEntries(reader, entriesLength);
int remainderLength = valueLength % ValueAlignmentBoundary;
if (remainderLength > 0)
{
reader.ReadBytes(ValueAlignmentBoundary - remainderLength); // Read fill bytes to boundary.
}
}
}
示例10: UncompressStream
public static byte[] UncompressStream(Stream stream, int filesize, int memsize)
{
BinaryReader r = new BinaryReader(stream);
long end = stream.Position + filesize;
byte[] uncdata = new byte[memsize];
BinaryWriter bw = new BinaryWriter(new MemoryStream(uncdata));
byte[] data = r.ReadBytes(2);
if (checking) if (data.Length != 2)
throw new InvalidDataException("Hit unexpected end of file at " + stream.Position);
int datalen = (((data[0] & 0x80) != 0) ? 4 : 3) * (((data[0] & 0x01) != 0) ? 2 : 1);
data = r.ReadBytes(datalen);
if (checking) if (data.Length != datalen)
throw new InvalidDataException("Hit unexpected end of file at " + stream.Position);
long realsize = 0;
for (int i = 0; i < data.Length; i++) realsize = (realsize << 8) + data[i];
if (checking) if (realsize != memsize)
throw new InvalidDataException(String.Format(
"Resource data indicates size does not match index at 0x{0}. Read 0x{1}. Expected 0x{2}.",
stream.Position.ToString("X8"), realsize.ToString("X8"), memsize.ToString("X8")));
while (stream.Position < end) { Dechunk(stream, bw); }
if (checking) if (bw.BaseStream.Position != memsize)
throw new InvalidDataException(String.Format("Read 0x{0:X8} bytes. Expected 0x{1:X8}.", bw.BaseStream.Position, memsize));
bw.Close();
return uncdata;
}
示例11: FAR3Archive
/// <summary>
/// Creates a new FAR3Archive instance from a path.
/// </summary>
/// <param name="Path">The path to the archive.</param>
public FAR3Archive(string Path)
{
m_ArchivePath = Path;
if (isReadingSomething == false)
{
isReadingSomething = true;
try
{
m_Reader = new BinaryReader(File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.Read));
}
catch (Exception)
{
throw new FAR3Exception("Could not open the specified archive - " + Path + "! (FAR3Archive())");
}
string Header = Encoding.ASCII.GetString(m_Reader.ReadBytes(8));
uint Version = m_Reader.ReadUInt32();
if ((Header != "FAR!byAZ") || (Version != 3))
{
throw new FAR3Exception("Archive wasn't a valid FAR V.3 archive! (FAR3Archive())");
}
uint ManifestOffset = m_Reader.ReadUInt32();
m_ManifestOffset = ManifestOffset;
m_Reader.BaseStream.Seek(ManifestOffset, SeekOrigin.Begin);
uint NumFiles = m_Reader.ReadUInt32();
for (int i = 0; i < NumFiles; i++)
{
Far3Entry Entry = new Far3Entry();
Entry.DecompressedFileSize = m_Reader.ReadUInt32();
byte[] Dummy = m_Reader.ReadBytes(3);
Entry.CompressedFileSize = (uint)((Dummy[0] << 0) | (Dummy[1] << 8) | (Dummy[2]) << 16);
Entry.DataType = m_Reader.ReadByte();
Entry.DataOffset = m_Reader.ReadUInt32();
//Entry.HasFilename = m_Reader.ReadUInt16();
Entry.IsCompressed = m_Reader.ReadByte();
Entry.AccessNumber = m_Reader.ReadByte();
Entry.FilenameLength = m_Reader.ReadUInt16();
Entry.TypeID = m_Reader.ReadUInt32();
Entry.FileID = m_Reader.ReadUInt32();
Entry.Filename = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength));
if (!m_Entries.ContainsKey(Entry.Filename))
m_Entries.Add(Entry.Filename, Entry);
m_EntriesList.Add(Entry);
m_EntryByID.Add(Entry.FileID, Entry); //isn't this a bad idea? i have a feeling this is a bad idea...
}
//Keep the stream open, it helps peformance.
//m_Reader.Close();
isReadingSomething = false;
}
}
示例12: Parse
/// <summary> Parses the Replay.Messages.Events file. </summary>
/// <param name="buffer"> Buffer containing the contents of the replay.messages.events file. </param>
/// <returns> A list of chat messages parsed from the buffer. </returns>
public static void Parse(Replay replay, byte[] buffer)
{
using (var stream = new MemoryStream(buffer))
{
using (var reader = new BinaryReader(stream))
{
int totalTime = 0;
while (reader.BaseStream.Position < reader.BaseStream.Length)
{
// While not EOF
var message = new ChatMessage();
var time = ParseTimestamp(reader);
// sometimes we only have a header for the message
if (reader.BaseStream.Position >= reader.BaseStream.Length)
break;
message.PlayerId = reader.ReadByte();
// I believe this 'PlayerId' is an index for this client list, which can include observers
// var player = replay.ClientList[message.PlayerId];
totalTime += time;
var opCode = reader.ReadByte();
if (opCode == 0x80)
reader.ReadBytes(4);
else if (opCode == 0x83)
reader.ReadBytes(8);
else if (opCode == 2 && message.PlayerId <= 10)
{
if (message.PlayerId == 80)
continue;
message.MessageTarget = (ChatMessageTarget)(opCode & 7);
var length = reader.ReadByte();
if ((opCode & 8) == 8)
length += 64;
if ((opCode & 16) == 16)
length += 128;
message.Message = Encoding.UTF8.GetString(reader.ReadBytes(length));
}
else
{
}
if (message.Message != null)
{
message.Timestamp = new TimeSpan(0, 0, (int)Math.Round(totalTime / 16.0));
replay.ChatMessages.Add(message);
}
}
}
}
}
示例13: FDSFile
public FDSFile(BinaryReader r)
{
byte[] tmp = r.ReadBytes(4);
int numdisks;
if (tmp.SequenceEqual(Check))
{
numdisks = r.ReadByte();
ExtraData = r.ReadBytes(11);
}
else if (tmp.SequenceEqual(CheckAlt))
{
// compensate (won't write identically)
r.BaseStream.Seek(0, SeekOrigin.Begin);
numdisks = (int)(r.BaseStream.Length / 65500);
ExtraData = new byte[11];
}
else
{
throw new InvalidOperationException("Bad Header!");
}
if (r.BaseStream.Length - r.BaseStream.Position != numdisks * 65500)
throw new InvalidOperationException("Bad File Length!");
while (numdisks > 0)
{
Disks.Add(new FDSDisk(r));
numdisks--;
}
}
示例14: Deserialize
public void Deserialize(byte[] buffer)
{
if (buffer.Length == 240)
{
MemoryStream MS = new MemoryStream(buffer);
BinaryReader BR = new BinaryReader(MS);
ushort length = BR.ReadUInt16();
if (length == 240)
{
ushort type = BR.ReadUInt16();
if (type == 1124)
{
Username = Encoding.ASCII.GetString(BR.ReadBytes(16));
Username = Username.Replace("\0", "");
BR.ReadBytes(112);
Password = Encoding.ASCII.GetString(BR.ReadBytes(16));
BR.ReadBytes(112);
Server = Encoding.ASCII.GetString(BR.ReadBytes(16));
Server = Server.Replace("\0", "");
}
}
BR.Close();
MS.Close();
}
}
示例15: Read
public void Read(BinaryReader reader, float CoordZ, float scale)
{
Position = new float[3];
for (int i = 0; i < Position.Length; i++)
{
Position[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
}
NormalVector = new float[3];
for (int i = 0; i < NormalVector.Length; i++)
{
NormalVector[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
}
UV = new float[2];
for (int i = 0; i < UV.Length; i++)
{
UV[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
}
BoneNum = new WORD[2];
for (int i = 0; i < BoneNum.Length; i++)
{
BoneNum[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
}
BoneWeight = reader.ReadByte();
NonEdgeFlag = reader.ReadByte();
Position[2] *= CoordZ;
NormalVector[2] *= CoordZ;
}