-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathNetHook.cs
More file actions
42 lines (38 loc) · 1.37 KB
/
NetHook.cs
File metadata and controls
42 lines (38 loc) · 1.37 KB
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
namespace NetHook
{
using System;
using System.Runtime.InteropServices;
public abstract class NetHook
{
public abstract void Install(IntPtr oldMethodAddress, IntPtr newMethodAddress);
public abstract void Suspend();
public abstract void Resume();
public abstract void Uninstall();
public abstract IntPtr GetProcAddress(Delegate d);
public abstract IntPtr GetProcAddress(string strLibraryName, string strMethodName);
public static NetHook CreateInstance() // ::IsWow64Process
{
if (IntPtr.Size != sizeof(int)) // Environment.Is64BitProcess
{
return new NetHook_x64();
}
return new NetHook_x86();
}
public static NetHook CreateInstance(IntPtr oldMethodAddress, IntPtr newMethodAddress)
{
NetHook hook = NetHook.CreateInstance();
try
{
return hook;
}
finally
{
hook.Install(oldMethodAddress, newMethodAddress);
}
}
public static NetHook CreateInstance(IntPtr oldMethodAddress, Delegate newMethodDelegate)
{
return NetHook.CreateInstance(oldMethodAddress, Marshal.GetFunctionPointerForDelegate(newMethodDelegate));
}
}
}