/// <summary> /// Reads the four by four matrix. /// </summary> /// <param name="handle">The handle to the process where the matrix is located in memory.</param> /// <param name="lpBaseAddress">The <see cref="IntPtr" /> address of where the four by four matrix is located in memory.</param> /// <returns></returns> public static Matrix4X4 ReadFourByFourMatrix(SafeMemoryHandle handle, IntPtr lpBaseAddress) { var tmp = new Matrix4X4(); var buffer = MemoryCore.ReadBytes(handle, lpBaseAddress, 64); tmp.M11 = BitConverter.ToSingle(buffer, 0 * 4); tmp.M12 = BitConverter.ToSingle(buffer, 1 * 4); tmp.M13 = BitConverter.ToSingle(buffer, 2 * 4); tmp.M14 = BitConverter.ToSingle(buffer, 3 * 4); tmp.M21 = BitConverter.ToSingle(buffer, 4 * 4); tmp.M22 = BitConverter.ToSingle(buffer, 5 * 4); tmp.M23 = BitConverter.ToSingle(buffer, 6 * 4); tmp.M24 = BitConverter.ToSingle(buffer, 7 * 4); tmp.M31 = BitConverter.ToSingle(buffer, 8 * 4); tmp.M32 = BitConverter.ToSingle(buffer, 9 * 4); tmp.M33 = BitConverter.ToSingle(buffer, 10 * 4); tmp.M34 = BitConverter.ToSingle(buffer, 11 * 4); tmp.M41 = BitConverter.ToSingle(buffer, 12 * 4); tmp.M42 = BitConverter.ToSingle(buffer, 13 * 4); tmp.M43 = BitConverter.ToSingle(buffer, 14 * 4); tmp.M44 = BitConverter.ToSingle(buffer, 15 * 4); return(tmp); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteModule" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="module">The native <see cref="ProcessModule" /> object corresponding to this module.</param> internal RemoteModule(MemoryBase memorySharp, ProcessModule module) : base(memorySharp, module.BaseAddress) { // Save the parameter Native = module; LazyData = new Lazy <byte[]>( () => MemoryCore.ReadBytes(memorySharp.Handle, module.BaseAddress, module.ModuleMemorySize)); }
public void VirtualProtectExWriteReadBytes() { // Arrange var handle = MemoryCore.OpenProcess(ProcessAccessFlags.AllAccess, Resources.ProcessTest.Id); var expected = new byte[] { 0x90, 0x90, 0x90, 0x90, 0x90 }; var memory = new IntPtr(0x00400000); // Act try { MemoryCore.ChangeProtection(handle, memory, 5, MemoryProtectionFlags.ExecuteReadWrite); MemoryCore.WriteBytes(handle, memory, expected); var actual = MemoryCore.ReadBytes(handle, memory, 5); // Assert CollectionAssert.AreEqual(expected, actual, "The collections are not equal."); } catch (Win32Exception ex) { Assert.Fail(ex.Message); } }
/// <summary> /// Reads an array of bytes in the remote process. /// </summary> /// <param name="address">The address where the array is read.</param> /// <param name="count">The number of cells.</param> /// <param name="isRelative">[Optional] State if the address is relative to the main module.</param> /// <returns>The array of bytes.</returns> protected byte[] ReadBytes(IntPtr address, int count, bool isRelative = true) { return(MemoryCore.ReadBytes(Handle, isRelative ? MakeAbsolute(address) : address, count)); }
/// <summary> /// Reads a specific number of bytes from memory. /// </summary> /// <param name="address">The address.</param> /// <param name="count">The count.</param> /// <param name="isRelative">if set to <c>true</c> [is relative].</param> /// <returns></returns> public override byte[] ReadBytes(IntPtr address, int count, bool isRelative = false) { return(MemoryCore.ReadBytes(Handle, isRelative ? GetAbsolute(address) : address, count)); }