Here are the examples of the csharp api System.BitConverter.ToUInt64(byte[], int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
567 Examples
19
View Source File : RandomHelper.cs
License : MIT License
Project Creator : 1996v
License : MIT License
Project Creator : 1996v
public static object RandomValue(this Type t, bool stringValueAllowEmpty = true)
{
if (t.IsPrimitive)
{
if (t == typeof(byte))
{
return (byte)(Rand.Next(byte.MaxValue - byte.MinValue + 1) + byte.MinValue);
}
if (t == typeof(sbyte))
{
return (sbyte)(Rand.Next(sbyte.MaxValue - sbyte.MinValue + 1) + sbyte.MinValue);
}
if (t == typeof(short))
{
return (short)(Rand.Next(short.MaxValue - short.MinValue + 1) + short.MinValue);
}
if (t == typeof(ushort))
{
return (ushort)(Rand.Next(ushort.MaxValue - ushort.MinValue + 1) + ushort.MinValue);
}
if (t == typeof(int))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
return BitConverter.ToInt32(bytes, 0);
}
if (t == typeof(uint))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
return BitConverter.ToUInt32(bytes, 0);
}
if (t == typeof(long))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
return BitConverter.ToInt64(bytes, 0);
}
if (t == typeof(ulong))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
return BitConverter.ToUInt64(bytes, 0);
}
if (t == typeof(float))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
var f = BitConverter.ToSingle(bytes, 0);
if (float.IsNaN(f))
f = (float)RandomValue<short>();
return f;
}
if (t == typeof(double))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
var d= BitConverter.ToDouble(bytes, 0);
if (double.IsNaN(d))
d = (double)RandomValue<short>();
return d;
}
if (t == typeof(char))
{
var roll = Rand.Next(ASCII.Length);
return ASCII[roll];
}
if (t == typeof(bool))
{
return (Rand.Next(2) == 1);
}
throw new InvalidOperationException();
}
if (t == typeof(decimal))
{
return new decimal((int)typeof(int).RandomValue(), (int)typeof(int).RandomValue(), (int)typeof(int).RandomValue(), false, 28);
}
if (t == typeof(string))
{
int start = stringValueAllowEmpty ? 0 : 1;
var len = Rand.Next(start, 40);
var c = new char[len];
for (var i = 0; i < c.Length; i++)
{
c[i] = (char)typeof(char).RandomValue();
}
return new string(c);
}
if (t == typeof(DateTime))
{
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var bytes = new byte[4];
Rand.NextBytes(bytes);
var secsOffset = BitConverter.ToInt32(bytes, 0);
var retDate = epoch.AddSeconds(secsOffset);
return retDate;
}
if (t == typeof(TimeSpan))
{
return new TimeSpan(RandomValue<DateTime>().Ticks);
}
if (t == typeof(DataTable))
{
DataTable dt = new DataTable();
int coluCount = Rand.Next(10, 30);
for (int i = 0; i < coluCount; i++)
{
string n = RandomHelper.RandomValue<string>(false);
while(dt.Columns.Contains(n))
n = RandomHelper.RandomValue<string>(false);
dt.Columns.Add(n, typeof(object));
}
int rowCount = Rand.Next(20, 50);
for (int i = 0; i < rowCount; i++)
{
var row = new object[coluCount];
for (int zi = 0; zi < coluCount; zi++)
{
row[zi] = RandomHelper.RandomValue<object>();
}
dt.Rows.Add(row);
}
return dt;
}
if (t.IsNullable())
{
// leave it unset
if (Rand.Next(2) == 0)
{
// null!
return Activator.CreateInstance(t);
}
var underlying = Nullable.GetUnderlyingType(t);
var val = underlying.RandomValue(stringValueAllowEmpty);
var cons = t.GetConstructor(new[] { underlying });
return cons.Invoke(new object[] { val });
}
if (t.IsEnum)
{
var allValues = Enum.GetValues(t);
var ix = Rand.Next(allValues.Length);
return allValues.GetValue(ix);
}
if (t.IsArray)
{
var valType = t.GetElementType();
var len = Rand.Next(20, 50);
var ret = Array.CreateInstance(valType, len);
//var add = t.GetMethod("SetValue");
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
ret.SetValue(elem, i);
}
return ret;
}
if (t.IsGenericType)
{
var defind = t.GetGenericTypeDefinition();
if (defind == typeof(HashSet<>))
{
var valType = t.GetGenericArguments()[0];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var contains = t.GetMethod("Contains");
var len = Rand.Next(20, 50);
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
while (elem == null || (bool)contains.Invoke(ret, new object[] { elem }))
elem = valType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { elem });
}
return ret;
}
if (defind == typeof(Dictionary<,>))
{
var keyType = t.GetGenericArguments()[0];
var valType = t.GetGenericArguments()[1];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var contains = t.GetMethod("ContainsKey");
var len = Rand.Next(20, 50);
if (keyType == typeof(Boolean))
len = 2;
for (var i = 0; i < len; i++)
{
var val = valType.RandomValue(stringValueAllowEmpty);
var key = keyType.RandomValue(stringValueAllowEmpty);
while (key == null || (bool)contains.Invoke(ret, new object[] { key }))
key = keyType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { key, val });
}
return ret;
}
if (defind == typeof(List<>))
{
var valType = t.GetGenericArguments()[0];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var len = Rand.Next(20, 50);
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { elem });
}
return ret;
}
if (defind == typeof(ArraySegment<>))
{
var valType = t.GetGenericArguments()[0];
var ary = valType.MakeArrayType().RandomValue(stringValueAllowEmpty);
var lenT = ary.GetType().GetProperty("Length");
var offset = Rand.Next(0, (int)lenT.GetValue(ary) - 1);
var len = (int)lenT.GetValue(ary) - offset;
return Activator.CreateInstance(t, ary, offset, len);
}
}
if (t == typeof(Guid))
return Guid.NewGuid();
if (t == typeof(object))
{
var code = Rand.Next(0, 9);
switch (code)
{
case 0:
return RandomValue<int>();
case 1:
return RandomValue<long>();
case 2:
return RandomValue<Char>();
case 3:
return RandomValue<DateTime>();
case 4:
return RandomValue<string>(stringValueAllowEmpty);
case 5:
return RandomValue<Guid>();
case 6:
return RandomValue<decimal>();
case 7:
return RandomValue<double>();
case 8:
return RandomValue<float>();
default:
return RandomValue<short>();
}
}
//model
var retObj = Activator.CreateInstance(t);
foreach (var p in t.GetFields())
{
//if (Rand.Next(5) == 0) continue;
var fieldType = p.FieldType;
p.SetValue(retObj, fieldType.RandomValue(stringValueAllowEmpty));
}
foreach (var p in t.GetProperties())
{
//if (Rand.Next(5) == 0) continue;
if (p.CanWrite && p.CanRead)
{
var fieldType = p.PropertyType;
p.SetValue(retObj, fieldType.RandomValue(stringValueAllowEmpty));
}
}
return retObj;
}
19
View Source File : RandomHelper.cs
License : MIT License
Project Creator : 1996v
License : MIT License
Project Creator : 1996v
public static object RandomValue(this Type t, bool stringValueAllowEmpty = true)
{
if (t.IsPrimitive)
{
if (t == typeof(byte))
{
return (byte)(Rand.Next(byte.MaxValue - byte.MinValue + 1) + byte.MinValue);
}
if (t == typeof(sbyte))
{
return (sbyte)(Rand.Next(sbyte.MaxValue - sbyte.MinValue + 1) + sbyte.MinValue);
}
if (t == typeof(short))
{
return (short)(Rand.Next(short.MaxValue - short.MinValue + 1) + short.MinValue);
}
if (t == typeof(ushort))
{
return (ushort)(Rand.Next(ushort.MaxValue - ushort.MinValue + 1) + ushort.MinValue);
}
if (t == typeof(int))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
return BitConverter.ToInt32(bytes, 0);
}
if (t == typeof(uint))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
return BitConverter.ToUInt32(bytes, 0);
}
if (t == typeof(long))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
return BitConverter.ToInt64(bytes, 0);
}
if (t == typeof(ulong))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
return BitConverter.ToUInt64(bytes, 0);
}
if (t == typeof(float))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
var f = BitConverter.ToSingle(bytes, 0);
if (float.IsNaN(f))
f = (float)RandomValue<short>();
return f;
}
if (t == typeof(double))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
var d = BitConverter.ToDouble(bytes, 0);
if (double.IsNaN(d))
d = (double)RandomValue<short>();
return d;
}
if (t == typeof(char))
{
var roll = Rand.Next(ASCII.Length);
return ASCII[roll];
}
if (t == typeof(bool))
{
return (Rand.Next(2) == 1);
}
throw new InvalidOperationException();
}
if (t == typeof(decimal))
{
return new decimal((int)typeof(int).RandomValue(), (int)typeof(int).RandomValue(), (int)typeof(int).RandomValue(), false, 28);
}
if (t == typeof(string))
{
int start = stringValueAllowEmpty ? 0 : 1;
var len = Rand.Next(start, 28);
var c = new char[len];
for (var i = 0; i < c.Length; i++)
{
c[i] = (char)typeof(char).RandomValue();
}
return new string(c);
}
if (t == typeof(DateTime))
{
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var bytes = new byte[4];
Rand.NextBytes(bytes);
var secsOffset = BitConverter.ToInt32(bytes, 0);
var retDate = epoch.AddSeconds(secsOffset);
return retDate;
}
if (t == typeof(TimeSpan))
{
return new TimeSpan(RandomValue<DateTime>().Ticks);
}
if (t == typeof(DataTable))
{
DataTable dt = new DataTable();
int coluCount = Rand.Next(10, 30);
for (int i = 0; i < coluCount; i++)
{
dt.Columns.Add(RandomHelper.RandomValue<string>(false), typeof(object));
}
int rowCount = Rand.Next(20, 50);
for (int i = 0; i < rowCount; i++)
{
var row = new object[coluCount];
for (int zi = 0; zi < coluCount; zi++)
{
row[zi] = RandomHelper.RandomValue<object>();
}
dt.Rows.Add(row);
}
return dt;
}
if (t.IsNullable())
{
// leave it unset
if (Rand.Next(2) == 0)
{
// null!
return Activator.CreateInstance(t);
}
var underlying = Nullable.GetUnderlyingType(t);
var val = underlying.RandomValue(stringValueAllowEmpty);
var cons = t.GetConstructor(new[] { underlying });
return cons.Invoke(new object[] { val });
}
if (t.IsEnum)
{
var allValues = Enum.GetValues(t);
var ix = Rand.Next(allValues.Length);
return allValues.GetValue(ix);
}
if (t.IsArray)
{
var valType = t.GetElementType();
var len = Rand.Next(20, 50);
var ret = Array.CreateInstance(valType, len);
//var add = t.GetMethod("SetValue");
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
ret.SetValue(elem, i);
}
return ret;
}
if (t.IsGenericType)
{
var defind = t.GetGenericTypeDefinition();
if (defind == typeof(HashSet<>))
{
var valType = t.GetGenericArguments()[0];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var contains = t.GetMethod("Contains");
var len = Rand.Next(20, 50);
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
while (elem == null || (bool)contains.Invoke(ret, new object[] { elem }))
elem = valType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { elem });
}
return ret;
}
if (defind == typeof(Dictionary<,>))
{
var keyType = t.GetGenericArguments()[0];
var valType = t.GetGenericArguments()[1];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var contains = t.GetMethod("ContainsKey");
var len = Rand.Next(20, 50);
if (keyType == typeof(Boolean))
len = 2;
for (var i = 0; i < len; i++)
{
var val = valType.RandomValue(stringValueAllowEmpty);
var key = keyType.RandomValue(stringValueAllowEmpty);
while (key == null || (bool)contains.Invoke(ret, new object[] { key }))
key = keyType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { key, val });
}
return ret;
}
if (defind == typeof(List<>))
{
var valType = t.GetGenericArguments()[0];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var len = Rand.Next(20, 50);
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { elem });
}
return ret;
}
if (defind == typeof(ArraySegment<>))
{
var valType = t.GetGenericArguments()[0];
var ary = valType.MakeArrayType().RandomValue(stringValueAllowEmpty);
var lenT = ary.GetType().GetProperty("Length");
var offset = Rand.Next(0, (int)lenT.GetValue(ary) - 1);
var len = (int)lenT.GetValue(ary) - offset;
return Activator.CreateInstance(t, ary, offset, len);
}
}
if (t == typeof(Guid))
return Guid.NewGuid();
if (t == typeof(object))
{
var code = Rand.Next(0, 9);
switch (code)
{
case 0:
return RandomValue<int>();
case 1:
return RandomValue<long>();
case 2:
return RandomValue<Char>();
case 3:
return RandomValue<DateTime>();
case 4:
return RandomValue<string>(stringValueAllowEmpty);
case 5:
return RandomValue<Guid>();
case 6:
return RandomValue<decimal>();
case 7:
return RandomValue<double>();
case 8:
return RandomValue<float>();
default:
return RandomValue<short>();
}
}
//model
var retObj = Activator.CreateInstance(t);
foreach (var p in t.GetFields())
{
//if (Rand.Next(5) == 0) continue;
var fieldType = p.FieldType;
p.SetValue(retObj, fieldType.RandomValue(stringValueAllowEmpty));
}
foreach (var p in t.GetProperties())
{
//if (Rand.Next(5) == 0) continue;
if (p.CanWrite && p.CanRead)
{
var fieldType = p.PropertyType;
p.SetValue(retObj, fieldType.RandomValue(stringValueAllowEmpty));
}
}
return retObj;
}
19
View Source File : Huid.cs
License : MIT License
Project Creator : 3F
License : MIT License
Project Creator : 3F
public static Guid NewGuid(Guid ns, string input)
{
if(ns == Guid.Empty) return NewGuid(NS_HUID_H, NS_HUID_L, input);
byte[] v = ns.ToByteArray();
// RFC 4122; '4.1.2. Layout and Byte Order'
// ... each field encoded with the Most Significant Byte first(known as network byte order).
// See `void format_uuid_v3or5(uuid_t *uuid, unsigned char hash[16], int v)`
/*Eg.:
[0xC2 0xB9 0xA2 0x30] [0xA5 0x0B] [0x45 0x24] 0xA7 0x32 0x54 0xC9 0xB4 0x2E 0x8C 0xA5
3 2 1 0 5 4 7 6 8 9 10 11 12 13 14 15
*/
// We'll use BitConverter which works around the IsLittleEndian check
return NewGuid
(
BitConverter.ToUInt64(v, 0),
BitConverter.ToUInt64(v, 8), //TODO: actually here we can use any byte order
input
);
}
19
View Source File : EndianBinaryReader.cs
License : MIT License
Project Creator : 91Act
License : MIT License
Project Creator : 91Act
public override ulong ReadUInt64()
{
if (endian == EndianType.BigEndian)
{
a64 = ReadBytes(8);
Array.Reverse(a64);
return BitConverter.ToUInt64(a64, 0);
}
return base.ReadUInt64();
}
19
View Source File : EndianBinaryReader.cs
License : MIT License
Project Creator : 91Act
License : MIT License
Project Creator : 91Act
public override double ReadDouble()
{
if (endian == EndianType.BigEndian)
{
a64 = ReadBytes(8);
Array.Reverse(a64);
return BitConverter.ToUInt64(a64, 0);
}
return base.ReadDouble();
}
19
View Source File : NetworkBitConverter.cs
License : MIT License
Project Creator : a1q123456
License : MIT License
Project Creator : a1q123456
public static ulong ToUInt64(Span<byte> buffer, bool littleEndian = false)
{
if (!littleEndian)
{
buffer.Slice(0, sizeof(ulong)).Reverse();
}
return BitConverter.ToUInt64(buffer);
}
19
View Source File : P2PManager.cs
License : MIT License
Project Creator : absurd-joy
License : MIT License
Project Creator : absurd-joy
ulong ReadULong(byte[] buf, ref int offset)
{
ulong val = BitConverter.ToUInt64(buf, offset);
offset += sizeof(ulong);
return val;
}
19
View Source File : Deserializer.cs
License : MIT License
Project Creator : ADeltaX
License : MIT License
Project Creator : ADeltaX
public static ulong GetUInt64(byte[] data, int index = 0)
=> BitConverter.ToUInt64(data, index);
19
View Source File : Deserializer.cs
License : MIT License
Project Creator : ADeltaX
License : MIT License
Project Creator : ADeltaX
public static ulong GetUInt64(byte[] data, int index = 0)
=> BitConverter.ToUInt64(data, index);
19
View Source File : Extensions.cs
License : MIT License
Project Creator : adrenak
License : MIT License
Project Creator : adrenak
public static ulong ToULong(this byte[] bytes) {
return BitConverter.ToUInt64(bytes, 0);
}
19
View Source File : IdenticonGenerator.cs
License : Apache License 2.0
Project Creator : advanced-cms
License : Apache License 2.0
Project Creator : advanced-cms
private int GetStringHash(string str)
{
var md5Hasher = MD5.Create();
var hashed = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(str));
var integerValue = BitConverter.ToUInt64(hashed, 0);
return (int)integerValue;
}
19
View Source File : ExtensionTests.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
[Fact]
public void NumericExtensions_ToBytes_For_ulong()
{
ulong number = ulong.MaxValue - 1;
var bigEndianBytes = number.ToBytes(true);
((int)bigEndianBytes.Last()).ShouldBe(254);
var numberFromBigEndianBytes = BitConverter.ToUInt64(BitConverter.IsLittleEndian ? bigEndianBytes.Reverse().ToArray() : bigEndianBytes);
numberFromBigEndianBytes.ShouldBe(number);
var littleEndianBytes = number.ToBytes(false);
((int)littleEndianBytes.Last()).ShouldBe(255);
numberFromBigEndianBytes = BitConverter.ToUInt64(BitConverter.IsLittleEndian ? littleEndianBytes: littleEndianBytes.Reverse().ToArray());
numberFromBigEndianBytes.ShouldBe(number);
}
19
View Source File : Form_SteamID64_Editor.cs
License : MIT License
Project Creator : Aemony
License : MIT License
Project Creator : Aemony
private void ReadSteamID()
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDoreplacedents) + "\\My Games\\NieR_Automata";
dlg.Filter = "Data files (*.dat)|*.dat";
if (dlg.ShowDialog() == DialogResult.OK)
{
filePath = dlg.FileName;
if (filePath.Contains("SlotData"))
{
// SlotData files stores the SteamID64 in offset 04-11, GameData and SystemData files stores the SteamID64 in offset 00-07
fileOffset = 4;
}
else
{
fileOffset = 0;
}
try {
using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
stream.Position = fileOffset;
stream.Read(byteSteamID64, 0, 8);
}
// Convert to proper IDs.
// SteamID64 is stored as Little-Endian in the files, but as Intel is little-endian as well no reversal is needed
steamID3 = BitConverter.ToUInt32(byteSteamID64, 0);
textBoxSteamID3.Text = steamID3.ToString();
steamID64 = BitConverter.ToUInt64(byteSteamID64, 0);
textBoxSteamID64.Text = steamID64.ToString();
#if DEBUG
Console.WriteLine("Read: " + BitConverter.ToString(byteSteamID64));
Console.WriteLine("SteamID3: " + steamID3.ToString());
Console.WriteLine("SteamID64: " + steamID64.ToString());
#endif
// Misc
textBoxWorkingFile.Text = filePath;
textBoxWorkingFile.SelectionStart = textBoxWorkingFile.TextLength;
toolStripStatusLabel1.Text = "Read from " + Path.GetFileName(filePath) + ": " + BitConverter.ToString(byteSteamID64);
lastStatus = toolStripStatusLabel1.Text;
// Check if a new ID is already written, and if so, enable the button
if (String.IsNullOrWhiteSpace(textBoxSteamID64_New.Text) == false && String.IsNullOrWhiteSpace(filePath) == false && textBoxSteamID64_New.Text != textBoxSteamID64.Text)
{
buttonUpdate.Enabled = true;
}
else
{
buttonUpdate.Enabled = false;
}
} catch (Exception ex)
{
throw ex;
}
}
}
19
View Source File : utils.cs
License : GNU General Public License v3.0
Project Creator : Aeroblast
License : GNU General Public License v3.0
Project Creator : Aeroblast
public static UInt64 GetUInt64(byte[] src, ulong start)
{
byte[] t = SubArray(src, start, 8);
Array.Reverse(t);
return BitConverter.ToUInt64(t);
}
19
View Source File : ZFrame.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public UInt64 ReadUInt64()
{
var bytes = new byte[8];
if (Read(bytes, 0, 8) < 8)
{
return default(UInt64);
}
return BitConverter.ToUInt64(bytes, 0);
}
19
View Source File : U64.cs
License : Apache License 2.0
Project Creator : ajuna-network
License : Apache License 2.0
Project Creator : ajuna-network
public override void Create(byte[] byteArray)
{
if (byteArray.Length < Size())
{
var newByteArray = new byte[Size()];
byteArray.CopyTo(newByteArray, 0);
byteArray = newByteArray;
}
Bytes = byteArray;
Value = BitConverter.ToUInt64(byteArray, 0);
}
19
View Source File : Utils.cs
License : Apache License 2.0
Project Creator : ajuna-network
License : Apache License 2.0
Project Creator : ajuna-network
public static object Bytes2Value(byte[] value, bool littleEndian = true)
{
if (!littleEndian) Array.Reverse(value);
switch (value.Length)
{
case 2:
return BitConverter.ToUInt16(value, 0);
case 4:
return BitConverter.ToUInt32(value, 0);
case 8:
return BitConverter.ToUInt64(value, 0);
default:
throw new Exception($"Unhandled byte size {value.Length} for this method!");
}
}
19
View Source File : UnnyNetPacker.cs
License : MIT License
Project Creator : alerdenisov
License : MIT License
Project Creator : alerdenisov
static public object[] UnpackObject(byte[] bytes, int bytesCount)
{
object[] arg = new object[1];
arg[0] = 0;
int size = 0;
int num = HeaderSize;
try
{
while (num < bytesCount)
{
switch ((TypeTags)bytes[num++])
{
case TypeTags.IntTag:
{
if (num + 4 <= bytesCount)
{
int intValue = System.BitConverter.ToInt32(bytes, num);
System.Array.Resize(ref arg, size + 1);
arg[size++] = intValue;
}
num += 4;
break;
}
case TypeTags.FloatTag:
{
if (num + 4 <= bytesCount)
{
var floatValue = System.BitConverter.ToSingle(bytes, num);
System.Array.Resize(ref arg, size + 1);
arg[size++] = floatValue;
}
num += 4;
break;
}
case TypeTags.Vector3Tag:
{
if (num + 12 <= bytesCount)
{
var vecValue = new Vector3();
for (int axis = 0; axis < 3; axis++)
{
vecValue[axis] = System.BitConverter.ToSingle(bytes, num + (4 * axis));
}
System.Array.Resize(ref arg, size + 1);
arg[size++] = vecValue;
}
num += 12;
break;
}
case TypeTags.UIntTag:
{
if (num + 4 <= bytesCount)
{
uint intValue = System.BitConverter.ToUInt32(bytes, num);
System.Array.Resize(ref arg, size + 1);
arg[size++] = intValue;
}
num += 4;
break;
}
case TypeTags.LongTag:
{
if (num + 8 <= bytesCount)
{
long intValue = System.BitConverter.ToInt64(bytes, num);
System.Array.Resize(ref arg, size + 1);
arg[size++] = intValue;
}
num += 8;
break;
}
case TypeTags.ULongTag:
{
if (num + 8 <= bytesCount)
{
ulong intValue = System.BitConverter.ToUInt64(bytes, num);
System.Array.Resize(ref arg, size + 1);
arg[size++] = intValue;
}
num += 8;
break;
}
case TypeTags.ShortTag:
{
if (num + 2 <= bytesCount)
{
short intValue = System.BitConverter.ToInt16(bytes, num);
System.Array.Resize(ref arg, size + 1);
arg[size++] = intValue;
}
num += 2;
break;
}
case TypeTags.UShortTag:
{
if (num + 2 <= bytesCount)
{
ushort intValue = System.BitConverter.ToUInt16(bytes, num);
System.Array.Resize(ref arg, size + 1);
arg[size++] = intValue;
}
num += 2;
break;
}
case TypeTags.ByteTag:
{
System.Array.Resize(ref arg, size + 1);
arg[size++] = bytes[num++];
break;
}
case TypeTags.SByteTag:
{
System.Array.Resize(ref arg, size + 1);
arg[size++] = (sbyte)bytes[num++];
break;
}
case TypeTags.BoolTag:
{
System.Array.Resize(ref arg, size + 1);
arg[size++] = (bytes[num++] == 1);
break;
}
case TypeTags.StringTag:
{
if (num + 2 <= bytesCount)
{
ushort intValue = System.BitConverter.ToUInt16(bytes, num);
num += 2;
if (num + intValue <= bytesCount)
{
System.Array.Resize(ref arg, size + 1);
arg[size++] = System.Text.Encoding.UTF8.GetString(bytes, num, intValue);
}
num += intValue;
}
else
num += 2;
break;
}
case TypeTags.UShortArraySmall:
{
byte length = bytes[num++];
if (num + 2 * length <= bytesCount)
{
ushort[] arr = new ushort[length];
for (int j = 0; j < length; j++)
{
arr[j] = System.BitConverter.ToUInt16(bytes, num);
num += 2;
}
System.Array.Resize(ref arg, size + 1);
arg[size++] = arr;
}
else
num += 2 * length;
break;
}
case TypeTags.UShortArrayBig:
{
if (num + 2 <= bytesCount)
{
ushort length = System.BitConverter.ToUInt16(bytes, num);
num += 2;
if (num + 2 * length <= bytesCount)
{
ushort[] arr = new ushort[length];
for (int j = 0; j < length; j++)
{
arr[j] = System.BitConverter.ToUInt16(bytes, num);
num += 2;
}
System.Array.Resize(ref arg, size + 1);
arg[size++] = arr;
}
else
num += 2 * length;
}
else
num += 2;
break;
}
default:
Debug.Log("Couldn't unpack");
return arg;
}
}
}
catch (System.ArgumentException e)
{
Debug.Log("e = " + e);
}
return arg;
}
19
View Source File : BitStream.cs
License : MIT License
Project Creator : Alexander-Scott
License : MIT License
Project Creator : Alexander-Scott
public UInt48 ReadUInt48()
{
byte[] bytes = ReadBytes(48);
Array.Resize(ref bytes, 8);
UInt48 value = BitConverter.ToUInt64(bytes, 0);
return value;
}
19
View Source File : BitStream.cs
License : MIT License
Project Creator : Alexander-Scott
License : MIT License
Project Creator : Alexander-Scott
public ulong ReadUInt64()
{
ulong value = BitConverter.ToUInt64(ReadBytes(64), 0);
return value;
}
19
View Source File : WebassemblyModule.cs
License : MIT License
Project Creator : alexanderkyte
License : MIT License
Project Creator : alexanderkyte
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ulong Load64BitAsUnsigned64 (int offset) {
return BitConverter.ToUInt64 (this.Copy (offset, 8), 0);
}
19
View Source File : WebassemblyModule.cs
License : MIT License
Project Creator : alexanderkyte
License : MIT License
Project Creator : alexanderkyte
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ulong LoadUnsigned32BitAsUnsigned64 (int offset) {
return BitConverter.ToUInt64(this.Copy (offset, 4), 0);
}
19
View Source File : WebassemblyModule.cs
License : MIT License
Project Creator : alexanderkyte
License : MIT License
Project Creator : alexanderkyte
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ulong LoadSigned32BitAsUnsigned64 (int offset) {
return BitConverter.ToUInt64(this.Copy (offset, 4), 0);
}
19
View Source File : WebassemblyModule.cs
License : MIT License
Project Creator : alexanderkyte
License : MIT License
Project Creator : alexanderkyte
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ulong LoadSigned16BitAsUnsigned64 (int offset) {
return BitConverter.ToUInt64(this.Copy (offset, 2), 0);
}
19
View Source File : WebassemblyModule.cs
License : MIT License
Project Creator : alexanderkyte
License : MIT License
Project Creator : alexanderkyte
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ulong LoadSigned8BitAsUnsigned64 (int offset) {
return BitConverter.ToUInt64(this.Copy (offset, 1), 0);
}
19
View Source File : WebassemblyModule.cs
License : MIT License
Project Creator : alexanderkyte
License : MIT License
Project Creator : alexanderkyte
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ulong LoadUnsigned8BitAsUnsigned64 (int offset) {
return BitConverter.ToUInt64(this.Copy (offset, 1), 0);
}
19
View Source File : WebassemblyModule.cs
License : MIT License
Project Creator : alexanderkyte
License : MIT License
Project Creator : alexanderkyte
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ulong LoadUnsigned16BitAsUnsigned64 (int offset) {
return BitConverter.ToUInt64(this.Copy (offset, 2), 0);
}
19
View Source File : PopcntBenchmark.cs
License : MIT License
Project Creator : alexandrnikitin
License : MIT License
Project Creator : alexandrnikitin
public ulong NextUInt64()
{
var buffer = new byte[sizeof(long)];
random.NextBytes(buffer);
return BitConverter.ToUInt64(buffer, 0);
}
19
View Source File : ObjectToByte.cs
License : MIT License
Project Creator : allartprotocol
License : MIT License
Project Creator : allartprotocol
public static void DecodeUlongFromByte(byte[] data, int offset, out ulong decodedData)
{
decodedData = 0;
byte[] dataCopy = new byte[8];
Array.Copy(data, (long)offset, dataCopy, 0, 8);
decodedData = BitConverter.ToUInt64(dataCopy, 0);
}
19
View Source File : Marvin.cs
License : MIT License
Project Creator : AllocZero
License : MIT License
Project Creator : AllocZero
private static ulong GenerateSeed()
{
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
var bytes = new byte[sizeof(ulong)];
rng.GetBytes(bytes);
return BitConverter.ToUInt64(bytes, 0);
}
}
19
View Source File : MemoryUtil.cs
License : GNU General Public License v3.0
Project Creator : am0nsec
License : GNU General Public License v3.0
Project Creator : am0nsec
protected UInt64 ReadPtr64(Int64 offset) {
Span<byte> s = stackalloc byte[8];
this.ModuleStream.Seek(offset, SeekOrigin.Begin);
this.ModuleStream.Read(s);
return BitConverter.ToUInt64(s);
}
19
View Source File : DynamicAssemblyTest.cs
License : MIT License
Project Creator : ancientproject
License : MIT License
Project Creator : ancientproject
[Fact]
public void Create()
{
var d = new Dynamicreplacedembly("test", ("foo", "bar"));
replacedert.Equal("test", d.Name);
replacedert.Equal(("foo", "bar"), d.Metadata.First());
replacedert.Throws<InvalidOperationException>(() => { d.GetBytes(); });
replacedert.NotNull(d.GetGenerator());
replacedert.IsType<ILGen>(d.GetGenerator());
d.GetGenerator().Emit(new ldi(0xF, 0xC));
replacedert.Equal(sizeof(ulong), d.GetILCode().Length);
replacedert.Equal($"{0x1F00C00000000:X}", $"{BitConverter.ToUInt64(d.GetILCode().Reverse().ToArray()):X}");
}
19
View Source File : Program.cs
License : MIT License
Project Creator : ancientproject
License : MIT License
Project Creator : ancientproject
public static ulong[] CastFromBytes(byte[] bytes)
{
if (bytes.Length % sizeof(ulong) == 0)
return bytes.Batch(sizeof(ulong)).Select(x => BitConverter.ToUInt64(x.Reverse().ToArray())).Reverse().ToArray();
throw new Exception("invalid offset file.");
}
19
View Source File : DataBuffer.cs
License : MIT License
Project Creator : AndreasAmMueller
License : MIT License
Project Creator : AndreasAmMueller
public ulong GetUInt64(int index)
{
byte[] blob = GetBytes(index, 8);
InternalSwap(blob);
return BitConverter.ToUInt64(blob, 0);
}
19
View Source File : Extensions.cs
License : MIT License
Project Creator : AndreasAmMueller
License : MIT License
Project Creator : AndreasAmMueller
public static ulong GetUInt64(this IEnumerable<ModbusObject> list, int startIndex = 0, bool inverseRegisters = false)
{
if (list == null)
throw new ArgumentNullException(nameof(list));
int count = list.Count();
if (count < 4)
throw new ArgumentException("At least four registers needed", nameof(list));
if (startIndex < 0 || count < startIndex + 4)
throw new ArgumentOutOfRangeException(nameof(startIndex));
if (!list.All(r => r.Type == ModbusObjectType.HoldingRegister) && !list.All(r => r.Type == ModbusObjectType.InputRegister))
throw new ArgumentException("Invalid register type");
list = list.OrderBy(r => r.Address).Skip(startIndex).Take(4);
if (inverseRegisters)
list = list.Reverse();
var registers = list.ToArray();
byte[] blob = new byte[registers.Length * 2];
for (int i = 0; i < registers.Length; i++)
{
blob[i * 2] = registers[i].HiByte;
blob[i * 2 + 1] = registers[i].LoByte;
}
if (BitConverter.IsLittleEndian)
Array.Reverse(blob);
return BitConverter.ToUInt64(blob, 0);
}
19
View Source File : Module_Info.cs
License : MIT License
Project Creator : Andy53
License : MIT License
Project Creator : Andy53
private unsafe void PopulateHeaderStructs(FileStream fin)
{
byte[] Data = new byte[4096];
int iRead = fin.Read(Data, 0, 4096);
fin.Flush();
fin.Close();
fixed (byte* p_Data = Data)
{
IMAGE_DOS_HEADER* idh = (IMAGE_DOS_HEADER*)p_Data;
IMAGE_NT_HEADERS32* inhs = (IMAGE_NT_HEADERS32*)(idh->nt_head_ptr + p_Data);
ModuleMachineType = (MachineType)inhs->FileHeader.Machine;
if (ModuleMachineType == MachineType.I386)
{
IMAGE_NT_HEADERS32* inhs32 = (IMAGE_NT_HEADERS32*)(idh->nt_head_ptr + p_Data);
ImageFileHeader = inhs32->FileHeader;
ModuleMachineType = (MachineType)inhs32->FileHeader.Machine;
ImageOptionalHeader32 = inhs32->OptionalHeader;
ModuleImageBase = (IntPtr)inhs32->OptionalHeader.ImageBase;
ImageNTHeaders32 = new IMAGE_NT_HEADERS32
{
Signature = inhs32->Signature,
FileHeader = inhs32->FileHeader,
OptionalHeader = inhs32->OptionalHeader
};
byte[] bytes = new byte[256];
var ret = ErcCore.ReadProcessMemory(ModuleProcess.Handle,
(IntPtr)((uint)ModuleBase + ImageOptionalHeader32.LoadConfigTable.VirtualAddress), bytes, 256, out int BytesRead);
if (BitConverter.ToUInt32(bytes, 58) > 0 || BitConverter.ToUInt32(bytes, 62) > 0)
{
ModuleSafeSEH = true;
}
}
else if (ModuleMachineType == MachineType.x64)
{
IMAGE_NT_HEADERS64* inhs64 = (IMAGE_NT_HEADERS64*)(idh->nt_head_ptr + p_Data);
ImageFileHeader = inhs64->FileHeader;
ImageOptionalHeader64 = inhs64->OptionalHeader;
ModuleImageBase = (IntPtr)inhs64->OptionalHeader.ImageBase;
ImageNTHeaders64 = new IMAGE_NT_HEADERS64
{
Signature = inhs64->Signature,
FileHeader = inhs64->FileHeader,
OptionalHeader = inhs64->OptionalHeader
};
byte[] bytes = new byte[256];
var ret = ErcCore.ReadProcessMemory(ModuleProcess.Handle,
(IntPtr)((long)ModuleBase + (long)ImageOptionalHeader64.LoadConfigTable.VirtualAddress), bytes, 256, out int BytesRead);
if (BitConverter.ToUInt64(bytes, 88) > 0 || BitConverter.ToUInt64(bytes, 96) > 0)
{
ModuleSafeSEH = true;
}
}
else
{
ModuleFailed = true;
}
}
}
19
View Source File : RandomHelper.cs
License : MIT License
Project Creator : AnotherEnd15
License : MIT License
Project Creator : AnotherEnd15
public static ulong RandUInt64(this Random random)
{
byte[] byte8 = new byte[8];
random.NextBytes(byte8);
return BitConverter.ToUInt64(byte8, 0);
}
19
View Source File : Mathf.cs
License : MIT License
Project Creator : AnotherEnd15
License : MIT License
Project Creator : AnotherEnd15
internal static long RandomToLong(System.Random r)
{
byte[] buffer = new byte[8];
r.NextBytes(buffer);
return (long) BitConverter.ToUInt64(buffer, 0) & long.MaxValue;
}
19
View Source File : RandomHelper.cs
License : MIT License
Project Creator : AnotherEnd15
License : MIT License
Project Creator : AnotherEnd15
public static ulong RandUInt64()
{
byte[] byte8 = new byte[8];
random.NextBytes(byte8);
return BitConverter.ToUInt64(byte8, 0);
}
19
View Source File : StreamUtils.cs
License : MIT License
Project Creator : ansel86castro
License : MIT License
Project Creator : ansel86castro
public static ulong ReadUInt64(Stream stream)
{
byte[] buff = new byte[8];
stream.Read(buff, 0, 8);
return BitConverter.ToUInt64(Convert(buff), 0);
}
19
View Source File : Mappings.cs
License : Apache License 2.0
Project Creator : AntonioDePau
License : Apache License 2.0
Project Creator : AntonioDePau
internal static Dictionary<Type, MappingDefinition> BigEndianMapping(Encoding encoding) => new Dictionary<Type, MappingDefinition>
{
[typeof(bool)] = new MappingDefinition
{
Writer = x =>
{
if (x.BitIndex >= 8)
RealBinaryMapping.FlushBitField(x);
if (x.DataAttribute.BitIndex >= 0)
x.BitIndex = x.DataAttribute.BitIndex;
if (x.Item is bool bit && bit)
x.BitData |= (byte)(1 << x.BitIndex);
x.BitIndex++;
},
Reader = x =>
{
if (x.BitIndex >= 8)
x.BitIndex = 0;
if (x.BitIndex == 0)
x.BitData = x.Reader.ReadByte();
if (x.DataAttribute.BitIndex >= 0)
x.BitIndex = x.DataAttribute.BitIndex;
return (x.BitData & (1 << x.BitIndex++)) != 0;
}
},
[typeof(byte)] = new MappingDefinition
{
Writer = x => x.Writer.Write((byte)x.Item),
Reader = x => x.Reader.ReadByte()
},
[typeof(sbyte)] = new MappingDefinition
{
Writer = x => x.Writer.Write((sbyte)x.Item),
Reader = x => x.Reader.ReadSByte()
},
[typeof(short)] = new MappingDefinition
{
Writer = x =>
{
x.Writer.Write((byte)(((short)x.Item >> 8) & 0xff));
x.Writer.Write((byte)(((short)x.Item >> 0) & 0xff));
},
Reader = x =>
{
var data = x.Reader.ReadBytes(2);
Array.Reverse(data);
return BitConverter.ToInt16(data, 0);
}
},
[typeof(ushort)] = new MappingDefinition
{
Writer = x =>
{
x.Writer.Write((byte)(((ushort)x.Item >> 8) & 0xff));
x.Writer.Write((byte)(((ushort)x.Item >> 0) & 0xff));
},
Reader = x =>
{
var data = x.Reader.ReadBytes(2);
Array.Reverse(data);
return BitConverter.ToUInt16(data, 0);
}
},
[typeof(int)] = new MappingDefinition
{
Writer = x =>
{
x.Writer.Write((byte)(((int)x.Item >> 24) & 0xff));
x.Writer.Write((byte)(((int)x.Item >> 16) & 0xff));
x.Writer.Write((byte)(((int)x.Item >> 8) & 0xff));
x.Writer.Write((byte)(((int)x.Item >> 0 & 0xff)));
},
Reader = x =>
{
var data = x.Reader.ReadBytes(4);
Array.Reverse(data);
return BitConverter.ToInt32(data, 0);
}
},
[typeof(uint)] = new MappingDefinition
{
Writer = x =>
{
x.Writer.Write((byte)(((uint)x.Item >> 24) & 0xff));
x.Writer.Write((byte)(((uint)x.Item >> 16) & 0xff));
x.Writer.Write((byte)(((uint)x.Item >> 8) & 0xff));
x.Writer.Write((byte)(((uint)x.Item >> 0) & 0xff));
},
Reader = x =>
{
var data = x.Reader.ReadBytes(4);
Array.Reverse(data);
return BitConverter.ToUInt32(data, 0);
}
},
[typeof(long)] = new MappingDefinition
{
Writer = x =>
{
x.Writer.Write((byte)(((long)x.Item >> 56) & 0xff));
x.Writer.Write((byte)(((long)x.Item >> 48) & 0xff));
x.Writer.Write((byte)(((long)x.Item >> 40) & 0xff));
x.Writer.Write((byte)(((long)x.Item >> 32) & 0xff));
x.Writer.Write((byte)(((long)x.Item >> 24) & 0xff));
x.Writer.Write((byte)(((long)x.Item >> 16) & 0xff));
x.Writer.Write((byte)(((long)x.Item >> 8) & 0xff));
x.Writer.Write((byte)(((long)x.Item >> 0) & 0xff));
},
Reader = x =>
{
var data = x.Reader.ReadBytes(8);
Array.Reverse(data);
return BitConverter.ToInt64(data, 0);
}
},
[typeof(ulong)] = new MappingDefinition
{
Writer = x =>
{
x.Writer.Write((byte)(((ulong)x.Item >> 56) & 0xff));
x.Writer.Write((byte)(((ulong)x.Item >> 48) & 0xff));
x.Writer.Write((byte)(((ulong)x.Item >> 40) & 0xff));
x.Writer.Write((byte)(((ulong)x.Item >> 32) & 0xff));
x.Writer.Write((byte)(((ulong)x.Item >> 24) & 0xff));
x.Writer.Write((byte)(((ulong)x.Item >> 16) & 0xff));
x.Writer.Write((byte)(((ulong)x.Item >> 8) & 0xff));
x.Writer.Write((byte)(((ulong)x.Item >> 0) & 0xff));
},
Reader = x =>
{
var data = x.Reader.ReadBytes(8);
Array.Reverse(data);
return BitConverter.ToUInt64(data, 0);
}
},
[typeof(float)] = new MappingDefinition
{
Writer = x => x.Writer.Write((float)x.Item),
Reader = x => x.Reader.ReadSingle()
},
[typeof(double)] = new MappingDefinition
{
Writer = x => x.Writer.Write((double)x.Item),
Reader = x => x.Reader.ReadDouble()
},
[typeof(TimeSpan)] = new MappingDefinition
{
Writer = x => x.Writer.Write(((TimeSpan)x.Item).Ticks),
Reader = x => new TimeSpan(x.Reader.ReadInt64())
},
[typeof(DateTime)] = new MappingDefinition
{
Writer = x => x.Writer.Write(((DateTime)x.Item).Ticks),
Reader = x => new DateTime(x.Reader.ReadInt64())
},
[typeof(string)] = new MappingDefinition
{
Writer = x => WriteString(x.Writer, (string)x.Item, encoding, x.Count),
Reader = x => ReadString(x.Reader, encoding, x.Count)
},
[typeof(byte[])] = new MappingDefinition
{
Writer = x =>
{
var data = (byte[])x.Item;
var bytesToWrite = Math.Min(data.Length, x.Count);
x.Writer.Write(data, 0, bytesToWrite);
var remainingBytes = x.Count - bytesToWrite;
if (remainingBytes > 0)
x.Writer.Write(new byte[remainingBytes], 0, remainingBytes);
},
Reader = x => x.Reader.ReadBytes(x.Count)
},
};
19
View Source File : Constant.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
static object GetValue(ElementType etype, byte[] data) {
switch (etype) {
case ElementType.Boolean:
if (data == null || data.Length < 1)
return false;
return BitConverter.ToBoolean(data, 0);
case ElementType.Char:
if (data == null || data.Length < 2)
return (char)0;
return BitConverter.ToChar(data, 0);
case ElementType.I1:
if (data == null || data.Length < 1)
return (sbyte)0;
return (sbyte)data[0];
case ElementType.U1:
if (data == null || data.Length < 1)
return (byte)0;
return data[0];
case ElementType.I2:
if (data == null || data.Length < 2)
return (short)0;
return BitConverter.ToInt16(data, 0);
case ElementType.U2:
if (data == null || data.Length < 2)
return (ushort)0;
return BitConverter.ToUInt16(data, 0);
case ElementType.I4:
if (data == null || data.Length < 4)
return (int)0;
return BitConverter.ToInt32(data, 0);
case ElementType.U4:
if (data == null || data.Length < 4)
return (uint)0;
return BitConverter.ToUInt32(data, 0);
case ElementType.I8:
if (data == null || data.Length < 8)
return (long)0;
return BitConverter.ToInt64(data, 0);
case ElementType.U8:
if (data == null || data.Length < 8)
return (ulong)0;
return BitConverter.ToUInt64(data, 0);
case ElementType.R4:
if (data == null || data.Length < 4)
return (float)0;
return BitConverter.ToSingle(data, 0);
case ElementType.R8:
if (data == null || data.Length < 8)
return (double)0;
return BitConverter.ToDouble(data, 0);
case ElementType.String:
if (data == null)
return string.Empty;
return Encoding.Unicode.GetString(data, 0, data.Length / 2 * 2);
case ElementType.Clreplaced:
return null;
default:
return null;
}
}
19
View Source File : LiveHexUI.cs
License : MIT License
Project Creator : architdate
License : MIT License
Project Creator : architdate
public ulong GetPointerAddress(ICommunicatorNX sb)
{
var ptr = TB_Pointer.Text;
uint finadd = 0;
if (!ptr.EndsWith("]"))
finadd = Util.GetHexValue(ptr.Split('+').Last());
var jumps = ptr.Replace("main", "").Replace("[", "").Replace("]", "").Split(new[] { "+" }, StringSplitOptions.RemoveEmptyEntries);
if (jumps.Length == 0)
{
WinFormsUtil.Alert("Invalid Pointer");
return 0;
}
var initaddress = Util.GetHexValue(jumps[0].Trim());
ulong address = BitConverter.ToUInt64(sb.ReadBytesMain(initaddress, 0x8), 0);
foreach (var j in jumps)
{
var val = Util.GetHexValue(j.Trim());
if (val == initaddress)
continue;
if (val == finadd)
{
address += val;
break;
}
address = BitConverter.ToUInt64(sb.ReadBytesAbsolute(address + val, 0x8), 0);
}
return address;
}
19
View Source File : UsbBotMini.cs
License : MIT License
Project Creator : architdate
License : MIT License
Project Creator : architdate
public ulong GetHeapBase()
{
var cmd = SwitchCommand.GetHeapBase();
SendInternal(cmd);
var buffer = new byte[(8 * 2) + 1];
var _ = ReadInternal(buffer);
return BitConverter.ToUInt64(buffer, 0);
}
19
View Source File : Endian.cs
License : MIT License
Project Creator : Arefu
License : MIT License
Project Creator : Arefu
public static ulong ToUInt64(byte[] value, int startIndex, bool convert)
{
var result = BitConverter.ToUInt64(value, startIndex);
return convert ? ConvertUInt64(result) : result;
}
19
View Source File : MatchingEngineResultSerializer.cs
License : MIT License
Project Creator : ArjunVachhani
License : MIT License
Project Creator : ArjunVachhani
[SuppressMessage("Microsoft.Globalization", "CA1303")]
public static MatchingEngineResult Deserialize(ReadOnlySpan<byte> bytes)
{
if (bytes == null)
throw new ArgumentNullException(nameof(bytes));
if (bytes.Length != sizeOfMessage)
throw new Exception("OrderMatchingResult Message must be of Size : " + sizeOfMessage);
var messageType = (MessageType)(bytes[messageTypeOffset]);
if (messageType != MessageType.OrderMatchingResult)
throw new Exception(Constant.INVALID_MESSAGE);
var version = BitConverter.ToInt16(bytes.Slice(versionOffset));
if (version != MatchingEngineResultSerializer.version)
throw new Exception(Constant.INVALID_VERSION);
var result = new MatchingEngineResult();
result.OrderId = BitConverter.ToUInt64(bytes.Slice(orderIdOffset));
result.Result = (OrderMatchingResult)bytes[resultOffset];
result.Timestamp = BitConverter.ToInt64(bytes.Slice(timestampOffset));
return result;
}
19
View Source File : ArchiveReader.cs
License : MIT License
Project Creator : ark-mod
License : MIT License
Project Creator : ark-mod
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void GetULong(out ulong value, string varName)
{
const int byteSize = 8;
if ((_size == 0 || _size - _offset < byteSize) && !Prepare(byteSize)) throw new IndexOutOfRangeException();
_structureLog?.Add<ulong>(_position, byteSize, varName);
value = BitConverter.ToUInt64(_mem.Span.Slice(_offset));
_offset += byteSize;
_position += byteSize;
}
19
View Source File : AccurateBinaryReader.cs
License : GNU General Public License v3.0
Project Creator : Artentus
License : GNU General Public License v3.0
Project Creator : Artentus
public override ulong ReadUInt64() => BitConverter.ToUInt64(ReadRaw(sizeof(ulong)), 0);
19
View Source File : SpotifyController.cs
License : GNU Affero General Public License v3.0
Project Creator : asmejkal
License : GNU Affero General Public License v3.0
Project Creator : asmejkal
private static ulong DecodeState(string state)
{
return BitConverter.ToUInt64(WebEncoders.Base64UrlDecode(state));
}
19
View Source File : KeyValue.cs
License : MIT License
Project Creator : Astropilot
License : MIT License
Project Creator : Astropilot
public static ulong ReadUInt64(this Stream stream)
{
stream.Read(s_data, 0, 8);
return BitConverter.ToUInt64(s_data, 0);
}
See More Examples