public bool ContainsDatas(T *datas, int length) { bool *result = stackalloc bool[length]; UnsafeUtility.MemClear(result, sizeof(bool) * length); Func <T, T, bool> func = GetObject <Func <T, T, bool> >(function); UIntPtr currentNode = data->start; while (currentNode.ToPointer() != null) { T *value = GetValuePtr(currentNode); for (int i = 0; i < length; ++i) { if (func(*value, datas[i])) { result[i] = true; break; } } currentNode = new UIntPtr(*GetNextPtr(currentNode)); } for (int i = 0; i < length; ++i) { if (!result[i]) { return(false); } } return(true); }
private unsafe bool CheckForSufficientStack() { if (s_pageSize == 0) { Win32Native.SYSTEM_INFO lpSystemInfo = new Win32Native.SYSTEM_INFO(); Win32Native.GetSystemInfo(ref lpSystemInfo); s_pageSize = lpSystemInfo.dwPageSize; } Win32Native.MEMORY_BASIC_INFORMATION buffer = new Win32Native.MEMORY_BASIC_INFORMATION(); UIntPtr ptr = new UIntPtr((void *)(&buffer - s_pageSize)); ulong num = ptr.ToUInt64(); if ((this.m_lastKnownWatermark != 0L) && (num > this.m_lastKnownWatermark)) { return(true); } Win32Native.VirtualQuery(ptr.ToPointer(), ref buffer, new IntPtr(sizeof(Win32Native.MEMORY_BASIC_INFORMATION))); UIntPtr allocationBase = (UIntPtr)buffer.AllocationBase; if ((num - allocationBase.ToUInt64()) > 0x10000L) { this.m_lastKnownWatermark = num; return(true); } return(false); }
public void SorterCallback(UIntPtr buf, int buf_length) { unsafe { Span <byte> byteArray = new Span <byte>(buf.ToPointer(), buf_length); ByteBuffer byteBuf = new ByteBuffer(byteArray.ToArray()); var server_message = ServerMessage.GetRootAsServerMessage(byteBuf); if (server_message.Id > 0) { _messageSorter.CheckMessage(server_message); } else { if (server_message.MessageType == ServerMessageType.DeviceAdded) { var device_added_message = server_message.Message <DeviceAdded>(); var device_handle = ButtplugFFI.SendCreateDevice(_clientHandle, device_added_message.Value.Index); var attribute_dict = new Dictionary <MessageAttributeType, ButtplugMessageAttributes>(); for (var i = 0; i < device_added_message.Value.AttributesLength; ++i) { var attributes = device_added_message.Value.Attributes(i).Value; var device_message_attributes = new ButtplugMessageAttributes(attributes.FeatureCount, attributes.GetStepCountArray(), attributes.GetEndpointsArray(), attributes.GetMaxDurationArray(), null, null); attribute_dict.Add(attributes.MessageType, device_message_attributes); } var device = new ButtplugClientDevice(_messageSorter, device_handle, device_added_message.Value.Index, device_added_message.Value.Name, attribute_dict); DeviceAdded.Invoke(this, new DeviceAddedEventArgs(device)); } } } }
private unsafe bool CheckForSufficientStack() { int num = StackGuard.s_pageSize; if (num == 0) { Win32Native.SYSTEM_INFO system_INFO = default(Win32Native.SYSTEM_INFO); Win32Native.GetSystemInfo(ref system_INFO); num = (StackGuard.s_pageSize = system_INFO.dwPageSize); } Win32Native.MEMORY_BASIC_INFORMATION memory_BASIC_INFORMATION = default(Win32Native.MEMORY_BASIC_INFORMATION); UIntPtr uintPtr = new UIntPtr((void *)((byte *)(&memory_BASIC_INFORMATION) - (IntPtr)num * (IntPtr)sizeof(Win32Native.MEMORY_BASIC_INFORMATION))); ulong num2 = uintPtr.ToUInt64(); if (this.m_lastKnownWatermark != 0UL && num2 > this.m_lastKnownWatermark) { return(true); } Win32Native.VirtualQuery(uintPtr.ToPointer(), ref memory_BASIC_INFORMATION, (UIntPtr)((ulong)((long)sizeof(Win32Native.MEMORY_BASIC_INFORMATION)))); if (num2 - ((UIntPtr)memory_BASIC_INFORMATION.AllocationBase).ToUInt64() > 65536UL) { this.m_lastKnownWatermark = num2; return(true); } return(false); }
private unsafe bool CheckForSufficientStack() { int num1 = StackGuard.s_pageSize; if (num1 == 0) { Win32Native.SYSTEM_INFO lpSystemInfo = new Win32Native.SYSTEM_INFO(); Win32Native.GetSystemInfo(ref lpSystemInfo); StackGuard.s_pageSize = num1 = lpSystemInfo.dwPageSize; } Win32Native.MEMORY_BASIC_INFORMATION buffer = new Win32Native.MEMORY_BASIC_INFORMATION(); UIntPtr num2 = new UIntPtr((void *)(&buffer - num1)); ulong uint64 = num2.ToUInt64(); if ((long)this.m_lastKnownWatermark != 0L && uint64 > this.m_lastKnownWatermark) { return(true); } IntPtr num3 = (IntPtr)Win32Native.VirtualQuery(num2.ToPointer(), ref buffer, (UIntPtr)((ulong)sizeof(Win32Native.MEMORY_BASIC_INFORMATION))); if (uint64 - (UIntPtr)buffer.AllocationBase.ToUInt64() <= 65536UL) { return(false); } this.m_lastKnownWatermark = uint64; return(true); }
public IntPtr Scan(IntPtr baseAddress, int size, string signature) { if (!MemoryService.GetIsProcessAlive()) { return(IntPtr.Zero); } byte?[]? needle = this.SigToNeedle(signature); // Fast byte[] bigBuffer = new byte[size]; MemoryService.Read(baseAddress, bigBuffer, size); unsafe { for (long offset = 0; offset < size - needle.Length; offset++) { if (this.IsMatch(needle, bigBuffer, offset)) { UIntPtr ptr = new UIntPtr(Convert.ToUInt64(baseAddress.ToInt64() + offset)); return((IntPtr)ptr.ToPointer()); } } } throw new KeyNotFoundException($"Can't find a signature of {signature}"); }
public void RemoveData(T *datas, int length) { Func <T, T, bool> func = GetObject <Func <T, T, bool> >(function); UIntPtr currentNode = data->start; while (currentNode.ToPointer() != null) { T * value = GetValuePtr(currentNode); bool contained = false; for (int i = 0; i < length; ++i) { if (func(*value, datas[i])) { contained = true; break; } } if (contained) { UIntPtr previous = new UIntPtr(*GetPrevious(currentNode)); UIntPtr next = new UIntPtr(*GetNextPtr(currentNode)); if (currentNode == data->start) { data->start = next; } if (currentNode == data->end) { data->end = previous; } if (previous.ToPointer() != null) { *GetNextPtr(previous) = next.ToPointer(); } if (next.ToPointer() != null) { *GetPrevious(next) = previous.ToPointer(); } data->length--; UnsafeUtility.Free(currentNode.ToPointer(), alloc); currentNode = next; } else { currentNode = new UIntPtr(*GetNextPtr(currentNode)); } } }
public void Dispose() { for (int i = 0; i < Length; ++i) { GetList(i).Dispose(); } UnsafeUtility.Free(mainArray.ToPointer(), alloc); }
public static T?Read <T>(UIntPtr address) where T : struct { unsafe { IntPtr ptr = (IntPtr)address.ToPointer(); return(Read <T>(ptr)); } }
public bool MoveNext() { ptr = next; if (ptr.ToPointer() == null) { return(false); } next = new UIntPtr(*NativeLinkedList <T> .GetNextPtr(next)); return(true); }
public UIntPtr this[int index] { get { return(dataPtr + index * stride); } set { UIntPtr targetPtr = dataPtr + index * stride; UnsafeUtility.MemCpy(targetPtr.ToPointer(), value.ToPointer(), stride); } }
public int Add() { if (length >= capacity) { int newCapacity = capacity * 2; UIntPtr newPtr = new UIntPtr(MUnsafeUtility.Malloc(newCapacity * stride, alloc)); UnsafeUtility.MemCpy(newPtr.ToPointer(), dataPtr.ToPointer(), capacity * stride); UnsafeUtility.Free(dataPtr.ToPointer(), alloc); capacity = newCapacity; dataPtr = newPtr; } return(length++); }
public void Add(void *targetPtr) { if (length >= capacity) { int newCapacity = capacity * 2; UIntPtr newPtr = new UIntPtr(MUnsafeUtility.Malloc(newCapacity * stride, alloc)); UnsafeUtility.MemCpy(newPtr.ToPointer(), dataPtr.ToPointer(), capacity * stride); UnsafeUtility.Free(dataPtr.ToPointer(), alloc); capacity = newCapacity; dataPtr = newPtr; } this[length++] = new UIntPtr(targetPtr); }
private static void addSunToSurface(Math.Vector3 direction, Math.Vector3 color, float radius, Math.Vector3 faceNormal, Math.Vector3 faceUp, BitmapSurface faceSurface, bool memory) { Math.Vector3 faceRight = faceNormal.Cross(faceUp); float t = -0.5f / faceNormal.Dot(-direction); if (t > 0) { return; // the sun never hits this plane } Math.Vector3 sunP = -direction * t; for (int y = 0; y < faceSurface.Height; y++) { for (int x = 0; x < faceSurface.Width; x++) { // calc the distance from this pixel to the sun float u = (float)x / faceSurface.Width - 0.5f; float v = (float)y / faceSurface.Height - 0.5f; Math.Vector3 texelP = faceUp * v + faceRight * u + -faceNormal * 0.5f; float distance = Math.Vector3.Distance(texelP, sunP); if (distance < radius) { if (!memory) { faceSurface.Pixels[(y * faceSurface.Width + x) * 4 + 0] = 255; faceSurface.Pixels[(y * faceSurface.Width + x) * 4 + 1] = 0; faceSurface.Pixels[(y * faceSurface.Width + x) * 4 + 2] = 0; } else { Color c = faceSurface.ReadColorAt(x, y); uint ptr = (uint)c.R | ((uint)c.G << 8) | ((uint)c.B << 16) | ((uint)c.A << 24); UIntPtr ptr2 = (UIntPtr)ptr; unsafe { float *f = (float *)ptr2.ToPointer(); f[0] = color.X; f[1] = color.Y; f[2] = color.Z; } } } } } }
public void Dispose() { isCreated = false; UIntPtr start = data->start; for (int i = 0; i < Length; ++i) { UIntPtr next = new UIntPtr(*GetNextPtr(start)); UnsafeUtility.Free(start.ToPointer(), alloc); start = next; } UnsafeUtility.Free(data, alloc); data = null; }
public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; string testDesc = string.Format("PosTest1: value is a random {0}-bit c-style generic pointer", 8 * UIntPtr.Size); string errorDesc; UIntPtr actualUIntPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(testDesc); try { void *ptr; if (UIntPtr.Size == 4) //32-bit platform { ptr = (void *)TestLibrary.Generator.GetInt32(-55); } else //64-bit platform { ptr = (void *)TestLibrary.Generator.GetInt64(-55); } actualUIntPtr = new UIntPtr(ptr); actualResult = actualUIntPtr.ToPointer() == ptr; if (!actualResult) { errorDesc = "Actual UIntPtr value is not " + (UInt64)ptr + " as expected: Actual(" + actualUIntPtr + ")"; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return(retVal); }
public bool PosTest3() { bool retVal = true; const string c_TEST_ID = "P002"; string testDesc = string.Format("PosTest1: value is max {0}-bit pointer: UInt{0}.MaxValue", 8 * UIntPtr.Size); string errorDesc; UIntPtr actualUIntPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(testDesc); try { void *ptr; if (UIntPtr.Size == 4) { ptr = (void *)UInt32.MaxValue; } else { ptr = (void *)UInt64.MaxValue; } actualUIntPtr = new UIntPtr(ptr); actualResult = actualUIntPtr.ToPointer() == ptr; if (!actualResult) { errorDesc = "Actual UIntPtr value is not " + (UInt64)ptr + " as expected: Actual(" + actualUIntPtr + ")"; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; string testDesc = string.Format("PosTest1: value is a random {0}-bit c-style generic pointer", 8*UIntPtr.Size); string errorDesc; UIntPtr actualUIntPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(testDesc); try { void * ptr; if(UIntPtr.Size == 4) //32-bit platform { ptr = (void *)TestLibrary.Generator.GetInt32(-55); } else //64-bit platform { ptr = (void *)TestLibrary.Generator.GetInt64(-55); } actualUIntPtr = new UIntPtr(ptr); actualResult = actualUIntPtr.ToPointer() == ptr; if (!actualResult) { errorDesc = "Actual UIntPtr value is not " + (UInt64)ptr + " as expected: Actual(" + actualUIntPtr + ")"; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public void AddStart(ref T value) { UIntPtr node = new UIntPtr(Malloc(NodeSize, alloc)); *GetNextPtr(node) = data->start.ToPointer(); *GetPrevious(node) = null; if (data->start.ToPointer() != null) { *GetPrevious(data->start) = node.ToPointer(); } if (Length == 0) { data->end = node; } data->length++; *GetValuePtr(node) = value; data->start = node; }
internal T ReadArray <T>(uint index) where T : struct { checked { // Figure out how big each structure is within the buffer. uint structSize = (uint)Marshal.SizeOf(typeof(T)); if (structSize % UIntPtr.Size != 0) { structSize += (uint)(UIntPtr.Size - (structSize % UIntPtr.Size)); } unsafe { UIntPtr pBufferBase = new UIntPtr(handle.ToPointer()); UIntPtr pElement = new UIntPtr(pBufferBase.ToUInt64() + (structSize * index)); return((T)Marshal.PtrToStructure(new IntPtr(pElement.ToPointer()), typeof(T))); } } }
internal T[] ReadArray <T>(int offset, int count) where T : struct { Debug.Assert(offset >= 0); Debug.Assert(count >= 0); T[] array = new T[count]; checked { // Figure out how big each structure is within the buffer. uint structSize = (uint)Marshal.SizeOf(typeof(T)); if (structSize % UIntPtr.Size != 0) { structSize += (uint)(UIntPtr.Size - (structSize % UIntPtr.Size)); } bool addedRef = false; RuntimeHelpers.PrepareConstrainedRegions(); try { DangerousAddRef(ref addedRef); for (int i = 0; i < count; ++i) { unsafe { UIntPtr pElement = new UIntPtr((byte *)handle.ToPointer() + offset + (structSize * i)); array[i] = (T)Marshal.PtrToStructure(new IntPtr(pElement.ToPointer()), typeof(T)); } } } finally { if (addedRef) { DangerousRelease(); } } } return(array); }
public bool PosTest2() { bool retVal = true; const string c_TEST_ID = "P002"; const string c_TEST_DESC = "PosTest2: UIntPtr with a random Int32 value "; string errorDesc; void * expectedPtr; void * actualPtr; UIntPtr uiPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { UInt32 ui = (UInt32)TestLibrary.Generator.GetInt32(-55); expectedPtr = (void *)ui; uiPtr = new UIntPtr(ui); actualPtr = uiPtr.ToPointer(); actualResult = actualPtr == expectedPtr; if (!actualResult) { errorDesc = "Actual pointer value is not " + (UInt32)expectedPtr + " as expected: Actual(" + (UInt32)actualPtr + ")"; TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; const string c_TEST_ID = "P002"; const string c_TEST_DESC = "PosTest2: value is 0"; string errorDesc; UIntPtr actualUIntPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { void *ptr = (void *)0; actualUIntPtr = new UIntPtr(ptr); actualResult = actualUIntPtr.ToPointer() == ptr; if (!actualResult) { errorDesc = "Actual UIntPtr value is not " + (int)ptr + " as expected: Actual(" + actualUIntPtr + ")"; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; const string c_TEST_ID = "P002"; const string c_TEST_DESC = "PosTest2: UIntPtr with a random Int32 value "; string errorDesc; void *expectedPtr; void *actualPtr; UIntPtr uiPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { UInt32 ui = (UInt32)TestLibrary.Generator.GetInt32(-55); expectedPtr = (void *)ui; uiPtr = new UIntPtr(ui); actualPtr = uiPtr.ToPointer(); actualResult = actualPtr == expectedPtr; if (!actualResult) { errorDesc = "Actual pointer value is not " + (UInt32)expectedPtr + " as expected: Actual(" + (UInt32)actualPtr + ")"; TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public bool PosTest3() { bool retVal = true; const string c_TEST_ID = "P002"; string testDesc = string.Format("PosTest1: value is max {0}-bit pointer: UInt{0}.MaxValue", 8 * UIntPtr.Size); string errorDesc; UIntPtr actualUIntPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(testDesc); try { void* ptr; if (UIntPtr.Size == 4) { ptr = (void*)UInt32.MaxValue; } else { ptr = (void *)UInt64.MaxValue; } actualUIntPtr = new UIntPtr(ptr); actualResult = actualUIntPtr.ToPointer() == ptr; if (!actualResult) { errorDesc = "Actual UIntPtr value is not " + (UInt64)ptr + " as expected: Actual(" + actualUIntPtr + ")"; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public unsafe virtual bool runTest() { Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; UIntPtr ip1; void * vd1; void * vd2; int * iptr1; Int32 iValue; Int64 lValue; Boolean fValue; Char chValue; Byte btValue; SByte sbValue; Int16 sValue; UInt16 usValue; UInt32 uiValue; UInt64 ulValue; DateTime dt1; String strValue; Int32[] iArr = { 1, 2, 3, 4, 5 }; MyEnum en1; String strReturned; try { strLoc = "Loc_743wg"; iValue = 16; vd1 = &iValue; ip1 = new UIntPtr(vd1); vd2 = ip1.ToPointer(); iCountTestcases++; if ((*((int *)vd2)) != iValue) { iCountErrors++; Console.WriteLine("Err_2975sf! Wrong value returned, " + (*((int *)vd2))); } strLoc = "Loc_0084wf"; lValue = 16; vd1 = &lValue; ip1 = new UIntPtr(vd1); vd2 = ip1.ToPointer(); iCountTestcases++; if ((*((long *)vd2)) != lValue) { iCountErrors++; Console.WriteLine("Err_974325sdg! Wrong value returned"); } if (BitConverter.IsLittleEndian) { strLoc = "Loc_0084wf"; lValue = 16; vd1 = &lValue; ip1 = new UIntPtr(vd1); iptr1 = (int *)ip1.ToPointer(); iCountTestcases++; if ((*iptr1) != lValue) { iCountErrors++; Console.WriteLine("Err_974325sdg! Wrong value returned! check the endiannees of this machine!!!, " + (*iptr1)); } } strLoc = "Loc_00845wsdg"; lValue = Int64.MaxValue; vd1 = &lValue; ip1 = new UIntPtr(vd1); vd2 = ip1.ToPointer(); iCountTestcases++; if ((*((long *)vd2)) != lValue) { iCountErrors++; Console.WriteLine("Err_94753sdg! Wrong value returned"); } if (BitConverter.IsLittleEndian) { strLoc = "Loc_875esfg"; lValue = Int64.MaxValue; vd1 = &lValue; ip1 = new UIntPtr(vd1); iptr1 = (int *)ip1.ToPointer(); iCountTestcases++; if ((*iptr1) != -1) { iCountErrors++; Console.WriteLine("Err_756wrg! Wrong value returned! , " + (*iptr1)); } } strLoc = "Loc_008742sf"; fValue = true; vd1 = &fValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if ((*((Boolean *)ip1.ToPointer())) != fValue) { iCountErrors++; Console.WriteLine("Err_984753sdg! Wrong value returned!"); } strLoc = "Loc_735sdg"; chValue = 'a'; vd1 = &chValue; ip1 = new UIntPtr(vd1); iptr1 = (int *)ip1.ToPointer(); iCountTestcases++; if ((*((char *)ip1.ToPointer())) != chValue) { iCountErrors++; Console.WriteLine("Err_9745sg! Wrong value returned!"); } strLoc = "Loc_735sdg"; btValue = 5; vd1 = &btValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if ((*((byte *)ip1.ToPointer())) != btValue) { iCountErrors++; Console.WriteLine("Err_7453rsg! Wrong value returned!"); } strLoc = "Loc_9743dg"; sbValue = -5; vd1 = &sbValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if ((*((SByte *)ip1.ToPointer())) != sbValue) { iCountErrors++; Console.WriteLine("Err_97345sg! Wrong value returned!"); } strLoc = "Loc_9743dg"; sValue = -5; vd1 = &sValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if ((*((Int16 *)ip1.ToPointer())) != sValue) { iCountErrors++; Console.WriteLine("Err_9374dg! Wrong value returned!"); } strLoc = "Loc_9743dg"; usValue = 5; vd1 = &usValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if ((*((UInt16 *)ip1.ToPointer())) != usValue) { iCountErrors++; Console.WriteLine("Err_9874sgd! Wrong value returned!"); } strLoc = "Loc_9743dg"; uiValue = 5; vd1 = &uiValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if ((*((UInt32 *)ip1.ToPointer())) != uiValue) { iCountErrors++; Console.WriteLine("Err_3463sg! Wrong value returned!"); } strLoc = "Loc_9743dg"; ulValue = 5; vd1 = &ulValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if ((*((UInt64 *)ip1.ToPointer())) != ulValue) { iCountErrors++; Console.WriteLine("Err_8274sdg! Wrong value returned!"); } strLoc = "Loc_0007432sf"; dt1 = DateTime.Now; vd1 = &dt1; ip1 = new UIntPtr(vd1); iCountTestcases++; if ((*((DateTime *)ip1.ToPointer())) != dt1) { iCountErrors++; Console.WriteLine("Err_9734sdg! Wrong value returned!"); } strLoc = "Loc_20875sg"; strValue = "Hello World"; fixed(Char *chPValue = strValue) { vd1 = chPValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if ((*((Char *)ip1.ToPointer())) != 'H') { iCountErrors++; Console.WriteLine("Err_874dsg! Wrong value returned!"); } iCountTestcases++; if ((*((Char *)ip1.ToPointer() + 2)) != 'l') { iCountErrors++; Console.WriteLine("Err_9347sdg! Wrong value returned!"); } (*((Char *)ip1.ToPointer() + 2)) = 'm'; iCountTestcases++; if ((*((Char *)ip1.ToPointer() + 2)) != 'm') { iCountErrors++; Console.WriteLine("Err_075wrg! Wrong value returned!"); } strReturned = "Hemlo World"; if (strReturned != strValue) { iCountErrors++; Console.WriteLine("Err_87453sg! We are playing with fire here!"); } } strLoc = "Loc_20875sg"; strValue = "Hello World"; fixed(int *iptr2 = iArr) { vd1 = iptr2; ip1 = new UIntPtr(vd1); iCountTestcases++; if ((*((int *)ip1.ToPointer())) != 1) { iCountErrors++; Console.WriteLine("Err_9376dg! Wrong value returned!"); } iCountTestcases++; if ((*((int *)ip1.ToPointer() + 2)) != 3) { iCountErrors++; Console.WriteLine("Err_94735ds! Wrong value returned!"); } (*((int *)ip1.ToPointer() + 2)) = 25; iCountTestcases++; if ((*((int *)ip1.ToPointer() + 2)) != 25) { iCountErrors++; Console.WriteLine("Err_753tsdg! Wrong value returned!"); } } strLoc = "Loc_907346sdg"; en1 = MyEnum.ONE; vd1 = &en1; ip1 = new UIntPtr(vd1); vd2 = ip1.ToPointer(); iCountTestcases++; if ((*((MyEnum *)vd2)) != en1) { iCountErrors++; Console.WriteLine("Err_9745sg! Wrong value returned, " + (*((MyEnum *)vd2))); } iCountTestcases++; } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general); } if (iCountErrors == 0) { Console.Error.WriteLine("paSs. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.Error.WriteLine("FAiL! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums); return(false); } }
public void SorterCallback(UIntPtr buf, int buf_length) { Span <byte> byteArray; unsafe { byteArray = new Span <byte>(buf.ToPointer(), buf_length); } var server_message = ButtplugFFIServerMessage.Parser.ParseFrom(byteArray.ToArray()); if (server_message.Id > 0) { _messageSorter.CheckMessage(server_message); } else if (server_message.Message.MsgCase == ButtplugFFIServerMessage.Types.FFIMessage.MsgOneofCase.ServerMessage) { if (server_message.Message.ServerMessage.MsgCase == ServerMessage.MsgOneofCase.DeviceAdded) { var device_added_message = server_message.Message.ServerMessage.DeviceAdded; var device_handle = ButtplugFFI.SendCreateDevice(_clientHandle, device_added_message.Index); var attribute_dict = new Dictionary <ServerMessage.Types.MessageAttributeType, ButtplugMessageAttributes>(); for (var i = 0; i < device_added_message.MessageAttributes.Count; ++i) { var attributes = device_added_message.MessageAttributes[i]; var device_message_attributes = new ButtplugMessageAttributes(attributes.FeatureCount, attributes.StepCount.ToArray(), attributes.Endpoints.ToArray(), attributes.MaxDuration.ToArray(), null, null); attribute_dict.Add(attributes.MessageType, device_message_attributes); } var device = new ButtplugClientDevice(_messageSorter, device_handle, device_added_message.Index, device_added_message.Name, attribute_dict); _devices.Add(device_added_message.Index, device); DeviceAdded.Invoke(this, new DeviceAddedEventArgs(device)); } else if (server_message.Message.ServerMessage.MsgCase == ServerMessage.MsgOneofCase.DeviceRemoved) { var device_removed_message = server_message.Message.ServerMessage.DeviceRemoved; var device = _devices[device_removed_message.Index]; _devices.Remove(device_removed_message.Index); DeviceRemoved.Invoke(this, new DeviceRemovedEventArgs(device)); } else if (server_message.Message.ServerMessage.MsgCase == ServerMessage.MsgOneofCase.Disconnect) { Connected = false; ServerDisconnect?.Invoke(this, null); } else if (server_message.Message.ServerMessage.MsgCase == ServerMessage.MsgOneofCase.Error) { var errorMsg = server_message.Message.ServerMessage.Error; var error = ButtplugException.FromError(errorMsg); if (error is ButtplugPingException) { PingTimeout?.Invoke(this, null); } ErrorReceived?.Invoke(this, new ButtplugExceptionEventArgs(error)); } else if (server_message.Message.ServerMessage.MsgCase == ServerMessage.MsgOneofCase.ScanningFinished) { ScanningFinished?.Invoke(this, null); } else { // We should probably do something here with unhandled events, but I'm not particularly sure what. I miss pattern matching. :( } } else { // We should probably do something here with unhandled events, but I'm not particularly sure what. I miss pattern matching. :( } }
public unsafe Pointer(UIntPtr value) { this.value = value.ToPointer(); }
/// <summary> /// Converts the given pointer to a <see cref="IntPtr"/>. /// </summary> /// <param name="intPtr">The pointer to convert.</param> /// <returns>The pointer converted to a <see cref="IntPtr"/>.</returns> public static unsafe IntPtr ToIntPtr(this UIntPtr intPtr) { return(unchecked ((IntPtr)intPtr.ToPointer())); }
/// <summary>Converts a <see cref="UIntPtr"/> to a <see cref="IntPtr"/>.</summary> /// <param name="p">The <see cref="UIntPtr"/>.</param> /// <returns>An equivalent <see cref="IntPtr"/>.</returns> public static IntPtr ToIntPtr(this UIntPtr p) { unsafe { return(new IntPtr(p.ToPointer())); } }
public static bool ReadBlockFromSRB(UIntPtr Srb, byte *pBuffer, uint Length, uint *pError) { return(ReadFromSRBBuffer(Srb.ToPointer(), pBuffer, Length, pError)); }
public unsafe virtual bool runTest() { Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; UIntPtr ip1; void* vd1; void* vd2; int* iptr1; Int32 iValue; Int64 lValue; Boolean fValue; Char chValue; Byte btValue; SByte sbValue; Int16 sValue; UInt16 usValue; UInt32 uiValue; UInt64 ulValue; DateTime dt1; String strValue; Int32[] iArr = {1, 2, 3, 4, 5}; MyEnum en1; String strReturned; try { strLoc = "Loc_743wg"; iValue = 16; vd1 = &iValue; ip1 = new UIntPtr(vd1); vd2 = ip1.ToPointer(); iCountTestcases++; if((*((int*)vd2)) != iValue){ iCountErrors++; Console.WriteLine("Err_2975sf! Wrong value returned, " + (*((int*)vd2))); } strLoc = "Loc_0084wf"; lValue = 16; vd1 = &lValue; ip1 = new UIntPtr(vd1); vd2 = ip1.ToPointer(); iCountTestcases++; if((*((long*)vd2)) != lValue){ iCountErrors++; Console.WriteLine("Err_974325sdg! Wrong value returned"); } strLoc = "Loc_0084wf"; lValue = 16; vd1 = &lValue; ip1 = new UIntPtr(vd1); iptr1 = (int*)ip1.ToPointer(); iCountTestcases++; if((*iptr1) != lValue){ iCountErrors++; Console.WriteLine("Err_974325sdg! Wrong value returned! check the endiannees of this machine!!!, " + (*iptr1)); } strLoc = "Loc_00845wsdg"; lValue = Int64.MaxValue; vd1 = &lValue; ip1 = new UIntPtr(vd1); vd2 = ip1.ToPointer(); iCountTestcases++; if((*((long*)vd2)) != lValue){ iCountErrors++; Console.WriteLine("Err_94753sdg! Wrong value returned"); } strLoc = "Loc_875esfg"; lValue = Int64.MaxValue; vd1 = &lValue; ip1 = new UIntPtr(vd1); iptr1 = (int*)ip1.ToPointer(); iCountTestcases++; if((*iptr1) != -1){ iCountErrors++; Console.WriteLine("Err_756wrg! Wrong value returned! , " + (*iptr1)); } strLoc = "Loc_008742sf"; fValue = true; vd1 = &fValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if((*((Boolean*)ip1.ToPointer())) != fValue){ iCountErrors++; Console.WriteLine("Err_984753sdg! Wrong value returned!"); } strLoc = "Loc_735sdg"; chValue = 'a'; vd1 = &chValue; ip1 = new UIntPtr(vd1); iptr1 = (int*)ip1.ToPointer(); iCountTestcases++; if((*((char*)ip1.ToPointer())) != chValue){ iCountErrors++; Console.WriteLine("Err_9745sg! Wrong value returned!"); } strLoc = "Loc_735sdg"; btValue = 5; vd1 = &btValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if((*((byte*)ip1.ToPointer())) != btValue){ iCountErrors++; Console.WriteLine("Err_7453rsg! Wrong value returned!"); } strLoc = "Loc_9743dg"; sbValue = -5; vd1 = &sbValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if((*((SByte*)ip1.ToPointer())) != sbValue){ iCountErrors++; Console.WriteLine("Err_97345sg! Wrong value returned!"); } strLoc = "Loc_9743dg"; sValue = -5; vd1 = &sValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if((*((Int16*)ip1.ToPointer())) != sValue){ iCountErrors++; Console.WriteLine("Err_9374dg! Wrong value returned!"); } strLoc = "Loc_9743dg"; usValue = 5; vd1 = &usValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if((*((UInt16*)ip1.ToPointer())) != usValue){ iCountErrors++; Console.WriteLine("Err_9874sgd! Wrong value returned!"); } strLoc = "Loc_9743dg"; uiValue = 5; vd1 = &uiValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if((*((UInt32*)ip1.ToPointer())) != uiValue){ iCountErrors++; Console.WriteLine("Err_3463sg! Wrong value returned!"); } strLoc = "Loc_9743dg"; ulValue = 5; vd1 = &ulValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if((*((UInt64*)ip1.ToPointer())) != ulValue){ iCountErrors++; Console.WriteLine("Err_8274sdg! Wrong value returned!"); } strLoc = "Loc_0007432sf"; dt1 = DateTime.Now; vd1 = &dt1; ip1 = new UIntPtr(vd1); iCountTestcases++; if((*((DateTime*)ip1.ToPointer())) != dt1){ iCountErrors++; Console.WriteLine("Err_9734sdg! Wrong value returned!"); } strLoc = "Loc_20875sg"; strValue = "Hello World"; fixed(Char* chPValue = strValue){ vd1 = chPValue; ip1 = new UIntPtr(vd1); iCountTestcases++; if((*((Char*)ip1.ToPointer())) != 'H'){ iCountErrors++; Console.WriteLine("Err_874dsg! Wrong value returned!"); } iCountTestcases++; if((*((Char*)ip1.ToPointer() + 2)) != 'l'){ iCountErrors++; Console.WriteLine("Err_9347sdg! Wrong value returned!"); } (*((Char*)ip1.ToPointer() + 2)) = 'm'; iCountTestcases++; if((*((Char*)ip1.ToPointer() + 2)) != 'm'){ iCountErrors++; Console.WriteLine("Err_075wrg! Wrong value returned!"); } strReturned = "Hemlo World"; if(strReturned != strValue){ iCountErrors++; Console.WriteLine("Err_87453sg! We are playing with fire here!"); } } strLoc = "Loc_20875sg"; strValue = "Hello World"; fixed(int* iptr2 = iArr){ vd1 = iptr2; ip1 = new UIntPtr(vd1); iCountTestcases++; if((*((int*)ip1.ToPointer())) != 1){ iCountErrors++; Console.WriteLine("Err_9376dg! Wrong value returned!"); } iCountTestcases++; if((*((int*)ip1.ToPointer() + 2)) != 3){ iCountErrors++; Console.WriteLine("Err_94735ds! Wrong value returned!"); } (*((int*)ip1.ToPointer() + 2)) = 25; iCountTestcases++; if((*((int*)ip1.ToPointer() + 2)) != 25){ iCountErrors++; Console.WriteLine("Err_753tsdg! Wrong value returned!"); } } strLoc = "Loc_907346sdg"; en1 = MyEnum.ONE; vd1 = &en1; ip1 = new UIntPtr(vd1); vd2 = ip1.ToPointer(); iCountTestcases++; if((*((MyEnum*)vd2)) != en1){ iCountErrors++; Console.WriteLine("Err_9745sg! Wrong value returned, " + (*((MyEnum*)vd2))); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general); } if ( iCountErrors == 0 ) { Console.Error.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.Error.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
/// <summary>Initializes a new instance of the <see cref="XPointer" /> struct.</summary> /// <param name="value">The value of the instance.</param> public XPointer(UIntPtr value) : this((byte *)(value.ToPointer())) { }
public bool PosTest2() { bool retVal = true; const string c_TEST_ID = "P002"; const string c_TEST_DESC = "PosTest2: value is 0"; string errorDesc; UIntPtr actualUIntPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { void *ptr = (void *) 0; actualUIntPtr = new UIntPtr(ptr); actualResult = actualUIntPtr.ToPointer() == ptr; if (!actualResult) { errorDesc = "Actual UIntPtr value is not " + (int)ptr + " as expected: Actual(" + actualUIntPtr + ")"; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public static unsafe void TestBasics() { UIntPtr p; uint i; ulong l; if (sizeof(void*) == 4) { // Skip UIntPtr tests on 32-bit platforms return; } int size = UIntPtr.Size; Assert.Equal(size, sizeof(void*)); TestPointer(UIntPtr.Zero, 0); i = 42; TestPointer(new UIntPtr(i), i); TestPointer((UIntPtr)i, i); i = 42; TestPointer(new UIntPtr(i), i); l = 0x0fffffffffffffff; TestPointer(new UIntPtr(l), l); TestPointer((UIntPtr)l, l); void* pv = new UIntPtr(42).ToPointer(); TestPointer(new UIntPtr(pv), 42); TestPointer((UIntPtr)pv, 42); p = UIntPtr.Add(new UIntPtr(42), 5); TestPointer(p, 42 + 5); // Add is spected NOT to generate an OverflowException p = UIntPtr.Add(new UIntPtr(0xffffffffffffffff), 5); unchecked { TestPointer(p, (long)0x0000000000000004); } p = UIntPtr.Subtract(new UIntPtr(42), 5); TestPointer(p, 42 - 5); bool b; p = new UIntPtr(42); b = p.Equals(null); Assert.False(b); b = p.Equals((object)42); Assert.False(b); b = p.Equals((object)(new UIntPtr(42))); Assert.True(b); int h = p.GetHashCode(); int h2 = p.GetHashCode(); Assert.Equal(h, h2); p = new UIntPtr(42); i = (uint)p; Assert.Equal(i, 42u); l = (ulong)p; Assert.Equal(l, 42u); UIntPtr p2; p2 = (UIntPtr)i; Assert.Equal(p, p2); p2 = (UIntPtr)l; Assert.Equal(p, p2); p2 = (UIntPtr)(p.ToPointer()); Assert.Equal(p, p2); p2 = new UIntPtr(40) + 2; Assert.Equal(p, p2); p2 = new UIntPtr(44) - 2; Assert.Equal(p, p2); p = new UIntPtr(0x7fffffffffffffff); Assert.Throws<OverflowException>(() => (uint)p); }
static public string GetStringFromPointer(UIntPtr Pointer) { return(GetStringFromPointer(new IntPtr(Pointer.ToPointer()))); }