-
Notifications
You must be signed in to change notification settings - Fork 2
/
Xbox360PluginExt.cs
257 lines (224 loc) · 9.62 KB
/
Xbox360PluginExt.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using JRPC_Client;
using ReClassNET.Core;
using ReClassNET.Debugger;
using ReClassNET.Memory;
using ReClassNET.Plugins;
using ReClassNET.Util.Conversion;
using Xbox360Plugin.Pointer32;
using Xbox360Plugin.TextPointers;
using XDevkit;
namespace Xbox360Plugin
{
public class Xbox360PluginExt : Plugin, ICoreProcessFunctions
{
private readonly object sync = new object();
private IPluginHost host;
private IXboxConsole console;
private IXboxDebugTarget debugTarget;
private byte[] lastBuffer;
private uint lastAddress;
public override Image Icon => Properties.Resources.icon;
public override bool Initialize(IPluginHost host)
{
this.host = host ?? throw new ArgumentNullException(nameof(host));
host.Process.CoreFunctions.RegisterFunctions("Xbox 360", this);
host.Process.BitConverter = EndianBitConverter.Big;
return true;
}
public override void Terminate()
{
host = null;
}
public bool IsProcessValid(IntPtr process)
{
return true;
}
public IntPtr OpenRemoteProcess(IntPtr id, ProcessAccess desiredAccess)
{
host.MainWindow.CurrentClassNode.AddressFormula = ((uint)(id.ToInt64() & 0xFFFFFFFF)).ToString("X");
return id;
}
public void CloseRemoteProcess(IntPtr process)
{
debugTarget.DisconnectAsDebugger();
}
public bool ReadRemoteMemory(IntPtr process, IntPtr address, ref byte[] buffer, int offset, int size)
{
lock (sync)
{
try
{
uint newAddress = (uint)(address.ToInt64() & 0xFFFFFFFF);
byte[] newBuffer = console.GetMemory(newAddress, (uint)size);
if (checkNotEmpty(newBuffer))
{
Buffer.BlockCopy(newBuffer, 0, buffer, 0, size);
lastAddress = newAddress;
lastBuffer = newBuffer;
return true;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// Prevents data from nulling when peeking memory fails.
if (lastBuffer != null && (uint)(address.ToInt64() & 0xFFFFFFFF) == lastAddress)
{
Buffer.BlockCopy(lastBuffer, 0, buffer, 0, size);
return true;
}
return false;
}
}
private bool checkNotEmpty(byte[] buffer)
{
if (buffer == null || buffer.Length == 0) return false;
foreach (byte b in buffer)
{
if (b > 0) return true;
}
return false;
}
public bool WriteRemoteMemory(IntPtr process, IntPtr address, ref byte[] buffer, int offset, int size)
{
lock (sync)
{
try
{
uint newAddr = (uint)(address.ToInt64() & 0xFFFFFFFF);
byte[] newBuffer = new byte[size];
Buffer.BlockCopy(buffer, 0, newBuffer, 0, size);
console.SetMemory(newAddr, newBuffer);
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
}
public void EnumerateProcesses(EnumerateProcessCallback callbackProcess)
{
lock (sync)
{
try
{
console.Connect(out console);
debugTarget = console.DebugTarget;
debugTarget.ConnectAsDebugger(console.XboxIP(), XboxDebugConnectFlags.Force);
foreach (IXboxModule module in debugTarget.Modules)
{
XBOX_MODULE_INFO moduleInfo = module.ModuleInfo;
var data = new EnumerateProcessData
{
Id = new IntPtr(moduleInfo.BaseAddress),
Name = moduleInfo.Name,
Path = "Base(0x" + moduleInfo.BaseAddress.ToString("X") + "), Entry(0x" +
module.GetEntryPointAddress().ToString("X") + "), Size(0x" +
moduleInfo.Size.ToString("X") + "), CRC32(0x" + moduleInfo.GetHashCode().ToString("X") + ")",
};
callbackProcess(ref data);
}
}
catch (Exception ex)
{
MessageBox.Show("Could not connect Xbox 360.", "Connection Error");
Console.WriteLine(ex.Message);
}
}
}
public void EnumerateRemoteSectionsAndModules(IntPtr process, EnumerateRemoteSectionCallback callbackSection, EnumerateRemoteModuleCallback callbackModule)
{
lock (sync)
{
try
{
foreach (IXboxModule module in debugTarget.Modules)
{
uint processAddress = (uint)(process.ToInt64() & 0xFFFFFFFF);
if (processAddress != module.ModuleInfo.BaseAddress) continue;
XBOX_MODULE_INFO moduleInfo = module.ModuleInfo;
var moduleData = new EnumerateRemoteModuleData
{
BaseAddress = new IntPtr(moduleInfo.BaseAddress),
Path = moduleInfo.Name,
Size = new IntPtr(moduleInfo.Size),
};
callbackModule(ref moduleData);
foreach (IXboxSection section in module.Sections)
{
XBOX_SECTION_INFO sectionInfo = section.SectionInfo;
SectionCategory category = SectionCategory.Unknown;
if ((sectionInfo.Flags & XboxSectionInfoFlags.Executable) == XboxSectionInfoFlags.Executable || new string[] { ".text", ".ptext" }.Contains(sectionInfo.Name)) category = SectionCategory.CODE;
else if (new string[]{ ".data", ".rdata" }.Contains(sectionInfo.Name)) category = SectionCategory.DATA;
SectionProtection protection = SectionProtection.NoAccess;
if ((sectionInfo.Flags & XboxSectionInfoFlags.Executable) == XboxSectionInfoFlags.Executable)
protection |= SectionProtection.Execute;
if ((sectionInfo.Flags & XboxSectionInfoFlags.Writeable) == XboxSectionInfoFlags.Writeable)
protection |= SectionProtection.Write;
if ((sectionInfo.Flags & XboxSectionInfoFlags.Readable) == XboxSectionInfoFlags.Readable)
protection |= SectionProtection.Read;
var sectionData = new EnumerateRemoteSectionData
{
BaseAddress = new IntPtr(sectionInfo.BaseAddress),
Size = new IntPtr(sectionInfo.Size),
Type = SectionType.Image,
Category = category,
ModulePath = moduleInfo.Name,
Name = sectionInfo.Name,
Protection = protection
};
callbackSection(ref sectionData);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
public void ControlRemoteProcess(IntPtr process, ControlRemoteProcessAction action)
{
MessageBox.Show("Not yet implemented!", "Error");
}
public bool AttachDebuggerToProcess(IntPtr id)
{
// Not supported.
return false;
}
public void DetachDebuggerFromProcess(IntPtr id)
{
// Not supported.
}
public bool AwaitDebugEvent(ref DebugEvent evt, int timeoutInMilliseconds)
{
// Not supported.
return false;
}
public void HandleDebugEvent(ref DebugEvent evt)
{
// Not supported.
}
public bool SetHardwareBreakpoint(IntPtr id, IntPtr address, HardwareBreakpointRegister register, HardwareBreakpointTrigger trigger, HardwareBreakpointSize size, bool set)
{
// Not supported.
return false;
}
public override CustomNodeTypes GetCustomNodeTypes()
{
return new CustomNodeTypes
{
CodeGenerator = new Xbox360PluginCodeGenerator(),
Serializer = new Xbox360PluginNodeConverter(),
NodeTypes = new[] { typeof(Pointer32Node), typeof(Utf16TextPtr32Node), typeof(Utf8TextPtr32Node) }
};
}
}
}