/
Program.cs
95 lines (74 loc) · 1.92 KB
/
Program.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
/*
* User: William
* Date: 4/16/2011
* Time: 7:46 PM
*/
using System;
using TrainProcess;
namespace GTTest
{
class GTTest
{
public static void Main(string[] args)
{
Console.WriteLine("GTTest!");
if(args.Length < 1) {
Console.WriteLine("No process name specified.");
return;
}
GTTest test = new GTTest();
test.Run(args);
Console.WriteLine("Done.");
}
public void Run(string[] args) {
Process targetProcess = OpenProcess(args[0]);
Console.WriteLine(args[0]);
if(targetProcess == null) {
Console.WriteLine("Failed to open target process.");
return;
}
Console.WriteLine("Opened successfully!");
if(args.Length == 3) {
if(args[1] == "find") {
byte[] memory = Conversion.HexToBytes(args[2]);
IntPtr[] Locations = targetProcess.FindInMemory(memory, 0, long.MaxValue);
foreach(IntPtr Location in Locations) {
Console.WriteLine(Location);
}
}
if(args[1] == "read") {
byte[] memory = targetProcess.ReadMemory((IntPtr)long.Parse(args[2]), 4);
foreach(byte byt in memory) {
Console.WriteLine(byt);
}
}
}
if (args.Length == 4) {
if(args[1] == "replace") {
byte[] oldBytes = Conversion.HexToBytes(args[2]);
byte[] newBytes = Conversion.HexToBytes(args[3]);
IntPtr[] Locations = targetProcess.FindInMemory(oldBytes);
foreach(IntPtr Location in Locations) {
Console.WriteLine(Location);
targetProcess.WriteMemory(Location, newBytes);
}
}
}
}
private Process OpenProcess(string ProcessName)
{
Process TargetProcess = new Process();
if (!TargetProcess.ChooseProcess(ProcessName))
{
Console.WriteLine(ProcessName + " not found!");
return null;
}
if (!TargetProcess.OpenProcess())
{
Console.WriteLine("Can't open process!");
return null;
}
return TargetProcess;
}
}
}