吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 12836|回复: 35
收起左侧

[系统底层] 使用 EasyHook 让系统计算器显示文字

[复制链接]
wtujoxk 发表于 2020-1-5 13:17
本帖最后由 wtujoxk 于 2020-1-5 15:54 编辑

效果:
1578199991(1).png

我在学习使用EasyHook的时候,遇到一些坑,也慢慢解决了。
我将采用MarshalByRefObject按引用传递和Serializable按值传递这两种方式实现计算器显示文字的效果
这也是对EasyHook学习的一个过程

第一种方式:使用RemoteHooking.IpcConnectClient和RemoteHooking.IpcCreateServer进行传递
[C#] 纯文本查看 复制代码
RemoteHooking.IpcConnectClient<MarshalByRefObject>(InChannelName);

RemoteHooking.IpcCreateServer<MarshalByRefObject>(ref channelName,WellKnownObjectMode.SingleCall);


第二种方式:使用类的Serializable,并在函数构造时要加入类
[C#] 纯文本查看 复制代码
[Serializable]
public class FileMonInterface { }
 
public Main(RemoteHooking.IContext context, string InChnnelName, FileMonInterface fmi)
{
 
}

两种方式创建的时候Run函数与构造函数的参数都要对应
[C#] 纯文本查看 复制代码
public void Run(RemoteHooking.IContext context, string InChannelName)

public void Run(RemoteHooking.IContext context, string InChannelName, FileMonInterface fmi)


使用方法:
1、打开软件
2、打开系统计算器
3、点击软件上的注入
4、在计算器任意点击
附上软件界面,很Low
image.png

源码: 分为两个类
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using EasyHook;

namespace EasyHookDemo
{
    [Serializable]
    public class FileMonInterface { }
    public class Main : EasyHook.IEntryPoint
    {
        private LocalHook Hook;

        [DllImport("user32.dll")]
        public static extern bool SetWindowText(IntPtr hWnd, string text);

        [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
        public delegate bool DSetWindowText(IntPtr hWnd, string text);

        public bool SetWindowTextHook(IntPtr hWnd, string text)
        {
            return SetWindowText(hWnd, "吾爱破解-wtujoxk");
        }

        #region 第一种方式,按引用传递,MarshalByRefObject
        public Main(RemoteHooking.IContext context, string InChannelName)
        {
            RemoteHooking.IpcConnectClient<MarshalByRefObject>(InChannelName);
        }
        public void Run(RemoteHooking.IContext context, string InChannelName)
        {
            Hook = LocalHook.Create(
                LocalHook.GetProcAddress("user32.dll", "SetWindowTextW"),
                new DSetWindowText(SetWindowTextHook),
                this
            );

            Hook.ThreadACL.SetExclusiveACL(new[] { 0 });
            try
            {
                while (true)
                {
                    Thread.Sleep(500);
                }
            }
            catch { }
        }
        #endregion


        #region 第二种方式,按值传递,Serializable
        public Main(RemoteHooking.IContext context, string InChnnelName, FileMonInterface fmi)
        {

        }
        public void Run(RemoteHooking.IContext context, string InChannelName, FileMonInterface fmi)
        {
            Hook = LocalHook.Create(
                LocalHook.GetProcAddress("user32.dll", "SetWindowTextW"),
                new DSetWindowText(SetWindowTextHook),
                this
            );

            Hook.ThreadACL.SetExclusiveACL(new[] { 0 });
            try
            {
                while (true)
                {
                    Thread.Sleep(500);
                }
            }
            catch { }
        }
        #endregion
    }
}


[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.Remoting;
using System.Text;
using System.Windows.Forms;
using EasyHook;

namespace EasyHookDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int targetPID = 0;
            string channelName = null;
            targetPID = Process.GetProcessesByName("calc")[0].Id;

            #region 第一种方式,按引用传递,MarshalByRefObject
            //RemoteHooking.IpcCreateServer<MarshalByRefObject>(ref channelName,WellKnownObjectMode.SingleCall);
            //RemoteHooking.Inject(
            //    targetPID,
            //    typeof(Main).Assembly.Location,
            //    typeof(Main).Assembly.Location,
            //    channelName
            //);
            #endregion


            #region 第二种方式,按值传递,Serializable,这种方式Dll要在根目录,不知道为什么
            FileMonInterface fmi = new FileMonInterface();
            RemoteHooking.Inject(
                targetPID,
                typeof(Main).Assembly.Location,
                typeof(Main).Assembly.Location,
                "这个参数必须要有",
                fmi
            );
            #endregion
        }
    }
}


编译好的可执行文件: EasyHookDemo.rar (249.86 KB, 下载次数: 70)

最后附上工程,为VS2015  .net4.0 环境编写
EasyHookDemo.rar (295.58 KB, 下载次数: 166)

免费评分

参与人数 7吾爱币 +11 热心值 +7 收起 理由
Hmily + 6 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
straychild + 1 + 1 我很赞同!
CrazyNut + 1 + 1 谢谢@Thanks!
dogz + 1 用心讨论,共获提升!
城陈 + 1 + 1 可以,牛逼
满身肌肉的山楂 + 1 + 1 我很赞同!
DemoCc10 + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

cdj68765 发表于 2020-1-6 20:16
ohacn 发表于 2020-1-6 11:23
请教个问题,怎么能在被注入程序启动的时候实现注入?有些注册是在启动的时候进行判断的。
看到其他人用C+ ...

这个Easyhook提供一个API叫RemoteHooking.CreateAndInject(exe路径),使用这个API能够启动指定进程并且注入
 楼主| wtujoxk 发表于 2020-1-6 17:20
本帖最后由 wtujoxk 于 2020-7-2 17:26 编辑
ohacn 发表于 2020-1-6 11:23
请教个问题,怎么能在被注入程序启动的时候实现注入?有些注册是在启动的时候进行判断的。
看到其他人用C+ ...

API叫RemoteHooking.CreateAndInject(exe路径),使用这个API能够启动指定进程并且注入
bester 发表于 2020-1-5 13:39
 楼主| wtujoxk 发表于 2020-1-5 13:57
bester 发表于 2020-1-5 13:39
咦?不注入DLL也可以hook api参数?

可以!不信,你看!
FtsOZz 发表于 2020-1-5 13:59
仅供娱乐的吗~
DemoCc10 发表于 2020-1-5 14:19
收藏先,谢谢楼主
cdj68765 发表于 2020-1-5 14:49
本帖最后由 cdj68765 于 2020-1-5 15:13 编辑

wow,溜啊,我咋没想到注入本体也算是注入的一种啊
分享一个我写的https://www.52pojie.cn/home.php?mod=space&uid=397182&do=blog&id=15896

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
bester + 1 + 1 我很赞同!

查看全部评分

 楼主| wtujoxk 发表于 2020-1-5 15:05
本帖最后由 wtujoxk 于 2020-1-5 17:21 编辑
cdj68765 发表于 2020-1-5 14:49
wow,溜啊,我咋没想到注入本体也算是注入的一种啊
分享一个我写的https://www.52pojie.cn/home.php?mod=s ...

哈哈!!!

看到你关于hook的文章了,NICE!!!
bwjy 发表于 2020-1-5 15:24
学到了呢&#128591;
yang806 发表于 2020-1-5 15:27
想法不错 挺新奇
wsasecy 发表于 2020-1-5 15:28

娱乐也是要有技术含量的哦
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-27 09:10

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表