From 79041a786f95362744e1b19bc3fc025a2c7a22c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Thu, 28 May 2020 00:29:52 +0200 Subject: [PATCH] Add fix for FunctionResult --- DllUtils/Memory/FunctionResult.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DllUtils/Memory/FunctionResult.cs b/DllUtils/Memory/FunctionResult.cs index 9a9e459..d6c6930 100644 --- a/DllUtils/Memory/FunctionResult.cs +++ b/DllUtils/Memory/FunctionResult.cs @@ -24,7 +24,7 @@ namespace DllUtils.Memory public T To(bool reference = true) { - if (default(T) != null || !reference) + if (typeof(T).IsPrimitive) { return (T) Convert.ChangeType((int)Address, typeof(T)); } @@ -32,13 +32,13 @@ namespace DllUtils.Memory int size = Marshal.SizeOf(typeof(T)); byte[] bytes = new byte[size]; Kernel32.ReadProcessMemory(Process.Handle, Address, bytes, (uint)size, out int bytesRead); - GCHandle gcHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned); if (bytesRead != size) { throw new FunctionException("Whole function result could not be read."); } + GCHandle gcHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned); T obj = Marshal.PtrToStructure(gcHandle.AddrOfPinnedObject()); gcHandle.Free(); -- 2.48.1