public UIntPtr GetAbsoluteAddress(uint n64Address, int size) { n64Address &= ~0x80000000U; UIntPtr absoluteAddress = (UIntPtr)(BaseOffset.ToUInt64() + n64Address); return(EndiannessUtilities.SwapAddressEndianness(absoluteAddress, size)); }
public bool WriteAbsolute(UIntPtr address, byte[] buffer, EndiannessType endianness) { int numOfBytes = 0; // Safety bounds check if (address.ToUInt64() < BaseOffset.ToUInt64() || address.ToUInt64() + (uint)buffer.Length >= BaseOffset.ToUInt64() + _ramSize) { return(false); } if (Endianness == endianness) { return(WriteFunc(address, buffer)); } else { bool success = true; IEnumerable <byte> bytes = buffer; int numberToWrite = Math.Min(EndiannessUtilities.NumberOfBytesToAlignment(address), buffer.Length); if (numberToWrite > 0) { byte[] toWrite = bytes.Take(numberToWrite).Reverse().ToArray(); success &= WriteFunc(EndiannessUtilities.AlignedAddressFloor(address), toWrite); bytes = bytes.Skip(toWrite.Length); address += toWrite.Length; } numberToWrite = bytes.Count(); if (bytes.Count() >= 4) { byte[] toWrite = EndiannessUtilities.SwapByteEndianness(bytes.Take(bytes.Count() & ~0x03).ToArray()); success &= WriteFunc(address, toWrite); bytes = bytes.Skip(toWrite.Length); address += toWrite.Length; } numberToWrite = bytes.Count(); if (numberToWrite > 0) { byte[] toWrite = bytes.Reverse().ToArray(); address = EndiannessUtilities.SwapAddressEndianness(address, toWrite.Length); success &= WriteFunc(address, toWrite); } return(success); } }
public bool WriteAbsolute(UIntPtr address, byte[] buffer, EndiannessType endianness) { // Safety bounds check if (address.ToUInt64() < BaseOffset.ToUInt64() || address.ToUInt64() + (uint)buffer.Length >= BaseOffset.ToUInt64() + Config.RamSize) { return(false); } if (Endianness == endianness) { return(WriteFunc(address, buffer)); } else { bool success = true; byte[] toWrite = EndiannessUtilities.SwapByteEndianness(buffer); // Between alignment writes if (buffer.Length < 4) { address = EndiannessUtilities.SwapAddressEndianness(address, toWrite.Length); success &= WriteFunc(address, toWrite); } else if (buffer.Length % 4 == 0) // Full alignment writes { success &= WriteFunc(address, toWrite); } else { throw new Exception("Misaligned data"); } return(success); } }
public uint GetRelativeAddress(UIntPtr absoluteAddress, int size) { uint n64address = 0x80000000 | (uint)(absoluteAddress.ToUInt64() - BaseOffset.ToUInt64()); return(EndiannessUtilities.SwapAddressEndianness(n64address, size)); }