Ejemplo n.º 1
0
        /// <summary>
        /// Reads 16 consecutive floats into a Matrix
        /// </summary>
        public static Matrix ReadMatrix(Int64 baseAddress)
        {
            //float matrix[16]; 16-value array laid out contiguously in memory
            byte[] buffer = new byte[16 * 4];

            //read memory into buffer
            IntPtr bytesRead;

            Win32API.ReadProcessMemory(handle, baseAddress, buffer, (ulong)buffer.Length, out bytesRead);

            //convert bytes to floats
            Matrix tmp = new Matrix();

            tmp.m11 = BitConverter.ToSingle(buffer, (0 * 4));
            tmp.m12 = BitConverter.ToSingle(buffer, (1 * 4));
            tmp.m13 = BitConverter.ToSingle(buffer, (2 * 4));
            tmp.m14 = BitConverter.ToSingle(buffer, (3 * 4));

            tmp.m21 = BitConverter.ToSingle(buffer, (4 * 4));
            tmp.m22 = BitConverter.ToSingle(buffer, (5 * 4));
            tmp.m23 = BitConverter.ToSingle(buffer, (6 * 4));
            tmp.m24 = BitConverter.ToSingle(buffer, (7 * 4));

            tmp.m31 = BitConverter.ToSingle(buffer, (8 * 4));
            tmp.m32 = BitConverter.ToSingle(buffer, (9 * 4));
            tmp.m33 = BitConverter.ToSingle(buffer, (10 * 4));
            tmp.m34 = BitConverter.ToSingle(buffer, (11 * 4));

            tmp.m41 = BitConverter.ToSingle(buffer, (12 * 4));
            tmp.m42 = BitConverter.ToSingle(buffer, (13 * 4));
            tmp.m43 = BitConverter.ToSingle(buffer, (14 * 4));
            tmp.m44 = BitConverter.ToSingle(buffer, (15 * 4));
            return(tmp);
        }
Ejemplo n.º 2
0
        public static string ReadString2(Int64 baseAddress, UInt64 size)
        {
            //create buffer for string
            byte[] buffer = new byte[size];

            //read memory into buffer
            IntPtr bytesRead;

            Win32API.ReadProcessMemory(handle, baseAddress, buffer, size, out bytesRead);

            //encode bytes to ASCII
            return(Encoding.ASCII.GetString(buffer));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Read 3 consecutive floats into x,y,z of a Vector
        /// </summary>
        public static Vector3 ReadVector3(Int64 baseAddress)
        {
            //3 floats contiguously in memory
            byte[] buffer = new byte[3 * 4];

            //read memory into buffer
            IntPtr bytesRead;

            Win32API.ReadProcessMemory(handle, baseAddress, buffer, (ulong)buffer.Length, out bytesRead);

            //convert bytes to floats
            Vector3 tmp = new Vector3();

            tmp.x = BitConverter.ToSingle(buffer, (0 * 4));
            tmp.y = BitConverter.ToSingle(buffer, (1 * 4));
            tmp.z = BitConverter.ToSingle(buffer, (2 * 4));
            return(tmp);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads memory of generic type at address.
        /// </summary>
        public static T Read <T>(Int64 address)
        {
            //create byte array with size of type
            byte[] buffer = new byte[Marshal.SizeOf(typeof(T))];

            //read memory
            IntPtr bytesRead;

            Win32API.ReadProcessMemory(handle, address, buffer, (uint)buffer.Length, out bytesRead);

            //allocate handle for buffer
            GCHandle gHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            //arrange data from unmanaged block of memory to structure of type T
            T data = (T)Marshal.PtrToStructure(gHandle.AddrOfPinnedObject(), typeof(T));

            gHandle.Free(); //release handle

            return(data);
        }
Ejemplo n.º 5
0
        public static string ReadString(Int64 baseAddress, UInt64 size)
        {
            //create buffer for string
            byte[] buffer = new byte[size];

            //read memory into buffer
            IntPtr bytesRead;

            Win32API.ReadProcessMemory(handle, baseAddress, buffer, size, out bytesRead);

            //encode bytes to ascii
            for (int i = 0; i < buffer.Length; i++)
            {
                if (buffer[i] == 0)
                {
                    byte[] tmpBuffer = new byte[i];
                    Buffer.BlockCopy(buffer, 0, tmpBuffer, 0, i);
                    return(Encoding.ASCII.GetString(tmpBuffer));
                }
            }
            return(Encoding.ASCII.GetString(buffer));
        }