本文整理汇总了C#中HexPosition.ToUInt64方法的典型用法代码示例。如果您正苦于以下问题:C# HexPosition.ToUInt64方法的具体用法?C# HexPosition.ToUInt64怎么用?C# HexPosition.ToUInt64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HexPosition
的用法示例。
在下文中一共展示了HexPosition.ToUInt64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryReadByte
public override int TryReadByte(HexPosition position) {
Debug.Assert(position < HexPosition.MaxEndPosition);
var pos = position.ToUInt64();
var d = data;
if (pos >= (ulong)d.LongLength)
return -1;
return d[pos];
}
示例2: ReadSByte
public override sbyte ReadSByte(HexPosition position) {
Debug.Assert(position < HexPosition.MaxEndPosition);
var pos = position.ToUInt64();
var d = data;
if (pos >= (ulong)d.LongLength)
return 0;
return (sbyte)d[pos];
}
示例3: ReadInt16
public override short ReadInt16(HexPosition position) {
Debug.Assert(position < HexPosition.MaxEndPosition);
var pos = position.ToUInt64();
var d = data;
if (pos + 1 < pos || pos + 1 >= (ulong)d.LongLength)
return pos < (ulong)d.LongLength ? d[pos] : (short)0;
return (short)(d[pos] | (d[pos + 1] << 8));
}
示例4: FormatOffset
public void FormatOffset(StringBuilder dest, HexPosition position) {
var offset = position.ToUInt64() << (64 - bitSize);
dest.Append(prefix);
for (int i = 0; i < bitSize; i += 4, offset <<= 4) {
var nibble = (offset >> 60) & 0x0F;
if (nibble < 10)
dest.Append((char)('0' + nibble));
else
dest.Append((char)((lowerCaseHex ? 'a' : 'A') + nibble - 10));
}
dest.Append(suffix);
}
示例5: GetSpanInfo
public unsafe override HexSpanInfo GetSpanInfo(HexPosition position) {
if (position >= HexPosition.MaxEndPosition)
throw new ArgumentOutOfRangeException(nameof(position));
if (position >= endAddress)
return new HexSpanInfo(HexSpan.FromBounds(endAddress, HexPosition.MaxEndPosition), HexSpanInfoFlags.None);
ulong baseAddress, regionSize;
uint state, protect;
int res;
if (IntPtr.Size == 4) {
NativeMethods.MEMORY_BASIC_INFORMATION32 info;
res = NativeMethods.VirtualQueryEx32(hProcess, new IntPtr((void*)position.ToUInt64()), out info, NativeMethods.MEMORY_BASIC_INFORMATION32_SIZE);
baseAddress = info.BaseAddress;
regionSize = info.RegionSize;
state = info.State;
protect = info.Protect;
Debug.Assert(res == 0 || res == NativeMethods.MEMORY_BASIC_INFORMATION32_SIZE);
}
else {
NativeMethods.MEMORY_BASIC_INFORMATION64 info;
res = NativeMethods.VirtualQueryEx64(hProcess, new IntPtr((void*)position.ToUInt64()), out info, NativeMethods.MEMORY_BASIC_INFORMATION64_SIZE);
baseAddress = info.BaseAddress;
regionSize = info.RegionSize;
state = info.State;
protect = info.Protect;
Debug.Assert(res == 0 || res == NativeMethods.MEMORY_BASIC_INFORMATION64_SIZE);
}
// Could fail if eg. the process has exited
if (res == 0)
return new HexSpanInfo(HexSpan.FromBounds(HexPosition.Zero, endAddress), HexSpanInfoFlags.None);
var flags = HexSpanInfoFlags.None;
if (state == NativeMethods.MEM_COMMIT) {
uint access = protect & 0xFF;
if (access != NativeMethods.PAGE_NOACCESS && (protect & NativeMethods.PAGE_GUARD) == 0)
flags |= HexSpanInfoFlags.HasData;
}
return new HexSpanInfo(new HexSpan(baseAddress, regionSize), flags);
}
示例6: GetCachedPage
CachedPage GetCachedPage(HexPosition position) {
ulong pageOffset = position.ToUInt64() & ~pageSizeMask;
for (int i = 0; i < cachedPages.Length; i++) {
var cp = cachedPages[(i + lastHitIndex) % cachedPages.Length];
if (cp.IsInitialized && cp.Offset == pageOffset)
return cp;
}
CachedPage foundCp = null;
for (int i = 0; i < cachedPages.Length; i++) {
var cp = cachedPages[(i + lastHitIndex) % cachedPages.Length];
if (!cp.IsInitialized) {
foundCp = cp;
break;
}
}
if (foundCp == null)
foundCp = cachedPages[(lastHitIndex + 1) % cachedPages.Length];
lastHitIndex = foundCp.Index;
Initialize(foundCp, pageOffset);
return foundCp;
}
示例7: Write
public override void Write(HexPosition position, byte[] source, long sourceIndex, long length) {
Debug.Assert(position < HexPosition.MaxEndPosition);
var pos = position.ToUInt64();
var d = data;
if (pos >= (ulong)d.LongLength)
return;
long bytesLeft = d.LongLength - (long)pos;
long validBytes = length <= bytesLeft ? length : bytesLeft;
Array.Copy(source, sourceIndex, d, (long)pos, validBytes);
}
示例8: ReadUInt64
public override ulong ReadUInt64(HexPosition position) {
Debug.Assert(position < HexPosition.MaxEndPosition);
int index = (int)(position.ToUInt64() & pageSizeMask);
var cp = GetCachedPage(position);
if (index + 7 < cp.Data.Length) {
return ((ulong)cp.Data[0] | ((ulong)cp.Data[1] << 8) | ((ulong)cp.Data[2] << 16) | ((ulong)cp.Data[3] << 24) |
((ulong)cp.Data[4] << 32) | ((ulong)cp.Data[5] << 40) | ((ulong)cp.Data[6] << 48) | ((ulong)cp.Data[7] << 56));
}
return BitConverter.ToUInt64(ReadSlow(position, 8), 0);
}
示例9: ReadBytes
public override void ReadBytes(HexPosition position, byte[] destination, long destinationIndex, long length) {
Debug.Assert(position < HexPosition.MaxEndPosition);
while (length > 0) {
var cp = GetCachedPage(position);
long srcIndex = (long)(position.ToUInt64() - cp.Offset);
int partSize = (int)(pageSize - (ulong)srcIndex);
if (partSize > length)
partSize = (int)length;
Array.Copy(cp.Data, srcIndex, destination, destinationIndex, partSize);
position += (ulong)partSize;
length -= partSize;
destinationIndex += partSize;
}
}
示例10: ReadUInt16
public override ushort ReadUInt16(HexPosition position) {
Debug.Assert(position < HexPosition.MaxEndPosition);
int index = (int)(position.ToUInt64() & pageSizeMask);
var cp = GetCachedPage(position);
if (index + 1 < cp.Data.Length)
return (ushort)(cp.Data[0] | (cp.Data[1] << 8));
return BitConverter.ToUInt16(ReadSlow(position, 2), 0);
}
示例11: ReadUInt32
public override uint ReadUInt32(HexPosition position) {
Debug.Assert(position < HexPosition.MaxEndPosition);
int index = (int)(position.ToUInt64() & pageSizeMask);
var cp = GetCachedPage(position);
if (index + 3 < cp.Data.Length)
return (uint)(cp.Data[0] | (cp.Data[1] << 8) | (cp.Data[2] << 16) | (cp.Data[3] << 24));
return BitConverter.ToUInt32(ReadSlow(position, 4), 0);
}
示例12: ReadInt32
public override int ReadInt32(HexPosition position) {
Debug.Assert(position < HexPosition.MaxEndPosition);
var pos = position.ToUInt64();
var d = data;
if (pos + 3 < pos)
return 0;
if (pos + 3 >= (ulong)d.LongLength) {
int res = 0;
if (pos < (ulong)d.LongLength)
res = d[pos];
if (pos + 1 < (ulong)d.LongLength)
res |= d[pos + 1] << 8;
if (pos + 2 < (ulong)d.LongLength)
res |= d[pos + 2] << 16;
return res;
}
return d[pos] |
(d[pos + 1] << 8) |
(d[pos + 2] << 16) |
(d[pos + 3] << 24);
}
示例13: ReadSByte
public override sbyte ReadSByte(HexPosition position) {
Debug.Assert(position < HexPosition.MaxEndPosition);
int index = (int)(position.ToUInt64() & pageSizeMask);
var cp = GetCachedPage(position);
if (index >= cp.DataSize)
return 0;
return (sbyte)cp.Data[index];
}
示例14: ReadInt32
public override int ReadInt32(HexPosition position) {
Debug.Assert(position < HexPosition.MaxEndPosition);
int index = (int)(position.ToUInt64() & pageSizeMask);
lock (lockObj) {
var cp = GetCachedPage_NoLock(position);
var data = cp.Data;
if (index + 3 < data.Length)
return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
return BitConverter.ToInt32(ReadSlow(position, 4), 0);
}
}
示例15: ReadInt16
public override short ReadInt16(HexPosition position) {
Debug.Assert(position < HexPosition.MaxEndPosition);
int index = (int)(position.ToUInt64() & pageSizeMask);
lock (lockObj) {
var cp = GetCachedPage_NoLock(position);
var data = cp.Data;
if (index + 1 < data.Length)
return (short)(data[0] | (data[1] << 8));
return BitConverter.ToInt16(ReadSlow(position, 2), 0);
}
}