-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathProcessInfo.cs
More file actions
55 lines (45 loc) · 987 Bytes
/
Copy pathProcessInfo.cs
File metadata and controls
55 lines (45 loc) · 987 Bytes
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
using System;
using System.Diagnostics.Contracts;
using ReClassNET.Util;
namespace ReClassNET.Memory
{
public class ProcessInfo : IDisposable
{
private readonly NativeHelper nativeHelper;
private IntPtr handle;
public int Id { get; }
public IntPtr Handle => Open();
public string Name { get; }
public string Path { get; }
public ProcessInfo(NativeHelper nativeHelper, int id, string name, string path)
{
Contract.Requires(nativeHelper != null);
Contract.Requires(name != null);
Contract.Requires(path != null);
this.nativeHelper = nativeHelper;
Id = id;
Name = name;
Path = path;
}
public void Dispose()
{
Close();
}
public IntPtr Open()
{
if (handle.IsNull())
{
handle = nativeHelper.OpenRemoteProcess(Id, NativeMethods.PROCESS_ALL_ACCESS);
}
return handle;
}
public void Close()
{
if (!handle.IsNull())
{
nativeHelper.CloseRemoteProcess(handle);
handle = IntPtr.Zero;
}
}
}
}