コード例 #1
0
        /*
         *  -------------------------
         *  Read/Write Implementation
         *  -------------------------
         */

        /// <inheritdoc />
        public void Read <T>(IntPtr memoryAddress, out T value, bool marshal = false)
        {
            int structSize = Struct.GetSize <T>(marshal);

            byte[] buffer = new byte[structSize];

            fixed(byte *bufferPtr = buffer)
            {
                bool succeeded = Kernel32.ReadProcessMemory(_processHandle, memoryAddress, (IntPtr)bufferPtr, (uint)structSize, out _);

                Struct.FromPtr((IntPtr)bufferPtr, out value, _localMemory.Read, marshal);

                if (!succeeded)
                {
                    throw new MemoryException($"ReadProcessMemory failed to read {structSize} bytes of memory from {memoryAddress.ToString("X")}");
                }
            }
        }