Skip to content

Commit 61a9b4b

Browse files
committed
Moved native functions to seperate files.
Removed windows enum dependencies.
1 parent 8f99f29 commit 61a9b4b

26 files changed

+828
-514
lines changed

Forms/MainForm.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,14 @@ private void ControlRemoteProcessToolStripMenuItem_Click(object sender, EventArg
311311
return;
312312
}
313313

314-
var action = NativeHelper.ControlRemoteProcessAction.Terminate;
314+
var action = ControlRemoteProcessAction.Terminate;
315315
if (sender == resumeProcessToolStripMenuItem)
316316
{
317-
action = NativeHelper.ControlRemoteProcessAction.Resume;
317+
action = ControlRemoteProcessAction.Resume;
318318
}
319319
else if (sender == suspendProcessToolStripMenuItem)
320320
{
321-
action = NativeHelper.ControlRemoteProcessAction.Suspend;
321+
action = ControlRemoteProcessAction.Suspend;
322322
}
323323

324324
nativeHelper.ControlRemoteProcess(remoteProcess.Process.Handle, action);

Forms/PluginForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal PluginForm(PluginManager pluginManager, NativeHelper nativeHelper)
6161
FillComboBox(closeRemoteProcessComboBox, NativeHelper.RequestFunction.CloseRemoteProcess);
6262
FillComboBox(readRemoteMemoryComboBox, NativeHelper.RequestFunction.ReadRemoteMemory);
6363
FillComboBox(writeRemoteMemoryComboBox, NativeHelper.RequestFunction.WriteRemoteMemory);
64-
FillComboBox(disassembleRemoteCodeComboBox, NativeHelper.RequestFunction.DisassembleRemoteCode);
64+
FillComboBox(disassembleRemoteCodeComboBox, NativeHelper.RequestFunction.DisassembleCode);
6565
FillComboBox(controlRemoteProcessComboBox, NativeHelper.RequestFunction.ControlRemoteProcess);
6666

6767
setAllComboBox.DisplayMember = nameof(NativeHelper.MethodInfo.Provider);

Forms/ProcessBrowserForm.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ProcessInfo SelectedProcess
3030
var row = (processDataGridView.SelectedRows.Cast<DataGridViewRow>().FirstOrDefault()?.DataBoundItem as DataRowView)?.Row;
3131
if (row != null)
3232
{
33-
return new ProcessInfo(nativeHelper, row.Field<int>("id"), row.Field<string>("name"), row.Field<string>("path"));
33+
return new ProcessInfo(nativeHelper, row.Field<IntPtr>("id"), row.Field<string>("name"), row.Field<string>("path"));
3434
}
3535
return null;
3636
}
@@ -112,21 +112,23 @@ private void RefreshProcessList()
112112
var dt = new DataTable();
113113
dt.Columns.Add("icon", typeof(Icon));
114114
dt.Columns.Add("name", typeof(string));
115-
dt.Columns.Add("id", typeof(int));
115+
dt.Columns.Add("id", typeof(IntPtr));
116116
dt.Columns.Add("path", typeof(string));
117117

118-
nativeHelper.EnumerateProcesses((pid, path) =>
118+
nativeHelper.EnumerateProcesses(delegate (ref NativeHelper.EnumerateProcessData data)
119119
{
120-
var moduleName = Path.GetFileName(path);
120+
var moduleName = Path.GetFileName(data.ModulePath);
121121
if (!filterCheckBox.Checked || !CommonProcesses.Contains(moduleName.ToLower()))
122122
{
123123
var row = dt.NewRow();
124-
row["icon"] = ShellIcon.GetSmallIcon(path);
124+
row["icon"] = ShellIcon.GetSmallIcon(data.ModulePath);
125125
row["name"] = moduleName;
126-
row["id"] = pid;
127-
row["path"] = path;
126+
row["id"] = data.Id;
127+
row["path"] = data.ModulePath;
128128
dt.Rows.Add(row);
129129
}
130+
131+
return true;
130132
});
131133

132134
dt.DefaultView.Sort = "name ASC";

Memory/Disassembler.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.Contracts;
4+
using System.Runtime.InteropServices;
5+
using ReClassNET.Util;
6+
7+
namespace ReClassNET.Memory
8+
{
9+
public class Disassembler
10+
{
11+
public List<DisassembledInstruction> DisassembleRemoteCode(RemoteProcess process, IntPtr address, int length)
12+
{
13+
Contract.Requires(process != null);
14+
15+
var instructions = new List<DisassembledInstruction>();
16+
17+
var buffer = process.ReadRemoteMemory(address, length);
18+
19+
var handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
20+
try
21+
{
22+
var eip = handle.AddrOfPinnedObject();
23+
var end = eip + length;
24+
var virtualAddress = address;
25+
26+
var instruction = new NativeHelper.InstructionData();
27+
while (true)
28+
{
29+
if (!process.NativeHelper.DisassembleCode(eip, end.Sub(eip).ToInt32(), virtualAddress, out instruction))
30+
{
31+
break;
32+
}
33+
34+
instructions.Add(new DisassembledInstruction
35+
{
36+
Address = virtualAddress,
37+
Length = instruction.Length,
38+
Instruction = instruction.Instruction
39+
});
40+
41+
eip = eip + instruction.Length;
42+
if (eip.CompareTo(end) >= 0 || buffer[eip.Sub(handle.AddrOfPinnedObject()).ToInt32()] == 0xCC)
43+
{
44+
break;
45+
}
46+
virtualAddress = virtualAddress + instruction.Length;
47+
}
48+
}
49+
finally
50+
{
51+
if (handle.IsAllocated)
52+
{
53+
handle.Free();
54+
}
55+
}
56+
57+
return instructions;
58+
}
59+
}
60+
61+
public class DisassembledInstruction
62+
{
63+
public IntPtr Address;
64+
public int Length;
65+
public string Instruction;
66+
}
67+
}

0 commit comments

Comments
 (0)