-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
104 lines (74 loc) · 2.4 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Diagnostics;
using System.Media;
using System.Runtime.InteropServices;
namespace WinFormsApp4
{
public partial class Form1 : Form
{
[DllImport("Dll4",CallingConvention = CallingConvention.Cdecl)]
private static extern void Memory(int pid, IntPtr ptr, int newvalue, out int byteswritten);
private TextBox id;
private TextBox address;
private TextBox newvalue;
private Button button;
public Form1()
{
InitializeComponent();
InitializeMyComponents();
}
private void InitializeMyComponents()
{
id = new TextBox();
id.Location = new Point(10, 20);
id.Size = new Size(100, 20);
address = new TextBox();
address.Location = new Point(10, 50);
address.Size = new Size(100, 20);
newvalue = new TextBox();
newvalue.Location = new Point(10, 80);
newvalue.Size = new Size(100, 20);
button = new Button();
button.Text = "Write Memory";
button.Location = new Point(10, 110);
button.Size = new Size(100, 20);
button.Click += click;
this.Controls.Add(id);
this.Controls.Add(address);
this.Controls.Add(newvalue);
this.Controls.Add(button);
}
private void click(object sender, EventArgs e)
{
int pid = int.Parse(id.Text);
if (CheckId(pid))
{
try
{
IntPtr ptr = new IntPtr(Convert.ToInt64(address.Text, 16));
int bytes;
int newvalue = int.Parse(this.newvalue.Text);
Memory(pid,ptr,newvalue,out bytes);
}
catch (Exception exception)
{
MessageBox.Show($"Error:{exception.Message}", "Error");
}
}
}
private bool CheckId(int pid)
{
Process[] process = Process.GetProcesses();
foreach (var _pid in process)
{
if (pid == _pid.Id)
{
// MessageBox.Show("未找到pid", "Error");
return true;
}
}
MessageBox.Show("未找到pid", "Error");
return false;
}
}
}