Advertisement
Guest User

Untitled

a guest
Oct 1st, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1.  #region WriteMem
  2.         public int WriteMem(int MemoryAddress, byte[] buf)
  3.         {
  4.             IntPtr procHandle = ProcessMemoryReaderApi.OpenProcess(ProcessMemoryReaderApi.PROCESS_VM_READ | ProcessMemoryReaderApi.PROCESS_VM_WRITE | ProcessMemoryReaderApi.PROCESS_VM_OPERATION, 1, (uint)m_ReadProcess.Id);
  5.             if (procHandle == IntPtr.Zero)
  6.                 return 0;
  7.  
  8.             uint oldProtect;
  9.             ProcessMemoryReaderApi.VirtualProtectEx(procHandle, (IntPtr)MemoryAddress, (uint)buf.Length, ProcessMemoryReaderApi.PAGE_READWRITE, out oldProtect);
  10.             IntPtr ptrBytesWritten;
  11.             ProcessMemoryReaderApi.WriteProcessMemory(procHandle, (IntPtr)MemoryAddress, buf, (uint)buf.Length, out ptrBytesWritten);
  12.             ProcessMemoryReaderApi.CloseHandle(procHandle);
  13.             return ptrBytesWritten.ToInt32();
  14.         }
  15.  
  16.         public void WriteByte(int MemoryAddress, byte b)
  17.         {
  18.             WriteMem(MemoryAddress, new byte[] { b });
  19.         }
  20.         public void WriteInt(int MemoryAddress, int w)
  21.         {
  22.             byte[] buf = BitConverter.GetBytes(w);
  23.             WriteMem(MemoryAddress, buf);
  24.         }
  25.         public void WriteUInt(int MemoryAddress, uint u)
  26.         {
  27.             byte[] buf = BitConverter.GetBytes(u);
  28.             WriteMem(MemoryAddress, buf);
  29.         }
  30.         public void WriteFloat(int MemoryAddress, float f)
  31.         {
  32.             byte[] buf = BitConverter.GetBytes(f);
  33.             WriteMem(MemoryAddress, buf);
  34.         }
  35.         public void WriteAMem(IntPtr MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
  36.         {
  37.             IntPtr ptrBytesWritten;
  38.             ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
  39.  
  40.             bytesWritten = ptrBytesWritten.ToInt32();
  41.         }
  42.         #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement