diff --git a/Memory/AMemory.cs b/Memory/AMemory.cs index 2adf540..fe250d4 100644 --- a/Memory/AMemory.cs +++ b/Memory/AMemory.cs @@ -353,22 +353,6 @@ namespace ChocolArm64.Memory return *((ulong*)(RamPtr + (uint)Position)); } - public byte[] ReadBytes(long Position, long Size) - { - if ((uint)Size > int.MaxValue) - { - throw new ArgumentOutOfRangeException(nameof(Size)); - } - - EnsureRangeIsValid(Position, Size, AMemoryPerm.Read); - - byte[] Data = new byte[Size]; - - Marshal.Copy((IntPtr)(RamPtr + (uint)Position), Data, 0, (int)Size); - - return Data; - } - public Vector128 ReadVector8Unchecked(long Position) { if (Sse2.IsSupported) @@ -433,6 +417,22 @@ namespace ChocolArm64.Memory } } + public byte[] ReadBytes(long Position, long Size) + { + if ((uint)Size > int.MaxValue) + { + throw new ArgumentOutOfRangeException(nameof(Size)); + } + + EnsureRangeIsValid(Position, Size, AMemoryPerm.Read); + + byte[] Data = new byte[Size]; + + Marshal.Copy((IntPtr)(RamPtr + (uint)Position), Data, 0, (int)Size); + + return Data; + } + public void WriteSByte(long Position, sbyte Value) { WriteByte(Position, (byte)Value); @@ -666,6 +666,27 @@ namespace ChocolArm64.Memory } } + public void WriteBytes(long Position, byte[] Data) + { + EnsureRangeIsValid(Position, (uint)Data.Length, AMemoryPerm.Write); + + Marshal.Copy(Data, 0, (IntPtr)(RamPtr + (uint)Position), Data.Length); + } + + private void EnsureRangeIsValid(long Position, long Size, AMemoryPerm Perm) + { + long EndPos = Position + Size; + + Position &= ~AMemoryMgr.PageMask; + + while ((ulong)Position < (ulong)EndPos) + { + EnsureAccessIsValid(Position, Perm); + + Position += AMemoryMgr.PageSize; + } + } + private void EnsureAccessIsValid(long Position, AMemoryPerm Perm) { if (!Manager.IsMapped(Position)) @@ -679,18 +700,6 @@ namespace ChocolArm64.Memory } } - private void EnsureRangeIsValid(long Position, long Size, AMemoryPerm Perm) - { - long EndPos = Position + Size; - - while ((ulong)Position < (ulong)EndPos) - { - EnsureAccessIsValid(Position, Perm); - - Position += AMemoryMgr.PageSize; - } - } - public void Dispose() { Dispose(true); diff --git a/Memory/AMemoryHelper.cs b/Memory/AMemoryHelper.cs index c0ade89..0a23a2f 100644 --- a/Memory/AMemoryHelper.cs +++ b/Memory/AMemoryHelper.cs @@ -22,14 +22,6 @@ namespace ChocolArm64.Memory } } - public static void WriteBytes(AMemory Memory, long Position, byte[] Data) - { - for (int Offs = 0; Offs < Data.Length; Offs++) - { - Memory.WriteByte(Position + Offs, Data[Offs]); - } - } - public unsafe static T Read(AMemory Memory, long Position) where T : struct { long Size = Marshal.SizeOf();