最近、プログラムのメモリを変更するプログラムを C# で作成しましたが、動作しますが、プログラムを閉じて再度開くたびに、もう一度メモリ値を見つけなければなりません。できる方法はありますか?プログラムを閉じた後、プログラムのメモリが変更されないようにしますか?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("kernel32.dll")]
static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesWritten);
[DllImport("kernel32.dll")]
public static extern Int32 CloseHandle(IntPtr hProcess);
[Flags]
public enum ProcessAccessFlags : uint
{
All = 0x001F0FFF,
Terminate = 0x00000001,
CreateThread = 0x00000002,
VMOperation = 0x00000008,
VMRead = 0x00000010,
VMWrite = 0x00000020,
DupHandle = 0x00000040,
SetInformation = 0x00000200,
QueryInformation = 0x00000400,
Synchronize = 0x00100000
}
public static void WriteMem(Process p, int address, long v)
{
var hProc = OpenProcess(ProcessAccessFlags.All, false, (int)p.Id);
var val = new byte[] { (byte)v };
int wtf = 0;
WriteProcessMemory(hProc, new IntPtr(address), val, (UInt32)val.LongLength, out wtf);
CloseHandle(hProc);
}
private void notify(string not)
{
if (textBox1.Text != "")
{
textBox1.Text += Environment.NewLine;
}
textBox1.Text += not;
}
private void button1_Click(object sender, EventArgs e)
{
var p = Process.GetProcessesByName("SAFlashPlayer").FirstOrDefault();
WriteMem(p, 0x07A6A0C1, 1000);
notify("A lot of Ability Points added.");
}
private void button2_Click(object sender, EventArgs e)
{
var p = Process.GetProcessesByName("SAFlashPlayer").FirstOrDefault();
//WriteMem(p, 0x008373CC, 0);
notify("Power set to 0.");
}
private void Checker_Tick(object sender, EventArgs e)
{
Process[] pname = Process.GetProcessesByName("SAFlashPlayer");
if (pname.Length == 0)
{
button1.Enabled = false;
button2.Enabled = false;
status.ForeColor = System.Drawing.Color.Red;
status.Text = "Flash Player not running!";
}
else
{
button1.Enabled = true;
button2.Enabled = true;
status.ForeColor = System.Drawing.Color.Green;
status.Text = "Flash Player running!";
}
}
}