diff options
| author | riperiperi <rhy3756547@hotmail.com> | 2018-06-09 01:15:02 +0100 |
|---|---|---|
| committer | gdkchan <gab.dark.100@gmail.com> | 2018-06-08 21:15:02 -0300 |
| commit | 6fe51f970501fe732276c17ed0dacb564b92a73d (patch) | |
| tree | 0c18f8b4422399f90726d93269c62ae7228d6d4c /ChocolArm64/Memory | |
| parent | 39ebb83453245004fe3d9bd7ede9dc05b94e7e0e (diff) | |
ReadBytes function in AMemory, with cleaner range check. (#136)
Diffstat (limited to 'ChocolArm64/Memory')
| -rw-r--r-- | ChocolArm64/Memory/AMemory.cs | 20 | ||||
| -rw-r--r-- | ChocolArm64/Memory/AMemoryHelper.cs | 12 |
2 files changed, 20 insertions, 12 deletions
diff --git a/ChocolArm64/Memory/AMemory.cs b/ChocolArm64/Memory/AMemory.cs index c24a9e8e..e7d46565 100644 --- a/ChocolArm64/Memory/AMemory.cs +++ b/ChocolArm64/Memory/AMemory.cs @@ -301,6 +301,15 @@ namespace ChocolArm64.Memory return *((ulong*)(RamPtr + (uint)Position)); } + public byte[] ReadBytes(long Position, long Size) + { + EnsureRangeIsValid(Position, Size, AMemoryPerm.Read); + + byte[] Result = new byte[Size]; + Marshal.Copy((IntPtr)(RamPtr + (uint)Position), Result, 0, (int)Size); + return Result; + } + public Vector128<float> ReadVector8Unchecked(long Position) { if (Sse2.IsSupported) @@ -611,6 +620,17 @@ namespace ChocolArm64.Memory } } + private void EnsureRangeIsValid(long Position, long Size, AMemoryPerm Perm) + { + long EndPos = (Position + Size); + Position = Position & ~AMemoryMgr.PageMask; //check base of each page + while (Position < EndPos) + { + EnsureAccessIsValid(Position, Perm); + Position += AMemoryMgr.PageSize; + } + } + public void Dispose() { Dispose(true); diff --git a/ChocolArm64/Memory/AMemoryHelper.cs b/ChocolArm64/Memory/AMemoryHelper.cs index 1e346298..c0ade89c 100644 --- a/ChocolArm64/Memory/AMemoryHelper.cs +++ b/ChocolArm64/Memory/AMemoryHelper.cs @@ -22,18 +22,6 @@ namespace ChocolArm64.Memory } } - public static byte[] ReadBytes(AMemory Memory, long Position, long Size) - { - byte[] Data = new byte[Size]; - - for (long Offs = 0; Offs < Size; Offs++) - { - Data[Offs] = (byte)Memory.ReadByte(Position + Offs); - } - - return Data; - } - public static void WriteBytes(AMemory Memory, long Position, byte[] Data) { for (int Offs = 0; Offs < Data.Length; Offs++) |
