public byte[] Read(IntPtr address, int length) { var info = new CopyMem(); var buf = new byte[length]; info.SourcePid = 0; info.TargetPid = Pid; info.Size = buf.Length; //todo: make param to specify if base is needed if (address == H.GameManager || address == H.Renderer || address == H.Interface || address == H.WeaponManager) { info.Read = 2; //tell driver to get base address } else { info.Read = 1; } info.Addr = address; info.Value = IntPtr.Zero; var bytes = 0; if (info.Read != 0 && address != IntPtr.Zero && (long)address > 0) { var res = Win32.DeviceIoControl(Handle, CtlCode(0x00000022, 0x905, 2, 0), info, Marshal.SizeOf(info), buf, (uint)length, ref bytes, IntPtr.Zero); } return(buf); }
private void WriteMem(IReadOnlyCollection <byte> bytes, IntPtr address) { var info = new CopyMem(); var buf = new byte[bytes.Count]; info.SourcePid = Process.GetCurrentProcess().Id; info.TargetPid = Pid; info.Size = bytes.Count; info.Read = 3; //todo: add another ctl code instead of passing different read value info.Addr = address; var pinnedByteArr = GCHandle.Alloc(bytes, GCHandleType.Pinned); var addr = pinnedByteArr.AddrOfPinnedObject(); info.Value = addr; var bytes1 = 0; if (info.Read != 0 && address != IntPtr.Zero && (long)address > 0) { var res = Win32.DeviceIoControl(Handle, CtlCode(0x00000022, 0x905, 2, 0), info, Marshal.SizeOf(info), buf, (uint)buf.Length, ref bytes1, IntPtr.Zero); } }