c#使用easyhook库进行API钩取
目标:使calc程序输入的数自动加1
(当别人使用时,总会得不到正确的结果,哈哈)
编写注入程序
—————————————————————————————————
class Program中的方法,注入dll到目标进程
——————————————————————-——————————
static String ChannelName = null; static void Main(string[] args)
{
Int32.TryParse(args[], out TargetPID) ;
RemoteHooking.IpcCreateServer<FileMonInterface>(ref ChannelName, WellKnownObjectMode.SingleCall);
string injectionLibrary = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Inject.dll");
RemoteHooking.Inject(
TargetPID,
injectionLibrary,
injectionLibrary,
ChannelName);
Console.WriteLine("Injected to process {0}", TargetPID);
Console.WriteLine("<Press any key to exit>");
Console.ReadKey();
}
__________________________________________________
MarshalByRefObject的实现,供dll进行调用,判断是否正常
__________________________________________________
public class FileMonInterface : MarshalByRefObject
{
public void IsInstalled(Int32 InClientPID)
{
Console.WriteLine("FileMon has been installed in target {0}.\r\n", InClientPID);
}
}
编写注入使用的dll程序
—————————————————————————————————
注入成功后,调用Run方法,钩取SetWindowTextW API,修改为DSetWindowText的委托
—————————————————————————————————
public void Run(
RemoteHooking.IContext InContext,
String InChannelName)
{
// install hook...
Hook = LocalHook.Create(
LocalHook.GetProcAddress("user32.dll", "SetWindowTextW"),
new DSetWindowText(SetWindowText_Hooked),
this); Hook.ThreadACL.SetExclusiveACL(new Int32[] { });
Interface.IsInstalled(RemoteHooking.GetCurrentProcessId());
RemoteHooking.WakeUpProcess();while (true)
{
Thread.Sleep();
}
} —————————————————————————————————
委托
—————————————————————————————————
[UnmanagedFunctionPointer(CallingConvention.StdCall,
CharSet = CharSet.Ansi,
SetLastError = true)]
delegate bool DSetWindowText(
IntPtr hWnd, //对于句柄采用IntPtr类型
string text
);
—————————————————————————————————
API
—————————————————————————————————
[DllImport("user32.dll",
CharSet = CharSet.Ansi,
SetLastError = true,
CallingConvention = CallingConvention.StdCall)]
static extern bool SetWindowText(
IntPtr hWnd, string text
);
—————————————————————————————————
傀儡API
—————————————————————————————————
static bool SetWindowText_Hooked(
IntPtr hWnd,
string text)
{
text = (int.Parse(text.Remove(text.Length-))+).ToString();//修改要显示的数据
return SetWindowText( hWnd, text);//调用API
}
效果图

c#使用easyhook库进行API钩取的更多相关文章
- x64 下记事本WriteFile() API钩取
<逆向工程核心原理>第30章 记事本WriteFile() API钩取 原文是在x86下,而在x64下函数调用方式为fastcall,前4个参数保存在寄存器中.在原代码基础上进行修改: 1 ...
- 高级全局API钩取 - IE连接控制
@author: dlive @date: 2017/02/14 0x01 调试IE进程 常见网络连接库:ws2_32.dll(套接字),wininet.dll,winhttp.dll 使用Proce ...
- 调试钩取技术 - 记事本WriteFile() API钩取
@author: dlive 0x01 简介 本章将讲解前面介绍过的调试钩取技术,钩取记事本的kernel32!WriteFile() API 调试钩取技术能进行与用户更具有交互性(interacti ...
- 通过注入DLL修改API代码实现钩取(一)
通过注入DLL修改API代码实现钩取(一) Ox00 大致思路 通过CreateRemoteThread函数开辟新线程,并将DLL注入进去 通过GetProcessAddress函数找到需钩取的API ...
- 通过注入DLL后使用热补丁钩取API
通过注入DLL后使用热补丁钩取API 0x00 对比修改API的前五个字节钩取API 对前一种方法钩取API的流程梳理如下: 注入相应的DLL 修改原始AI的函数的前五个字节跳往新函数(钩取API) ...
- 通过调试对WriteFile()API的钩取
通过调试对WriteFile()API的钩取 0x00 目标与思路 目标:钩取指定的notepad.exe进程writeFile()API函数,对notepad.exe进程的写入的字符保存时保存为大写 ...
- EasyHook库系列使用教程之四钩子的启动与停止
此文的产生花费了大量时间对EasyHook进行深入了解同一时候參考了大量文档 先来简单比較一下EasyHook与Detour钩取后程序流程 Detours:钩取API函数后.产生两个地址,一个地址相应 ...
- Java8新特性时间日期库DateTime API及示例
Java8新特性的功能已经更新了不少篇幅了,今天重点讲解时间日期库中DateTime相关处理.同样的,如果你现在依旧在项目中使用传统Date.Calendar和SimpleDateFormat等API ...
- 《逆向工程核心原理》Windows消息钩取
DLL注入--使用SetWindowsHookEx函数实现消息钩取 MSDN: SetWindowsHookEx Function The SetWindowsHookEx function inst ...
随机推荐
- node.js Web应用框架Express.js(一)
什么是Express.js Express 是一个简洁而灵活的 node.js Web应用框架, 提供一系列强大特性帮助你创建各种Web应用,提供丰富的HTTP工具以及来自Connect框架的中间件随 ...
- hdu-5683 zxa and xor (位运算)
题目链接: zxa and xor Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- Smart法则
设立目标不是一个很简单的事情.人们经常会犯一些基本的错误,即过于理想化.不符合客观情况.不容易执行落实,因此计划容易变成一种“美好的愿望”而已.在20世纪70年代,一位美国人为设立目标做出了一个简单而 ...
- js对象,原型,call,apply浅析
//对象直接量,创建对象最简单的方式是在js里使用对象直接量 var book = { "main title": "js", //属性里有空格,要用引号 &q ...
- GridView自带分页 1总页数 首页 下一页 上一页 尾页 X 页 go 实现方法 .
在前台GRIDVIEW中添加如下代码 <PagerTemplate> <table> <tr> <td style="text-align: rig ...
- asp.net(c#)网页跳转七种方法小结
在asp.net下,经常需要页面的跳转,下面是具体的几种方法.跳转页面是大部编辑语言中都会有的,正面我们来分别介绍一下关于.net中response.redirect sever.execute se ...
- 【Linux C中文函数手册】之 目录操作函数
目录操作函数 1)closedir 关闭目录 相关函数: opendir表头文件: #include<sys/types.h> #include<dirent.h>定义函数: ...
- javaScript中的数组迭代方法
ECMAScript5为数组定义了5个迭代方法. 每个方法都接收两个参数:要在每一项上运行的函数 和 (可选的)运行该函数的作用域对象. 传入这些方法中的函数会接收三个参数:数组项的值,该项在数组 ...
- 将string转换成char*
string 是c++标准库里面其中一个,封装了对字符串的操作 把string转换为char* 有3中方法: 1.data 如: string str="abc"; ch ...
- wix xslt for adding node
Using xslt to add new node item to wix source code. Original wix code: <Fragment> <Director ...