~ruther/csharp-dll-injector

79041a786f95362744e1b19bc3fc025a2c7a22c3 — František Boháček 4 years ago 057ae90
Add fix for FunctionResult
1 files changed, 2 insertions(+), 2 deletions(-)

M DllUtils/Memory/FunctionResult.cs
M DllUtils/Memory/FunctionResult.cs => DllUtils/Memory/FunctionResult.cs +2 -2
@@ 24,7 24,7 @@ namespace DllUtils.Memory

        public T To<T>(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<T>(gcHandle.AddrOfPinnedObject());
            gcHandle.Free();


Do not follow this link