本文整理汇总了C#中System.IO.BinaryReader.ReadUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryReader.ReadUInt32方法的具体用法?C# System.IO.BinaryReader.ReadUInt32怎么用?C# System.IO.BinaryReader.ReadUInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了System.IO.BinaryReader.ReadUInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public void Parse(Header header, byte[] data)
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data))
{
using (System.IO.BinaryReader br = new System.IO.BinaryReader(ms))
{
_authCode = br.ReadInt32();
_accountId = br.ReadUInt32();
_userLevel = br.ReadUInt32();
_lastLoginIP = br.ReadUInt32();
_lastLoginTime = br.ReadBytes(26);
_sex = br.ReadByte();
_serverList = new Dictionary<string, Server>();
for (int i = (int)ms.Position; i < header.Size; i += 32)
{
Server s = new Server();
s.IP = string.Format("{0}.{1}.{2}.{3}", br.ReadByte(), br.ReadByte(), br.ReadByte(), br.ReadByte());
s.Port = br.ReadInt16();
s.Name = br.ReadBytes(22).NullByteTerminatedString();
s.Type = br.ReadInt16();
s.UserCount = br.ReadInt16();
_serverList.Add(s.Name, s);
}
}
}
}
示例2: GetDllMachineType
public static MachineType GetDllMachineType(this string dllPath)
{
// See http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
// Offset to PE header is always at 0x3C.
// The PE header starts with "PE\0\0" = 0x50 0x45 0x00 0x00,
// followed by a 2-byte machine type field (see the document above for the enum).
//
using (var fs = new System.IO.FileStream(dllPath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
using (var br = new System.IO.BinaryReader(fs)) {
MachineType machineType = MachineType.IMAGE_FILE_MACHINE_UNKNOWN;
// bool isgood = false;
try {
fs.Seek(0x3c, System.IO.SeekOrigin.Begin);
Int32 peOffset = br.ReadInt32();
fs.Seek(peOffset, System.IO.SeekOrigin.Begin);
UInt32 peHead = br.ReadUInt32();
if (peHead != 0x00004550)
// "PE\0\0", little-endian
throw new Exception("Can't find PE header");
machineType = (MachineType)br.ReadUInt16();
// isgood = true;
}
catch {
// isgood = false;
}
finally {
br.Close();
fs.Close();
}
return machineType;
}
}
示例3: Main
static void Main( string[] args )
{
using ( var mem = new System.IO.MemoryStream( Consts.SuccessfulResponse ) ) {
mem.Seek( 0, System.IO.SeekOrigin.Begin );
var br = new System.IO.BinaryReader( mem );
var pl = br.ReadUInt32();
br.ReadUInt32();
var decoded = new byte[pl];
Buffer.BlockCopy( Consts.SuccessfulResponse,
(int) br.BaseStream.Position,
decoded, 0, (int) pl );
decoded = NetworkHelper.PacketDecoding( decoded );
NetworkHelper.DumpArray( Console.OpenStandardOutput( ), decoded );
}
var srv = new HatServer();
srv.EventOccured += srv_EventOccured;
srv.Start( "127.0.0.1", 8000 );
}
示例4: ParseFile
public static System.Windows.Forms.TreeNode ParseFile(string path)
{
// Read archive tree
uint nFiles, baseOffset;
System.Windows.Forms.TreeNode node = new System.Windows.Forms.TreeNode();
System.IO.BinaryReader stream = new System.IO.BinaryReader(System.IO.File.OpenRead(path));
stream.ReadUInt32();
nFiles = stream.ReadUInt32();
baseOffset = stream.ReadUInt32();
for (int i = 0; i < nFiles; i++)
{
char b;
FileEntry f = new FileEntry();
do
{
b = (char)stream.ReadByte();
if (b != 0)
f.name += b;
} while (b != 0);
f.length = stream.ReadUInt32();
stream.ReadUInt32();
f.offset = baseOffset;
baseOffset += f.length;
f.idx = (uint)i;
System.Windows.Forms.TreeNode n = new System.Windows.Forms.TreeNode(f.name);
n.Tag = f;
node.Nodes.Add(n);
}
return node;
}
示例5: Cursors_v2
public Cursors_v2(string path)
{
System.IO.BinaryReader stream = new System.IO.BinaryReader(new System.IO.FileStream(path + "system\\icons.ph", System.IO.FileMode.Open, System.IO.FileAccess.Read));
if (stream.ReadUInt32() != 0x6e6f6369 || stream.ReadUInt16() != 1)
throw new Exception("Invalid icon file");
_numCursors = stream.ReadUInt16();
cursors = new V2_Cursor[_numCursors];
for (int i = 0; i < _numCursors; i++)
{
readCursor(i, stream);
}
}
示例6: ValidateExe
protected static bool ValidateExe(string path, long time_stamp_offset, uint time_stamp)
{
using (var fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
using (var s = new System.IO.BinaryReader(fs))
{
if (fs.Length > (time_stamp_offset+4))
{
fs.Seek(time_stamp_offset, System.IO.SeekOrigin.Begin);
uint ts = s.ReadUInt32();
return ts == time_stamp;
}
}
return false;
}
示例7: CheckWin32Header
/// <summary>Checks whether a specified file is a valid Win32 plugin.</summary>
/// <param name="file">The file to check.</param>
/// <returns>Whether the file is a valid Win32 plugin.</returns>
private static bool CheckWin32Header(string file)
{
using (System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read)) {
using (System.IO.BinaryReader reader = new System.IO.BinaryReader(stream)) {
if (reader.ReadUInt16() != 0x5A4D) {
/* Not MZ signature */
return false;
}
stream.Position = 0x3C;
stream.Position = reader.ReadInt32();
if (reader.ReadUInt32() != 0x00004550) {
/* Not PE signature */
return false;
}
if (reader.ReadUInt16() != 0x014C) {
/* Not IMAGE_FILE_MACHINE_I386 */
return false;
}
}
}
return true;
}
示例8: GetSerial
static UInt32 GetSerial(byte[] bytes)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes, 8, 4))
{
System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
return reader.ReadUInt32();
}
}
示例9: Despoof
/// <summary>
/// Return an array of bytes without the length prefix and the spoofed suffix.
/// </summary>
/// <param name="bytes">The byte array previously encoded with the Spoof method.</param>
/// <returns>The resulting array is the signal found in the bytes: { byte[4] signal length} + { byte[] signal } + { byte[] noise }.</returns>
public static byte[] Despoof(byte[] bytes)
{
System.IO.BinaryReader reader = new System.IO.BinaryReader(new System.IO.MemoryStream(bytes, 0, bytes.Length));
int length = (int)reader.ReadUInt32();
byte[] message = reader.ReadBytes(length);
return message;
}
示例10: Populate
public void Populate(int iOffset, int iIndexedReflexiveOffset)
{
this.isNulledOutReflexive = false;
System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);
int mapMetaOffset = meta.offset;
if (this._EntIndex.reflexiveTagType + this._EntIndex.reflexiveTagName != string.Empty)
{
int tagNum = map.Functions.ForMeta.FindByNameAndTagType(this._EntIndex.reflexiveTagType, this._EntIndex.reflexiveTagName);
if (tagNum != -1)
{
Meta meta2 = new Meta(map);
map.OpenMap(MapTypes.Internal);
meta2.ReadMetaFromMap(tagNum, true);
map.CloseMap();
mapMetaOffset = meta2.offset;
this._EntIndex.reflexiveLayer = "root";
}
}
if (this._EntIndex.reflexiveLayer.ToLower() == "root")
this._IndexedReflexiveOffset = mapMetaOffset + this._EntIndex.ReflexiveOffset;
else if (this._EntIndex.reflexiveLayer.ToLower() == "oneup")
this._IndexedReflexiveOffset = iIndexedReflexiveOffset + this._EntIndex.ReflexiveOffset;
/*
bool openedMap = false;
if (map.isOpen == false)
{
map.OpenMap(MapTypes.Internal);
openedMap = true;
}
map.BA.Position = iOffset + this.chunkOffset;
*/
BR.BaseStream.Position = iOffset + this.chunkOffset;
this.offsetInMap = meta.offset + iOffset + this.chunkOffset;
switch (_ValueType)
{
case IFPIO.ObjectEnum.Short:
{
this.Value = (int)BR.ReadInt16();
break;
}
case IFPIO.ObjectEnum.Int:
{
this.Value = BR.ReadInt32();
break;
}
case IFPIO.ObjectEnum.UShort:
{
this.Value = (int)BR.ReadUInt16();
break;
}
case IFPIO.ObjectEnum.UInt:
{
this.Value = (int)BR.ReadUInt32();
break;
}
case IFPIO.ObjectEnum.Byte:
{
this.Value = (int)BR.ReadByte();
break;
}
}
UpdateSelectionList(false);
/*
if (openedMap == true)
map.CloseMap();
*/
}
示例11: Main
static void Main(string[] args)
{
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Bind(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 7001));
socket.Listen(10);
for (;;)
{
var client = socket.Accept();
Console.WriteLine("connected..");
var thread = new System.Threading.Thread(() =>
{
try
{
var clientReader = new System.IO.BinaryReader(new NetworkStream(client));
for (;;)
{
if (client.Poll(1, SelectMode.SelectRead) && client.Available == 0)
{
Console.WriteLine("disconnected..");
break;
}
if (client.Available > 0)
{
var msgSize = clientReader.ReadInt32();
var message = clientReader.ReadBytes(msgSize);
var messageReader = new System.IO.BinaryReader(new System.IO.MemoryStream(message));
var msgKind = messageReader.ReadInt32();
Console.WriteLine("message: kind:{0}, len:{1}", msgKind, message.Length);
switch (msgKind)
{
case 0:
{
var activeProcessId = GetWindowProcessId(GetForegroundWindow());
if (activeProcessId == null)
break;
if (Process.GetProcessById(activeProcessId.Value)?.ProcessName != "ZumasRevenge")
break;
var flags = messageReader.ReadUInt32();
var x = messageReader.ReadInt32();
var y = messageReader.ReadInt32();
var data = messageReader.ReadUInt32();
mouse_event(flags, x, y, data, UIntPtr.Zero);
}
break;
case 1://reset
{
Process.GetProcessesByName("ZumasRevenge").FirstOrDefault()?.Kill();
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(4));
var info = new ProcessStartInfo
{
FileName = @"C:\Program Files\Games\Zuma's Revenge! v1.0.4\ZumasRevenge.exe",
WorkingDirectory = @"C:\Program Files\Games\Zuma's Revenge! v1.0.4",
UseShellExecute = false,
};
Process.Start(info);
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
}
break;
}
}
else
System.Threading.Thread.Sleep(10);
}
}
catch (Exception exc)
{
Console.WriteLine(exc);
}
})
{ IsBackground = true };
thread.Start();
}
}
示例12: Read_pachm
/// <summary>
/// reads a file and populates the map receiver instance.
/// </summary>
/// <returns></returns>
public static bool Read_pachm(out Mapping.PachMapReceiver[] Map)
{
System.Windows.Forms.OpenFileDialog of = new System.Windows.Forms.OpenFileDialog();
of.DefaultExt = ".pachm";
of.AddExtension = true;
of.Filter = "Pachyderm Mapping Data File (*.pachm)|*.pachm|" + "All Files|";
if (of.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
Map = null;
return false;
}
System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(of.FileName, System.IO.FileMode.Open));
//1. Write calculation type. (string)
string CalcType = sr.ReadString();
if (CalcType != "Type;Map_Data" && CalcType != "Type;Map_Data_NoDir") throw new Exception("Map Data File Expected");
bool Directional = (CalcType == "Type;Map_Data");
//2. Write the number of samples in each histogram. (int)
int SampleCT = (int)sr.ReadUInt32();
//3. Write the sample rate. (int)
int SampleRate = (int)sr.ReadUInt32();
//4. Write the number of Receivers (int)
int Rec_CT = (int)sr.ReadUInt32();
//4.5 Write the version number
double version = 1.1;
double rev = 0;
//5. Announce that the following data pertains to the form of the analysis mesh. (string)
int s_ct=1;
Rhino.Geometry.Mesh Map_Mesh = new Rhino.Geometry.Mesh();
Map = new Mapping.PachMapReceiver[1];
//Map[0] = new Pach_Map_Receiver();
//double[] Rho_C = null;
double[] delay;
do
{
switch (sr.ReadString())
{
case "Version":
//Pach1.7 = Versioning functionality added.
string v = sr.ReadString();
version = double.Parse(v.Substring(0, 3));
rev = int.Parse(v.Split(new char[1] { '.' })[3]);
break;
case "Mesh Information":
//6. Announce Mesh Vertices (string)
//Write the number of vertices & faces (int) (int)
if (sr.ReadString() != "Mesh Vertices") throw new Exception("Mesh Vertices Expected");
int VC = (int)sr.ReadUInt32();
int FC = (int)sr.ReadUInt32();
for (int i = 0; i < VC; i++)
{
//Write Vertex: (double) (double) (double)
Map_Mesh.Vertices.Add(new Rhino.Geometry.Point3d(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()));
}
//7. Announce Mesh Faces (string)
if (sr.ReadString() != "Mesh Faces") throw new Exception("Mesh Faces Expected");
for (int i = 0; i < FC; i++)
{
// Write mesh vertex indices: (int) (int) (int) (int)
Map_Mesh.Faces.AddFace((int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32());
}
break;
case "Sources":
//7.5: Announce the number of sources.
s_ct = sr.ReadInt32();
delay = new double[s_ct];
Map = new Mapping.PachMapReceiver[s_ct];
//7.5a Announce the type of source.
for (int s = 0; s < s_ct; s++)
{
Map[s] = new Mapping.PachMapReceiver();
Map[s].CutOffTime = (double)SampleCT / (double)SampleRate;
Map[s].SampleCT = SampleCT;
Map[s].SampleRate = SampleRate;
Map[s].Map_Mesh = Map_Mesh;
Map[s].Rec_List = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
Map[s].SrcType = sr.ReadString();
//4.4 Source delay (ms)
if (version > 2.0 || (version == 2.0 && rev >= 1))
{
delay[s] = sr.ReadDouble();
}
}
break;
case "SourceswLoc":
//7.5: Announce the number of sources.
s_ct = sr.ReadInt32();
delay = new double[s_ct];
Map = new Mapping.PachMapReceiver[s_ct];
//7.5a Announce the type of source.
//.........这里部分代码省略.........
示例13: Load
// Per spot:
// uint32 magic
// uint32 reserved;
// uint32 flags;
// float x;
// float y;
// float z;
// uint32 no_paths
// for each path
// float x;
// float y;
// float z;
public bool Load(string baseDir)
{
string fileName = FileName();
string filenamebin = baseDir + fileName;
System.IO.Stream stream = null;
System.IO.BinaryReader file = null;
int n_spots = 0;
int n_steps = 0;
try
{
stream = System.IO.File.OpenRead(filenamebin);
if (stream != null)
{
file = new System.IO.BinaryReader(stream);
if (file != null)
{
uint magic = file.ReadUInt32();
if (magic == FILE_MAGIC)
{
uint type;
while ((type = file.ReadUInt32()) != FILE_ENDMAGIC)
{
n_spots++;
uint reserved = file.ReadUInt32();
uint flags = file.ReadUInt32();
float x = file.ReadSingle();
float y = file.ReadSingle();
float z = file.ReadSingle();
uint n_paths = file.ReadUInt32();
if (x != 0 && y != 0)
{
Spot s = new Spot(x, y, z);
s.flags = flags;
for (uint i = 0; i < n_paths; i++)
{
n_steps++;
float sx = file.ReadSingle();
float sy = file.ReadSingle();
float sz = file.ReadSingle();
s.AddPathTo(sx, sy, sz);
}
AddSpot(s);
}
}
}
}
}
}
catch (System.IO.FileNotFoundException e)
{
Console.WriteLine(e.Message);
}
catch (System.IO.DirectoryNotFoundException e)
{
Console.WriteLine(e.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
if (file != null)
{
file.Close();
}
if (stream != null)
{
stream.Close();
}
Log("Loaded " + fileName + " " + n_spots + " spots " + n_steps + " steps");
modified = false;
return false;
}
示例14: _LoadTexture
private TextureHandle _LoadTexture(string name)
{
var device = mDevice;
Stormlib.MPQFile fl = new Stormlib.MPQFile(name);
System.IO.BinaryReader reader = new System.IO.BinaryReader(fl);
uint sig = reader.ReadUInt32();
if (sig == 0x32504C42)
{
return LoadBlpTexture(device, reader);
}
try
{
var tex = SlimDX.Direct3D9.Texture.FromStream(device, fl);
if (tex != null)
return new TextureHandle(tex);
}
catch (Exception)
{
}
return null;
}
示例15: readGameData
private void readGameData()
{
textBox2.Text = path;
if (roq != null)
roq.stop();
roq = null;
if (vdx != null)
vdx.stop();
vdx = null;
switch (game)
{
case GameID.T7G:
lblGame.Text = "The 7th Guest";
System.IO.DirectoryInfo DI = new System.IO.DirectoryInfo(path);
System.IO.FileInfo[] files = DI.GetFiles("*.rl");
this.gjdChooser.Items.Clear();
foreach (System.IO.FileInfo rl in files)
{
this.gjdChooser.Items.Add(rl.Name);
}
break;
case GameID.T11H:
lblGame.Text = "The 11th Hour";
//ROQ roq = new ROQ(new System.IO.BinaryReader(new System.IO.FileStream(path + "\\media\\final_hr.rol", System.IO.FileMode.Open)));
this.gjdChooser.Items.Clear();
System.IO.BinaryReader idx = new System.IO.BinaryReader(new System.IO.FileStream(path + "\\groovie\\gjd.gjd", System.IO.FileMode.Open));
string name = "";
while (idx.BaseStream.Position < idx.BaseStream.Length)
{
if (idx.PeekChar() == 0x0A)
{
idx.ReadChar();
if (name.Length > 0)
this.gjdChooser.Items.Add(name.Substring(0, name.IndexOf(" ")));
name = "";
}
else
name += "" + idx.ReadChar();
}
idx.Close();
V2_RL = new List<GJD.RLData>[this.gjdChooser.Items.Count];
for (int i = 0; i < V2_RL.Length; i++)
V2_RL[i] = new List<GJD.RLData>();
this.gjdChooser.Items.Add("Icons");
idx = new System.IO.BinaryReader(new System.IO.FileStream(path + "\\groovie\\dir.rl", System.IO.FileMode.Open));
uint ctr = 0;
while (idx.BaseStream.Position < idx.BaseStream.Length)
{
// Get RL content
GJD.RLData rl = new GJD.RLData();
idx.ReadUInt32();
rl.offset = idx.ReadUInt32();
rl.length = idx.ReadUInt32();
rl.number = ctr;
ctr++;
ushort target = idx.ReadUInt16();
byte[] filename;
filename = idx.ReadBytes(12);
rl.filename = System.Text.Encoding.ASCII.GetString(filename).Trim();
idx.ReadBytes(6);
V2_RL[target].Add(rl);
}
break;
default:
lblGame.Text = "None";
break;
}
}