原帖地址:https://www.52pojie.cn/thread-1087920-1-1.html
文件地址:蓝奏云
注入器和注入的dll放在同一目录下,需要注入的程序下可以不用放置dll
注入的dll依赖DotNetDetour模块
注入器依赖FastWin32模块
获取指定进程名id
processHwnd=Process.GetProcessesByName("TargetHookWinForm")[0].Id注入代码
Injector.InjectManaged(processHwnd , "InjectionDll.dll", "InjectionDll.FileMonInterface", "Injection", "这里填写注入的参数", out num) ? "成功" : "失败";注入dll写法:
//注入入口
public class FileMonInterface
{
// Methods
private static int Injection(string msg)
{
MethodHook.Install(null);
Console.WriteLine(msg);
return 1;
}
}hook方法
public class Main : IMethodHook
{
// Methods
// hook实例方法的时候没法拿到实例对象,只能hook掉用法返回值。
// 需要修改对象实例数据,请hook属性
// 这里hook的是TargetHookWinForm.Form1下的Run方法。
[HookMethod("TargetHookWinForm.Form1", null, null)]
public string Run(string msg) =>
("注入成功:" + msg);
//如果需要调用原始方法,则创建一个同样签名,名字后面_Original就行,就可以再我们的hook方法中调用原始方法了。
[OriginalMethod]
public string Run_Original(string msg) =>
null;
}hook属性
//这里一样的,string是hook属性的类型,SelectPath就是hook实例的属性
public string SelectPath{
//FloderBrowserDIalog是我此处hook的类,可以像上面一样传入字符串,也可以是使用typeof传入原始类
// 使用hook get set,就可以像hook方法一样了。
[HookMethod(typeof(FloderBrowserDIalog))]
get { return ""; }
}