Exemple #1
0
        public static int ReadBytes(long iMemoryAddress, uint b, bool bigEndian = true)
        {
            var    bBuffer = new byte[b];
            IntPtr lpNumberOfBytesRead;

            if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, b, out lpNumberOfBytesRead) == 0)
            {
                return((int)0);
            }
            if (bigEndian)
            {
                Array.Reverse(bBuffer);
            }
            switch (b)
            {
            case 4:
                return((int)BitConverter.ToInt32(bBuffer, 0));

            case 2:
                return((int)BitConverter.ToInt16(bBuffer, 0));

            default:
                return((int)bBuffer[0]);
            }
        }
Exemple #2
0
        public static byte ReadByte(long iMemoryAddress)
        {
            var    bBuffer = new byte[1];
            IntPtr lpNumberOfBytesRead;

            if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, 1U, out lpNumberOfBytesRead) == 0)
            {
                return((byte)0);
            }
            return(bBuffer[0]);
        }
Exemple #3
0
        public static double ReadDouble(long iMemoryAddress)
        {
            var    bBuffer = new byte[8];
            IntPtr lpNumberOfBytesRead;

            if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, 8U, out lpNumberOfBytesRead) == 0)
            {
                return(0.0);
            }
            Array.Reverse(bBuffer);
            return(BitConverter.ToDouble(bBuffer, 0));
        }
Exemple #4
0
        public static float ReadFloat(long iMemoryAddress)
        {
            var    bBuffer = new byte[4];
            IntPtr lpNumberOfBytesRead;

            if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, 4U, out lpNumberOfBytesRead) == 0)
            {
                return(0.0f);
            }
            Array.Reverse(bBuffer);
            return(BitConverter.ToSingle(bBuffer, 0));
        }
Exemple #5
0
        public static ushort ReadShort(long iMemoryAddress)
        {
            var    bBuffer = new byte[2];
            IntPtr lpNumberOfBytesRead;

            if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, 2U, out lpNumberOfBytesRead) == 0)
            {
                return((ushort)0);
            }
            Array.Reverse(bBuffer);
            return(BitConverter.ToUInt16(bBuffer, 0));
        }
Exemple #6
0
        public static byte[] ReadBytesAsBytes(long iMemoryAddress, uint b, bool bigEndian = true)
        {
            var    bBuffer = new byte[b];
            IntPtr lpNumberOfBytesRead;

            if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, b, out lpNumberOfBytesRead) == 0)
            {
                return(null);
            }
            if (bigEndian)
            {
                Array.Reverse(bBuffer);
            }
            return(bBuffer);
        }