Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace CSharpConsole
- {
- class Program
- {
- [DllImport("kernel32.dll")]
- public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
- [DllImport("kernel32.dll", SetLastError = true)]
- static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesWritten);
- [DllImport("kernel32.dll")]
- static extern bool VirtualProtectEx(int hProcess, int lpAddress, int dwSize, uint flNewProtect, ref uint lpflOldProtect);
- static IntPtr processHandle;
- const int PROCESS_ALL_ACCESS = 0x1F0FFF;
- static void Main(string[] args)
- {
- Process process = Process.GetProcessesByName("ConsoleApplication1")[0];
- processHandle = OpenProcess(PROCESS_ALL_ACCESS, false, process.Id);
- int Add = 0x00CFF840;
- Write<string>(Add, "ZZZZZ");
- Console.ReadKey();
- }
- public static bool Write<T>(int address, T t)
- {
- int bytesWritten = 0;
- uint oldProtect = 0;
- Byte[] Buffer;
- if (typeof(T) == typeof(string))
- {
- Buffer = System.Text.Encoding.ASCII.GetBytes(t + "\0");
- //Buffer = System.Text.Encoding.Unicode.GetBytes(t + "\0");
- }
- else
- {
- Buffer = new Byte[Marshal.SizeOf(typeof(T))];
- }
- bool bVProtect = VirtualProtectEx((int)processHandle, 0x00CFF840, Buffer.Length, 0x40, ref oldProtect);
- bool bWProc = WriteProcessMemory((int)processHandle, address, Buffer, Buffer.Length, ref bytesWritten);
- return bVProtect && bWProc;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement