Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region WriteMem
- public int WriteMem(int MemoryAddress, byte[] buf)
- {
- IntPtr procHandle = ProcessMemoryReaderApi.OpenProcess(ProcessMemoryReaderApi.PROCESS_VM_READ | ProcessMemoryReaderApi.PROCESS_VM_WRITE | ProcessMemoryReaderApi.PROCESS_VM_OPERATION, 1, (uint)m_ReadProcess.Id);
- if (procHandle == IntPtr.Zero)
- return 0;
- uint oldProtect;
- ProcessMemoryReaderApi.VirtualProtectEx(procHandle, (IntPtr)MemoryAddress, (uint)buf.Length, ProcessMemoryReaderApi.PAGE_READWRITE, out oldProtect);
- IntPtr ptrBytesWritten;
- ProcessMemoryReaderApi.WriteProcessMemory(procHandle, (IntPtr)MemoryAddress, buf, (uint)buf.Length, out ptrBytesWritten);
- ProcessMemoryReaderApi.CloseHandle(procHandle);
- return ptrBytesWritten.ToInt32();
- }
- public void WriteByte(int MemoryAddress, byte b)
- {
- WriteMem(MemoryAddress, new byte[] { b });
- }
- public void WriteInt(int MemoryAddress, int w)
- {
- byte[] buf = BitConverter.GetBytes(w);
- WriteMem(MemoryAddress, buf);
- }
- public void WriteUInt(int MemoryAddress, uint u)
- {
- byte[] buf = BitConverter.GetBytes(u);
- WriteMem(MemoryAddress, buf);
- }
- public void WriteFloat(int MemoryAddress, float f)
- {
- byte[] buf = BitConverter.GetBytes(f);
- WriteMem(MemoryAddress, buf);
- }
- public void WriteAMem(IntPtr MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
- {
- IntPtr ptrBytesWritten;
- ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
- bytesWritten = ptrBytesWritten.ToInt32();
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement