Exemple #1
0
        public bool WriteRam(byte[] buffer, int bufferStart, uint address, int length, bool absoluteAddress = false, bool?fixAddress = null, bool safeWrite = true)
        {
            byte[] writeBytes = new byte[length];
            address &= ~0x80000000U;
            Array.Copy(buffer, bufferStart, writeBytes, 0, length);

            // Fix little endianess addresssing
            if ((fixAddress.HasValue && fixAddress.Value) || (fixAddress == null && !absoluteAddress))
            {
                address = (uint)LittleEndianessAddressing.AddressFix((int)address, length);
            }

            // Attempt to pause the game before writing
            bool preSuspended = IsSuspended;

            if (safeWrite)
            {
                Suspend();
            }

            // Write memory to game/process
            bool result = WriteProcessMemory((int)address, writeBytes, absoluteAddress);

            // Resume stream
            if (safeWrite && !preSuspended)
            {
                Resume();
            }

            return(result);
        }
Exemple #2
0
        public byte[] ReadRam(uint address, int length, bool absoluteAddress = false, bool?fixAddress = null)
        {
            byte[] readBytes = new byte[length];
            address &= ~0x80000000U;

            // Fix little endianess addressing
            if ((fixAddress.HasValue && fixAddress.Value) || (fixAddress == null && !absoluteAddress))
            {
                address = (uint)LittleEndianessAddressing.AddressFix((int)address, length);
            }

            // Handling absolute addressing (remove process offset from address)
            if (absoluteAddress)
            {
                address = (uint)(address - _offset);
            }

            if (address + length > _ram.Length)
            {
                return(new byte[length]);
            }

            // Retrieve ram bytes from final address
            Array.Copy(_ram, address, readBytes, 0, length);

            return(readBytes);
        }